Skip to content

Commit 8becf3d

Browse files
authored
Merge pull request #861 from Janmm14/fix-context-new-thread
Fix context not copying all necessary data to new thread
2 parents 84a3bda + ed7738d commit 8becf3d

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/main/java/com/javadeobfuscator/deobfuscator/executor/Context.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,32 @@ public class Context { //FIXME clinit classes
1717
public Provider provider;
1818
public Map<String, ClassNode> dictionary;
1919
public Map<ClassNode, ConstantPool> constantPools;
20-
public final Map<AbstractInsnNode, BiFunction<List<JavaValue>, Context, JavaValue>> customMethodFunc = new HashMap<>();
21-
public final ThreadStore threadStore = new ThreadStore();
22-
public final Monitor monitor = new Monitor();
20+
public Map<AbstractInsnNode, BiFunction<List<JavaValue>, Context, JavaValue>> customMethodFunc = new HashMap<>();
21+
public ThreadStore threadStore = new ThreadStore();
22+
public Monitor monitor = new Monitor();
2323

24-
public Set<String> clinit = new HashSet<>();
24+
public Set<String> clinit = Collections.synchronizedSet(new HashSet<>());
2525

2626
public File file;
2727

2828
public Context(Provider provider) {
2929
this.provider = provider;
3030
}
3131

32+
public Context copyForNewThread() {
33+
Context threadContext = new Context(provider);
34+
threadContext.dictionary = dictionary;
35+
threadContext.constantPools = constantPools;
36+
threadContext.customMethodFunc = customMethodFunc;
37+
threadContext.threadStore = threadStore;
38+
threadContext.monitor = monitor;
39+
threadContext.clinit = clinit;
40+
threadContext.file = file;
41+
threadContext.breakpointsBefore = breakpointsBefore;
42+
threadContext.breakpointsAfter = breakpointsAfter;
43+
return threadContext;
44+
}
45+
3246
public StackTraceElement at(int index) {
3347
return stackTrace.get(index);
3448
}
@@ -64,8 +78,8 @@ public void clearStackTrace() {
6478
stackTrace.clear();
6579
}
6680

67-
private final Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsBefore = new HashMap<>();
68-
private final Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsAfter = new HashMap<>();
81+
private Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsBefore = new HashMap<>();
82+
private Map<AbstractInsnNode, Consumer<BreakpointInfo>> breakpointsAfter = new HashMap<>();
6983

7084
public void doBreakpoint(AbstractInsnNode now, boolean before, List<JavaValue> stack, List<JavaValue> locals, Object tothrow) {
7185
if (before && breakpointsBefore.containsKey(now)) {

src/main/java/com/javadeobfuscator/deobfuscator/executor/defined/types/JavaThread.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public void start() {
4444
if (classNode != null) {
4545
MethodNode method = classNode.methods.stream().filter(mn -> mn.name.equals("run") && mn.desc.equals("()V")).findFirst().orElse(null);
4646
if (method != null) {
47-
Context threadContext = new Context(context.provider);
48-
threadContext.dictionary = context.dictionary;
49-
threadContext.file = context.file;
47+
Context threadContext = context.copyForNewThread();
5048

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

0 commit comments

Comments
 (0)