Fixed: #2562 ABC explorer not working in some obfuscated code

Fixed: #2562 P-code not showing in some obfuscated code (NumberContext related)
This commit is contained in:
Jindra Petřík
2025-11-16 17:30:59 +01:00
parent 09ec4d2f1d
commit 396cd97801
5 changed files with 22 additions and 11 deletions

View File

@@ -87,8 +87,9 @@ public class NumberContext {
* @param usage Usage
*/
public void setUsage(int usage) {
if (usage > usageNames.length || usage < 0) {
throw new IllegalArgumentException("Invalid usage value :" + usage);
if (usage >= usageNames.length || usage < 0) {
this.usage = USE_NUMBER;
return;
}
this.usage = usage;
}
@@ -118,7 +119,7 @@ public class NumberContext {
*/
public void setPrecision(int precision) {
if (precision > 34) {
throw new IllegalArgumentException("Maximum value of precision is 34");
precision = 34;
}
this.precision = precision;
}
@@ -129,8 +130,9 @@ public class NumberContext {
* @param rounding Rounding
*/
public void setRounding(int rounding) {
if (rounding > roundingNames.length || rounding < 0) {
throw new IllegalArgumentException("Invalid rounding value :" + rounding);
if (rounding >= roundingNames.length || rounding < 0) {
this.rounding = ROUND_HALF_EVEN;
return;
}
this.rounding = rounding;
}
@@ -165,8 +167,8 @@ public class NumberContext {
* @return Name
*/
public static String usageToName(int usage) {
if (usage > usageNames.length || usage < 0) {
throw new IllegalArgumentException("Invalid usage value :" + usage);
if (usage >= usageNames.length || usage < 0) {
return "Number";
}
return usageNames[usage];
}
@@ -177,8 +179,8 @@ public class NumberContext {
* @return Name
*/
public static String roundingToName(int rounding) {
if (rounding > roundingNames.length || rounding < 0) {
throw new IllegalArgumentException("Invalid rounding value :" + rounding);
if (rounding >= roundingNames.length || rounding < 0) {
return "HALF_EVEN";
}
return roundingNames[rounding];
}

View File

@@ -712,6 +712,9 @@ public class AVM2Graph extends Graph {
continue;
}
for (int ip = p.start; ip <= p.end; ip++) {
if (ip >= avm2code.code.size()) {
continue;
}
AVM2Instruction ins = avm2code.code.get(ip);
if (ins.definition instanceof SetLocalTypeIns) {
int regId = ((SetLocalTypeIns) ins.definition).getRegisterId(ins);
@@ -3306,6 +3309,9 @@ public class AVM2Graph extends Graph {
if (part.end < 0) {
return false;
}
if (part.end >= avm2code.code.size()) {
return false;
}
return avm2code.code.get(part.end).definition instanceof LookupSwitchIns;
}

View File

@@ -351,7 +351,7 @@ public class ABCCleaner {
}
private int handleReplace(ABCSimpleUsageDetector.ItemKind kind, int index, Map<ABCSimpleUsageDetector.ItemKind, Map<Integer, Integer>> replaceMap) {
if (!replaceMap.get(kind).containsKey(index)) {
if (!replaceMap.containsKey(kind) || !replaceMap.get(kind).containsKey(index)) {
return index;
}
return replaceMap.get(kind).get(index);

View File

@@ -540,7 +540,7 @@ public class ABCSimpleUsageDetector {
* @return True if it is new
*/
private boolean handleUsage(ItemKind kind, int index, String usageDescription) {
if (index < 0 || index > usages.get(kind).size() - 1) {
if (!usages.containsKey(kind) || index < 0 || index > usages.get(kind).size() - 1) {
Logger.getLogger(ABCSimpleUsageDetector.class.getName()).log(Level.WARNING, "{0} with index {1} not found for usage {2}", new Object[]{kind, index, usageDescription});
return false;
}