Skip to content

Commit

Permalink
remove init obfuscation at all
Browse files Browse the repository at this point in the history
  • Loading branch information
radioegor146 committed May 31, 2022
1 parent b597177 commit 46454ba
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 52 deletions.
3 changes: 1 addition & 2 deletions obfuscator/src/main/java/by/radioegor146/MethodContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class MethodContext {
public ArrayList<Type> argTypes;

public int line;
public int invokeSpecialId;
public List<Integer> stack;
public List<Integer> locals;
public Set<TryCatchBlockNode> tryCatches;
Expand All @@ -51,7 +50,7 @@ public MethodContext(NativeObfuscator obfuscator, MethodNode method, int methodI
this.output = new StringBuilder();
this.nativeMethods = new StringBuilder();

this.line = this.invokeSpecialId = -1;
this.line = -1;
this.stack = new ArrayList<>();
this.locals = new ArrayList<>();
this.tryCatches = new HashSet<>();
Expand Down
14 changes: 5 additions & 9 deletions obfuscator/src/main/java/by/radioegor146/MethodProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import by.radioegor146.instructions.*;
import by.radioegor146.special.ClInitSpecialMethodProcessor;
import by.radioegor146.special.DefaultSpecialMethodProcessor;
import by.radioegor146.special.InitSpecialMethodProcessor;
import by.radioegor146.special.SpecialMethodProcessor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand Down Expand Up @@ -82,7 +81,7 @@ private <T extends AbstractInsnNode> void addHandler(int id, InstructionTypeHand
private SpecialMethodProcessor getSpecialMethodProcessor(String name) {
switch (name) {
case "<init>":
return new InitSpecialMethodProcessor();
return null;
case "<clinit>":
return new ClInitSpecialMethodProcessor();
default:
Expand Down Expand Up @@ -112,6 +111,10 @@ public void processMethod(MethodContext context) {

SpecialMethodProcessor specialMethodProcessor = getSpecialMethodProcessor(method.name);

if (specialMethodProcessor == null) {
throw new RuntimeException(String.format("Could not find special method processor for %s", method.name));
}

output.append("// ").append(Util.escapeCommentString(method.name)).append(Util.escapeCommentString(method.desc)).append("\n");

String methodName = specialMethodProcessor.preProcess(context);
Expand Down Expand Up @@ -244,13 +247,6 @@ public void processMethod(MethodContext context) {

for (int instruction = 0; instruction < method.instructions.size(); ++instruction) {
AbstractInsnNode node = method.instructions.get(instruction);

if (method.name.equals("<init>") && context.invokeSpecialId == -1) {
if (node.getOpcode() == Opcodes.INVOKESPECIAL) {
context.invokeSpecialId = instruction;
}
continue;
}
context.output.append(" // ").append(Util.escapeCommentString(handlers[node.getType()]
.insnToString(context, node))).append("; Stack: ").append(context.stackPointer).append("\n");
handlers[node.getType()].accept(context, node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public void postProcess(MethodContext context) {
context.method.instructions.clear();
if (Util.getFlag(context.clazz.access, Opcodes.ACC_INTERFACE)) {
InsnList list = new InsnList();
for (int i = 0; i <= context.invokeSpecialId; i++) {
list.add(context.method.instructions.get(i));
}
int localVarsPosition = 0;
for (Type arg : context.argTypes) {
list.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition));
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion obfuscator/src/test/java/by/radioegor146/ClassicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public void execute() throws Throwable {
} catch (IOException | RuntimeException e) {
e.printStackTrace(System.err);
throw e;
} finally {
}
}

Expand Down

0 comments on commit 46454ba

Please sign in to comment.