Search code examples
c#.netdecompiler

Force compiler to accept an unused string?


I'm making a crackme challenge that requires the user to decompile a binary.

I'm try to include the following to trip up users who attempt to reverse the binary using strings:

const string pointless = "Strings would be too easy";

Unfortunately without referencing this somewhere in my code the redundant code is removed at compile time. Is there a way I can tell the compiler to include it anyway?


Solution

  • using a variable is the only way to keep the variable in compiled code. Now the next thing not to get this using statement in compiled code.

    So finally we have two tasks.

    • Use variable
    • and then not to get this using code in compiled code,

    and you know if you used you will get it in compiled code for sure. We will use the variable with Debug class so you will get only if you compile it as a debug mode and if you compile same code as release mode you will not get this using your variablecode. as below -

    const string pointless = "Strings would be too easy";
    Debug.WriteLine(pointless);
    

    now because you have used the variable it will not be removed from the compiled format. Now if you compile your code as debug you will get this Debug.WriteLine(pointless);

    but now compile your code as release mode you will get your variable but not this Debug.WriteLine(pointless);

    Hope it helps.!!