Commit Graph

162 Commits

Author SHA1 Message Date
md_5
898cb2320b Skip empty lines + comments in SRG 2013-02-03 19:28:47 +11:00
Agaricus
e602ed5dc8 Improve error messages for csrg/srg mapping file parsing 2013-02-02 22:38:46 -08:00
Agaricus
79bc85e8b0 Add standard srg format support to --srg-in
Previously, only the (much easier to parse) 'csrg' format was supported
2013-02-02 20:52:57 -08:00
Agaricus
ccf4bd5abd Add empty inheritance provider singleton
Previously, an empty list would signify no inheritance information.
2013-02-01 23:41:25 -08:00
Agaricus
fbd2b64a61 Simplify inheritance lookup
Remap through only one inheritance provider, instead of a list of them.

The multiple inheritance provider lookup functionality (check each one,
in order, until one provider responds for the class name) is still
available, but refactored into a new InheritanceProviders class.

Simplifies the common case of only having one inheritance provider, and
also reduces the redundant looping code previously in JarMapper/InheritanceMap.
2013-01-31 19:49:45 -08:00
Agaricus
8ee18916f1 Add remapped inheritance map file reading
The inheritance map, as generated with --write-inheritance/-H, can now
be read using --read-inheritance/-H. It will be remapped through the
currently loaded inverse mapping before supplying the inheritance provider.

Example usage:

java -cp target/SpecialSource-1.3-SNAPSHOT-shaded.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/target/bukkit-sample-plugin-0.5.jar  --out-jar /tmp/sp/out.jar  -h /tmp/h

where the inheritance map was previously generated using:

java -cp target/SpecialSource-1.3-SNAPSHOT-shaded.jar:mcpc-plus-1.4.7-R0.2-SNAPSHOT.jar net.md_5.specialsource.SpecialSource --srg-in ~/minecraft/1.4.x/jars/1.4.7/cb2obf.csrg --live --write-inheritance /tmp/h
2013-01-29 21:32:50 -08:00
Agaricus
4725e6d913 Add inheritance map file reading 2013-01-29 20:31:47 -08:00
Agaricus
29900947d1 Add missing copyrights 2013-01-29 19:33:39 -08:00
Agaricus
0ecf1100de Reduce unnecessary output in generated inheritance map
Only includes mapped classes in the parents, and only includes entries
for classes which have relevant parents (extends/implements classes).
Shrinks inheritance map on MCPC+ build 73 by 279 lines.
2013-01-29 19:25:31 -08:00
Agaricus
fbe56aec27 Add option to generate unrenamed symbols in mapping output 2013-01-28 22:42:01 -08:00
Agaricus
97b6e4179f Sort inheritance map written to file 2013-01-27 13:32:04 -08:00
Agaricus
a64fb14abd Add inheritance map writing
New --write-inheritance/-H command-line option, iterates all classes
in mapping and writes inheritance (interfaces and superclasses) to file.

Example usage, generating inheritance map from MCPC+:

java -cp target/SpecialSource-1.3-SNAPSHOT-shaded.jar:mcpc-plus-1.4.7-R0.2-SNAPSHOT.jar net.md_5.specialsource.SpecialSource --srg-in ~/minecraft/1.4.x/jars/1.4.7/cb2obf.csrg --live --write-inheritance /tmp/h
2013-01-27 13:22:44 -08:00
Agaricus
d23c72ae7a Add Guava dependency 2013-01-27 13:10:33 -08:00
Agaricus
c5964ee89d Add verbose mode to URLClassLoaderInheritanceProvider 2013-01-26 01:42:46 -08:00
Agaricus
4499220c61 Optimize RemappedRuntimeInheritanceProvider to not traverse inheritance if not remapped
Used to lookup the inheritance if every single class - now will return
null and allow other inheritance providers to answer instead.

Consequentially mapTypeName() has been enhanced to accept a 'default' type name:
pass the same typeName to 'pass through' unmapped names, or null if you want to
distinguish between unmapped and mapped names, as RemappedRuntimeInheritanceProvider does.
2013-01-26 01:30:29 -08:00
Agaricus
718ffc8bb5 Add verbose mode to RemappedRuntimeInheritanceProvider 2013-01-26 01:16:51 -08:00
Agaricus
89c00557a7 Fix recent regression in remapping inner classes
Broken in refactor in 3ff134311d
The outer class name (before '$') should be used for mapClassName.
2013-01-26 00:05:22 -08:00
Agaricus
25fcbb40fe Require explicit classloader for runtime inheritance
Previously, the runtime inheritance providers would always use the
system classloader. Now you have to explicitly pass the classloader
to use. Also add a 'verbose' flag for debugging.
2013-01-25 23:27:40 -08:00
Agaricus
41fefc0167 Always output class names in generated mappings, even if not renamed
Although SpecialSource avoids generating unnecessary output where
methods/fields are not renamed, the _absence_ of a class rename is
arguably as important as a class rename, especially when comparing
jars where nearly all classes are renamed.

In the common case of generating Minecraft mappings from an obfuscated
jar and an internally-renamed deobfuscated mc-dev jar, all classes
are renamed, except for one -- the main class:

net/minecraft/server/MinecraftServer net/minecraft/server/MinecraftServer

When the mc-dev server jar is shaded into CraftBukkit, all classes are
relocated under a versioned package. However, the shading relocation
simulator misses MinecraftServer since it is not included in the mappings,
as it isn't renamed.

Always outputting class names, regardless of whether they are renamed,
only increases the mapping file by one line and removes the need to
special-case MinecraftServer.
2013-01-25 21:48:00 -08:00
Agaricus
ba63cd9803 Remove obsolete throws on JarRemapper constructor
Now that mappings are loaded in JarRemapping, IOException is no longer thrown here.
2013-01-25 20:40:37 -08:00
md_5
db4ed56212 [maven-release-plugin] prepare for next development iteration 2013-01-25 14:29:15 +11:00
md_5
322c96347a [maven-release-plugin] prepare release SpecialSource-1.2.1 2013-01-25 14:28:59 +11:00
Agaricus
d60caf4345 Fix class file loading in URLClassLoaderInheritanceProvider 2013-01-24 19:22:14 -08:00
md_5
2b589946e8 [maven-release-plugin] prepare for next development iteration 2013-01-24 19:19:45 +11:00
md_5
b4a9f08e80 [maven-release-plugin] prepare release SpecialSource-1.2 2013-01-24 19:19:32 +11:00
Agaricus
0ea3957d6f Add support for loading multiple mappings
New loadMappings() method in JarMapping, can be called to merge two
mapping files. Useful for loading both 1.4.6 and 1.4.7 (relocated).
2013-01-23 22:40:15 -08:00
Agaricus
112f780e85 Add classloader inheritance provider
Allows inheritance to be loaded through URLClassLoader, as an alternative
to JarFile/Jar with JarInheritanceProvider. This is how CB loads plugins, and
it may avoid some of the idiosyncrasies in loading the jar directly as a zip -
for example https://github.com/MinecraftPortCentral/MCPC-Plus/issues/51
java.util.zip.ZipException: duplicate entry (CB can load this plugin just fine)

Also allows more convenient remapping in PluginClassLoader, since the
URLClassLoader object is readily available
2013-01-23 22:25:08 -08:00
Agaricus
b5b967b850 Fix NPE in log() when used in a library 2013-01-23 22:24:52 -08:00
Agaricus
25cc65de41 Fix explicit ShadeRelocationSimulator constructor 2013-01-23 21:51:00 -08:00
Agaricus
769c398dd5 Add support for non-file jar mapping reading
The input is now a BufferedReader, so you can read from a file with
new BufferedReader(new FileReader(...)), or from an input stream with
new BufferedReader(new InputStreamReader(...)).
2013-01-23 21:27:45 -08:00
Agaricus
37ce7f0b37 Add remapped runtime inheritance provider
RemappedRuntimeInheritanceProvider is similar to RuntimeInheritanceProvider, providing
access to inheritance information at runtime, but class names are remapped before
looking up, and the inheritance is reverse-remapped before returning.

This allows the inheritance to be provided from an obfuscated jar, via the cb2obf
mappings. For example:

java -cp target/SpecialSource-1.2-SNAPSHOT-shaded.jar:mcpc-plus-1.4.7-R0.2-SNAPSHOT-023.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/IncompatiblePlugin-01.jar  --out-jar /tmp/sp/out.jar -L

-L enables remapped runtime inheritance, in order to use the obfuscated MCPC+ jar classes
to lookup the inherited classes for remapping. The same mappings are used as for remapping
the plugin (--srg-in and --shade-relocation take effect).

The original option, -l, in contrast does not remap on class lookup, and can be used to
lookup inheritance from a jar with CraftBukkit mappings, for example:

java -cp target/SpecialSource-1.2-SNAPSHOT-shaded.jar:craftbukkit-1.4.7-R0.1.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/IncompatiblePlugin-01.jar  --out-jar /tmp/sp/out.jar -l
2013-01-23 20:48:24 -08:00
Agaricus
7ed216d944 Fix inheritance provider chaining
Previously, each provider would be consulted until a matching parent is
found. This is incorrect and caused spurious warnings with --live
(jar + runtime inheritance), as unmatched classes in the jar would fall
through to the runtime inheritance provider.

Now once a provider returns non-null, no other providers are checked.
null indicates the provider knows nothing about the class and should
ask elsewhere, non-null indicates a definitive list of inheritance
(extends/implements list) classes. Should be slightly faster, too.
2013-01-23 19:55:44 -08:00
Agaricus
b69a11cf5b Cleanup output (cosmetic changes only) 2013-01-23 19:47:15 -08:00
Agaricus
03fe7d426b Fix unchecked cast warning on shade-relocation parameter 2013-01-23 19:40:26 -08:00
Agaricus
03a418d4b3 Expose individual class remapping in JarRemapper
The JarRemapper constructor is now public; you can create a remapper
with a JarMapping and list of IInheritanceProviders, and then use it
to remap an entire jar with remapJar(), or individual classes using
remapClassFile().
2013-01-23 19:32:21 -08:00
md_5
d6619b5d19 [maven-release-plugin] prepare for next development iteration 2013-01-23 20:11:49 +11:00
md_5
0355845dde [maven-release-plugin] prepare release SpecialSource-1.1 2013-01-23 20:06:54 +11:00
md_5
b839f98de2 Formattng + a few nitpicks of previous patches. 2013-01-23 20:05:24 +11:00
Agaricus
297b9f5a33 Add runtime class inheritance remapping
If -l is specified, will now traverse the runtime class hierarchy in
tryClimb to determine the method/symbol from the parent to remap, in
addition to the classes in the jar.

This can be used to remap plugins that call into external classes.
For example, with a Bukkit plugin:

 java -cp ../jars/craftbukkit-1.4.7-R0.1.jar:target/SpecialSource-1.1-SNAPSHOT.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg  --in ../IncompatiblePlugin/IncompatiblePlugin-01.jar --out /tmp/bp/out.jar

using:
 https://bitbucket.org/agaricusb/incompatibleplugin/downloads/IncompatiblePlugin-01.jar
 6d75d94496

agaricus/plugins/IncompatiblePlugin/SamplePosCommand.java will be remapped:

  worldServer.q(...)

from worldServer.getTileEntity(). World provides getTileEntity and is remapped in cb2obf;
but WorldServer subclasses World and overrides getTileEntiy.. this information is not
available in the plugin itself and would not be remapped alone. By adding the CB jar to
the classpath and enabling runtime inheritance, the call is correctly remapped.
2013-01-23 00:23:38 -08:00
Agaricus
fa2089271a Abstract inheritance lookup into IInheritanceProvider 2013-01-22 23:21:08 -08:00
Agaricus
06adbcdb63 Fix shading of method descriptors 2013-01-22 22:31:16 -08:00
Agaricus
3ff134311d 13x performance increase in jar comparison by parsing method signatures
New class to parse and replace method signatures, instead of iterating over
each class. On my machine, old technique takes 6.8 to compare Minecraft 1.4.7,
new technique: 0.5 seconds, with identical results.
2013-01-22 22:18:08 -08:00
Agaricus
97d8e80769 Add maven-shade-plugin relocation simulation on input mapping
The --shade-relocation/-R option causes the --srg-in mapping old class
names to be transformed with the pattern. Multiple patterns can be given,
though currently only exact prefix matches are supported.

Example:

--shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1
--shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle

The mapping will be 'shaded' before being applied to the jar.

You can use these options with --srg-in 1.4.7/cb2obf.csrg to remap plugins
which depend on the version-shaded class names (aka 'vcb').
2013-01-22 20:53:05 -08:00
Agaricus
01edc9471c Add package remapping
Package remaps are not generated by the jar compare, but can be added
programmatically by adding to JarMapping#packages, or in a .csrg as a
class remap but with a trailing slash, for example:

com/google/ guava10/com/google

will remap all classes in com/google/ to classes in guava10/com/google
2013-01-22 12:17:09 -08:00
Agaricus
5437eb4c9e Add remapping from csrg input file 2013-01-22 00:17:48 -08:00
Agaricus
642612e1c3 Allow remapping jars without Main-Class attribute (ex: Bukkit plugins) 2013-01-22 00:17:01 -08:00
Agaricus
1b15d3b29f Add 'compact srg' output format
This is a simpler mapping format, somewhat easier to parse, and without
the redundant information in the original .srg file format.
2013-01-21 20:58:55 -08:00
Agaricus
a11c2c4698 Move .srg writing into SrgWriter 2013-01-21 20:33:44 -08:00
Agaricus
b20840a65e Add -q option to suppress verbose output 2013-01-21 20:21:33 -08:00
Agaricus
ce4b890f87 Option parsing with joptsimple
Allow optionally writing srg to a file, or to stdout if unspecified.
2013-01-21 20:12:31 -08:00