mirror of
https://github.com/revanced/smali.git
synced 2025-05-21 16:37:04 +02:00
Add support for the payload instructions while calculating offsets
This commit is contained in:
parent
a7f77ff8d0
commit
0a2debe4e6
@ -57,4 +57,8 @@ public class SmalideaArrayPayload extends SmalideaInstruction implements ArrayPa
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public int getCodeUnits() {
|
||||
return psiInstruction.getInstructionSize()/2;
|
||||
}
|
||||
}
|
||||
|
@ -95,6 +95,6 @@ public class SmalideaPackedSwitchPayload extends SmalideaInstruction implements
|
||||
}
|
||||
|
||||
@Override public int getCodeUnits() {
|
||||
return 4 + psiInstruction.getPackedSwitchElements().size() * 2;
|
||||
return psiInstruction.getInstructionSize()/2;
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,6 @@ public class SmalideaSparseSwitchPayload extends SmalideaInstruction implements
|
||||
}
|
||||
|
||||
@Override public int getCodeUnits() {
|
||||
return 2 + psiInstruction.getSparseSwitchElements().size() * 4;
|
||||
return psiInstruction.getInstructionSize()/2;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jf.dexlib2.Format;
|
||||
import org.jf.dexlib2.Opcode;
|
||||
import org.jf.dexlib2.Opcodes;
|
||||
import org.jf.dexlib2.analysis.AnalyzedInstruction;
|
||||
@ -99,8 +100,7 @@ public class SmaliInstruction extends SmaliCompositeElement {
|
||||
if (previousInstruction == null) {
|
||||
offset = 0;
|
||||
} else {
|
||||
// TODO: handle variable size instructions
|
||||
offset = previousInstruction.getOffset() + previousInstruction.getOpcode().format.size;
|
||||
offset = previousInstruction.getOffset() + previousInstruction.getInstructionSize();
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
@ -172,6 +172,24 @@ public class SmaliInstruction extends SmaliCompositeElement {
|
||||
return Arrays.asList(findChildrenByClass(SmaliArrayDataElement.class));
|
||||
}
|
||||
|
||||
public int getInstructionSize() {
|
||||
Opcode opcode = getOpcode();
|
||||
if (!opcode.format.isPayloadFormat) {
|
||||
return opcode.format.size;
|
||||
} else if (opcode.format == Format.ArrayPayload) {
|
||||
int elementWidth = (int)getArrayDataWidth().getIntegralValue();
|
||||
int elementCount = getArrayDataElements().size();
|
||||
|
||||
return 8 + (elementWidth * elementCount + 1);
|
||||
} else if (opcode.format == Format.PackedSwitchPayload) {
|
||||
return 8 + getPackedSwitchElements().size() * 4;
|
||||
} else if (opcode.format == Format.SparseSwitchPayload) {
|
||||
return 2 + getSparseSwitchElements().size() * 4;
|
||||
}
|
||||
assert false;
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
private AnalyzedInstruction analyzedInstruction = null;
|
||||
|
||||
@NotNull
|
||||
|
Loading…
x
Reference in New Issue
Block a user