aboutsummaryrefslogtreecommitdiff
path: root/baksmali
diff options
context:
space:
mode:
authorBen Gruver <bgruv@google.com>2015-03-31 20:02:14 -0700
committerBen Gruver <bgruv@google.com>2015-03-31 20:02:14 -0700
commit912a474644491b44297ece2354f21cdbf10d4cc5 (patch)
treec8041cc23c0aaffc5a0fd50bd7e9c4ca1b5991ab /baksmali
parent312921148d7d7b7d38fdd90c73f70b778605d5e7 (diff)
parent923f5a7d104038e244777fc89f825105edc77942 (diff)
downloadsmali-912a474644491b44297ece2354f21cdbf10d4cc5.tar.gz
Merge branch 'master' into smalidea
Diffstat (limited to 'baksmali')
-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) {