aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gruver <bgruv@google.com>2015-03-20 16:38:19 -0700
committerBen Gruver <bgruv@google.com>2015-03-20 16:38:19 -0700
commitb742c402631ca85ffe72e556ce97f4533cb6083e (patch)
tree823494afde39e6a36d5f198608843a9a83715e75
parent2a0e4657ea73c67a44d1711da2539aa9c1a88524 (diff)
downloadsmali-b742c402631ca85ffe72e556ce97f4533cb6083e.tar.gz
Comment out unused switch payload instructions
-rw-r--r--baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/PackedSwitchMethodItem.java9
-rw-r--r--baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java9
2 files changed, 17 insertions, 1 deletions
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<PackedSwitchPa
private final List<PackedSwitchTarget> 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<PackedSwitchPa
targets = new ArrayList<PackedSwitchTarget>();
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<PackedSwitchPa
targets.add(new PackedSwitchLabelTarget(label));
}
} else {
+ commentedOut = true;
for (SwitchElement switchElement: instruction.getSwitchElements()) {
if (first) {
firstKey = switchElement.getKey();
@@ -78,6 +82,9 @@ public class PackedSwitchMethodItem extends InstructionMethodItem<PackedSwitchPa
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
+ if (commentedOut) {
+ writer = new CommentingIndentingWriter(writer);
+ }
writer.write(".packed-switch ");
IntegerRenderer.writeTo(writer, firstKey);
writer.indent(4);
diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java
index 0e01f41b..68d7e92b 100644
--- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.java
+++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/SparseSwitchMethodItem.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;
@@ -42,6 +43,9 @@ import java.util.List;
public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPayload> {
private final List<SparseSwitchTarget> 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<SparseSwitchPa
targets.add(new SparseSwitchLabelTarget(switchElement.getKey(), label));
}
} else {
+ commentedOut = true;
//if we couldn't determine a base address, just use relative offsets rather than labels
for (SwitchElement switchElement: instruction.getSwitchElements()) {
targets.add(new SparseSwitchOffsetTarget(switchElement.getKey(), switchElement.getOffset()));
@@ -65,6 +70,10 @@ public class SparseSwitchMethodItem extends InstructionMethodItem<SparseSwitchPa
@Override
public boolean writeTo(IndentingWriter writer) throws IOException {
+ if (commentedOut) {
+ writer = new CommentingIndentingWriter(writer);
+ }
+
writer.write(".sparse-switch\n");
writer.indent(4);
for (SparseSwitchTarget target: targets) {