I'm intending to use this in a patched version of Fernflower to track
the original index of each local variable's STORE instruction, allowing
us to retain local variable names even if the deobfuscator is run
multiple times.
This is necessary for a future commit that will track the original
indexes of AbstractInsnNodes throughout the deobfuscator, with the aim
of using this information to track local variables in the decompiled
code.
I suspect this will also improve performance, as we don't need to
re-allocate all of the tree objects.
I've been considering this for a long time, and have decided to switch to it at
the last minute before opening the repository up publicly. My reasons include:
* It's a much simpler license. GPL's complexity adds some risk - for example, it
might be incompatible with future open-source licenses (like the well-known
GPLv2/Apache v2 incompatibility problem). The "or any later version" clause
requires placing some trust in the Free Software Foundation.
* The simplicity makes it easier for people to understand and comply with the
license.
* Dishonest users who disobey the GPL would have an advantage over honest users
who refuse to do so. The ISC license provides a much more even playing field.
* OpenRS2 will primarily be server software accessible over a network. As such,
the GPL can do little to prevent use of the code in a proprietary system, as
the code is never distributed. (While the AGPL would fix this, I have already
discounted it. Enforcement would be too difficult and dishonest users would
have an unfair advantage.)
* It's much easier to switch to a stricter license in future versions, if it
turns out that is desirable (as the ISC license allows users to sublicense
the code). However, switching from the GPL to the ISC license requires all
copyright holders to grant permission.
* Other open-source projects in the community, such as Apollo, use the ISC
license and will be able to make use of OpenRS2 code if they so desire.
I've removed the FAQ entry about the reasons for using the GPL license, as I
think the ISC license is less controversial and therefore does not require an
entry.
I've discussed this with Desetude, and he's okay with his commit being
relicensed.
Fernflower was previously placing constructors in the middle of instance
methods. They look much nicer at the top.
This commit also ensures static methods appear before instance methods.
These might be added to the user's ~/gradle.properties file, at which
point having a per-project prefix is useful.
Ideally I'd have preferred to use openrs2.repo.{username,password}.
However, Gradle properties with dots in them can't be configured with
the ORG_GRADLE_PROJECT_* environment variables, which we use in the
Jenkinsfile.
By moving all the static fields in a single class in one go, we can just
combine the <clinit> methods together. This allows us to remove all the
really complicated logic for extracting initializers, and also allows us
to move the last few array fields with complex initializers.
Depending on the class loading order, moving them can result in arrays
being empty, which breaks the client's functionality (e.g. it can't get
past the JS5 CRC check).
The client scrambles static fields and methods - moving each to a
random class where it does not logically belong.
This transformer moves all static methods to a new set of empty classes.
The intention is that the human refactoring the deobfuscated client can
move the static methods around with an IDE to classes where it makes
sense.
In theory we could use heuristics to move some methods around - e.g.
ideas I have include:
* If the method takes no arguments, move it to the same class as its
return type.
* If it's a void method that takes one argument, move it to the same
class as its single argument.
* Group related methods together based on where they are called.
However, some of the heuristics are probably fairly complicated to
implement. Furthermore, as they are heuristics, they will make mistakes.
In the naive approach, the Static* classes generated by this transformer
effectively act as a queue of methods that a human has yet to move to an
appropriate class. If the Static* classes are ever emptied after
refactoring, then we will know that all static methods have been moved
to an appropriate class.
We wouldn't be able to guarantee this if some methods were moved to
Class* classes with heuristics. The heuristics would also be fairly
complicated to implement. Therefore, the transformer does not use
heuristics.
Field scrambling support will be included in a future commit.