Java decompiler and editor for quick modifications [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am trying to find a Java decompiler just like swf-decompiler, that allows to edit and recompile the source, without having to export it anywhere, and do any external actions. What I want is to very quickly apply small changes to .jars and save them, without taking extra time on manually recompiling java code with other tools, Is there a decompiler like that? Is there anything similar (like .class variable editor) and is it even possible to make a Java decompiler like swf-decompiler?

Recommending a tool is offtopic, but as for the question of whether it is possible, the answer is yes and no.
Java is relatively decompiler friendly, so for simple cases, it should be possible to create such a tool. However, there are some features or patterns that tend to trip up current decompilers, and given the complexity of the language, there is unlikely to ever be a decompiler that can reliably roundtrip arbitrary Java.
Furthermore, while compiling Java loses a lot less information than C, it does lose information. Obviously, you'll lose stuff like comments and whitespace, but under default settings, you'll lose a lot more: local variable names, flags, and types, generic types, compile time annotations, etc. Most of this information is preserved to some extent for reflection purposes, and passing the -g flag to the compiler can force it to save more information, but you can't get it all back.
So in short, you can do a reasonable job most of the time, but you can't ever do it perfectly all of the time.
Also note that this is for ordinary Java compiled yourself. If the classfiles were not originally written in Java or they are obfuscated at all, you can forget recompiling. Even when decompilers produce readable output, the output is unlikely to be recompileable.
If you want to modify arbitrary jars, what you need is a disassembler and assembler. The best one I know of is Krakatau (Disclosure: I wrote it). The advantage of this is that it will work for any classfiles, even if they are obfuscated. However, it is not user friendly at all. If you don't know your way around the classfile format and bytecode, you won't be able to make more than trivial changes (such as changing a constant string).

Related

Generic java bug-estimator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I heard there is software available that you can feed Java-code and it gives you back an indication on where your code is likely to produce unexpected behaviour. However, I cannot find such software, nor anything resemblng this. Does anyone have an idea on where to look? (I don't know where I heard this, so no, I cannot go back to the source and ask :( )
For example:
-it might check whether the same code is found at multiple places (when editing you are likely to forget to update one of the two, hence this could give prblems in the future)
-it might check whether you might be returning null somewhere where the null stays untreated,
-it might check for 'magic numbers' (numbers that are used in code without being assigned to a variable), especially when these numbers appear at various places in the code.
-etc, etc.
(What it doesn't need to check is whether the code can be compiled. that's, ofcourse, where we have already many other tools for, like Eclipse).
I do not know for certain whether the described software exists and what it looks like, but any help in this direction would be great!
Sounds like the code inspections you find in IntelliJ Idea.
There is FindBugs which does a static code analysis to find "bug patterns". That is code that falls in one of these category:
Difficult language features
Misunderstood API methods
Misunderstood invariants when code is modified during maintenance
Garden variety mistakes: typos, use of the wrong boolean operator
It's nice to use and tends to find some bugs. However it can not do everything you want (i.e. "returned null" checks).
There are a few tools like this. I've found PMD and Findbugs particularly useful.
findbugs is one such tool. More generally, what you're talking about is called static analysis.
If you work with eclipse, you could use codepro
Use sonar. It is a web application that has all these functionality and nice UI. Visit the site (http://www.sonarsource.org/) and see nemo - the live instance where all jakarta projects are hosted: http://nemo.sonarsource.org/

What JVM assemblers are there? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want a JVM assembler that is straightforward and simple. It should take a text file written in the mnemonic language described in The Java Virtual Machine Specification and produce class files, i.e. bytecode.
To be clear: I don't want a library that can generate class files from invocations of an API.
What are the current statuses of the JVM assemblers? Do they support invokedynamic (not mandatory to me, but an advantage)? On what operative system can I use them? What are their individual pros and cons?
Some time has passed, and now there is an alternative to Jasmin called Krakatau.
From the README.txt:
The Krakatau assembler is intended as a replacement for Jasmin, and was originally written due to the limitations of Jasmin. It is mostly backwards compatible with Jasmin's syntax, though not necessarily with the extensions introduced in JasminXT. However, Krakatau offers many new features, most importantly the ability to directly specify constant pool references.
At this time, it seems that Krakatau was last updated a month ago, and Jasmin was last updated nine years ago.
Krakatau does support invokedynamic and utilizes the same instruction names as are used in the JVMS.
Krakatau is implemented in Python. Personally, I like my Java tools to be implemented in Java, but given the nature of this tool (constructing class files from non-Java source) and the lack of competition in this niche, I'll give it a chance.
Jasmin is the de facto standard. Recent versions support invokedynamic. It's written in Java, so it's portable.

Tools to detect duplicated code (Java) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I am in a project where previous programmers have been copy-pasting codes all over the place. These codes are actually identical (or very similar) and they could have been refactored into one.
I have spent countless hours refactoring these codes manually but I think there must be a better way. Some are very trivial static methods that could have been moved into an ancestor class (but instead was copy pasted all over by previous junior programmers).
Is there a code analysis tool that can detect this and provide reports/recommendations? I prefer free/open source tool if possible.
I use the following tools:
PMD/CPD (BSD-style License).
Checkstyle (LGPL License) - support was removed, see details.
Both tools have code duplication detection support. But both of them lack the ability to advise you how to refactor your code.
JetBrains IntelliJ IDEA Ultimate has good static code analysis with code duplication support, but it is not free.
Most of the tools listed on the Wikipedia article on Duplicate Code Tools will detect duplicates in many different languages, including Java.
SonarQube can detect duplicated codes but does not give recommendation on eliminating them. It is free and - although with the default setup it can only detect lexically identical clones
Either Simian or PMD's CPD. The former supports a wider set of languages but is non free for commercial projects.
http://checkstyle.sourceforge.net/ has support for finding duplicates
See our SD Java CloneDR, a tool for detecting exact and near-miss duplicate code in large Java systems.
The CloneDR will find code clones in spite of whitespace changes, line breaks, comment insertions deletions, modification of constants or identifiers, and in a number of cases, even replacement of one statement by another or a block of statements.
It shows where each set of clones is found, each individual clone, an abstraction of the clones having their shared commonality and parameterization of the abstraction to show how each clone instance can be derived from the abstraction.
It finds 10-20% clones in most Java systems.

Automated Python to Java translation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Is there a tool out there that can automatically convert Python to Java?
Can Jython do this?
Actually, this may or may not be much help but you could write a script which created a Java class for each Python class, including method stubs, placing the Python implementation of the method inside the Javadoc
In fact, this is probably pretty easy to knock up in Python.
I worked for a company which undertook a port to Java of a huge Smalltalk (similar-ish to Python) system and this is exactly what they did. Filling in the methods was manual but invaluable, because it got you to really think about what was going on. I doubt that a brute-force method would result in nice code.
Here's another possibility: can you convert your Python to Jython more easily? Jython is just Python for the JVM. It may be possible to use a Java decompiler (e.g. JAD) to then convert the bytecode back into Java code (or you may just wish to run on a JVM). I'm not sure about this however, perhaps someone else would have a better idea.
It may not be an easy problem.
Determining how to map classes defined in Python into types in Java will be a big challange because of differences in each of type binding time. (duck typing vs. compile time binding).
Yes Jython does this, but it may or may not be what you want
to clarify your question:
From Python Source code to Java source code? (I don't think so)
.. or from Python source code to Java Bytecode? (Jython does this under the hood)

Tools for converting non-Java into Java source [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
Are there any good tools out there for automatically converting non-Java source code into Java source?
I'm not expecting something perfect, just to get the worst of the grunt work out of the way.
I guess there is a sliding scale of difficulty. C# should be relatively easy (so long as you ignore all the libraries). (well written) C++ not so bad. C requires making a little OO. (Statically type) functional languages may be easy to grok. Dynamic OO languages may require non-local analysis.
One thing you can try is find a Java bytecode compiler for the language you're talking about (there are JVM compilers for all kinds of languages) and then decompile the bytecode back into Java using a decompiler like Jad.
This is fraught with peril. The regenerated code will suck and will probably be unreadable.
Source-to-source migrations fall under the umbrella of Program Transformation. Program-Transformation.org tracks a bunch of tools that are useful for language recognition, analysis, and transformation. Here are few that are capable of source-to-source migrations:
ASF+SDF Meta-Environment - As noted, there is no new development on this tool. Instead, the developers are focusing on Rascal.
Rascal Meta Programming Language
Stratego /XT
TXL
DMSĀ® Software Reengineering Toolkit (commercial)
If you spend any time with one of the open source tools, you'll notice that even though they include source-to-source migration as a feature, it's hard to find working examples. I imagine this is because there's no such thing as a one-size-fits-all migration. Each project/team makes unique use of a language and can vary by libraries used, type complexity, idioms, style, etc. It makes sense to define some transformations per migration. This means a project must reach some critical mass before automatic migration is worth the effort.
A few related documents:
An introduction to Rascal - includes a migration between the toy language Pico and Assembly starting at page 94.
Cracking the 500 Language Problem
An Experiment in Automatic Conversion of Legacy Java Programs to C# (gated) - uses TXL
Google: ANTLR
The language conversion is fairly simple, but you will find the libraries are different.
This is likely to be most of your work.
If you just want to use some legacy C/Pascal code, you could also use JNI to call it from Java.
If you want to run it in a Java applet or similar constrained environment, and it does not have to be very efficient, you can use NestedVM (which is a MIPS to Java bytecode converter) in conjunction with a gcc cross-compiler that compiles to MIPS). But don't expect to get readably Java code from that.
Any of those tools might help only if your non java code is not huge enough.
If its huge non java code and if you want to seriously translate it to java, then few things need to be thought of, its not just hundreds of lines of code, there is a design beneath it, there are few decisions taken by people beneath the code due to which certain problems might have been solved and few things have been working there. and investing time on any good translator won't be worth as it won't exist, it's not just syntax translation from one language to another.
If its not so huge code, its better to re write in java, as it has so many APIs packages out of box, it might not be big deal, hiring few interns for this also might help.
ADA to Java can be done with a find-and-replace!

Categories

Resources