From b742c402631ca85ffe72e556ce97f4533cb6083e Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Fri, 20 Mar 2015 16:38:19 -0700 Subject: [PATCH 1/2] Comment out unused switch payload instructions --- .../baksmali/Adaptors/Format/PackedSwitchMethodItem.java | 9 ++++++++- .../baksmali/Adaptors/Format/SparseSwitchMethodItem.java | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java index f0dd656b..30edfcd4 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java @@ -28,6 +28,7 @@ package org.jf.baksmali.Adaptors.Format; +import org.jf.baksmali.Adaptors.CommentingIndentingWriter; import org.jf.baksmali.Adaptors.LabelMethodItem; import org.jf.baksmali.Adaptors.MethodDefinition; import org.jf.dexlib2.iface.instruction.SwitchElement; @@ -43,6 +44,9 @@ public class PackedSwitchMethodItem extends InstructionMethodItem targets; private final int firstKey; + // Whether this sparse switch instruction should be commented out because it is never referenced + private boolean commentedOut; + public PackedSwitchMethodItem(MethodDefinition methodDef, int codeAddress, PackedSwitchPayload instruction) { super(methodDef, codeAddress, instruction); @@ -51,7 +55,6 @@ public class PackedSwitchMethodItem extends InstructionMethodItem(); boolean first = true; - //TODO: does dalvik allow switc payloads with no cases? int firstKey = 0; if (baseCodeAddress >= 0) { for (SwitchElement switchElement: instruction.getSwitchElements()) { @@ -65,6 +68,7 @@ public class PackedSwitchMethodItem extends InstructionMethodItem { private final List targets; + // Whether this sparse switch instruction should be commented out because it is never referenced + private boolean commentedOut; + public SparseSwitchMethodItem(MethodDefinition methodDef, int codeAddress, SparseSwitchPayload instruction) { super(methodDef, codeAddress, instruction); @@ -56,6 +60,7 @@ public class SparseSwitchMethodItem extends InstructionMethodItem Date: Fri, 20 Mar 2015 16:39:07 -0700 Subject: [PATCH 2/2] Fix a bounds check problem in IndentingWriter --- util/src/main/java/org/jf/util/IndentingWriter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/src/main/java/org/jf/util/IndentingWriter.java b/util/src/main/java/org/jf/util/IndentingWriter.java index 95d6c320..8e4ca628 100644 --- a/util/src/main/java/org/jf/util/IndentingWriter.java +++ b/util/src/main/java/org/jf/util/IndentingWriter.java @@ -120,7 +120,7 @@ public class IndentingWriter extends Writer { int pos = start; while (pos < end) { pos = str.indexOf('\n', start); - if (pos == -1) { + if (pos == -1 || pos >= end) { writeLine(str, start, end-start); return; } else {