-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from EpicPlayerA10/fix/method-matcher
Fix method matcher wrongly matching method names
- Loading branch information
Showing
9 changed files
with
130 additions
and
37 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
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
38 changes: 38 additions & 0 deletions
38
...ain/java/uwu/narumi/deobfuscator/core/other/impl/clean/InvalidMethodCleanTransformer.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,38 @@ | ||
package uwu.narumi.deobfuscator.core.other.impl.clean; | ||
|
||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.analysis.Analyzer; | ||
import org.objectweb.asm.tree.analysis.AnalyzerException; | ||
import org.objectweb.asm.tree.analysis.BasicInterpreter; | ||
import uwu.narumi.deobfuscator.api.asm.ClassWrapper; | ||
import uwu.narumi.deobfuscator.api.context.Context; | ||
import uwu.narumi.deobfuscator.api.transformer.Transformer; | ||
|
||
/** | ||
* Remove invalid methods. WARNING: If some transformer will produce invalid bytecode in methods, this transformer will remove them. | ||
*/ | ||
public class InvalidMethodCleanTransformer extends Transformer { | ||
private boolean changed = false; | ||
|
||
@Override | ||
protected boolean transform(ClassWrapper scope, Context context) throws Exception { | ||
context.classes(scope).forEach(classWrapper -> { | ||
var iterator = classWrapper.methods().iterator(); | ||
while (iterator.hasNext()) { | ||
MethodNode methodNode = iterator.next(); | ||
|
||
Analyzer<?> analyzer = new Analyzer<>(new BasicInterpreter()); | ||
try { | ||
analyzer.analyze(classWrapper.name(), methodNode); | ||
} catch (AnalyzerException e) { | ||
// Remove invalid method | ||
LOGGER.warn("Found invalid method: {}#{}{}. Removing...", classWrapper.name(), methodNode.name, methodNode.desc); | ||
iterator.remove(); | ||
changed = true; | ||
} | ||
} | ||
}); | ||
|
||
return changed; | ||
} | ||
} |
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
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
28 changes: 28 additions & 0 deletions
28
testData/results/java/TestInlineStaticFieldsWithModification.dec
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,28 @@ | ||
import java.io.File; | ||
|
||
public class TestInlineStaticFieldsWithModification { | ||
private static final char SYSTEM_SEPARATOR = File.separatorChar; | ||
private static final char OTHER_SEPARATOR; | ||
|
||
private static int getAdsCriticalOffset(String fileName) { | ||
int offset1 = fileName.lastIndexOf(SYSTEM_SEPARATOR); | ||
int offset2 = fileName.lastIndexOf(92); | ||
if (offset1 == -1) { | ||
return offset2 == -1 ? 0 : offset2 + 1; | ||
} else { | ||
return offset2 == -1 ? offset1 + 1 : Math.max(offset1, offset2) + 1; | ||
} | ||
} | ||
|
||
static boolean isSystemWindows() { | ||
return SYSTEM_SEPARATOR == '\\'; | ||
} | ||
|
||
static { | ||
if (isSystemWindows()) { | ||
OTHER_SEPARATOR = '/'; | ||
} else { | ||
OTHER_SEPARATOR = '\\'; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
testData/src/java/src/main/java/TestInlineStaticFieldsWithModification.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,28 @@ | ||
import java.io.File; | ||
|
||
public class TestInlineStaticFieldsWithModification { | ||
private static final char SYSTEM_SEPARATOR = File.separatorChar; | ||
private static final char OTHER_SEPARATOR; | ||
|
||
private static int getAdsCriticalOffset(String fileName) { | ||
int offset1 = fileName.lastIndexOf(SYSTEM_SEPARATOR); | ||
int offset2 = fileName.lastIndexOf(OTHER_SEPARATOR); | ||
if (offset1 == -1) { | ||
return offset2 == -1 ? 0 : offset2 + 1; | ||
} else { | ||
return offset2 == -1 ? offset1 + 1 : Math.max(offset1, offset2) + 1; | ||
} | ||
} | ||
|
||
static { | ||
if (isSystemWindows()) { | ||
OTHER_SEPARATOR = '/'; | ||
} else { | ||
OTHER_SEPARATOR = '\\'; | ||
} | ||
} | ||
|
||
static boolean isSystemWindows() { | ||
return SYSTEM_SEPARATOR == '\\'; | ||
} | ||
} |