Skip to content

Commit 60c204b

Browse files
authored
Quicker Hook Method
1 parent 4495c7a commit 60c204b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

ILProtectorUnpacker.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static public void Main(string[] args)
5959
assembly = Assembly.LoadFrom(path);
6060
Console.WriteLine("[+] Wait...");
6161

62-
Memory.Hook(typeof(StackTrace).GetMethod("GetFrame", BindingFlags.Instance | BindingFlags.Public), typeof(Script).GetMethod("Hook", BindingFlags.Instance | BindingFlags.Public));
62+
Memory.Hook(typeof(StackFrame).GetMethod("SetMethodBase", BindingFlags.Instance | BindingFlags.NonPublic), typeof(Script).GetMethod("Hook2", BindingFlags.Instance | BindingFlags.Public));
6363

6464
var types = assemblyWriter.moduleDef.GetTypes();
6565
var list = (types as IList<TypeDef>) ?? types.ToList<TypeDef>();
@@ -85,13 +85,13 @@ static public void Main(string[] args)
8585

8686
InvokeDelegates(list, method, fieldValue);
8787

88-
StringDecrypter stringDecrypter = new StringDecrypter(assembly);
89-
stringDecrypter.ReplaceStrings(list);
88+
new StringDecrypter(assembly).ReplaceStrings(list);
9089

9190
foreach (var typeDef in junkType)
9291
{
9392
typeDef.DeclaringType.NestedTypes.Remove(typeDef);
9493
}
94+
9595
MethodDef methodDef = globalType.FindStaticConstructor();
9696

9797
if (methodDef.HasBody)
@@ -181,6 +181,14 @@ public StackFrame Hook(int num)
181181
}
182182
return null;
183183
}
184+
185+
public void Hook2(MethodBase mb)
186+
{
187+
if (mb.Name == "InvokeMethod")
188+
typeof(StackFrame).GetField("method", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, assembly.Modules.FirstOrDefault<Module>().ResolveMethod(currentMethod.MDToken.ToInt32()));
189+
else
190+
typeof(StackFrame).GetField("method", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, mb);
191+
}
184192
}
185193

186194
internal class StringDecrypter

0 commit comments

Comments
 (0)