-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7eea5b9
commit 9fea3f9
Showing
15 changed files
with
367 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/asm/matcher/impl/FrameMatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package uwu.narumi.deobfuscator.api.asm.matcher.impl; | ||
|
||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.analysis.Frame; | ||
import org.objectweb.asm.tree.analysis.OriginalSourceValue; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.Match; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.MatchContext; | ||
|
||
/** | ||
* Match instruction from stack | ||
*/ | ||
public class FrameMatch extends Match { | ||
private final Match match; | ||
private final FrameMatchOptions options; | ||
|
||
/** | ||
* @param match A {@link Match} to match against that stack value | ||
* @param options Options for the frame match | ||
*/ | ||
private FrameMatch(Match match, FrameMatchOptions options) { | ||
this.match = match; | ||
this.options = options; | ||
} | ||
|
||
public static FrameMatch stack(int stackValueIdx, Match match) { | ||
return new FrameMatch(match, new StackFrameOptions(stackValueIdx, false)); | ||
} | ||
|
||
public static FrameMatch stackOriginal(int stackValueIdx, Match match) { | ||
return new FrameMatch(match, new StackFrameOptions(stackValueIdx, true)); | ||
} | ||
|
||
public static FrameMatch localVariable(int localVariableIdx, Match match) { | ||
return new FrameMatch(match, new LocalVariableFrameOptions(localVariableIdx)); | ||
} | ||
|
||
@Override | ||
protected boolean test(MatchContext context) { | ||
if (context.insnContext().methodContext().frames() == null) { | ||
throw new IllegalStateException("Got frameless method context"); | ||
} | ||
|
||
if (context.frame() == null) { | ||
// If we expect stack values, then frame can't be null | ||
return false; | ||
} | ||
|
||
// Get the source value | ||
OriginalSourceValue sourceValue; | ||
if (this.options instanceof StackFrameOptions stackFrameOptions) { | ||
// Pop values from stack and match them | ||
int index = context.frame().getStackSize() - (stackFrameOptions.stackValueIdx + 1); | ||
if (index < 0) { | ||
// If the stack value should exist but does not, then it does not match | ||
return false; | ||
} | ||
|
||
if (this.match instanceof SkipMatch) { | ||
// Skip match earlier | ||
return true; | ||
} | ||
|
||
Frame<OriginalSourceValue> frame = context.frame(); | ||
sourceValue = frame.getStack(index); | ||
if (stackFrameOptions.originalValue) { | ||
sourceValue = sourceValue.originalSource; | ||
} | ||
} else if (this.options instanceof LocalVariableFrameOptions lvFrameOptions) { | ||
if (this.match instanceof SkipMatch) { | ||
// Skip match earlier | ||
return true; | ||
} | ||
|
||
Frame<OriginalSourceValue> frame = context.frame(); | ||
sourceValue = frame.getLocal(lvFrameOptions.localVariableIdx); | ||
} else { | ||
throw new IllegalStateException("Unknown frame match options"); | ||
} | ||
|
||
if (!sourceValue.isOneWayProduced()) { | ||
// We only want stack values that are one way produced | ||
return false; | ||
} | ||
|
||
AbstractInsnNode stackValueInsn = sourceValue.getProducer(); | ||
return this.match.matchAndMerge(context.insnContext().of(stackValueInsn), context); | ||
} | ||
|
||
sealed interface FrameMatchOptions permits StackFrameOptions, LocalVariableFrameOptions { | ||
} | ||
|
||
/** | ||
* @param stackValueIdx Index of the value in the stack, starting from the top of the stack, so '0' is the top value. | ||
* @param originalValue | ||
*/ | ||
record StackFrameOptions(int stackValueIdx, boolean originalValue) implements FrameMatchOptions { | ||
} | ||
|
||
record LocalVariableFrameOptions(int localVariableIdx) implements FrameMatchOptions { | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/asm/matcher/impl/StackMatch.java
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...fuscator-api/src/main/java/uwu/narumi/deobfuscator/api/asm/matcher/impl/VarLoadMatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package uwu.narumi.deobfuscator.api.asm.matcher.impl; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.Match; | ||
import uwu.narumi.deobfuscator.api.asm.matcher.MatchContext; | ||
|
||
public class VarLoadMatch extends Match { | ||
private Match localStoreMatch = null; | ||
|
||
private VarLoadMatch() { | ||
} | ||
|
||
public static VarLoadMatch of() { | ||
return new VarLoadMatch(); | ||
} | ||
|
||
/** | ||
* Match local variable store instruction of this variable | ||
*/ | ||
public VarLoadMatch localStoreMatch(@Nullable Match match) { | ||
this.localStoreMatch = match; | ||
return this; | ||
} | ||
|
||
@Override | ||
protected boolean test(MatchContext context) { | ||
boolean matches = context.insnContext().insn().isVarLoad(); | ||
|
||
// Match local variable store instruction | ||
if (matches && localStoreMatch != null) { | ||
VarInsnNode varInsn = (VarInsnNode) context.insnContext().insn(); | ||
|
||
matches = FrameMatch.localVariable(varInsn.var, localStoreMatch).matchAndMerge(context.insnContext(), context); | ||
} | ||
|
||
return matches; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...main/java/uwu/narumi/deobfuscator/core/other/composed/ComposedUnknownObf1Transformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package uwu.narumi.deobfuscator.core.other.composed; | ||
|
||
import uwu.narumi.deobfuscator.api.transformer.ComposedTransformer; | ||
import uwu.narumi.deobfuscator.core.other.composed.general.ComposedGeneralFlowTransformer; | ||
import uwu.narumi.deobfuscator.core.other.impl.clean.LocalVariableNamesCleanTransformer; | ||
import uwu.narumi.deobfuscator.core.other.impl.unknown.obf1.UnknownObf1_StringByteArrayTransformer; | ||
|
||
public class ComposedUnknownObf1Transformer extends ComposedTransformer { | ||
public ComposedUnknownObf1Transformer() { | ||
super( | ||
// Remove local variables names | ||
LocalVariableNamesCleanTransformer::new, | ||
|
||
// Fix flow | ||
ComposedGeneralFlowTransformer::new, | ||
|
||
// Decrypt strings | ||
UnknownObf1_StringByteArrayTransformer::new | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.