From 3608d61c87bb15221a6cd0ac5d9b055ea0e5240c Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 26 Oct 2024 03:04:55 -0400 Subject: [PATCH] fix: Reset duplicate escaped names when de-duplicating names If two variables are the literal " " then we don't want the escaped \u0020 to become \u0020 and \u00201 for deduplication. The second is not a valid escape. Thus we'll reset it to "vX" where X is the variable index. --- .../me/darknet/assembler/printer/JvmMethodPrinter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jasm-composition-jvm/src/main/java/me/darknet/assembler/printer/JvmMethodPrinter.java b/jasm-composition-jvm/src/main/java/me/darknet/assembler/printer/JvmMethodPrinter.java index 737a560..c2e0507 100644 --- a/jasm-composition-jvm/src/main/java/me/darknet/assembler/printer/JvmMethodPrinter.java +++ b/jasm-composition-jvm/src/main/java/me/darknet/assembler/printer/JvmMethodPrinter.java @@ -54,9 +54,11 @@ public void setLabelPrefix(String labelPrefix) { for (Local local : code.localVariables()) { // Transform local name to be legal int index = local.index(); - String name = escapeName(local.name(), index, isStatic); + String baseName = local.name(); + String name = escapeName(baseName, index, isStatic); String descriptor = local.type().descriptor(); Type varType = Types.typeFromDescriptor(descriptor); + boolean escaped = !baseName.equals(name); // De-conflict variable names if two names of incompatible types occupy the same name. // int foo = 0 ---> foo @@ -67,6 +69,11 @@ public void setLabelPrefix(String labelPrefix) { (varType.getClass() != existingVarType.getClass() || (varType instanceof PrimitiveType varPrim && existingVarType instanceof PrimitiveType existingPrim && varPrim.kind() != existingPrim.kind()))) { + // If we have an escaped name like "\\u0000" we cannot just append a number to it and call it a day. + // In these cases we will revert the name back to an auto-generated value based on its index. + if (escaped) + name = "v" + local.index(); + int i = 2; String prefix = name; while (nameToType.get(name) != null)