Code stripping/obfuscation, a comprehensive how-to
Posted: Sat Feb 10, 2018 3:25 am
This lecture is technical and not for everyone. If you are not a coder already, you might as well skip it since it won't likely make much sense. If you are a coder and you are interested in how protection is done then enjoy!
First off I messaged Heston and got permission to write this small lecture. Knowing this would contain sensitive information I wanted to be sure he was OK with me doing it. Since he's been gracious enough to give me mod rights on the forum I don't have to worry about being censored or having my posts edited. As a thank you I've been posting some source codes and now I'm going to move into more technical territory that's usually not discussed openly: how to write and compile your code so that it cannot be used by someone else.
First off let's discuss some theory so the further lessons make sense. Let's take the example of a simple sniper rifle mod. That .u file contains a single class called "MyUberRifle" that extends SniperRifle (a stock class). If you look at that .u file with a program like WOTGreal or UTPT you will see source code. If you summon the rifle in a game you can see the changes made. All seems good. It's a normal mod like everything else you are used to using.
So what's really going on under the hood? Well I want you to think of the .u file as a box. Inside that box is the sniper rifle. Sounds good so far? Well, here's the part most people don't get...If you look on the outside of that box you will see an envelope stuck to the side. Inside that envelope is the code that you are seeing with WOTGreal/UTPT. The code and the rifle are two different things. This is super important to understand. Everything from here on will depend on you knowing this.
Now I know you are probably thinking "Well, what's in the box?" When you 'compiled' your mod and made the .u file the compiler (that's the UCC you see in your system folder) converted your script code into machine code but saved a copy of that code and stuck it on the side of the box for you to reference. That's why you can take a hex editor and poke into the .u file and see the changes your script created. In essence the .u file contains 2 copies of your mod work, one in normal script form (for reference) and one in machine code (the engine actually uses this one).
With very few exceptions we cannot make changes to the machine code (more on that in another tutorial) but we can do all kinds of stuff to the code that is saved on the side of the box. It can be discarded and the mod is considered "Stripped" or you can make it so the code is very, very difficult to interpret and then it's considered "Obfuscated". There are positives and negatives to either choice and so you'll have to decide which way best suits what you want to do.
So now you understand the basics of what a .u file contains let's get on with the task at hand and I'll teach you how to protect your work.
First off I messaged Heston and got permission to write this small lecture. Knowing this would contain sensitive information I wanted to be sure he was OK with me doing it. Since he's been gracious enough to give me mod rights on the forum I don't have to worry about being censored or having my posts edited. As a thank you I've been posting some source codes and now I'm going to move into more technical territory that's usually not discussed openly: how to write and compile your code so that it cannot be used by someone else.
First off let's discuss some theory so the further lessons make sense. Let's take the example of a simple sniper rifle mod. That .u file contains a single class called "MyUberRifle" that extends SniperRifle (a stock class). If you look at that .u file with a program like WOTGreal or UTPT you will see source code. If you summon the rifle in a game you can see the changes made. All seems good. It's a normal mod like everything else you are used to using.
So what's really going on under the hood? Well I want you to think of the .u file as a box. Inside that box is the sniper rifle. Sounds good so far? Well, here's the part most people don't get...If you look on the outside of that box you will see an envelope stuck to the side. Inside that envelope is the code that you are seeing with WOTGreal/UTPT. The code and the rifle are two different things. This is super important to understand. Everything from here on will depend on you knowing this.
Now I know you are probably thinking "Well, what's in the box?" When you 'compiled' your mod and made the .u file the compiler (that's the UCC you see in your system folder) converted your script code into machine code but saved a copy of that code and stuck it on the side of the box for you to reference. That's why you can take a hex editor and poke into the .u file and see the changes your script created. In essence the .u file contains 2 copies of your mod work, one in normal script form (for reference) and one in machine code (the engine actually uses this one).
With very few exceptions we cannot make changes to the machine code (more on that in another tutorial) but we can do all kinds of stuff to the code that is saved on the side of the box. It can be discarded and the mod is considered "Stripped" or you can make it so the code is very, very difficult to interpret and then it's considered "Obfuscated". There are positives and negatives to either choice and so you'll have to decide which way best suits what you want to do.
So now you understand the basics of what a .u file contains let's get on with the task at hand and I'll teach you how to protect your work.