Changed the "from-scratch" constructor in the format classes to a static emit method

git-svn-id: https://smali.googlecode.com/svn/trunk@410 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-08-24 05:42:49 +00:00
parent f75a5c351c
commit 83e6f4bb60
29 changed files with 453 additions and 437 deletions

View File

@ -31,6 +31,7 @@ package org.jf.dexlib.Code.Format;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import java.util.Iterator; import java.util.Iterator;
@ -44,27 +45,18 @@ public class ArrayDataPseudoInstruction extends Instruction {
return size + (size & 0x01) + 8; return size + (size & 0x01) + 8;
} }
public ArrayDataPseudoInstruction(int elementWidth, byte[] encodedValues) { public static void emit(Output out, int elementWidth, byte[] encodedValues) {
super(Opcode.NOP, encodedValues.length + (encodedValues.length & 1) + 8);
if (encodedValues.length % elementWidth != 0) { if (encodedValues.length % elementWidth != 0) {
throw new RuntimeException("There are not a whole number of " + elementWidth + " byte elements"); throw new RuntimeException("There are not a whole number of " + elementWidth + " byte elements");
} }
int elementCount = buffer.length / elementWidth; int elementCount = encodedValues.length / elementWidth;
buffer[0] = 0x00; out.writeByte(0x00);
buffer[1] = 0x03; //fill-array-data psuedo-opcode out.writeShort(0x03);
out.writeShort(elementWidth);
buffer[2] = (byte) elementWidth; out.writeInt(elementCount);
buffer[3] = (byte) (elementWidth >> 8); out.write(encodedValues);
buffer[4] = (byte) elementCount;
buffer[5] = (byte) (elementCount >> 8);
buffer[6] = (byte) (elementCount >> 16);
buffer[7] = (byte) (elementCount >> 24);
System.arraycopy(encodedValues, 0, buffer, 8, encodedValues.length);
} }
public ArrayDataPseudoInstruction(byte[] buffer, int bufferIndex) { public ArrayDataPseudoInstruction(byte[] buffer, int bufferIndex) {

View File

@ -31,19 +31,18 @@ package org.jf.dexlib.Code.Format;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.Output;
public class Instruction10t extends Instruction { public class Instruction10t extends Instruction {
public static final InstructionFactory Factory = new Factory(); public static final InstructionFactory Factory = new Factory();
public Instruction10t(Opcode opcode, byte offA) { public static void emit(Output out, Opcode opcode, byte offA) {
super(opcode);
if (offA == 0) { if (offA == 0) {
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead."); throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = offA; out.writeByte(offA);
} }
private Instruction10t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction10t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -31,14 +31,13 @@ package org.jf.dexlib.Code.Format;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.Output;
public class Instruction10x extends Instruction { public class Instruction10x extends Instruction {
public static final InstructionFactory Factory = new Factory(); public static final InstructionFactory Factory = new Factory();
public Instruction10x(Opcode opcode) { public static void emit(Output out, Opcode opcode) {
super(opcode); out.writeByte(opcode.value);
buffer[0] = opcode.value;
} }
public Instruction10x(Opcode opcode, byte[] buffer, int bufferIndex) { public Instruction10x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,13 +32,12 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction11n extends Instruction { public class Instruction11n extends Instruction {
public static final InstructionFactory Factory = new Factory(); public static final InstructionFactory Factory = new Factory();
public Instruction11n(Opcode opcode, byte regA, byte litB) { public static void emit(Output out, Opcode opcode, byte regA, byte litB) {
super(opcode);
if (regA >= 1 << 4) { if (regA >= 1 << 4) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
} }
@ -48,8 +47,8 @@ public class Instruction11n extends Instruction {
throw new RuntimeException("The literal value must be between -8 and 7 inclusive"); throw new RuntimeException("The literal value must be between -8 and 7 inclusive");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((litB << 4) | regA); out.writeByte((litB << 4) | regA);
} }
private Instruction11n(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction11n(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,19 +32,18 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction11x extends Instruction { public class Instruction11x extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction11x(Opcode opcode, short regA) { public static void emit(Output out, Opcode opcode, short regA) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
} }
private Instruction11x(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction11x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,20 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction12x extends Instruction { public class Instruction12x extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction12x(Opcode opcode, byte regA, byte regB) { public static void emit(Output out, Opcode opcode, byte regA, byte regB) {
super(opcode);
if (regA >= 1 << 4 || if (regA >= 1 << 4 ||
regB >= 1 << 4) { regB >= 1 << 4) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((regB << 4) | regA); out.writeByte((regB << 4) | regA);
} }
private Instruction12x(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction12x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,20 +32,18 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction20t extends Instruction { public class Instruction20t extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction20t(Opcode opcode, short offA) { public static void emit(Output out, Opcode opcode, short offA) {
super(opcode);
if (offA == 0) { if (offA == 0) {
throw new RuntimeException("The offset cannot be 0. Use goto/32 instead."); throw new RuntimeException("The offset cannot be 0. Use goto/32 instead.");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[2] = (byte) offA; out.writeShort(offA);
buffer[3] = (byte) (offA >> 8);
} }
private Instruction20t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction20t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -35,24 +35,26 @@ import org.jf.dexlib.DexFile;
import org.jf.dexlib.Item; import org.jf.dexlib.Item;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction21c extends InstructionWithReference { public class Instruction21c extends InstructionWithReference {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction21c(Opcode opcode, short regA, Item referencedItem) { public static void emit(Output out, Opcode opcode, short regA, Item referencedItem) {
super(opcode, referencedItem);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
if (opcode == Opcode.NEW_INSTANCE && ((TypeIdItem) referencedItem).getTypeDescriptor().charAt(0) != 'L') { if (opcode == Opcode.NEW_INSTANCE) {
assert referencedItem instanceof TypeIdItem;
if (((TypeIdItem)referencedItem).getTypeDescriptor().charAt(0) != 'L') {
throw new RuntimeException("Only class references can be used with the new-instance opcode"); throw new RuntimeException("Only class references can be used with the new-instance opcode");
} }
}
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
//the item index will be set later, during placement/writing out.writeShort(0);
} }
private Instruction21c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction21c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,21 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction21h extends Instruction { public class Instruction21h extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction21h(Opcode opcode, short regA, short litB) { public static void emit(Output out, Opcode opcode, short regA, short litB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) litB; out.writeShort(litB);
buffer[3] = (byte) (litB >> 8);
} }
private Instruction21h(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction21h(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,21 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction21s extends Instruction { public class Instruction21s extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction21s(Opcode opcode, short regA, short litB) { public static void emit(Output out, Opcode opcode, short regA, short litB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) litB; out.writeShort(litB);
buffer[3] = (byte) (litB >> 8);
} }
private Instruction21s(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction21s(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,13 +32,12 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction21t extends Instruction { public class Instruction21t extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction21t(Opcode opcode, short regA, short offB) { public static void emit(Output out, Opcode opcode, short regA, short offB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
@ -47,10 +46,9 @@ public class Instruction21t extends Instruction {
throw new RuntimeException("The offset cannot be 0."); throw new RuntimeException("The offset cannot be 0.");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) offB; out.writeShort(offB);
buffer[3] = (byte) (offB >> 8);
} }
private Instruction21t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction21t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,22 +32,21 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction22b extends Instruction { public class Instruction22b extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction22b(Opcode opcode, short regA, short regB, byte litC) { public static void emit(Output out, Opcode opcode, short regA, short regB, byte litC) {
super(opcode);
if (regA >= 1 << 8 || if (regA >= 1 << 8 ||
regB >= 1 << 8) { regB >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) regB; out.writeByte(regB);
buffer[3] = litC; out.writeByte(litC);
} }
private Instruction22b(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction22b(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -34,21 +34,20 @@ import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Item; import org.jf.dexlib.Item;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction22c extends InstructionWithReference { public class Instruction22c extends InstructionWithReference {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction22c(Opcode opcode, byte regA, byte regB, Item referencedItem) { public static void emit(Output out, Opcode opcode, byte regA, byte regB) {
super(opcode, referencedItem);
if (regA >= 1 << 4 || if (regA >= 1 << 4 ||
regB >= 1 << 4) { regB >= 1 << 4) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((regB << 4) | regA); out.writeByte((regB << 4) | regA);
//the item index will be set later, during placement/writing out.writeShort(0);
} }
private Instruction22c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction22c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,22 +32,20 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction22s extends Instruction { public class Instruction22s extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction22s(Opcode opcode, byte regA, byte regB, short litC) { public static void emit(Output out, Opcode opcode, byte regA, byte regB, short litC) {
super(opcode);
if (regA >= 1 << 4 || if (regA >= 1 << 4 ||
regB >= 1 << 4) { regB >= 1 << 4) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((regB << 4) | regA); out.writeByte((regB << 4) | regA);
buffer[2] = (byte) litC; out.writeShort(litC);
buffer[3] = (byte) (litC >> 8);
} }
private Instruction22s(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction22s(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,13 +32,12 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction22t extends Instruction { public class Instruction22t extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction22t(Opcode opcode, byte regA, byte regB, short offC) { public static void emit(Output out, Opcode opcode, byte regA, byte regB, short offC) {
super(opcode);
if (regA >= 1 << 4 || if (regA >= 1 << 4 ||
regB >= 1 << 4) { regB >= 1 << 4) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
@ -48,10 +47,9 @@ public class Instruction22t extends Instruction {
throw new RuntimeException("The offset cannot be 0."); throw new RuntimeException("The offset cannot be 0.");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((regB << 4) | regA); out.writeByte((regB << 4) | regA);
buffer[2] = (byte) offC; out.writeShort(offC);
buffer[3] = (byte) (offC >> 8);
} }
private Instruction22t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction22t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,13 +32,12 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction22x extends Instruction { public class Instruction22x extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction22x(Opcode opcode, short regA, int regB) { public static void emit(Output out, Opcode opcode, short regA, int regB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v16"); throw new RuntimeException("The register number must be less than v16");
} }
@ -47,10 +46,9 @@ public class Instruction22x extends Instruction {
throw new RuntimeException("The register number must be less than v65536"); throw new RuntimeException("The register number must be less than v65536");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) regB; out.writeShort(regB);
buffer[3] = (byte) (regB >> 8);
} }
private Instruction22x(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction22x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,23 +32,22 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction23x extends Instruction { public class Instruction23x extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction23x(Opcode opcode, short regA, short regB, short regC) { public static void emit(Output out, Opcode opcode, short regA, short regB, short regC) {
super(opcode);
if (regA >= 1 << 8 || if (regA >= 1 << 8 ||
regB >= 1 << 8 || regB >= 1 << 8 ||
regC >= 1 << 8) { regC >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) regB; out.writeByte(regB);
buffer[3] = (byte) regC; out.writeByte(regC);
} }
private Instruction23x(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction23x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,19 +32,15 @@ import org.jf.dexlib.DexFile;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction30t extends Instruction public class Instruction30t extends Instruction
{ {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction30t(Opcode opcode, int offA) { public static void emit(Output out, Opcode opcode, int offA) {
super(opcode); out.writeByte(opcode.value);
out.writeInt(offA);
buffer[0] = opcode.value;
buffer[2] = (byte)offA;
buffer[3] = (byte)(offA >> 8);
buffer[4] = (byte)(offA >> 16);
buffer[5] = (byte)(offA >> 24);
} }
private Instruction30t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction30t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -34,20 +34,19 @@ import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Item; import org.jf.dexlib.Item;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction31c extends InstructionWithReference { public class Instruction31c extends InstructionWithReference {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction31c(Opcode opcode, short regA, Item referencedItem) { public static void emit(Output out, Opcode opcode, short regA) {
super(opcode, referencedItem);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
//the item index will be set later, during placement/writing out.writeInt(0);
} }
private Instruction31c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction31c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,23 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction31i extends Instruction { public class Instruction31i extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction31i(Opcode opcode, short regA, int litB) { public static void emit(Output out, Opcode opcode, short regA, int litB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) litB; out.writeInt(litB);
buffer[3] = (byte) (litB >> 8);
buffer[4] = (byte) (litB >> 16);
buffer[5] = (byte) (litB >> 24);
} }
private Instruction31i(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction31i(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,23 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction31t extends Instruction { public class Instruction31t extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction31t(Opcode opcode, short regA, int offB) { public static void emit(Output out, Opcode opcode, short regA, int offB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) offB; out.writeInt(offB);
buffer[3] = (byte) (offB >> 8);
buffer[4] = (byte) (offB >> 16);
buffer[5] = (byte) (offB >> 24);
} }
private Instruction31t(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction31t(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -32,24 +32,22 @@ import org.jf.dexlib.DexFile;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction32x extends Instruction public class Instruction32x extends Instruction
{ {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction32x(Opcode opcode, int regA, int regB) { public static void emit(Output out, Opcode opcode, int regA, int regB) {
super(opcode);
if (regA >= 1<<16 || if (regA >= 1<<16 ||
regB >= 1<<16) { regB >= 1<<16) {
throw new RuntimeException("The register number must be less than v65536"); throw new RuntimeException("The register number must be less than v65536");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[2] = (byte)regA; out.writeByte(0);
buffer[3] = (byte)(regA >> 8); out.writeShort(regA);
buffer[4] = (byte)regB; out.writeShort(regB);
buffer[5] = (byte)(regB >> 8);
} }
private Instruction32x(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction32x(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -37,14 +37,13 @@ import org.jf.dexlib.Item;
import org.jf.dexlib.MethodIdItem; import org.jf.dexlib.MethodIdItem;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction35c extends InstructionWithReference { public class Instruction35c extends InstructionWithReference {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction35c(Opcode opcode, int regCount, byte regD, byte regE, byte regF, byte regG, public static void emit(Output out, Opcode opcode, int regCount, byte regD, byte regE, byte regF, byte regG,
byte regA, Item referencedItem) { byte regA, Item referencedItem) {
super(opcode, referencedItem);
if (regCount > 5) { if (regCount > 5) {
throw new RuntimeException("regCount cannot be greater than 5"); throw new RuntimeException("regCount cannot be greater than 5");
} }
@ -57,13 +56,13 @@ public class Instruction35c extends InstructionWithReference {
throw new RuntimeException("All register args must fit in 4 bits"); throw new RuntimeException("All register args must fit in 4 bits");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) ((regCount << 4) | regA); out.writeByte((regCount << 4) | regA);
//the item index will be set later, during placement/writing out.writeShort(0);
buffer[4] = (byte) ((regE << 4) | regD); out.writeByte((regE << 4) | regD);
buffer[5] = (byte) ((regG << 4) | regF); out.writeByte((regG << 4) | regF);
checkItem(); checkItem(opcode, referencedItem, regCount);
} }
private Instruction35c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction35c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
@ -73,7 +72,7 @@ public class Instruction35c extends InstructionWithReference {
throw new RuntimeException("regCount cannot be greater than 5"); throw new RuntimeException("regCount cannot be greater than 5");
} }
checkItem(); checkItem(opcode, getReferencedItem(), getRegCount());
} }
public Format getFormat() { public Format getFormat() {
@ -104,9 +103,7 @@ public class Instruction35c extends InstructionWithReference {
return NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 5]); return NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 5]);
} }
private void checkItem() { private static void checkItem(Opcode opcode, Item item, int regCount) {
Item item = getReferencedItem();
if (opcode == FILLED_NEW_ARRAY) { if (opcode == FILLED_NEW_ARRAY) {
//check data for filled-new-array opcode //check data for filled-new-array opcode
String type = ((TypeIdItem) item).getTypeDescriptor(); String type = ((TypeIdItem) item).getTypeDescriptor();
@ -123,7 +120,7 @@ public class Instruction35c extends InstructionWithReference {
if (opcode != INVOKE_STATIC) { if (opcode != INVOKE_STATIC) {
parameterRegisterCount++; parameterRegisterCount++;
} }
if (parameterRegisterCount != getRegCount()) { if (parameterRegisterCount != regCount) {
throw new RuntimeException("regCount does not match the number of arguments of the method"); throw new RuntimeException("regCount does not match the number of arguments of the method");
} }
} }

View File

@ -37,13 +37,12 @@ import org.jf.dexlib.Item;
import org.jf.dexlib.MethodIdItem; import org.jf.dexlib.MethodIdItem;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction3rc extends InstructionWithReference { public class Instruction3rc extends InstructionWithReference {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction3rc(Opcode opcode, short regCount, int startReg, Item referencedItem) { public static void emit(Output out, Opcode opcode, short regCount, int startReg, Item referencedItem) {
super(opcode, referencedItem);
if (regCount >= 1 << 8) { if (regCount >= 1 << 8) {
throw new RuntimeException("regCount must be less than 256"); throw new RuntimeException("regCount must be less than 256");
} }
@ -58,19 +57,18 @@ public class Instruction3rc extends InstructionWithReference {
throw new RuntimeException("The beginning register of the range cannot be negative"); throw new RuntimeException("The beginning register of the range cannot be negative");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regCount; out.writeByte(regCount);
//the item index will be set later, during placement/writing out.writeShort(0);
buffer[4] = (byte) startReg; out.writeShort(startReg);
buffer[5] = (byte) (startReg >> 8);
checkItem(); checkItem(opcode, referencedItem, regCount);
} }
private Instruction3rc(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction3rc(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
super(dexFile, opcode, buffer, bufferIndex); super(dexFile, opcode, buffer, bufferIndex);
checkItem(); checkItem(opcode, getReferencedItem(), getRegCount());
} }
public Format getFormat() { public Format getFormat() {
@ -85,9 +83,7 @@ public class Instruction3rc extends InstructionWithReference {
return NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 4); return NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 4);
} }
private void checkItem() { private static void checkItem(Opcode opcode, Item item, int regCount) {
Item item = getReferencedItem();
if (opcode == FILLED_NEW_ARRAY_RANGE) { if (opcode == FILLED_NEW_ARRAY_RANGE) {
//check data for filled-new-array/range opcode //check data for filled-new-array/range opcode
String type = ((TypeIdItem) item).getTypeDescriptor(); String type = ((TypeIdItem) item).getTypeDescriptor();
@ -104,7 +100,7 @@ public class Instruction3rc extends InstructionWithReference {
if (opcode != INVOKE_STATIC_RANGE) { if (opcode != INVOKE_STATIC_RANGE) {
parameterRegisterCount++; parameterRegisterCount++;
} }
if (parameterRegisterCount != getRegCount()) { if (parameterRegisterCount != regCount) {
throw new RuntimeException("regCount does not match the number of arguments of the method"); throw new RuntimeException("regCount does not match the number of arguments of the method");
} }
} }

View File

@ -32,27 +32,19 @@ import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
public class Instruction51l extends Instruction { public class Instruction51l extends Instruction {
public static final Instruction.InstructionFactory Factory = new Factory(); public static final Instruction.InstructionFactory Factory = new Factory();
public Instruction51l(Opcode opcode, short regA, long litB) { public static void emit(Output out, Opcode opcode, short regA, long litB) {
super(opcode);
if (regA >= 1 << 8) { if (regA >= 1 << 8) {
throw new RuntimeException("The register number must be less than v256"); throw new RuntimeException("The register number must be less than v256");
} }
buffer[0] = opcode.value; out.writeByte(opcode.value);
buffer[1] = (byte) regA; out.writeByte(regA);
buffer[2] = (byte) litB; out.writeLong(litB);
buffer[3] = (byte) (litB >> 8);
buffer[4] = (byte) (litB >> 16);
buffer[5] = (byte) (litB >> 24);
buffer[6] = (byte) (litB >> 32);
buffer[7] = (byte) (litB >> 40);
buffer[8] = (byte) (litB >> 48);
buffer[9] = (byte) (litB >> 56);
} }
private Instruction51l(Opcode opcode, byte[] buffer, int bufferIndex) { private Instruction51l(Opcode opcode, byte[] buffer, int bufferIndex) {

View File

@ -31,6 +31,7 @@ package org.jf.dexlib.Code.Format;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import java.util.Iterator; import java.util.Iterator;
@ -43,34 +44,19 @@ public class PackedSwitchDataPseudoInstruction extends Instruction {
return getTargetCount() * 4 + 8; return getTargetCount() * 4 + 8;
} }
public PackedSwitchDataPseudoInstruction(int firstKey, int[] targets) { public static void emit(Output out, int firstKey, int[] targets) {
super(Opcode.NOP, targets.length * 4 + 8);
/*this.firstKey = firstKey;
this.targets = targets;*/
if (targets.length > 0xFFFF) { if (targets.length > 0xFFFF) {
throw new RuntimeException("The packed-switch data contains too many elements. " + throw new RuntimeException("The packed-switch data contains too many elements. " +
"The maximum number of switch elements is 65535"); "The maximum number of switch elements is 65535");
} }
buffer[0] = 0x00; out.writeByte(0x00);
buffer[1] = 0x01; //packed-switch pseudo-opcode out.writeByte(0x01);
out.writeShort(targets.length);
out.writeInt(firstKey);
buffer[2] = (byte) targets.length;
buffer[3] = (byte) (targets.length >> 8);
buffer[4] = (byte) firstKey;
buffer[5] = (byte) (firstKey >> 8);
buffer[6] = (byte) (firstKey >> 16);
buffer[7] = (byte) (firstKey >> 24);
int position = 8;
for (int target : targets) { for (int target : targets) {
buffer[position++] = (byte) target; out.writeInt(target);
buffer[position++] = (byte) (target >> 8);
buffer[position++] = (byte) (target >> 16);
buffer[position++] = (byte) (target >> 24);
} }
} }

View File

@ -31,6 +31,7 @@ package org.jf.dexlib.Code.Format;
import org.jf.dexlib.Code.Instruction; import org.jf.dexlib.Code.Instruction;
import org.jf.dexlib.Code.Opcode; import org.jf.dexlib.Code.Opcode;
import org.jf.dexlib.Util.NumberUtils; import org.jf.dexlib.Util.NumberUtils;
import org.jf.dexlib.Util.Output;
import org.jf.dexlib.DexFile; import org.jf.dexlib.DexFile;
import java.util.Iterator; import java.util.Iterator;
@ -43,9 +44,7 @@ public class SparseSwitchDataPseudoInstruction extends Instruction {
return getTargetCount() * 8 + 4; return getTargetCount() * 8 + 4;
} }
public SparseSwitchDataPseudoInstruction(int[] keys, int[] targets) { public static void emit(Output out, int[] keys, int[] targets) {
super(Opcode.NOP, keys.length * 8 + 4);
if (keys.length != targets.length) { if (keys.length != targets.length) {
throw new RuntimeException("The number of keys and offsets don't match"); throw new RuntimeException("The number of keys and offsets don't match");
} }
@ -59,20 +58,14 @@ public class SparseSwitchDataPseudoInstruction extends Instruction {
"The maximum number of switch elements is 65535"); "The maximum number of switch elements is 65535");
} }
buffer[0] = 0x00; out.writeByte(0x00);
buffer[1] = 0x02; //sparse-switch psuedo-opcode out.writeByte(0x02);
out.writeShort(targets.length);
buffer[2] = (byte) targets.length;
buffer[3] = (byte) (targets.length >> 8);
int position = 8;
if (targets.length > 0) { if (targets.length > 0) {
int key = keys[0]; int key = keys[0];
buffer[4] = (byte) key;
buffer[5] = (byte) (key >> 8); out.writeInt(key);
buffer[6] = (byte) (key >> 16);
buffer[7] = (byte) (key >> 24);
for (int i = 1; i < keys.length; i++) { for (int i = 1; i < keys.length; i++) {
key = keys[i]; key = keys[i];
@ -80,18 +73,11 @@ public class SparseSwitchDataPseudoInstruction extends Instruction {
throw new RuntimeException("The targets in a sparse switch block must be sorted in ascending" + throw new RuntimeException("The targets in a sparse switch block must be sorted in ascending" +
"order, by key"); "order, by key");
} }
out.writeInt(key);
buffer[position++] = (byte) key;
buffer[position++] = (byte) (key >> 8);
buffer[position++] = (byte) (key >> 16);
buffer[position++] = (byte) (key >> 24);
} }
for (int target : targets) { for (int target : targets) {
buffer[position++] = (byte) target; out.writeInt(target);
buffer[position++] = (byte) (target >> 8);
buffer[position++] = (byte) (target >> 16);
buffer[position++] = (byte) (target >> 24);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -228,7 +228,6 @@ public class main {
return false; return false;
} }
dexFile.ClassDefsSection.intern(dexGen.classDefItem);
return true; return true;
} }