From 23b29c45b06d64fdac17984a6b0af1132b2210ae Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 9 Jan 2025 22:44:17 -0500 Subject: [PATCH] Update jasm to handle bad kotlin variable ranges --- gradle/libs.versions.toml | 4 ++-- .../recaf/services/assembler/AbstractAssemblerPipeline.java | 3 +++ .../coley/recaf/services/assembler/ExpressionCompiler.java | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index dfd6bc2cd..fe472edc5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,7 +21,7 @@ image-io-ext-ico = "3.0.2" instrument-server = "1.4.2" jackson = "2.17.1" jakarta-annotation = "3.0.0" -jasm = "9a413ea936" +jasm = "552630c411" jlinker = "1.0.7" jphantom = "1.4.4" junit = "5.11.0" @@ -39,7 +39,7 @@ richtextfx = "0.11.3" treemapfx = "1.1.0" vineflower = "1.10.1" wordwrap = "0.1.12" -sourcesolver = "1.0.1" +sourcesolver = "1.0.2" # Plugins benmanes-versions = "0.42.0" gradle-coverage-report-aggregator = "1.3.2" diff --git a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AbstractAssemblerPipeline.java b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AbstractAssemblerPipeline.java index 9859c0b97..3befe5ecd 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AbstractAssemblerPipeline.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AbstractAssemblerPipeline.java @@ -47,6 +47,9 @@ public AbstractAssemblerPipeline(@Nonnull AssemblerPipelineGeneralConfig general private void refreshContext() { context = new PrintContext<>(generalConfig.getDisassemblyIndent().getValue()); + // Enable aggressive variable name dropping to prevent use of bogus kotlin variable ranges. + context.setAggressivelyDropVars(true); + // Enable comments that outline where try-catch ranges begin/end. if (pipelineConfig instanceof JvmAssemblerPipelineConfig jvmConfig && jvmConfig.emitTryRangeComments()) context.setDebugTryCatchRanges(true); diff --git a/recaf-core/src/main/java/software/coley/recaf/services/assembler/ExpressionCompiler.java b/recaf-core/src/main/java/software/coley/recaf/services/assembler/ExpressionCompiler.java index d251107e1..e7df98ca7 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/assembler/ExpressionCompiler.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/assembler/ExpressionCompiler.java @@ -6,7 +6,7 @@ import jakarta.enterprise.context.Dependent; import jakarta.inject.Inject; import me.darknet.assembler.printer.JvmClassPrinter; -import me.darknet.assembler.printer.JvmMethodPrinter; +import me.darknet.assembler.printer.MethodPrinter; import me.darknet.assembler.printer.PrintContext; import org.objectweb.asm.Opcodes; import org.slf4j.Logger; @@ -186,11 +186,11 @@ public ExpressionResult compile(@Nonnull String expression) { // Convert the compiled class to JASM try { PrintContext context = new PrintContext<>(assemblerConfig.getDisassemblyIndent().getValue()); + context.setLabelPrefix("g"); JvmClassPrinter printer = new JvmClassPrinter(new ByteArrayInputStream(klass)); - JvmMethodPrinter method = (JvmMethodPrinter) printer.method(stubber.getAdaptedMethodName(), stubber.methodDescriptorWithVariables()); + MethodPrinter method = printer.method(stubber.getAdaptedMethodName(), stubber.methodDescriptorWithVariables()); if (method == null) return new ExpressionResult(new ExpressionCompileException("Target method was not in generated class")); - method.setLabelPrefix("g"); method.print(context); return new ExpressionResult(context.toString()); } catch (IOException ex) {