Skip to content

Commit

Permalink
also pass current frames
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Sep 3, 2024
1 parent d72dd20 commit d7d448b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ public abstract class FramedInstructionsTransformer extends FramedMethodsTransfo
* @param context Current context
* @param classWrapper Current class
* @param methodNode Current method
* @param frames Frames of the current method
* @param insn Current instruction
* @param frame Current frame
* @return If changed
*/
protected abstract boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame);
protected abstract boolean transformInstruction(
Context context,
ClassWrapper classWrapper,
MethodNode methodNode,
Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames,
AbstractInsnNode insn,
Frame<OriginalSourceValue> frame
);

/**
* Returns instructions stream on which the transformer will be iterating
Expand All @@ -45,7 +53,7 @@ protected void transformMethod(Context context, ClassWrapper classWrapper, Metho
if (frame == null) return;

// Run the instruction transformer
boolean transformerChanged = transformInstruction(context, classWrapper, methodNode, insn, frame);
boolean transformerChanged = transformInstruction(context, classWrapper, methodNode, frames, insn, frame);
if (transformerChanged) {
this.markChange();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uwu.narumi.deobfuscator.api.context.Context;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.stream.Stream;

// TODO: Remove pair of DUP and POP
Expand All @@ -21,7 +22,7 @@ protected Stream<AbstractInsnNode> buildInstructionsStream(Stream<AbstractInsnNo
}

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
boolean shouldRemovePop = false;

OriginalSourceValue firstValue = frame.getStack(frame.getStackSize() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import uwu.narumi.deobfuscator.api.context.Context;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.stream.Stream;

/**
Expand All @@ -26,7 +27,7 @@ protected Stream<AbstractInsnNode> buildInstructionsStream(Stream<AbstractInsnNo
}

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
VarInsnNode varInsn = (VarInsnNode) insn;

// Var store instruction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
import uwu.narumi.deobfuscator.api.helper.AsmMathHelper;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.Optional;

public class CleanRedundantJumpsTransformer extends FramedInstructionsTransformer {
@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
if (!(insn instanceof JumpInsnNode jumpInsn)) return false;

Optional<Boolean> optIfResult = AsmMathHelper.predictIf(jumpInsn, frame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import uwu.narumi.deobfuscator.api.helper.AsmMathHelper;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.Optional;

/**
Expand All @@ -22,7 +23,7 @@
public class CleanRedundantSwitchesTransformer extends FramedInstructionsTransformer {

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
if (insn.getOpcode() == LOOKUPSWITCH) {
LookupSwitchInsnNode lookupSwitchInsn = (LookupSwitchInsnNode) insn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uwu.narumi.deobfuscator.api.helper.AsmMathHelper;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.stream.Stream;

/**
Expand All @@ -24,7 +25,7 @@ protected Stream<AbstractInsnNode> buildInstructionsStream(Stream<AbstractInsnNo
}

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
// Get instructions from stack that are passed
OriginalSourceValue value1SourceValue = frame.getStack(frame.getStackSize() - 2);
OriginalSourceValue value2SourceValue = frame.getStack(frame.getStackSize() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import uwu.narumi.deobfuscator.api.helper.AsmMathHelper;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;
import java.util.stream.Stream;

/**
Expand All @@ -23,7 +24,7 @@ protected Stream<AbstractInsnNode> buildInstructionsStream(Stream<AbstractInsnNo
}

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
// Get instructions from stack that are passed
OriginalSourceValue sourceValue = frame.getStack(frame.getStackSize() - 1);
OriginalSourceValue originalSource = sourceValue.originalSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import uwu.narumi.deobfuscator.api.helper.AsmMathHelper;
import uwu.narumi.deobfuscator.api.transformer.FramedInstructionsTransformer;

import java.util.Map;

/**
* Simplifies method calls on constant literals.
*/
public class MethodCallsOnLiteralsTransformer extends FramedInstructionsTransformer {

@Override
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
protected boolean transformInstruction(Context context, ClassWrapper classWrapper, MethodNode methodNode, Map<AbstractInsnNode, Frame<OriginalSourceValue>> frames, AbstractInsnNode insn, Frame<OriginalSourceValue> frame) {
// Transform method calls on literals
for (Match mathMatch : AsmMathHelper.METHOD_CALLS_ON_LITERALS) {
if (mathMatch.test(insn)) {
Expand Down

0 comments on commit d7d448b

Please sign in to comment.