I've been having some issues with static constructors with my project. I need to add a static constructor to the type "" in order to call my resource decryption method.
Below in the gif you will see the issue I run into.
I will also include the code snippet.
Code for creating cctor:
MethodDefinition method = new MethodDefinition(
".cctor",
Mono.Cecil.MethodAttributes.Private
| Mono.Cecil.MethodAttributes.Static
| Mono.Cecil.MethodAttributes.HideBySig
| Mono.Cecil.MethodAttributes.SpecialName
| Mono.Cecil.MethodAttributes.RTSpecialName,
mod.Import(typeof(void))
);
I have also tried changing the attributes to the exact same as Yano's. It somehow never works. By "works" I mean detect it as a static constructor in DotNet Resolver.
Here's some more information about real outcome and expected result.
I do not have an ResolveEventHandler attached to my entrypoint. I have it attached to the application, which is being obfuscated and it is located in the "" type's static constructor which is executed before even the entrypoint is called.
Application resources have been encrypted with AES and are not recognised as valid resources by dotnet resolver or other decompilers. I am simply asking why the event is not being triggered as it should be triggered when a resource is invalid or missing. As you can see in the example a messagebox should pop up before the application is launched but it never does (string encryption encrypts the strings, so its a bit hard to see theres a string there).
Any help is appreciated.
use this :
void AddConstructor(TypeDefinition type, MethodReference baseEmptyConstructor)
{
var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName;
var method = new MethodDefinition(".ctor", methodAttributes, ModuleDefinition.TypeSystem.Void);
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Call, baseEmptyConstructor));
method.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
type.Methods.Add(method);
}
you can also refer :
http://www.mono-project.com/Cecil:FAQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With