forked from openrs2/openrs2
parent
6425a874fd
commit
9b81c813dd
@ -1,98 +0,0 @@ |
||||
package dev.openrs2.deob.ast; |
||||
|
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
|
||||
import com.github.javaparser.ParserConfiguration; |
||||
import com.github.javaparser.printer.PrettyPrinter; |
||||
import com.github.javaparser.printer.PrettyPrinterConfiguration; |
||||
import com.github.javaparser.symbolsolver.JavaSymbolSolver; |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; |
||||
import com.github.javaparser.utils.SourceRoot; |
||||
import com.google.common.collect.ImmutableList; |
||||
import dev.openrs2.deob.ast.transform.AddSubTransformer; |
||||
import dev.openrs2.deob.ast.transform.BinaryExprOrderTransformer; |
||||
import dev.openrs2.deob.ast.transform.BitMaskTransformer; |
||||
import dev.openrs2.deob.ast.transform.ComplementTransformer; |
||||
import dev.openrs2.deob.ast.transform.EncloseTransformer; |
||||
import dev.openrs2.deob.ast.transform.IfElseTransformer; |
||||
import dev.openrs2.deob.ast.transform.NegativeLiteralTransformer; |
||||
import dev.openrs2.deob.ast.transform.NewInstanceTransformer; |
||||
import dev.openrs2.deob.ast.transform.TernaryTransformer; |
||||
import dev.openrs2.deob.ast.transform.Transformer; |
||||
import dev.openrs2.deob.ast.transform.UnencloseTransformer; |
||||
import dev.openrs2.deob.ast.transform.ValueOfTransformer; |
||||
|
||||
public final class AstDeobfuscator { |
||||
private static final ImmutableList<Transformer> TRANSFORMERS = ImmutableList.of( |
||||
new UnencloseTransformer(), |
||||
new NegativeLiteralTransformer(), |
||||
new ComplementTransformer(), |
||||
new IfElseTransformer(), |
||||
new TernaryTransformer(), |
||||
new BinaryExprOrderTransformer(), |
||||
new AddSubTransformer(), |
||||
new BitMaskTransformer(), |
||||
new ValueOfTransformer(), |
||||
new NewInstanceTransformer(), |
||||
new EncloseTransformer() |
||||
); |
||||
|
||||
public static void main(String[] args) { |
||||
var deobfuscator = new AstDeobfuscator(ImmutableList.of( |
||||
Paths.get("nonfree/client/src/main/java"), |
||||
Paths.get("nonfree/gl/src/main/java"), |
||||
Paths.get("nonfree/gl-dri/src/main/java"), |
||||
Paths.get("nonfree/loader/src/main/java"), |
||||
Paths.get("nonfree/signlink/src/main/java"), |
||||
Paths.get("nonfree/unpack/src/main/java"), |
||||
Paths.get("nonfree/unpacker/src/main/java") |
||||
)); |
||||
deobfuscator.run(); |
||||
} |
||||
|
||||
private final ImmutableList<Path> modules; |
||||
|
||||
public AstDeobfuscator(ImmutableList<Path> modules) { |
||||
this.modules = modules; |
||||
} |
||||
|
||||
public void run() { |
||||
var solver = new CombinedTypeSolver(new ReflectionTypeSolver(true)); |
||||
for (var module : modules) { |
||||
solver.add(new JavaParserTypeSolver(module)); |
||||
} |
||||
|
||||
var config = new ParserConfiguration() |
||||
.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_8) |
||||
.setSymbolResolver(new JavaSymbolSolver(solver)); |
||||
|
||||
var printerConfig = new PrettyPrinterConfiguration() |
||||
.setIndentType(PrettyPrinterConfiguration.IndentType.TABS_WITH_SPACE_ALIGN) |
||||
.setIndentSize(1); |
||||
|
||||
var printer = new PrettyPrinter(printerConfig); |
||||
|
||||
for (var module : modules) { |
||||
var root = new SourceRoot(module, config); |
||||
|
||||
var results = root.tryToParseParallelized(); |
||||
for (var result : results) { |
||||
if (!result.isSuccessful()) { |
||||
throw new IllegalArgumentException(result.toString()); |
||||
} |
||||
} |
||||
|
||||
root.getCompilationUnits().forEach(unit -> { |
||||
TRANSFORMERS.forEach(transformer -> { |
||||
transformer.transform(unit); |
||||
}); |
||||
}); |
||||
|
||||
root.setPrinter(printer::print); |
||||
root.saveAll(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@ |
||||
package dev.openrs2.deob.ast |
||||
|
||||
import com.github.javaparser.ParserConfiguration |
||||
import com.github.javaparser.printer.PrettyPrinter |
||||
import com.github.javaparser.printer.PrettyPrinterConfiguration |
||||
import com.github.javaparser.symbolsolver.JavaSymbolSolver |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver |
||||
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver |
||||
import com.github.javaparser.utils.SourceRoot |
||||
import dev.openrs2.deob.ast.transform.* |
||||
import java.nio.file.Path |
||||
import java.nio.file.Paths |
||||
import java.util.function.Function |
||||
|
||||
class AstDeobfuscator(private val modules: List<Path>) { |
||||
fun run() { |
||||
val solver = CombinedTypeSolver(ReflectionTypeSolver(true)) |
||||
for (module in modules) { |
||||
solver.add(JavaParserTypeSolver(module)) |
||||
} |
||||
|
||||
val config = ParserConfiguration() |
||||
.setLanguageLevel(ParserConfiguration.LanguageLevel.JAVA_8) |
||||
.setSymbolResolver(JavaSymbolSolver(solver)) |
||||
|
||||
val printerConfig = PrettyPrinterConfiguration() |
||||
.setIndentType(PrettyPrinterConfiguration.IndentType.TABS_WITH_SPACE_ALIGN) |
||||
.setIndentSize(1) |
||||
|
||||
val printer = PrettyPrinter(printerConfig) |
||||
|
||||
for (module in modules) { |
||||
val root = SourceRoot(module, config) |
||||
|
||||
val results = root.tryToParseParallelized() |
||||
for (result in results) { |
||||
require(result.isSuccessful) { result } |
||||
} |
||||
|
||||
root.compilationUnits.forEach { unit -> |
||||
TRANSFORMERS.forEach { transformer -> |
||||
transformer.transform(unit) |
||||
} |
||||
} |
||||
|
||||
root.printer = Function(printer::print) |
||||
root.saveAll() |
||||
} |
||||
} |
||||
|
||||
companion object { |
||||
private val TRANSFORMERS = listOf( |
||||
UnencloseTransformer(), |
||||
NegativeLiteralTransformer(), |
||||
ComplementTransformer(), |
||||
IfElseTransformer(), |
||||
TernaryTransformer(), |
||||
BinaryExprOrderTransformer(), |
||||
AddSubTransformer(), |
||||
BitMaskTransformer(), |
||||
ValueOfTransformer(), |
||||
NewInstanceTransformer(), |
||||
EncloseTransformer() |
||||
) |
||||
|
||||
@JvmStatic |
||||
fun main(args: Array<String>) { |
||||
val deobfuscator = AstDeobfuscator( |
||||
listOf( |
||||
Paths.get("nonfree/client/src/main/java"), |
||||
Paths.get("nonfree/gl/src/main/java"), |
||||
Paths.get("nonfree/gl-dri/src/main/java"), |
||||
Paths.get("nonfree/loader/src/main/java"), |
||||
Paths.get("nonfree/signlink/src/main/java"), |
||||
Paths.get("nonfree/unpack/src/main/java"), |
||||
Paths.get("nonfree/unpacker/src/main/java") |
||||
) |
||||
) |
||||
deobfuscator.run() |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue