Reflector for Java? - java

Is there a Java equivalent to .NET Reflector?
Edit: more specifically, decompiling is what I'm after.

See How do I decompile Java class files? There's a link there to JD-GUI, which seems to be about what you're looking for.
Edit: Also see Open Java *.Class Files.
Edit 2: And Best free Java .class viewer?, which specifically mentions .NET Reflector.

From what little I know the functionality of .NET Reflector is available in pretty much all Java IDEs, including Eclipse. Just add a jar file to a projects and you can browse its classes just as you browse your own classes.
For the decompiler aspect (as opposed to the pure class browser) there are some alternatives as well. The JDK tool javap only decompiles to byte-code so it isn't really useful to get to the source code (but might help with getting an understanding of the code).
JAD is a pretty popular decompiler in the Java world and it produces compilable Java code most of the time (some bytecode sequences aren't easily translatable to valid Java 'though, so some corner cases exist).

You can get JAD for decompiling .class into .java. It's pretty good at it.
If you use Eclipse get the jadclipse plugin too. You'll need to configure the path to the jad.exe. Next time you open a .class you'll see the decompiled source instead of the .class declaration. And you can browse with F3 too. It's very useful.

I'm not super familiar with Java, but does JBrowser work for you?

Related

Using Java Decompiler (JD-GUI) on a .class file gives me multiple errors on src file, but it runs fine within a .jar? How does it work?

I'm new to Java and I'm trying to understand something. I managed to get a .jar file for a local device to communicate with my laptop. It works fine, but I would like to do an upgrade and scoop around the codes and change some details. I used a Java Decompiler on the .jar file and managed to take a look at the class files. However, whenever I decompile them into source codes, errors will occur in my IDE, and I'm unable to build them. What exactly happened? If it's working fine in the .jar why does it produce errors?
Compilation is a lossy process, so decompilation is always a "best effort" endeavor. Java bytecode is unusually high level, so Java decompilation is relatively easy compared to other languages, but it will still never be 100% complete. Therefore, you should not be surprised to see errors when re-compiling decompiled source.
If you want to work directly with bytecode, I would recommend using the Krakatau disassembler and assembler. Instead of decompiling to Java source, the disassembler converts bytecode into a human readable assembly format which is specifically designed to be converted to and from bytecode losslessly. However, it requires a good understanding of low level Java bytecode to use.
Completely agree with Antimony. There is no decompiler which decompiles always without any error. Sometimes it decompiles well, sometimes not.
The best way is to have several decompilers and use them each by other to decrease errors in decompiled source.
If you use Eclipse I would suggest https://marketplace.eclipse.org/content/enhanced-class-decompiler
If you use IntelliJ try this decompiler Jar Explorer.

See what's inside classes we import from jar files

Started coding in java , just wanted to see the implementation of classes and interfaces we actually import to use their methods.
Ex:
import java.util.Scanner;
I am curious to see what's inside the class Scanner(){}
Is that possible?
Tried Searching but couldn't find the implementation and definitely did not understand how they hide them from public.
Please follow the following Steps to See Java predefined classes implementation
1) Get rt.jar (It contains all Core Java API Classes which required for JRE at Runtime)
Download it from the internet directly or Search it in JDK at Path like C:\Program Files\Java\jdk1.8.0_181\jre\lib and copy it to other location on your Desktop
2) Extract the copy of rt.jar
Extracting .jar file with command line
https://www.wikihow.com/Extract-a-JAR-File
After extracting you can see all the Core Java Classes in .class file (cant read it Directly) which we use normally in our programs
3) Download tools like cavaj java decompiler to open and read .class file
You Can see any code in Any jar with this approach... Its very smart way to understand basics of java with fun ..
There is nothing "hidden from public" concerning java.util.Scanner.
#shmosel already linked to the source of it, #Stultuske pointed out, that there are various websites covering source code of java.
Modern IDEs also allow you to view into source for your libraries (aka .jar files).
My Netbeans IDE shows source from known jar files whenever I ctrl-click on a class.
Same goes with Eclipse, IntelliJ, ...
For a lot of open-source libraries (e.g. from Apache) there is also source code available. Just by cloning the version control repository, downloading source packages (zip, ...-source.jar) or browsing the version control repository online.
If project is buildable with maven, the IDE can even download and show sources for open source project automatically.

Is it possible to view dynamically generated bytecode in eclipse?

I know of several solutions for files that end in ".class", where you can use the ByteCode Outline plugin, or the Bytecode Visualiser plugin, or even the built-in "javap-like" viewer for classfiles.
But I would like this ability for runtime-generated code while debugging! What I am trying to achieve is to see the actual generated code from a clojure call executing. This uses ASM to generate classes on the fly.
Using the eclipse IDE, you can combine JAD(a java decompiler) with the JADClipse plugin to decompile your class files on the fly whenever the debugger attempts to open a class file that has no linked source. Without eclipse, you can use JAD as an independant executable, but it is less user friendly.
JAD will generate the java source for a class file even if it was built with a java assembler. This is possible because the java language is close enough to the functionality of the jvm. The only class files this wont work on is ones that have been run through an obfuscator to prevent decompilation
Apart from JAD, there are other tools. One's called JD (Java Decompiler). It also has an eclipse plugin and is a little better than JAD since it supports Java 5, JAD only supports Java 4 (as far as I know there hasn't been any development on JAD since 2001 or something). A tool that seems to be supporting Java 6 is DJ Java Decompiler, but I haven't tested that yet.
And I don't know if any of these tools actually support on-the-fly-generated code, on the other hand I don't really see why they should not.

Conversion of class file to Java files

I have one War files (a Java application) consist of 64 class file along with image/CSS/JS files. I have lost the source of this war file. Now I want to do some changes in code. I am looking for some expert advice from community on following questions.
Is there best way to convert .class files to .java file without losing any section of code?
What are the tools if any for this task?
What are challenges/drawbacks of converting .class files to .java files to recreate war file?
If you do not want to spend horrible times in understanding decompiled bytecode, please start using a version control system and a remote repository for any project of more than two classes.
In particular, you can use Git with GitHub, open source are hosted for free while if you want to protect your code you can get a commercial subscription which is cheap anyway.
For this time, help yourself with a java decompiler such as JD:
Use a java decompiler to decompile the bytecode.
Create a git repository out of the decompiled java classes
Constantly synchronize it with the remote repository
Conversion to Java Bytecode is almost completely reversible. As #StephenC said, In the regenerated sources, you will lose comments, names of local variables etc. It might not compile right away but you should be able to get it to compile again, with a little modification.
You need a Java Decompiler to do that. Try JD-GUI or DJ Java Decompiler
In case you obfuscated your sources, the sources you recover will not be harder to understand and reverse engineer. Otherwise, with just a little tinkering, you should be able to get back your sources.

restore project from jar file

first i'd like to point out that im fairly new to netbeans and java, couldnt exactly find what i need on the web.
I downloaded a software's source files and was modifying it on netbeans. naturally when building the project, netbeans creates in (for example) documents/project_folder/dist/ a lib folder and the finished JAR file that i can use.
if i delete by mistake the source files, and would like to apply all the changes i previously made to fresh source files using the JAR and lib folder i still have, is it possible and how?
First of all it is not possible to get a source again from jar file in lib folder. Jar file is executable file which will just contain class files. You can use java decompilers to get source again.
NB do not has a version control nor auto save by default. You may have a look on git in NB7.
When you restore from Jar with decompiler there is a big chance to get the source back, even more if you know what your code is all about.
You can get the source back by using some decompiler. There are many decompilers available like DJ Decomipler. My favourite is Jd Java Decompiler. Its very small in size and does its job pretty well
I'm rather an Eclipse user but I guess both Eclipse and Netbeans are similar to a certain extent. Unless the jar has been created including the source, you won't have other choices that decompile the class files.
When needed, I usually go with JD-GUI which does a pretty good job decompiling jars.
It is not possible to retrieve exact source code from a compiled byte code. But there is a possibility to recover your code to some extent
JD is a good Java decompiler.
http://java.decompiler.free.fr/?q=jdgui
I think JD is a super hero in cases that the original source code is lost.
Keep your source code on any SCM. Use remote SCM not to loose your code. See: google code, github, launchpad etc.

Categories