I am trying to run the source code taken from online. the problem shows decompiled .class file, bytecode version:46.0 (java1.3 or older)
This is not error. It is just android studio telling you that the code you see might not be completely correct, because its decompiled from the class file. You should rather use the .java files in your project, because this is the correct not yet compiled java file format.
Related
I decompiled an Android APK using Jadx-GUI to view the Java source code. I want to modify the application, but the only way to do that is to make changes to the smali code and repackage the files into an APK via apktool.
I currently have made some changes to the Java code for a particular file. I now want to make the changes to the corresponding smali and then repackage the app. I am confused on how to do this.
Convert .Java file to .Smali file
From this post:
"You can compile the java classes using a normal java compiler, and then use Android's 'dx' utility to convert the compiled .class files to a dex file. And then run baksmali on the dex file to produce the smali files."
I'm not sure what this means. Do I need to just compile the one file I made the changes to? Or do I compile all the files of the project together? Since smali is android assembly, I would imagine that I would need to compile everything together so that registers are allocated properly, etc.
Lastly, if I use a normal java compiler, won't the compiler throw an error when it encounters Android specific imports?
Eg. import android.graphics.drawable
Was given a couple of .class files but the .java files weren't sent with and I was hoping to find a way to get the .java files using the .class files. Thanks
You can use a decompiler to do so. One of the most major ones is JD-GUI.
JD-Core is a library that reconstructs Java source code from one or more “.class” files. JD-Core may be used to recover lost source code and explore the source of Java runtime libraries. New features of Java 5, such as annotations, generics or type “enum”, are supported. JD-GUI and JD-Eclipse include JD-Core library.
EDIT (2018-02-23): It seems that JD-GUI is incapable of decompiling bytecode compatible with Java 8+ JREs. This, obviously, changes the utility of my answer.
EDIT (2018-05-24): For replacing JD-GUI, I would recommend Luyten, which can be found here. It's very similar to JD-GUI, but supports Java 8 byte code, itself being based on Procyon.
You can use any of the java decompiler utility for this. There are a couple of few good utilities available over the internet, e.g., JD decompiler, you can also look for the eclipse plugin as well for the same.
To view java content from .class files many decompilers are available.
I'm using JD compiler which is very good.
http://jd.benow.ca/
If you want it for edit/ update puropse, one way is copy + paste from decompilers. Other solutions i'm not aware of.
You can use Jadclipse which is basically a Java Decompiler. It can be used with eclipse integration..
You can use decompiler to get .java files from a jar file or a .class file
I had no problem running my java code in eclipse last week and I have no problem creating a new java application in eclipse. However, I am unable to open any of the java program files in eclipse that I saved. I checked to see if my jdk se development kit was removed from my computer by mistake and it is still there. What do you think is wrong? Why can't I open my old files? All of my java programs are saved as CLASS files.
Source files are normally saved with a .java extension. Once you compile your source files, javac will generate you some files with a .class extension. These are not source files, and are usually deleted and recreated every time you compile your code. If you want to find your source code, you'll need to look for the .java files on your disk.
If you've deleted your .java files by accident, it is usually possible to decompile the class files into something resembling the original source, but much of the original formatting will be lost - comments etc. This approach is far from ideal, but may help you recover the situation if you cannot recover the original source files. A good decompiler can be found at http://jd.benow.ca/ - you can either download the standalone application, or it has plugins for Eclipse and IntelliJ.
Hi once you compile the source java files .java extn the class files will be created. Check your workspace in your disk there will be a folder as package as you created in eclipse under src folder.
I have a jar that I want to take out a class file and add a few lines of code to it. I got class editor, but you can't actually change any code, you can change constants and that is all. I have a program that you can read the source code from a .class but you can't change anything on it. Is there a program or eclipse plugin that you can read and EDIT the source code from a .class file?
Have a look at decompilers. They'll transform the java-bytecode back to source code. One example of such a compiler would be JD: http://jd.benow.ca/
After editing the source code you would have to compile the code again and pack it in the respective .jar file.
If your file is an old enough version, you can use jasper to disassemble it into bytecode, edit the bytecode and reassemble it using jasmin. Unfortunately these tools have not been updated in some time.
They do not produce Java code; you'll have to learn Java bytecode. But it is more reliable than the so-called "decompiler" methods.
As Java .class files are in byte-code format, you cannot modify them the way you would edit a .java source file. Bytecode is a low level language closer to the machine language rather than Java itself.
If you need to modify the source, one option is to use a decompiler, e.g. JAD (Java Decompiler), to get a source file and then change it and recompile to .class using javac. Make sure you figure out which version of Java language (1.4, 5, 6, 7, 8) has been used for the original jar file.
What you need for this is a java de-compiler. This will take the bytecode out of your class file and convert it back to its source. From there you will need to recompile the .java files that the de-compiler produces.
Here are some java de-compilers that I have seen:
http://dcompiler.sourceforge.net/
http://jd.benow.ca
I have decompiled a jar file,
and made two classes from it. After that, I tried to make a new jar file with these two class files, using this code
jar cvf AB.jar WinRegistry.class StartPageChangeApplet.class
The file created without any errors. However, when I look at the source code on Java Decompiler, it says "Internel Error", means that I couldn't make the jar file properly.
Where am I doing doing wrong ?
Please define "made two classes from it". Which java compiler (e.g. javac.exe) are you using? Did you just copy the source to a .class file without compiling maybe?
The java decompiler JAD actually displays source code, not class bytecode. Don't get confused by the title of the editor which is saying WinRegistry.class.
So you can't just save that as a .class. You need to save it as a .java and then compile it to .class using a java compiler:
javac WinRegistry.java StartPageChangeApplet.java
jar cf AB.jar WinRegistry.class StartPageChangeApplet.class
From Eclipse, you can do this way..