python – Against reverse engineering — How to enforce a conditional statement?


Consider the following general scheme. I want to create an executable that

  • checks whether a given condition C is satisfied and if so launches a process P;
  • is most robust against reverse engineering, in particular that makes it very hard to launch P if the condition is not satisfied.

Since it’s possible to “compile” .py files to executables (and I’m guessing it’s done in a poorly structured way, thus hard to decompile), I thought I could write my code in Python, as well as the code sketches below; but of course I’m open to any programming language that will perform better at meeting the requirements above.

A sketch of the program could be the following.

def condition_is_met():
    # the condition that is to be satisfied in order to launch the process

def proceed():
    # the process in question

def main():
    if condition_is_met():
        proceed()

main()

What strategies can be adopted when defining the main() function (or its equivalent in any other language) so as to make it very hard to bypass the condition? I don’t care at all about efficiency (neither condition_is_met() nor proceed() are computationally expensive) so I thought the following.

Maybe if I check the condition multiple times inside proceed() it will mess up the “compiled” code. I don’t know how the fundamental conditional statement if condition_is_met(): proceed() is reflected in the executable, but surely changing this

def proceed():
    # line 1
    # line 2
    # line 3

to this

def proceed():
    if condition_is_met():
        # line 1
        if condition_is_met():
            # line 2
            if condition_is_met():
                # line 3

should make it a bit harder for a reverse engineer to launch the process without meeting the condition.

What strategy best fulfils this goal? I’m aware of some obfuscating compilers out there and of the fact that it’s impossible to completely prevent reverse engineering, but I wanted to get feedback for this specific use case.



Source link

Leave a Comment