public static void Main(string[] args) { if (args.Length < 1) { return; } string path = args[0]; _assemblyWriter = new AssemblyWriter(path); _assembly = Assembly.LoadFrom(path); Console.WriteLine("Unpacking.."); var stringDecrypter = new StringDecrypter(_assembly); Memory.Hook(typeof(StackFrame).GetMethod("GetMethod", BindingFlags.Instance | BindingFlags.Public), typeof(Program).GetMethod("HookGetMethod", BindingFlags.Instance | BindingFlags.Public)); int invokeToken = 0; var types = _assemblyWriter.ModuleDef.GetTypes(); var typeDefs = types as IList <TypeDef> ?? types.ToList(); foreach (TypeDef typeDef in typeDefs) { if (typeDef.Name == "<Module>") { foreach (FieldDef fieldDef in typeDef.Fields) { if (fieldDef.FullName.Contains("<Module>::Invoke")) { invokeToken = fieldDef.MDToken.ToInt32(); goto exitLoop; } } } } exitLoop: if (invokeToken == 0) { throw new Exception("Couldn't find Invoke"); } FieldInfo field = _assembly.Modules.FirstOrDefault().ResolveField(invokeToken); var invokeField = field.GetValue(null); MethodInfo invokeMethod = invokeField.GetType().GetMethod("Invoke"); if (invokeMethod == null) { throw new NullReferenceException("Couldn't find InvokeMethod"); } InvokeDelegates(typeDefs, invokeMethod, invokeField); stringDecrypter.ReplaceStrings(typeDefs); CleanCctor(typeDefs); _assemblyWriter.Save(); Console.WriteLine("Unpacked file!"); Console.Read(); }
internal IlReader(AssemblyWriter assemblyWriter) { _assemblyWriter = assemblyWriter; }