Skip to content

Commit

Permalink
Merge pull request java-deobfuscator#861 from Janmm14/fix-context-new…
Browse files Browse the repository at this point in the history
…-thread

Fix context not copying all necessary data to new thread
  • Loading branch information
ThisTestUser authored Jan 10, 2022
2 parents 84a3bda + ed7738d commit 8becf3d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,32 @@ public class Context { //FIXME clinit classes
public Provider provider;
public Map<String, ClassNode> dictionary;
public Map<ClassNode, ConstantPool> constantPools;
public final Map<AbstractInsnNode, BiFunction<List<JavaValue>, Context, JavaValue>> customMethodFunc = new HashMap<>();
public final ThreadStore threadStore = new ThreadStore();
public final Monitor monitor = new Monitor();
public Map<AbstractInsnNode, BiFunction<List<JavaValue>, Context, JavaValue>> customMethodFunc = new HashMap<>();
public ThreadStore threadStore = new ThreadStore();
public Monitor monitor = new Monitor();

public Set<String> clinit = new HashSet<>();
public Set<String> clinit = Collections.synchronizedSet(new HashSet<>());

public File file;

public Context(Provider provider) {
this.provider = provider;
}

public Context copyForNewThread() {
Context threadContext = new Context(provider);
threadContext.dictionary = dictionary;
threadContext.constantPools = constantPools;
threadContext.customMethodFunc = customMethodFunc;
threadContext.threadStore = threadStore;
threadContext.monitor = monitor;
threadContext.clinit = clinit;
threadContext.file = file;
threadContext.breakpointsBefore = breakpointsBefore;
threadContext.breakpointsAfter = breakpointsAfter;
return threadContext;
}

public StackTraceElement at(int index) {
return stackTrace.get(index);
}
Expand Down Expand Up @@ -64,8 +78,8 @@ public void clearStackTrace() {
stackTrace.clear();
}

private final Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsBefore = new HashMap<>();
private final Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsAfter = new HashMap<>();
private Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsBefore = new HashMap<>();
private Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsAfter = new HashMap<>();

public void doBreakpoint(AbstractInsnNode now, boolean before, List<JavaValue> stack, List<JavaValue> locals, Object tothrow) {
if (before && breakpointsBefore.containsKey(now)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public void start() {
if (classNode != null) {
MethodNode method = classNode.methods.stream().filter(mn -> mn.name.equals("run") && mn.desc.equals("()V")).findFirst().orElse(null);
if (method != null) {
Context threadContext = new Context(context.provider);
threadContext.dictionary = context.dictionary;
threadContext.file = context.file;
Context threadContext = context.copyForNewThread();

thread = new Thread(() -> MethodExecutor.execute(classNode, method, Collections.emptyList(), instance, threadContext));
context.threadStore.addThread(thread.getId(), this);
Expand Down

0 comments on commit 8becf3d

Please sign in to comment.