Skip to content

Commit 75cc093

Browse files
committed
fix SimpleInterpreter crash when parseInt was given a non-number string
1 parent 9d02f43 commit 75cc093

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

deobfuscator-api/src/main/java/uwu/narumi/deobfuscator/api/helper/SimpleInterpreter.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ public static void registerInterpreter(MethodInterpreter interpreter) {
6262
// Get value from stack
6363
OriginalSourceValue sourceValue = stackValues.get(stackValues.size() - 1);
6464
if (sourceValue.getConstantValue() != null && sourceValue.getConstantValue().value() instanceof String text) {
65-
return OriginalSourceValue.ConstantValue.of(Integer.parseInt(text));
65+
try {
66+
return OriginalSourceValue.ConstantValue.of(Integer.parseInt(text));
67+
} catch (NumberFormatException e) {
68+
return null;
69+
}
6670
}
6771
return null;
6872
}
@@ -79,7 +83,11 @@ public static void registerInterpreter(MethodInterpreter interpreter) {
7983
OriginalSourceValue secondValue = stackValues.get(stackValues.size() - 1);
8084
if (firstValue.getConstantValue() != null && firstValue.getConstantValue().value() instanceof String text &&
8185
secondValue.getConstantValue() != null && secondValue.getConstantValue().value() instanceof Integer radix) {
82-
return OriginalSourceValue.ConstantValue.of(Integer.parseInt(text, radix));
86+
try {
87+
return OriginalSourceValue.ConstantValue.of(Integer.parseInt(text, radix));
88+
} catch (NumberFormatException e) {
89+
return null;
90+
}
8391
}
8492
return null;
8593
}

testData/results/java/TestUniversalNumberTransformer.dec

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ public class TestUniversalNumberTransformer {
1212
}
1313
}
1414

15-
public void divideByZero() {
15+
public void illegalOperations() {
1616
int a = 2;
1717
if (a == 0) {
1818
int b = 9 / 0;
1919
System.out.println(b);
20+
System.out.println(Integer.parseInt("aaa"));
21+
System.out.println(Float.parseFloat("bbb"));
22+
System.out.println(Double.parseDouble("ccc"));
2023
}
2124
}
2225

testData/src/java/src/main/java/TestUniversalNumberTransformer.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ public void testNumbers1() {
1313
}
1414
}
1515

16-
public void divideByZero() {
16+
public void illegalOperations() {
1717
int a = 2;
1818
if (a == 0) {
1919
// Transformer shouldn't touch it
2020
int b = 9 / 0;
2121
System.out.println(b);
22+
System.out.println(Integer.parseInt("aaa"));
23+
System.out.println(Float.parseFloat("bbb"));
24+
System.out.println(Double.parseDouble("ccc"));
2225
}
2326
}
2427

0 commit comments

Comments
 (0)