Skip to content

Commit

Permalink
pop useless var load and dup2
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Jan 6, 2025
1 parent 3b46fb8 commit 7eea5b9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 34 deletions.
12 changes: 11 additions & 1 deletion deobfuscator-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<asm.version>9.7.1</asm.version>
<!--
We need to use a snapshot version of asm lib as there are some recent important changes to it
that are not in a release version yet:
- https://gitlab.ow2.org/asm/asm/-/merge_requests/418
-->
<asm.version>9.8-SNAPSHOT</asm.version>

<log4j.version>2.23.1</log4j.version>
<slf4j.version>2.0.13</slf4j.version>
Expand All @@ -30,6 +35,11 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

<repository>
<id>ow2-repo</id>
<url>https://repository.ow2.org/nexus/content/repositories/snapshots</url>
</repository>
</repositories>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class UselessPopCleanTransformer extends Transformer {
public UselessPopCleanTransformer() {
this.rerunOnChange = true;
}

private final Set<AbstractInsnNode> poppedDups = new HashSet<>();
private final Set<AbstractInsnNode> poppedInsns = ConcurrentHashMap.newKeySet();

@Override
protected void transform() throws Exception {
Expand Down Expand Up @@ -87,10 +87,15 @@ private boolean canPop(OriginalSourceValue sourceValue) {

// Check if all producers of the source value are constants
for (AbstractInsnNode producer : sourceValue.insns) {
// Prevent popping instructions twice (especially DUPs)
if (poppedInsns.contains(producer)) return false;

// Can be popped if the value is constant
if (producer.isConstant()) continue;
// Can be popped if the value is DUP, and it wasn't popped yet
if (producer.getOpcode() == DUP && !poppedDups.contains(producer)) continue;
// Can be popped if the value is DUP or DUP2
if (producer.getOpcode() == DUP || producer.getOpcode() == DUP2) continue;
// Can be popped if value is a local variable
if (producer.isVarLoad()) continue;

return false;
}
Expand All @@ -99,10 +104,9 @@ private boolean canPop(OriginalSourceValue sourceValue) {

private void popSourceValue(OriginalSourceValue value, MethodNode methodNode) {
for (AbstractInsnNode producer : value.insns) {
if (producer.getOpcode() == DUP) {
// Prevent popping DUP twice
poppedDups.add(producer);
}
// Prevent popping instructions twice (especially DUPs)
poppedInsns.add(producer);

methodNode.instructions.remove(producer);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public final class PacketEvents implements Listener, EventManager {
int var17;
PacketEvents var24;
label89: {
long var1 = 37314761108082L;
var3 = 100924278520616L;
var5 = 26099128416120L;
var7 = 127830791373044L;
Expand Down Expand Up @@ -318,7 +317,6 @@ public final class PacketEvents implements Listener, EventManager {
Runnable var6;
label37: {
var6 = () -> {
long var1x = 66876338785522L;
long var3 = 119084676127620L;
long var5x = 123797029215992L;
Bukkit.getPluginManager().registerEvents(this.bukkitEventProcessorInternal, plugin);
Expand Down Expand Up @@ -373,7 +371,6 @@ public final class PacketEvents implements Listener, EventManager {
}

public void Vulcan_o() {
long var1 = 47666491843353L;
long var3 = 94080624911225L;
long var5 = 53297714112873L;
int var7 = Vulcan_Q();
Expand Down Expand Up @@ -498,7 +495,6 @@ public final class PacketEvents implements Listener, EventManager {
}

Thread var4 = new Thread(() -> {
long var1 = 73114304934084L;
long var3x = 71820540609001L;
int var10000x = Vulcan_a();
this.Vulcan_a().getLogger().info("[packetevents] Checking for an update, please wait...");
Expand Down
34 changes: 16 additions & 18 deletions testData/results/custom-classes/zkm/sample2/a/a/a/a/a_.dec
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public class a_<T> implements Serializable {
@Deprecated
public static a_ a(Comparable var0, Comparable var1, long var2) {
var2 = 104039320445854L ^ var2;
long var10001 = var2 ^ 126902786326681L;
long var10000 = var2 ^ 126902786326681L;
int var5 = (int)((var2 ^ 126902786326681L) >>> 48);
int var6 = (int)((var2 ^ 126902786326681L) << 16 >>> 32);
int var7 = (int)(var10001 << 48 >>> 48);
char var10000 = (char)var5;
int var7 = (int)(var10000 << 48 >>> 48);
char var9 = (char)var5;
Object[] var10007 = new Object[]{null, null, null, null, null, var7};
var10007[4] = var6;
var10007[3] = null;
var10007[2] = var1;
var10007[1] = var0;
var10007[0] = Integer.valueOf(var10000);
var10007[0] = Integer.valueOf(var9);
return f(var10007);
}

Expand All @@ -58,49 +58,49 @@ public class a_<T> implements Serializable {

public static a_ c(long var0, Comparable var2) {
var0 = 104039320445854L ^ var0;
long var10001 = var0 ^ 18483036967427L;
long var10000 = var0 ^ 18483036967427L;
int var4 = (int)((var0 ^ 18483036967427L) >>> 48);
int var5 = (int)((var0 ^ 18483036967427L) << 16 >>> 32);
int var6 = (int)(var10001 << 48 >>> 48);
char var10000 = (char)var4;
int var6 = (int)(var10000 << 48 >>> 48);
char var8 = (char)var4;
Object[] var10007 = new Object[]{null, null, null, null, null, var6};
var10007[4] = var5;
var10007[3] = null;
var10007[2] = var2;
var10007[1] = var2;
var10007[0] = Integer.valueOf(var10000);
var10007[0] = Integer.valueOf(var8);
return f(var10007);
}

public static a_ d(Object var0, long var1, Comparator var3) {
var1 = 104039320445854L ^ var1;
long var10001 = var1 ^ 21537914483950L;
long var10000 = var1 ^ 21537914483950L;
int var5 = (int)((var1 ^ 21537914483950L) >>> 48);
int var6 = (int)((var1 ^ 21537914483950L) << 16 >>> 32);
int var7 = (int)(var10001 << 48 >>> 48);
char var10000 = (char)var5;
int var7 = (int)(var10000 << 48 >>> 48);
char var9 = (char)var5;
Object[] var10007 = new Object[]{null, null, null, null, null, var7};
var10007[4] = var6;
var10007[3] = var3;
var10007[2] = var0;
var10007[1] = var0;
var10007[0] = Integer.valueOf(var10000);
var10007[0] = Integer.valueOf(var9);
return f(var10007);
}

public static a_ e(long var0, Comparable var2, Comparable var3) {
var0 = 104039320445854L ^ var0;
long var10001 = var0 ^ 30036545302711L;
long var10000 = var0 ^ 30036545302711L;
int var5 = (int)((var0 ^ 30036545302711L) >>> 48);
int var6 = (int)((var0 ^ 30036545302711L) << 16 >>> 32);
int var7 = (int)(var10001 << 48 >>> 48);
char var10000 = (char)var5;
int var7 = (int)(var10000 << 48 >>> 48);
char var9 = (char)var5;
Object[] var10007 = new Object[]{null, null, null, null, null, var7};
var10007[4] = var6;
var10007[3] = null;
var10007[2] = var3;
var10007[1] = var2;
var10007[0] = Integer.valueOf(var10000);
var10007[0] = Integer.valueOf(var9);
return f(var10007);
}

Expand Down Expand Up @@ -190,7 +190,6 @@ public class a_<T> implements Serializable {
}

public int hashCode() {
long var1 = 98334368194806L;
int var3 = this.b;
if (this.b == 0) {
int var4 = b<"m">(26604, 8453020672365342500L);
Expand Down Expand Up @@ -343,7 +342,6 @@ public class a_<T> implements Serializable {
}

public String toString() {
long var1 = 15341762901975L;
if (this.e == null) {
this.e = "[" + this.d + a<"c">(18317, 6648620723262088254L) + this.c + "]";
}
Expand Down
1 change: 0 additions & 1 deletion testData/results/custom-jars/SnakeGame-obf-zkm/Main.dec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class Main {
private static final Integer[] c;

public static void main(String[] var0) {
long var1 = 53836601486112L;
e var3 = new e();
var3.setTitle(a);
var3.setSize(a(23704, 8408508685984484905L), a(21193, 5113680640368394361L));
Expand Down
1 change: 0 additions & 1 deletion testData/results/custom-jars/SnakeGame-obf-zkm/d.dec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public class d extends Thread {
}

public void run() {
long var1 = 89995196843699L;
long var3 = 12972172530972L;
long var5 = 121593940001805L;
long var7 = 41896598891982L;
Expand Down
1 change: 0 additions & 1 deletion testData/results/custom-jars/SnakeGame-obf-zkm/e.dec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class e extends JFrame {
private static final Integer[] e;

public e() {
long var1 = 71224974300475L;
long var3 = 61070374780970L;
byte var10000 = d.h;
super();
Expand Down

0 comments on commit 7eea5b9

Please sign in to comment.