Skip to content

Commit 0338906

Browse files
committed
Merge branch 'master' of github.com:LLVM-but-worse/jda
2 parents f5ca8d5 + 63ba63b commit 0338906

File tree

155 files changed

+424
-43290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+424
-43290
lines changed

compiling.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
# Compiling
1+
# Compiling - JDA
2+
3+
## maple-ir
4+
5+
This project now depends on [Maple-IR](https://github.com/LLVM-but-worse/maple-ir). To install it:
6+
```
7+
git clone https://github.com/LLVM-but-worse/maple-ir
8+
cd maple-ir
9+
mvn clean compile test install
10+
```
211

312
## Manual dependencies
413
- [CFR](http://www.benf.org/other/cfr/)
@@ -11,4 +20,20 @@ mvn install:install-file -Dfile=path-to\cfr.jar -DgroupId=org.benf -DartifactId=
1120
For example, the version of CFR might be 0.121, depending on `pom.xml`. Note that you will need to replace <version> with whatever version is specified in `pom.xml`.
1221
Optionally, you can use `-DlocalRepositoryPath=path-to-specific-local-repo` to specify a specific location to store the local repository.
1322

14-
Then, `mvn compile package`.
23+
Then, `mvn clean compile test package`.
24+
25+
Two jars are produced: one with dependencies, which should be used for running JDA standalone, and one without, used by plugins for linking against JDA.
26+
27+
# MapleIR plugin
28+
29+
To compile the MapleIR plugin, JDA must be installed to the local Maven repository first. Hence, in the root project (JDA) directory:
30+
```
31+
mvn install
32+
```
33+
34+
Next, build MapleIR:
35+
```
36+
cd mapleir
37+
mvn clean compile test package
38+
```
39+

mapleir/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
dependency-reduced-pom.xml

mapleir/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.mapleir</groupId>
8+
<artifactId>jdaplugin</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.apache.maven.plugins</groupId>
15+
<artifactId>maven-compiler-plugin</artifactId>
16+
<version>3.5.1</version>
17+
<configuration>
18+
<source>1.8</source>
19+
<target>1.8</target>
20+
</configuration>
21+
</plugin>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-shade-plugin</artifactId>
25+
<version>2.4.3</version>
26+
<executions>
27+
<execution>
28+
<phase>package</phase>
29+
<goals>
30+
<goal>shade</goal>
31+
</goals>
32+
<configuration>
33+
<artifactSet>
34+
<includes>
35+
<include>org.mapleir</include>
36+
</includes>
37+
</artifactSet>
38+
<transformers>
39+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
40+
<mainClass>org.mapleir.jdaplugin.MaplePlugin</mainClass>
41+
</transformer>
42+
</transformers>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
<plugin>
48+
<groupId>org.apache.maven.plugins</groupId>
49+
<artifactId>maven-jar-plugin</artifactId>
50+
<version>3.0.2</version>
51+
<configuration>
52+
<archive>
53+
<manifestEntries>
54+
<Built-By>maple-ir</Built-By>
55+
</manifestEntries>
56+
</archive>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
<resources>
61+
<resource>
62+
<directory>${project.basedir}/src/main/resources</directory>
63+
</resource>
64+
</resources>
65+
</build>
66+
67+
<dependencies>
68+
<dependency>
69+
<groupId>club.bytecode.the</groupId>
70+
<artifactId>jda</artifactId>
71+
<version>0.0.8</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.mapleir</groupId>
75+
<artifactId>main</artifactId>
76+
<version>0.0.1-ALPHA</version>
77+
</dependency>
78+
</dependencies>
79+
</project>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.FileContainer;
4+
import club.bytecode.the.jda.decompilers.JDADecompiler;
5+
import org.mapleir.ir.algorithms.BoissinotDestructor;
6+
import org.mapleir.ir.cfg.ControlFlowGraph;
7+
import org.mapleir.ir.printer.ClassPrinter;
8+
import org.mapleir.ir.printer.FieldNodePrinter;
9+
import org.mapleir.ir.printer.MethodNodePrinter;
10+
import org.mapleir.propertyframework.api.IPropertyDictionary;
11+
import org.mapleir.propertyframework.util.PropertyHelper;
12+
import org.mapleir.stdlib.util.TabbedStringWriter;
13+
import org.objectweb.asm.tree.ClassNode;
14+
import org.objectweb.asm.tree.MethodNode;
15+
16+
public class ILDecompiler extends JDADecompiler {
17+
@Override
18+
public String decompileClassNode(FileContainer container, ClassNode cn) {
19+
TabbedStringWriter sw = new TabbedStringWriter();
20+
sw.setTabString(" ");
21+
IPropertyDictionary settings = PropertyHelper.createDictionary();
22+
final FieldNodePrinter fieldPrinter = new FieldNodePrinter(sw, settings);
23+
final MethodNodePrinter methodPrinter = new MethodNodePrinter(sw, settings) {
24+
@Override
25+
protected ControlFlowGraph getCfg(MethodNode mn) {
26+
ControlFlowGraph cfg = MaplePlugin.cxts.get(container).getIRCache().getFor(mn);
27+
BoissinotDestructor.leaveSSA(cfg);
28+
cfg.getLocals().realloc(cfg);
29+
return cfg;
30+
}
31+
};
32+
ClassPrinter cp = new ClassPrinter(sw, settings, fieldPrinter, methodPrinter);
33+
cp.print(cn);
34+
return sw.toString();
35+
}
36+
37+
@Override
38+
public void decompileToZip(String zipName) {
39+
40+
}
41+
42+
@Override
43+
public String getName() {
44+
return "MapleIL";
45+
}
46+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.decompilers.bytecode.*;
4+
import org.mapleir.ir.algorithms.BoissinotDestructor;
5+
import org.mapleir.ir.cfg.ControlFlowGraph;
6+
import org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder;
7+
import org.objectweb.asm.tree.ClassNode;
8+
import org.objectweb.asm.tree.MethodNode;
9+
10+
import java.util.ArrayList;
11+
import java.util.Arrays;
12+
import java.util.Iterator;
13+
14+
public class IRDecompiler extends BytecodeDecompiler {
15+
@Override
16+
protected MethodNodeDecompiler getMethodNodeDecompiler(PrefixedStringBuilder sb, ClassNode cn, Iterator<MethodNode> it) {
17+
return new IRMethodDecompiler(this, sb, it.next(), cn);
18+
}
19+
20+
@Override
21+
public void decompileToZip(String zipName) {
22+
}
23+
24+
@Override
25+
public String getName() {
26+
return "MapleIR";
27+
}
28+
}
29+
30+
class IRMethodDecompiler extends MethodNodeDecompiler {
31+
public IRMethodDecompiler(BytecodeDecompiler parent, PrefixedStringBuilder sb, MethodNode mn, ClassNode cn) {
32+
super(parent, sb, mn, cn);
33+
}
34+
35+
@Override
36+
protected InstructionPrinter getInstructionPrinter(MethodNode m, TypeAndName[] args) {
37+
return new IRInstructionPrinter(this, m, args);
38+
}
39+
}
40+
41+
class IRInstructionPrinter extends InstructionPrinter {
42+
public IRInstructionPrinter(MethodNodeDecompiler parent, MethodNode m, TypeAndName[] args) {
43+
super(parent, m, args);
44+
}
45+
46+
@Override
47+
public ArrayList<String> createPrint() {
48+
ControlFlowGraph cfg = ControlFlowGraphBuilder.build(mNode);
49+
BoissinotDestructor.leaveSSA(cfg);
50+
cfg.getLocals().realloc(cfg);
51+
String result = cfg.toString();
52+
return new ArrayList<>(Arrays.asList(result.split("\n")));
53+
}
54+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.FileContainer;
4+
import club.bytecode.the.jda.api.JDAPlugin;
5+
import club.bytecode.the.jda.decompilers.Decompilers;
6+
import club.bytecode.the.jda.decompilers.JDADecompiler;
7+
import org.mapleir.DefaultInvocationResolver;
8+
import org.mapleir.app.client.SimpleApplicationContext;
9+
import org.mapleir.app.service.ApplicationClassSource;
10+
import org.mapleir.context.AnalysisContext;
11+
import org.mapleir.context.BasicAnalysisContext;
12+
import org.mapleir.context.IRCache;
13+
import org.mapleir.ir.cfg.builder.ControlFlowGraphBuilder;
14+
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
15+
16+
import java.util.HashMap;
17+
import java.util.Map;
18+
19+
public class MaplePlugin implements JDAPlugin {
20+
public static final Map<FileContainer, AnalysisContext> cxts = new HashMap<>();
21+
public static final JDADecompiler MAPLEIR = new IRDecompiler();
22+
public static final JDADecompiler MAPLEIL = new ILDecompiler();
23+
24+
public MaplePlugin() {
25+
}
26+
27+
public static void main(String[] args) {
28+
throw new NotImplementedException();
29+
}
30+
31+
@Override
32+
public String getName() {
33+
return "MapleIR";
34+
}
35+
36+
@Override
37+
public void onLoad() {
38+
Decompilers.BY_NAME.put("MapleIR", MAPLEIR);
39+
Decompilers.BY_NAME.put("MapleIL", MAPLEIL);
40+
System.out.println("MapleIR plugin loaded");
41+
}
42+
43+
@Override
44+
public void onUnload() {
45+
46+
}
47+
48+
@Override
49+
public void onGUILoad() {
50+
}
51+
52+
@Override
53+
public void onExit() {
54+
}
55+
56+
@Override
57+
public void onOpenFile(FileContainer fileContainer) {
58+
ApplicationClassSource app = new ApplicationClassSource(fileContainer.name, fileContainer.getClasses());
59+
AnalysisContext newCxt = new BasicAnalysisContext.BasicContextBuilder()
60+
.setApplication(app)
61+
.setInvocationResolver(new DefaultInvocationResolver(app))
62+
.setCache(new IRCache(ControlFlowGraphBuilder::build))
63+
.setApplicationContext(new SimpleApplicationContext(app))
64+
.build();
65+
cxts.put(fileContainer, newCxt);
66+
}
67+
68+
@Override
69+
public void onCloseFile(FileContainer fc) {
70+
cxts.remove(fc);
71+
}
72+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.mapleir.jdaplugin;
2+
3+
import club.bytecode.the.jda.JDA;
4+
5+
/**
6+
* Quick dependency injector to hack the circular reference so I can debug this plugin in my IDE
7+
*/
8+
public class MapleInjectedJDA {
9+
public static void main(String[] args) {
10+
JDA.injectedPlugin = MaplePlugin::new;
11+
JDA.main(args);
12+
}
13+
}

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>groupId</groupId>
7+
<groupId>club.bytecode.the</groupId>
88
<artifactId>jda</artifactId>
99
<version>0.0.8</version>
1010

@@ -48,6 +48,8 @@
4848
<mainClass>club.bytecode.the.jda.JDA</mainClass>
4949
</transformer>
5050
</transformers>
51+
<shadedArtifactAttached>true</shadedArtifactAttached>
52+
<shadedClassifierName>with-deps</shadedClassifierName> <!-- custom name -->
5153
</configuration>
5254
</execution>
5355
</executions>
@@ -146,5 +148,10 @@
146148
<artifactId>procyon-compilertools</artifactId>
147149
<version>0.5.32</version>
148150
</dependency>
151+
<dependency>
152+
<groupId>org.mapleir</groupId>
153+
<artifactId>modasm</artifactId>
154+
<version>0.0.1-ALPHA</version>
155+
</dependency>
149156
</dependencies>
150157
</project>

0 commit comments

Comments
 (0)