I was wondering if I put comments in my code and when someone tried to decompile it, if they could read the comments that I put?
No, comments are never included as part of the compilation process. They are typically removed in some sort of pre-processing, or first-pass stage.
Nope, comments are discarded by the compiler.
No. And you can verify this by using DJ Java Decompiler, for example. If you also refer to the Java Class File Format, you'll see there's no construct for storing comments.
Comments aren't included in the .class files, so a decompiler won't be able to produce them.
Related
When you write your java code, you also write corresponding Javadoc (especially those that are right above each method). I am wondering if there is a way to get the Javadoc contents print out in the console.
My reason for doing this is that I don't want to write help documentation twice. I've already written a good amount of information in my Javadoc, and I am really reluctant to write the same thing separately in another place.
I don't think I've found anything on Google that is related to this question, but I wonder if anyone knows how to do so.
I am thinking use this approach: use a scanner and read my java source code, and when it reads /**, it will start adding contents followed up to a string, and will stop adding content if it sees a */. Do you think this will be a good approach to implement? Why or why not?
There's the javadoc tool which will generate a website from you javadoc comments on the source code. It is included in your JDK's bin folder.
There is an API for writing your own Doclet to process the Javadoc comments into the form you need. See the Doclet Overview
I have a java program loaded in the memory. Using a Java debugger at runtime, can I access the assembly code and change the next OPCODE and then rerun the program? Please let me know if this is feasible.
Thanks in advance!
I'm not sure about editing it but with the java compiler you can certainly generate it with something like
javac MyClass.java
javap -c MyClass > MyClass.bc
here is a good article to understand it from
http://www.ibm.com/developerworks/ibm/library/it-haggar_bytecode/
I imagine there is a way to change it then recompile with javap
edit
There are apparently some open source compilers for java byte code see http://en.wikipedia.org/wiki/Jasmin_%28Java_assembler%29
You can alter bytecode at runtime using a library such as javassist. Have a look:
http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/
Which debugger are you using? If you use Eclipse IDE you can alter the code even when the program is already running without the need of stopping it. This can only be done if no interfaces of the class are affected, though.
So the short answer to your question is: Yes, it can be done.
But it depends on your debugger implementation.
Recently I have collected lots of api examples for java api(jdk,log4j,etc.), but I've got a problem about inserting the code example into the project's javadoc. People usually use the javadoc and doclet tools to do this, it seems that the source code of the projects maybe changed. For example an example , if I want to add an example to Button, then I may have to add an #example tag in the comment of the Button class...
Is there any tool or way can help me to solve this? to generate javadoc with a lot of collected examples from the Internet,without changing the source code too much~ Thanks a lot!
I find this article . It related to your question. But I agree with Michael Barth. So, why would you want to put commented source code into a comment? Сomments and source code should complement each other.
I have a limited selection of original source code overlayed onto decompiled code in a sources jar.
This is great as it gives me easy ability to drill down into the code when debugging however it seems to have a side effect of disabling the javadoc from the associated javadoc.jar from working in eclipse despite me having a separate javadoc.jar file with the javadoc in it.
I assume this happening because eclipse is finding the 'source code' and assumes that all the javadoc is in the source and therefore there is no need to check the javadoc.jar file.
I'd like to be able to tell eclipse (preferably using maven) to not use the sources.jar for javadoc and only use the javadoc.jar. I would still like to use the sources.jar for source code.
I have assumed that eclipse is preferring to display javadoc from sources and may be wrong so please correct me if that is the case.
Also, I may just be doing something simple the wrong way so please let me know if that is the case.
I am hunting for the same thing. I have some source jars I created with jad (and since they are decompiled, they have no JavaDoc in them) and attached as source attachments. I also have the JavaDoc attached. It seems like it is a limitation of Eclipse. It will scrape the JavaDoc from the sources and display it (even if its empty) rather than looking to the JavaDoc. I wish it would notice that the JavaDoc was missing from the source and try the JavaDoc location instead. If I don't find a solution, I'm going to post the question and/or feature request over at the Eclipse site.
One workaround might be to integrate into the java decompiler (like jad) the ability to examine both the source an the javadoc, and put the javadoc back into the source. It would also then have parameter names for methods available too so it could put those back in. Lots of people have suggested this, but I cannot find anyone who has done it.
A couple of caveats. First, jad hasn't been maintained in a long time. The JD-Core/JD-Eclips website has vanished. And I have not found a better Java decompiler than jad. What happened to all the great Java decompiling gurus and solutions? Second, it might be tricky with the "align for debugging" feature to make sure the JavaDoc comments don't take up more room than is available.
I am looking for a command line utility on *nix, that can dump the names of all the functions, classes etc. defined in a file(C/C++/Java)
ctags can give you that (and much more). It is included with most Linux distributions...
http://ctags.sourceforge.net/whatis.html
It is not clear which language you refer to: if:
complied elf file then you have readelf utility providing that you compiled file with debug information "-g"
Not sure if it would be useful for your exact purpose, but take a look at GCC-XML
You might also want to take a look at cscope which is similar to ctags suggested in the accepted answer. It creates its own symbol database. It provides a nice interface for you, enabling search of a given symbol/inclusion/file/declaration within your project.
You can try Doxygen to list all your functions (see also XML output possibility)
http://www.doxygen.nl/