The Black Tutorials- 1)How to strip code

Get some cool tips about how to tweak your UT graphic, gameplay, and much more!
Post Reply
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

The Black Tutorials- 1)How to strip code

Post by JackGriffin »

How to properly strip code...

There are a couple of ways to strip code. By far the easiest way-
1) Take your compiled mod (u file) and load it into the editor
2) In the actor tree find each class of your mod and right click it then select "Edit Script".
3) Each class will open up into a script page you can scroll through.
4) On each page do CTRL+A (select all) then hit space. This will blank the page.
5) Once you get all the classes blanked you still need to blank one more so grab anything from the actor tree and blank it (explained in a moment why).
6) Close the script browser and go back to the actor tree. Make sure View>Show Packages is checked.
7) Find your package in the list in the bottom and put a check mark by it and ONLY it.
8 ) At the top of the box hit "Save selected package".
Pro Tip: Make a safe copy of your mod code. Now not even you can recover the code if you lose it.

Your mod is now saved with the source code seriously garbled. It's still partially recoverable, especially using UTPT, but it's not ever going to be copy/paste good. This method is good enough for the vast majority of people who want to protect their coding. A more in-depth method follows for those with a deeper need profile.

Now a quick moment for theory and you need to understand this. The above method of stripping will preserve the mod's ability to 'speak' to other mods. What I mean is this method will not affect replication. If your mod needs to send a value out to another mod there won't be a problem. All this method is doing is removing the script that tags along with the mod and isn't directly modifying the mod's script itself. Think of it like a box you are mailing to someone. Inside the box is the thing and the outside of the box has an envelope with a manifest on it that lists the contents of the box. This method of stripping is like blanking those manifest pages. Your box contents remain intact and unchanged, however you no longer list what is there.

Oh, and I forgot to add this. You need to open one more class because the stripping forgets the last class you stripped and it will not clear that one. You open one more and strip it *without* saving that other package just to open one more so all of your chosen classes are stripped. Also you can strip some classes and not others. It's fine to mix them within the same mod since you are not changing any of the machine code.
Last edited by JackGriffin on Sun May 22, 2016 9:11 pm, edited 2 times in total.
So long, and thanks for all the fish
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: The Black Tutorials- 1)How to strip code

Post by JackGriffin »

Suppose you want a more robust way of stripping code. You need to hide values and functions better for things like anticheat or admin function mods. Well grab this:
ustripper.zip
(8.51 KiB) Downloaded 276 times
UStripper is a little program that will scramble the code for you but requires you to change you code a bit to trigger the changes where you want them. There's a readme in the download for you to follow and it will take a bit of experimenting to get it to work but I can promise you that it does in fact work VERY well. Here's a super simple mod I compiled then stripped:
StrippedMod.zip
(611 Bytes) Downloaded 224 times
See if you can recover the source code. Bet you can't. In fact you can't really tell at all what it was for. Anyway I'm not going to write a tut for this because if you need this level of protection you are perfectly capable of working this out on your own.

Another moment for code theory. This second method can and will create issues with value replication in and out of the mod because it does alter the names of the variables and functions. This means that as long as your value remains internal to the mod you'll be fine but if you need to replicate that value out from the mod to another mod then it may very well fail. Ustripped mods are best done as self-contained units that aren't dependent on other things. You wouldn't want to strip a mod that's used to compile another mod, stuff like that.

That's code stripping 101. Now you know.
So long, and thanks for all the fish
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: The Black Tutorials- 1)How to strip code

Post by sektor2111 »

I was trying a Hex Key with UStripper. Looks like editor can see package perfectly as in original. I would like to know if that thing do really works.

Aside, the faster and good code stripping operation is doable using XC stuff by Higor...
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: The Black Tutorials- 1)How to strip code

Post by JackGriffin »

Post the source code of that mod from the first post :satan: Yes, it definitely works.

I think I understand what you are asking though and that's more answered by tut #3. As for Higor's XC I just don't know anything about it. I can tell you though that if you don't rename the functions and variables and then run them through the encrypter it's not a hard matter to use a hex editor and recover them. You probably won't be able to totally rebuild the mod but I'll know all I need to know to either cheat it, bypass it, or copy it.
So long, and thanks for all the fish
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: The Black Tutorials- 1)How to strip code

Post by Wormbo »

Note that stripping code alone (without name table obfuscation) is pointless, as you can always throw something like UE Explorer at it. And people who really want to read your code will find a way to deobfuscate your name table entries to make the decompiled code compilable again.

Also note that stripping code is considered rude in the community, when used for anything other than anti-cheat measures. "Admin functions" should either reside on the server-side only or be safely unusable to non-admin players that have access to them.
Why? Well, how did you learn UnrealScript? Most likely by looking at other people's code. Give back to the community by sharing your code. If you don't want others to ever get hold of your code, you should never publish it - that includes making it downloadable from your UT server.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: The Black Tutorials- 1)How to strip code

Post by sektor2111 »

Proved by Mapvote. It was an inspiration for some toys which I did last time... I was testing what exactly does that UStripper, I'm not sure if is my goal... The rest is more simple: release a shorter mod stripped + source-code in original, that's the point, some people are not learning anyway even with good codes under their nose...
User avatar
papercoffee
Godlike
Posts: 10443
Joined: Wed Jul 15, 2009 11:36 am
Personal rank: coffee addicted !!!
Location: Cologne, the city with the big cathedral.
Contact:

Re: The Black Tutorials- 1)How to strip code

Post by papercoffee »

Wormbo wrote: Also note that stripping code is considered rude in the community, when used for anything other than anti-cheat measures. "Admin functions" should either reside on the server-side only or be safely unusable to non-admin players that have access to them.
Why? Well, how did you learn UnrealScript? Most likely by looking at other people's code. Give back to the community by sharing your code. If you don't want others to ever get hold of your code, you should never publish it - that includes making it downloadable from your UT server.
Jack/Gopostal is normally a giver ... :wink:
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: The Black Tutorials- 1)How to strip code

Post by JackGriffin »

Wormbo knows that. We've had a ton of exchange over the years and he knows the questions I've asked him and the respect I've always given. All that being said does not change a core fact: he is more right than I am over this. His response is the heart and soul of proper and I agree one thousand percent.

I expected some heat over this and it's fine. Stripping and obfuscation are subjects that make people really uncomfortable so let's bring it out into the light of day and openly debate it. The very best stuff is still being obfuscated so it's a current issue. If you play any coop Unreal at all you'll see that Zombie seriously encrypts everything he puts out and this hampers so many coop servers. There's absolutely no reason to do this. He says it's for 'security' but there are only a handful of players still around. I've emailed him and he ignores it.

People like him and several others who still post obfuscated mods will only stop when enough of the community understands why this is wrong and admins get together to say "OK, we aren't running your stuff any more until you stop". Either that or hand decompile the mods and post the source code, negating the stripping. I just really hate to do that. Yeah, I know my involvement in the mapvote source code but that mod is used by everyone and it's considered abandoned by the maker.

So, um...yeah. I never really stated my stand for the record in this thread. I think source code should always be available. Everything I've ever done posted with the full source code and a constant completely open permission to do anything with it without credit back.

Quick story: Way back I was struggling with how to improve the MH hud. I hated how the overlay of monster health slid all over the place. Wormbo suggested some work of his that would help and I was easily able to fix it using his code. The difference in play was enormous and I remember sitting at my computer really understanding for the first time: This is why you share code. His work is far above mine yet he allows me to stand on his shoulders, vastly improving my work in ways I could never accomplish myself. He never asked for anything and only freely gave. That right there *is* the ideal and we should all follow it.
So long, and thanks for all the fish
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: The Black Tutorials- 1)How to strip code

Post by Wormbo »

Just to make this clear: I was not pointing fingers, only voicing my general opinion on the entire source stripping thing.

Okay, with that out of the way, it's time to actually point fingers:
JackGriffin wrote:He says it's for 'security' but there are only a handful of players still around.
This just has to be the most ridiculous reason for obfuscation ever. If your security relies on hiding your code, it's hardly security at all, because tools like UTPT or UE Explorer are only one step away from decompiling obfuscated code. That last (or actually first) step is reassigning readable names to unreadable name table entries. Sure, those names would in no way match the original names, but it's enough to be able to read (and likely compile) the code decompiled from the Unreal bytecode.

[edit]
With a minor (and fun) addition to the UE Explorer name table code:

Code: Select all

/*******************************************************************************
 * StrippedMod generated by Eliot.UELib using UE Explorer.
 * Eliot.UELib © 2009-2015 Eliot van Uytfanghe. All rights reserved.
 * http://eliotvu.com
 *
 * All rights belong to their respective owners.
 *******************************************************************************/
class StrippedMod extends Mutator;

var protected int DeObf_MattFrondAesop;
var protected int DeObf_PunkHelloAfoot;

function DeObf_PhloxShearAlign()
{
    local protected Vector DeObf_MolarHovelAfter, DeObf_BrassGroveAgate, DeObf_ButteGloomAdopt;

    Log("I see you :)" @ string(DeObf_MolarHovelAfter));
    GetAxes(Rotation, DeObf_MolarHovelAfter, DeObf_BrassGroveAgate, DeObf_ButteGloomAdopt);
    DeObf_MattFrondAesop = DeObf_PunkHelloAfoot;
    return;
}

defaultproperties
{
    // Object Offset:0x000001E1
    DeObf_PhloxShearAlign=class'DeObf_MolarHovelAfter'
}
The defprops look a bit weird, but as far as code logic goes, this seems quite readable.
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: The Black Tutorials- 1)How to strip code

Post by JackGriffin »

Nicely done! You have the best var names ever. They are always funny.

I've given a lot of thought to just sitting down as a project and decompiling all of Zombies mod with the intention of releasing a compilable source code. No less than 10 coop servers are running on it. I haven't out of respect for another dev but I may do it anyway since I just don't care any more if someone is offended. The majority think it shouldn't be hidden anyway.

Yeah, think I'll do this.
So long, and thanks for all the fish
User avatar
Wormbo
Adept
Posts: 258
Joined: Sat Aug 24, 2013 6:04 pm
Contact:

Re: The Black Tutorials- 1)How to strip code

Post by Wormbo »

I think I'll make the code modification available on Github as fork of Eliot's UELib. Seems about the right thing to do.

I went for a different deobfuscation strategy than the usual tools, because I think sequential or random numbers are kinda hard for readability. So I simply took the Diceware list, thinned it out a bit and used the remaining words to generate replacement names for name table entries that contain unacceptable characters.
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: The Black Tutorials- 1)How to strip code

Post by MrLoathsome »

I stripped some code once. Didn't like it. It was ugly. Told it to get dressed and get the hell out. :mrgreen:

Last few years I have been trying whenever possible to look at nothing but Epics source and crap I wrote in the past.

I include all my source with stuff I post, but it is not commented, so look at it close before you try to change it.
blarg
User avatar
UnrealGGecko
Godlike
Posts: 2900
Joined: Wed Feb 01, 2012 11:26 am
Personal rank: GEx the Gecko
Location: Kaunas, Lithuania
Contact:

Re: The Black Tutorials- 1)How to strip code

Post by UnrealGGecko »

Unrelated: All of these Black Tutorials will now be sticky... wash your hands before ya post, folks ;)
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: The Black Tutorials- 1)How to strip code

Post by JackGriffin »

I'm pretty honored by that. Please feel free to move/join/whatever you want done, that's a lot of sticky posts to add. I'm glad the conversations went well. It's a sign of the maturity of the board members.
So long, and thanks for all the fish
Post Reply