mirror of
https://github.com/revanced/smali.git
synced 2025-05-29 20:20:12 +02:00
Fix the way offsets are handled in Instruction21t and Instruction22t
Use a short internally for the offset, and validate the value in updateOffset() git-svn-id: https://smali.googlecode.com/svn/trunk@505 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
parent
f6c7706102
commit
7570fe0382
@ -38,7 +38,7 @@ import org.jf.dexlib.Util.AnnotatedOutput;
|
|||||||
public class Instruction21t extends Instruction implements OffsetInstruction {
|
public class Instruction21t extends Instruction implements OffsetInstruction {
|
||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
public static final Instruction.InstructionFactory Factory = new Factory();
|
||||||
private byte regA;
|
private byte regA;
|
||||||
private int offset;
|
private short offset;
|
||||||
|
|
||||||
public Instruction21t(Opcode opcode, short regA, short offB) {
|
public Instruction21t(Opcode opcode, short regA, short offB) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
@ -66,17 +66,19 @@ public class Instruction21t extends Instruction implements OffsetInstruction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) {
|
protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) {
|
||||||
if (offset < -32768 || offset > 32767) {
|
|
||||||
throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]");
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeByte(opcode.value);
|
out.writeByte(opcode.value);
|
||||||
out.writeByte(regA);
|
out.writeByte(regA);
|
||||||
out.writeShort(offset);
|
out.writeShort(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOffset(int offset) {
|
public void updateOffset(int offset) {
|
||||||
this.offset = offset;
|
if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) {
|
||||||
|
throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]");
|
||||||
|
}
|
||||||
|
if (offset == 0) {
|
||||||
|
throw new RuntimeException("The offset cannot be 0");
|
||||||
|
}
|
||||||
|
this.offset = (short)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Format getFormat() {
|
public Format getFormat() {
|
||||||
|
@ -40,7 +40,7 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw
|
|||||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
public static final Instruction.InstructionFactory Factory = new Factory();
|
||||||
private byte regA;
|
private byte regA;
|
||||||
private byte regB;
|
private byte regB;
|
||||||
private int offset;
|
private short offset;
|
||||||
|
|
||||||
public Instruction22t(Opcode opcode, byte regA, byte regB, short offC) {
|
public Instruction22t(Opcode opcode, byte regA, byte regB, short offC) {
|
||||||
super(opcode);
|
super(opcode);
|
||||||
@ -72,17 +72,19 @@ public class Instruction22t extends Instruction implements OffsetInstruction, Tw
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) {
|
protected void writeInstruction(AnnotatedOutput out, int currentCodeOffset) {
|
||||||
if (offset < -32768 || offset > 32767) {
|
|
||||||
throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]");
|
|
||||||
}
|
|
||||||
|
|
||||||
out.writeByte(opcode.value);
|
out.writeByte(opcode.value);
|
||||||
out.writeByte((regB << 4) | regA);
|
out.writeByte((regB << 4) | regA);
|
||||||
out.writeShort(offset);
|
out.writeShort(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateOffset(int offset) {
|
public void updateOffset(int offset) {
|
||||||
this.offset = offset;
|
if (offset < -32768 || offset > 32767) {
|
||||||
|
throw new RuntimeException("The offset " + offset + " is out of range. It must be in [-32768, 32767]");
|
||||||
|
}
|
||||||
|
if (offset == 0) {
|
||||||
|
throw new RuntimeException("The offset cannot be 0");
|
||||||
|
}
|
||||||
|
this.offset = (short)offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Format getFormat() {
|
public Format getFormat() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user