Skip to content

Commit

Permalink
fix removing redundant pop2
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Oct 4, 2024
1 parent cd3b5a4 commit facba15
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public static FramedInstructionsStream of(ClassWrapper scope, Context context) {
private Function<Stream<ClassWrapper>, Stream<ClassWrapper>> classesStreamModifier = Function.identity();
private Function<Stream<MethodNode>, Stream<MethodNode>> methodsStreamModifier = Function.identity();
private Function<Stream<AbstractInsnNode>, Stream<AbstractInsnNode>> instructionsStreamModifier = Function.identity();
private boolean forceSync = false;

private FramedInstructionsStream(ClassWrapper scope, Context context) {
this.scope = scope;
Expand All @@ -52,11 +53,17 @@ public FramedInstructionsStream editInstructionsStream(Function<Stream<AbstractI
return this;
}

@Contract(" -> this")
public FramedInstructionsStream forceSync() {
this.forceSync = true;
return this;
}

public void forEach(Consumer<InsnContext> consumer) {
// Iterate over classes in parallel
this.classesStreamModifier.apply(this.context.classes(this.scope).parallelStream())
this.classesStreamModifier.apply(this.forceSync ? this.context.classes(this.scope).stream() : this.context.classes(this.scope).parallelStream())
// Iterate over methods in parallel
.forEach(classWrapper -> this.methodsStreamModifier.apply(classWrapper.methods().parallelStream())
.forEach(classWrapper -> this.methodsStreamModifier.apply(this.forceSync ? classWrapper.methods().stream() : classWrapper.methods().parallelStream())
.forEach(methodNode -> {
// Skip if no instructions
if (instructionsStreamModifier.apply(Arrays.stream(methodNode.instructions.toArray())).findAny().isEmpty()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uwu.narumi.deobfuscator.core.other.composed.general.ComposedGeneralFlowTransformer;
import uwu.narumi.deobfuscator.core.other.composed.general.ComposedPeepholeCleanTransformer;
import uwu.narumi.deobfuscator.core.other.impl.clean.peephole.JsrInlinerTransformer;
import uwu.narumi.deobfuscator.core.other.impl.clean.peephole.UselessPopCleanTransformer;
import uwu.narumi.deobfuscator.core.other.impl.pool.InlineLocalVariablesTransformer;
import uwu.narumi.deobfuscator.core.other.impl.pool.InlineStaticFieldTransformer;
import uwu.narumi.deobfuscator.core.other.impl.universal.UniversalNumberTransformer;
Expand Down Expand Up @@ -136,5 +137,7 @@ protected void registerAll() {
Source.of("hp888/ExampleClass"),
Source.of("hp888/Strings") // Obfuscated strings
);

register("POP2 Sample", InputType.CUSTOM_CLASS, List.of(UselessPopCleanTransformer::new), Source.of("Pop2Sample"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class UselessPopCleanTransformer extends Transformer {
public UselessPopCleanTransformer() {
Expand Down Expand Up @@ -57,15 +58,19 @@ private boolean tryRemovePop(InsnContext insnContext) {
// Pop two values from the stack

int index = insnContext.frame().getStackSize() - 2;
OriginalSourceValue secondValue = index >= 0 ? insnContext.frame().getStack(insnContext.frame().getStackSize() - 2) : null;
if (index < 0) return false;
OriginalSourceValue secondValue = insnContext.frame().getStack(index);
if (firstValue.getProducer().getOpcode() == DUP) {
// Extract the original source value from DUP
secondValue = Objects.requireNonNull(secondValue.copiedFrom);
}

// Return if we can't remove the source value
if (secondValue != null && !canPop(secondValue)) return false;
if (!canPop(secondValue)) return false;

// Pop
popSourceValue(firstValue, insnContext.methodNode());
if (secondValue != null) {
popSourceValue(secondValue, insnContext.methodNode());
}
popSourceValue(secondValue, insnContext.methodNode());
}
return true;
}
Expand Down
Binary file added testData/compiled/custom-classes/Pop2Sample.class
Binary file not shown.
65 changes: 65 additions & 0 deletions testData/results/custom-classes/Pop2Sample.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.arlania;

import com.arlania.r.H;
import com.arlania.r.W;
import javax.swing.ImageIcon;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.colorchooser.AbstractColorChooserPanel;

class Ld implements Runnable {
public void run() {
AbstractColorChooserPanel[] var5;
JColorChooser var7;
int var4 = (var5 = (var7 = new JColorChooser()).getChooserPanels()).length;

int var3;
for (int var10000 = var3 = 0; var10000 < var4; var10000 = ++var3) {
String var2;
AbstractColorChooserPanel var6;
switch ((var2 = (var6 = var5[var3]).getDisplayName()).hashCode()) {
case -249666038:
while (false) {
}

if (!var2.equals(H.ALLATORIxDEMO("\u0013\u001a!\u0019#\u0005%\u001e"))) {
continue;
}
break;
case 71851:
if (!var2.equals(W.ALLATORIxDEMO("\"\u0011<"))) {
continue;
}
break;
case 81069:
if (!var2.equals(H.ALLATORIxDEMO("?\u0007/"))) {
continue;
}
break;
case 2072828:
if (!var2.equals(W.ALLATORIxDEMO("\u0001'\u001b!"))) {
continue;
}
break;
default:
continue;
}

var7.removeChooserPanel(var6);
}

var7.setColor(com.arlania.H.Wa[a.ALLATORIxDEMO].KC);
var7.setPreviewPanel(new JPanel());
var7.getSelectionModel().addChangeListener(new BA(a, var7, a.E, a.ALLATORIxDEMO));
Client.ALLATORIxDEMO(var7);
JOptionPane.showMessageDialog(null, var7, a.M, -1, new ImageIcon());
}

Ld(Client var1, int var2, String var3, int var4) {
a.j = var1;
a.ALLATORIxDEMO = var2;
a.M = var3;
a.E = var4;
}
}

0 comments on commit facba15

Please sign in to comment.