Skip to content

Commit

Permalink
use set instead of list where order doesn't matter
Browse files Browse the repository at this point in the history
  • Loading branch information
EpicPlayerA10 committed Oct 21, 2024
1 parent 01f1de7 commit 1847e08
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import uwu.narumi.deobfuscator.api.asm.MethodContext;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;

public class PopUnUsedLocalVariablesTransformer extends Transformer {

Expand All @@ -19,7 +19,7 @@ protected void transform() throws Exception {
scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> {
MethodContext methodContext = MethodContext.framed(classWrapper, methodNode);

List<VarInsnNode> varStoresInUse = new ArrayList<>();
Set<VarInsnNode> varStoresInUse = new HashSet<>();

// Find all local variables in use
for (AbstractInsnNode insn : methodNode.instructions.toArray()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import uwu.narumi.deobfuscator.api.helper.FramedInstructionsStream;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

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

public class UselessPopCleanTransformer extends Transformer {
public UselessPopCleanTransformer() {
this.rerunOnChange = true;
}

private final List<AbstractInsnNode> poppedDups = new ArrayList<>();
private final Set<AbstractInsnNode> poppedDups = new HashSet<>();

@Override
protected void transform() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import uwu.narumi.deobfuscator.api.helper.MethodHelper;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -92,7 +90,7 @@ protected void transform() throws Exception {
}));

// Replace static fields accesses with corresponding values
List<FieldRef> inlinedFields = new ArrayList<>();
Set<FieldRef> inlinedFields = new HashSet<>();
scopedClasses().forEach(classWrapper -> classWrapper.methods().forEach(methodNode -> {
Arrays.stream(methodNode.instructions.toArray())
.filter(insn -> insn.getOpcode() == GETSTATIC)
Expand All @@ -105,9 +103,7 @@ protected void transform() throws Exception {
methodNode.instructions.set(insn, constValue.clone(null));

// Add to an inlined fields list
if (!inlinedFields.contains(fieldRef)) {
inlinedFields.add(fieldRef);
}
inlinedFields.add(fieldRef);

this.markChange();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import uwu.narumi.deobfuscator.api.helper.AsmHelper;
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ public class ZelixLongEncryptionMPCTransformer extends Transformer {
private final Map<String, String> classInitOrder;

private SandBox sandBox = null;
private final List<String> processedClasses = new ArrayList<>(); // class internal names
private final Set<String> processedClasses = new HashSet<>(); // class internal names

public ZelixLongEncryptionMPCTransformer() {
this.classInitOrder = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import uwu.narumi.deobfuscator.api.transformer.Transformer;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Removes useless try catches. References:
Expand Down Expand Up @@ -64,7 +66,7 @@ protected void transform() throws Exception {
}
});

List<MethodRef> toRemove = new ArrayList<>();
Set<MethodRef> toRemove = new HashSet<>();

// Remove try-catches with these instant return exception methods
classWrapper.methods().forEach(methodNode -> {
Expand All @@ -79,9 +81,7 @@ protected void transform() throws Exception {
// Check if method is returning an exception instantly
if (!instantReturnExceptionMethods.contains(methodRef)) return false;

if (!toRemove.contains(methodRef)) {
toRemove.add(methodRef);
}
toRemove.add(methodRef);

markChange();
return true;
Expand Down

0 comments on commit 1847e08

Please sign in to comment.