Jump to content

How to either recompile obfuscated code or deobfuscate decompiled code.


Talonos

Recommended Posts

Long story short: Can anybody tell me how to either recompile obfuscated code or deobfuscate decompiled code?

 

Short short long: I would like to alter the world-gen in one of my favorite (closed source) mods to make it compatible with some other mods. After decompiling the code with JD-GUI, it seems that the code could easily be made compatible by inserting a single, simple if statement in a single class. The problem is that JD-GUI decompiles the code into an obfuscated form. I really don't care, because I can easily tell what the code is doing, but it means I can't just drop the decompiled mod into my eclipse source tree like I would with an open source mod I'd edit. I either need to find some way to compile obfuscated code, or I need to de-obfuscate the whole mod so I can recompile it normally using forge.

 

Here is one idea, but before I spend the time to try it, I'd like to run it by the experts first: If I were to make a new project with nothing in it, put the obfuscated, decompiled class in (with my changes), generate stubs of all the obfuscated classes and methods referenced in the (single) class I'm editing, then compile the project, then drop the compiled class into the original mod's jar (replacing the original version) would everything "hook up" right? It seems like it might,  but despite having  programmed in java for years, the "guts" of the JVM are still kind of arcane to me.

 

Thanks for the help.

Link to comment
Share on other sites

Your best bet might actually to be to download the version of minecraft (the jar) for the version that mod is for, install the mod as if it was a jar mod, then decompile that.  That worked previously (I did it once for Mystcraft, so I could look at the internals and figure out its API by example), not sure how well it works now (had trouble in 1.6.2?).

 

Give it a shot, at least.  Might not leave it in a re-compilable state without fixing errors, but if it works at all, it will work quite well.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So, if I understand correctly, I would take the mod and move all it's class files into the appropriate folders in the mine-craft client jar file, then use the MCP to decompile and deobfuscate from there? Hmm... didn't realize I could do that. I'll give that a try and report back. If Anybody else has any additional insight, please let me know. Otherwise, I'll be back after I've tried it.

Link to comment
Share on other sites

You would just need to move the main mod class folder directory into the main minecraft .jar directory.  You don't need to put things "in the appropriate place."

But other than that, yes.

 

No guarantee that it'll work, the decompiler might still throw a fit, but if it DOES work, 99% of the work will be done for you.  The rest would be making sure there are no errors and verifying that it runs.  From there it's just copying the decompiled source into your current dev environment (and then fixing any new errors that show up).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

My apologies, but I have run into a roadblock, and I haven't been able to get past in the two hours I've worked on it. You might know offhand.

 

I was expecting the MCP directory to have a minecraft client jar somewhere within it, but I couldn't find it. Instead, from what I've been able to tell, it just decompiles the minecraft jar from your .minecraft directory in %appdata%. Is this true?

 

If so, it's an inconvenience. I've got 1.7 on my computer right now, but my mod (obviously) targets 1.6.4. I'd rather not mess with my vanilla install, but instead have the decompilation target a minecraft jar of my choosing. Is there any way to do it? Command line parameters, perhaps? (I looked in the decompile.py script, but my python-fu is too weak to derive the correct command line parameters myself)

 

Thanks again.

Link to comment
Share on other sites

I was expecting the MCP directory to have a minecraft client jar somewhere within it, but I couldn't find it. Instead, from what I've been able to tell, it just decompiles the minecraft jar from your .minecraft directory in %appdata%. Is this true?

 

That link is for ModLoader, not Forge (MCP is something else entirely).

 

What version of Minecraft are you trying to work with?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Noted, but both Forge and Modloader use MCP as their base, correct? I was simply trying to use that page as a basis for "Decompiling using MCP with mods installed." I figured the difference between decompiling with Modloader installed and forge/my mod installed was negligible. Was I incorrect in that assumption?

 

I'm working with 1.6.4.

Link to comment
Share on other sites

MCP is not a codebase.  It's an external package that performs deobfuscation because it has the mapping between obfuscated and deobfuscated names.

 

As for version, I'm asking what version the mod is for because that's the version of minecraft you need to use to decompile.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Again, I understand your point. Given that MCP is a way to decompile minecraft that provides a mapping between obfuscated and de-obfuscated names, it shouldn't matter whether the tutorial was specific for modloader or not. By "Forge uses MCP as its base," I mean that forge uses the MCP derived mappings instead of coming up their their own mappings of obfuscated to human-readable names. Anything I decompile with MCP will have the same mappings that Forge uses.

 

And I understood your second question as well. By "Working with" 1.6.4, I mean that both the mod I wish to modify and my targeted minecraft release for the modified mod are both 1.6.4. I apologize for being ambiguous.

Link to comment
Share on other sites

Ok.

 

Anyway, the jars are in (took me a little bit to figure this out, too) /mcp/jars/versions

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I searched for "jar" inside the jar folder because I knew that it didn't matter what it was called it would end in ".jar"

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Um... wow. Bearded Octo-nemesis. That's a deceptively off-topic title for such an on-topic utility. Thanks a ton. I'll look into that.

 

First, though, back to Draco: (And yes, that was a huge DERP moment on my part.)

 

I tried putting the mod into the JAR file, and the output was full of errors, so I tried putting both the mod and forge in the JAR file, and things were better. Still hundreds of errors, but much better. After that, I made the edits to the one source file I wish to modify, fixing any errors relating to missing methods by inserting method stubs into their appropriate classes. I can't compile it with MCP, because it complains about all the broken code, but after compiling it with Eclipse, I now have my one magic class file that does what I want it to. Problem is, it is still in deobfuscated form. I've tried to coax MCP into re-obfuscating just my one class file, but I cannot seem to get it to work. I'm only one step away from having my modded class file, now! You've been of wonderful help so far; do you have any advice on this last issue?

 

Edit: This Bearded Octo Nemesis thing is great stuff. I'm going to try a fresh install of forge and run BOC on the mod and see what happens.

Link to comment
Share on other sites

Sorry, no. :x

The only time I decompiled another mod was to watch how the author was using his own API, as it wasn't well documented at the time.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Done.

 

Bearded Octo Nemesis worked wonders, then I decompiled with JDGui and dumped it in the SRC directory in eclipse. It had lots of parsing errors (JDGui doesn't seem to know how to add diamond operators) but I didn't care; all I needed was the one altered class file, so I stubbed out any method throwing fits until I could get it to compile. Then, I compiled and reobfuscated it with MCP, then took the single class file I wanted altered from the deobfuscated folder and put it in the mod's jar folder, overwriting its class. It works beautifully.

 

Seems like a long process for such a simple task. I wish there were some way to edit a single class file without having to go through the whole deobfuscate/reobfuscate process, but oh well. At least I know how to do it now.

 

Thanks all around! (And I mean this mechanically. I'm going around hitting the thanks button.)

Link to comment
Share on other sites

I had a similar problem--updating someone else's semi-abandoned closed-source mod from 1.6.2 to 1.6.4.

 

BON using Searge deobfuscation got me something to work with, then I used JD-GUI, then sat down with MCPBot to update all the still semi-obfuscated names.

 

Which version of JD-GUI are you using? I had to grab a development snapshot (20130926) to get a version that would properly decompile classes with private internal classes, for example, and even then, I had to go in and hand-edit for bugs. It didn't apply trinary (?:) operators properly.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.