Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
refactor: strip down optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
zlataovce committed Aug 20, 2024
1 parent b0745a3 commit fc29843
Show file tree
Hide file tree
Showing 11 changed files with 1,353 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ For use as a library, see [how the CLI uses it](./cli/src/main/java/run/slicer/p
For use of the actual CLI, grab a build from GitHub Packages and run it with the `--help` option, you should see something like this:

```
Usage: poke [-hV] [--[no-]optimize] [--[no-]verify] [-p=<passes>] <input>
<output>
Usage: poke [-hV] [--[no-]inline] [--[no-]optimize] [--[no-]verify]
[-p=<passes>] <input> <output>
A Java library for performing bytecode normalization and generic deobfuscation.
<input> The class/JAR file to be analyzed.
<output> The analyzed class/JAR file destination.
-h, --help Show this help message and exit.
--[no-]inline Performs method inlining.
--[no-]optimize Performs optimizations.
-p, --passes=<passes> The amount of optimization passes.
-V, --version Print version information and exit.
--[no-]verify Performs preemptive verification and correction.
```

In most use cases, you'll want to use both `--optimize` and `--verify` with a decent amount of passes (5-10).
In most use cases, you'll want to use `--optimize`, `--verify` and `--inline` with a decent amount of passes (5-10).

## Licensing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "run.slicer"
version = "1.0.2"
version = "1.0.3"
description = "A Java library for performing bytecode normalization and generic deobfuscation."

repositories {
Expand Down
4 changes: 4 additions & 0 deletions cli/src/main/java/run/slicer/poke/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ public final class Main implements Callable<Integer> {
@CommandLine.Option(names = "--verify", description = "Performs preemptive verification and correction.", negatable = true)
private boolean verify;

@CommandLine.Option(names = "--inline", description = "Performs method inlining.", negatable = true)
private boolean inline;

@Override
public Integer call() throws Exception {
final Analyzer analyzer = Analyzer.builder()
.passes(this.passes)
.optimize(this.optimize)
.verify(this.verify)
.inline(this.inline)
.build();

boolean isClass = false;
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/run/slicer/poke/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ default Builder optimize() {
return this.optimize(true);
}

Builder inline(boolean inline);

default Builder inline() {
return this.inline(true);
}

Analyzer build();
}
}
17 changes: 14 additions & 3 deletions core/src/main/java/run/slicer/poke/AnalyzerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import proguard.classfile.pass.PrimitiveArrayConstantIntroducer;
import proguard.classfile.util.PrimitiveArrayConstantReplacer;
import proguard.optimize.LineNumberTrimmer;
import proguard.optimize.Optimizer;
import proguard.optimize.peephole.LineNumberLinearizer;
import proguard.preverify.PreverificationClearer;
import proguard.preverify.Preverifier;
import proguard.preverify.SubroutineInliner;
import run.slicer.poke.proguard.Optimizer;

import java.io.*;
import java.util.ArrayList;
Expand Down Expand Up @@ -90,6 +90,7 @@ static final class Builder implements Analyzer.Builder {
private int passes = 1;
private boolean verify = false;
private boolean optimize = false;
private boolean inline = false;

Builder() {
}
Expand All @@ -116,23 +117,33 @@ public Builder optimize(boolean optimize) {
return this;
}

@Override
public Builder inline(boolean inline) {
this.inline = inline;
return this;
}

@Override
public Analyzer build() {
final var config = new Configuration();

config.optimize = this.optimize;
config.preverify = this.verify;
config.keep = List.of();
config.optimizationPasses = this.passes;

final List<String> optimizations = new ArrayList<>(List.of(
"field/*",
"method/generalization/*",
"method/specialization/*",
"method/propagation/*",
"method/inlining/*",
"code/merging",
"code/removal/*",
"code/allocation/*"
));

if (this.inline) {
optimizations.add("method/inlining/*");
}
if (PEEPHOLE) {
optimizations.add("code/simplification/variable");
optimizations.add("code/simplification/arithmetic");
Expand Down
Loading

0 comments on commit fc29843

Please sign in to comment.