I have a jar file that contains a class file that I need to change a host name in. Simple change if I can get the code decompiled correctly.
When I tried extracting and decompiling with jd gui then recompiling with javac, I get compilation errors because I believe the decompiler didn't read the code correctly.
Next I tried to open the .class file in notepad++ and just change the host name amidst all the symbols and other things, then rejar, and that didn't work either.
I know this is similar to a lot of questions on here, but I can't seem to find my answer.
Related
So I'm not CS major or anything and I've been just poking around stuff to practice some Java skills I watched from a video. I know this isn't the major way to do it but please, let me.
So I extracted a .jar file of this: http://www.zenlunatics.com/quizcards/ (i also have its outright source version). It's open source. I used JD gui to get the source code and got everything in .java. However, once I imported it and tried to run it in Eclipse, it says there is "no main type."
I've searched around and it seems there has to be a public static ... String[] args and I don't see that in any of the generated .java files.
I tried searching about it on youtube and he's getting .class instead of .java files. So, say I renamed .jar to .zip and extracted class files, do I just edit the main .class and build? Any tips, please.
Thanks!
Looking in the source code download the main method is in the QuizCards class (QuizCards.java).
Since there is a source code download you should use that.
I deleted a Java project from my hard disk in an attempt to do some refactoring with Eclipse. Luckily I found a recent version of an Executable Jar File and decrompressed it into a bunch of .class files.
I've read some 'decompiling' threads on SO and tried showmycode.com, but I was hoping for more. Isn't it possible to convert .class files into the .java files that made them, comments included - nothing changed? Or find the in the .jar file? What are my best options if not? Other answers on the topic seem outdated. Do I need to download software?
You will not be able to get your comments back, they are lost when you go from .java to .class. As to how to do it any "Java Decompiler" can do it, your code will not be exactly what you wrote, however the code you get back will be functionally the same as what you originally wrote.
JD is a decompiler I have used before and have been happy with its output.
I recently accidentally submitted my .class file instead of the .java file for an assignment.
After feedback from the grader, I submitted my .java file. Everything worked out fine from there, the grader trusted that it was an honest mistake.
However, is there a simple way for the grader to check to see if the two files really match up?
So far, I've only thought of two solutions:
Compile the .java, and see if the .class outputted is identical/very similar. This is probably very compiler dependant. If the compilers were the same, are there other variables that would make the .class different?
Decompile the .class file, and do a character comparison. This seems like a lot more work, and probably match the .java file even less than solution 1.
Is there a reliable way to check this?
If you compile with the exact same compiler in the exact same enviornment, it is highly likely that you will get identical class files.
However, if there are variations in compiler or platform, you should look at this discussion.
Outside of that, you will probably have to evaluate it functionally. That is, write a test class that exercises all desired behaviors of each class and check whether they all return identical results.
I did a very simple test and it worked for me..
I compiled a simple java program and created its .class file
Then I just change one letter inside System.out.println and again crated a .class file
Then used diff command in linux and it tells me that two binary files are different
So I think instead of decompiling the .class file and then checking both .java files you can directly check for two .class files
At least it worked for me.
Hope this helps!
I am new to both java and eclipse, I have been trying to debug an android app on a device. It is a small project with a jar file reference. I read similar questions but they didn't help.
What I need is to be able to debug the source codes of the jar file so I attached the source codes ( which I obtained using a decompiler ) and I am able to go into source codes of the library so I thought I did that correctly. But I can not succeed in debugging into these source codes; in debug mode it skipps breakpoints (only the ones in the source files which are attached to jar file) and when I try to 'step into code' it goes to random lines skips lines when debugging.
I am using the latest versions of eclipse, android sdk and jdk. I don't know what causes this problem and I'd like to know.
Thanks in advance, I hope I explained sufficiently.
The problem is, that you can't decompile the class files to debug it. Because the lines of the decompiled files will differ to the original Java source code lines (imagine: the real source code has some comments and other things which will not be compiled into class files)!
So, if your Eclipse shows you the current debug line 42, then it only tells you, that the debugger will present you the 42th line of code in the class file. This won't match your decompiled java source file.
However, you could decompile the class files with the option add line numbers as comments. These line numbers in comments you can compare to the actual stacktrace line numbers. This could help you a little bit to imagine the issue.
edit: as Laurent B recommended, you will be able to realign the code with JD-Eclipse, see: http://mchr3k.github.io/jdeclipse-realign/
+1 for the comment! :)
edit2: You won't be able to decompile with line numbers if the class files are compiled with the flag -g:none:
-g:none
Do not generate any debugging information.
So if this is the case: try to find the original source code of your jar file!
Its shows that the source file and Jar is not same. Try to get the right version of Source.
A decompiler will not get the exact source code but will try to recreate it from the generated bytecode.
This is an entropic process so Decompile(Compile(Source)) will not output Source (you loose information) such as line number. That is why you will need the original source code. If you don't have it, you will have to use your immagination to be able to follow the code :)
EDIT : apparently some decompiler tools can do that for you as stated by bobbel.
see jdeclipse plugin.
Try debugging your code line by line by pressing F6
Decompiled source code sometimes acts like that. Unfortunately, the only solution for you is to stop debugging the jar and search the web for the source code and add it to your project.
Okay, so my programming teacher sent me an app that I should look at and modify. I downloaded the APK file, and turned it into a source code following these instructions: how to extract code of apk file.
I have the java (src) files, the resources files, and the XML files. I have the Manifest file too.
I imported them successfully on eclipse, but now it has like 2000 errors.
I really don't know what to do. The apk works fine on my phone.
Why is it doing this?
If anyone needs the apk, I'll upload it.
If someone can be so generous to convert it into a working eclipse workspace for me, I'll be more than grateful.
You can never get the exact source code from the .apk file. The .apk file is generated from the compiled classes which doesnt have all information like actual variable names, actual method names. so you cannot retrieve back 100% original source code.
Basically everything will be obfuscated. so when obfuscated, multiple classes may have same name.
eg: two classes may have name 'a'. Hence the Errors in Eclipse.
As far I know re-compiling apk file will not give you exact results except the images and xml resources. Some free tools available that cannot provide 100% accurate code. here's a tutorial you can check How To Retrieve The Source Code From A Compiled Android .Apk