mirror of
https://github.com/revanced/Apktool.git
synced 2024-12-13 06:17:46 +01:00
Comment out unused switch payload instructions
This commit is contained in:
parent
7b3e5a1668
commit
fa773b5382
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user