From d096b315bbfbb27204068dd10385c8499f5acd05 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 4 Sep 2024 06:32:40 -0400 Subject: [PATCH] Add config option to emit try-catch ranges in assembler --- .../assembler/AbstractAssemblerPipeline.java | 4 ++++ .../services/assembler/AssemblerPipelineConfig.java | 2 ++ .../assembler/AssemblerPipelineGeneralConfig.java | 2 +- .../assembler/JvmAssemblerPipelineConfig.java | 12 +++++++++++- recaf-ui/src/main/resources/translations/en_US.lang | 1 + 5 files changed, 19 insertions(+), 2 deletions(-) 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 7e4db2bcd..9859c0b97 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 @@ -46,6 +46,10 @@ public AbstractAssemblerPipeline(@Nonnull AssemblerPipelineGeneralConfig general private void refreshContext() { context = new PrintContext<>(generalConfig.getDisassemblyIndent().getValue()); + + // Enable comments that outline where try-catch ranges begin/end. + if (pipelineConfig instanceof JvmAssemblerPipelineConfig jvmConfig && jvmConfig.emitTryRangeComments()) + context.setDebugTryCatchRanges(true); } @Nonnull diff --git a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineConfig.java b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineConfig.java index e5d313387..e46be9481 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineConfig.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineConfig.java @@ -6,6 +6,8 @@ * Assembler pipeline config outline. * * @author Justus Garbe + * @see AndroidAssemblerPipelineConfig + * @see JvmAssemblerPipelineConfig */ public interface AssemblerPipelineConfig extends ConfigContainer { /** diff --git a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineGeneralConfig.java b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineGeneralConfig.java index a55a90a5e..9155d6dab 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineGeneralConfig.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/assembler/AssemblerPipelineGeneralConfig.java @@ -29,7 +29,7 @@ public AssemblerPipelineGeneralConfig() { } /** - * @return Indentation string. + * @return String of a single indentation level. */ @Nonnull public ObservableString getDisassemblyIndent() { diff --git a/recaf-core/src/main/java/software/coley/recaf/services/assembler/JvmAssemblerPipelineConfig.java b/recaf-core/src/main/java/software/coley/recaf/services/assembler/JvmAssemblerPipelineConfig.java index c28841b95..2058c0c05 100644 --- a/recaf-core/src/main/java/software/coley/recaf/services/assembler/JvmAssemblerPipelineConfig.java +++ b/recaf-core/src/main/java/software/coley/recaf/services/assembler/JvmAssemblerPipelineConfig.java @@ -17,12 +17,15 @@ public class JvmAssemblerPipelineConfig extends BasicConfigContainer implements ServiceConfig, AssemblerPipelineConfig { private final ObservableBoolean valueAnalysis = new ObservableBoolean(true); private final ObservableBoolean simulateJvmCalls = new ObservableBoolean(true); + private final ObservableBoolean tryRangeComments = new ObservableBoolean(true); + @Inject public JvmAssemblerPipelineConfig() { super(ConfigGroups.SERVICE_ASSEMBLER, JvmAssemblerPipeline.SERVICE_ID + CONFIG_SUFFIX); addValue(new BasicConfigValue<>("value-analysis", boolean.class, valueAnalysis)); addValue(new BasicConfigValue<>("simulate-jvm-calls", boolean.class, simulateJvmCalls)); + addValue(new BasicConfigValue<>("try-range-comments", boolean.class, tryRangeComments)); } @Override @@ -32,6 +35,13 @@ public boolean isValueAnalysisEnabled() { @Override public boolean isSimulatingCommonJvmCalls() { - return simulateJvmCalls.hasValue(); + return simulateJvmCalls.getValue(); + } + + /** + * @return {@code true} to emit comments for where try-catch ranges start/end/catch. + */ + public boolean emitTryRangeComments() { + return tryRangeComments.getValue(); } } diff --git a/recaf-ui/src/main/resources/translations/en_US.lang b/recaf-ui/src/main/resources/translations/en_US.lang index c3781a958..a85eb2a61 100644 --- a/recaf-ui/src/main/resources/translations/en_US.lang +++ b/recaf-ui/src/main/resources/translations/en_US.lang @@ -512,6 +512,7 @@ service.assembler.dalvik-assembler-config.simulate-jvm-calls=Simulate common JVM service.assembler.jvm-assembler-config=JVM service.assembler.jvm-assembler-config.value-analysis=Enable value analysis service.assembler.jvm-assembler-config.simulate-jvm-calls=Simulate common JVM calls +service.assembler.jvm-assembler-config.try-range-comments=Emit try-catch range comments service.assembler.flow-lines-config=Control flow lines service.assembler.flow-lines-config.connection-mode=Line mode service.assembler.flow-lines-config.render-mode=Render mode