Add DexBacked implementations for all instructions

This commit is contained in:
Ben Gruver
2012-11-04 16:47:20 -08:00
parent f4662586da
commit b116cb0ac9
30 changed files with 1430 additions and 319 deletions

View File

@ -187,6 +187,10 @@ public class DexReader {
return result;
}
public int peekUshort() {
return dexBuf.readUshort(offset);
}
public int readUshort() {
int o = offset;
int result = dexBuf.readUshort(offset);
@ -194,6 +198,10 @@ public class DexReader {
return result;
}
public int peekUbyte() {
return dexBuf.readUbyte(offset);
}
public int readUbyte() {
int o = offset;
int result = dexBuf.readUbyte(offset);

View File

@ -40,12 +40,9 @@ import org.jf.util.ExceptionWithContext;
import javax.annotation.Nonnull;
import java.util.List;
public class DexBackedArrayPayload implements ArrayPayload {
public class DexBackedArrayPayload extends DexBackedInstruction implements ArrayPayload {
public static final Opcode OPCODE = Opcode.ARRAY_PAYLOAD;
@Nonnull public final DexBuffer dexBuf;
private final int instructionOffset;
public final int elementWidth;
public final int elementCount;
@ -53,13 +50,12 @@ public class DexBackedArrayPayload implements ArrayPayload {
private static final int ELEMENT_COUNT_OFFSET = 4;
private static final int ELEMENTS_OFFSET = 8;
public DexBackedArrayPayload(DexBuffer dexBuf,
int instructionOffset) {
this.dexBuf = dexBuf;
this.instructionOffset = instructionOffset;
public DexBackedArrayPayload(@Nonnull DexBuffer dexBuf,
int instructionStart) {
super(dexBuf, OPCODE, instructionStart);
this.elementWidth = dexBuf.readUshort(instructionOffset + ELEMENT_WIDTH_OFFSET);
this.elementCount = dexBuf.readSmallUint(instructionOffset + ELEMENT_COUNT_OFFSET);
elementWidth = dexBuf.readUshort(instructionStart + ELEMENT_WIDTH_OFFSET);
elementCount = dexBuf.readSmallUint(instructionStart + ELEMENT_COUNT_OFFSET);
}
@Override public int getElementWidth() { return elementWidth; }
@ -67,7 +63,7 @@ public class DexBackedArrayPayload implements ArrayPayload {
@Nonnull
@Override
public List<Number> getArrayElements() {
final int elementsStart = instructionOffset + ELEMENTS_OFFSET;
final int elementsStart = instructionStart + ELEMENTS_OFFSET;
abstract class ReturnedList extends FixedSizeList<Number> {
@Override public int size() { return elementCount; }
@ -115,6 +111,4 @@ public class DexBackedArrayPayload implements ArrayPayload {
public int getCodeUnits() {
return 4 + (elementWidth*elementCount + 1) / 2;
}
@Override public Opcode getOpcode() { return OPCODE; }
}

View File

@ -34,330 +34,105 @@ package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.DexReader;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.Instruction;
import org.jf.dexlib2.iface.instruction.formats.*;
import org.jf.dexlib2.iface.reference.Reference;
import org.jf.dexlib2.immutable.instruction.*;
import org.jf.util.ExceptionWithContext;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public abstract class DexBackedInstruction {
public abstract class DexBackedInstruction implements Instruction {
@Nonnull public final DexBuffer dexBuf;
@Nonnull public final Opcode opcode;
public final int instructionStart;
public DexBackedInstruction(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
this.dexBuf = dexBuf;
this.opcode = opcode;
this.instructionStart = instructionStart;
}
@Nonnull public Opcode getOpcode() { return opcode; }
@Override public int getCodeUnits() { return opcode.format.size / 2; }
@Nonnull
public static Instruction readFrom(@Nonnull DexReader reader) {
int opcodeValue = reader.readUbyte();
int opcodeValue = reader.peekUbyte();
if (opcodeValue == 0) {
reader.moveRelative(-1);
opcodeValue = reader.readUshort();
if (opcodeValue == 0) {
// if we've got a real nop, and not a payload instruction, back up a byte,
// so that the reader is positioned just after the single opcode byte, for consistency
reader.moveRelative(-1);
}
opcodeValue = reader.peekUshort();
}
Opcode opcode = Opcode.getOpcodeByValue(opcodeValue);
//TODO: handle unexpected/unknown opcodes
Instruction instruction = buildInstruction(reader.getDexBuffer(), opcode, reader.getOffset());
reader.moveRelative(instruction.getCodeUnits()*2);
return instruction;
}
private static DexBackedInstruction buildInstruction(@Nonnull DexBuffer dexBuf, Opcode opcode,
int instructionStartOffset) {
switch (opcode.format) {
case Format10t:
return instruction10t(opcode, reader);
return new DexBackedInstruction10t(dexBuf, opcode, instructionStartOffset);
case Format10x:
return instruction10x(opcode, reader);
return new DexBackedInstruction10x(dexBuf, opcode, instructionStartOffset);
case Format11n:
return instruction11n(opcode, reader);
return new DexBackedInstruction11n(dexBuf, opcode, instructionStartOffset);
case Format11x:
return instruction11x(opcode, reader);
return new DexBackedInstruction11x(dexBuf, opcode, instructionStartOffset);
case Format12x:
return instruction12x(opcode, reader);
return new DexBackedInstruction12x(dexBuf, opcode, instructionStartOffset);
case Format20t:
return instruction20t(opcode, reader);
return new DexBackedInstruction20t(dexBuf, opcode, instructionStartOffset);
case Format21c:
return instruction21c(opcode, reader);
return new DexBackedInstruction21c(dexBuf, opcode, instructionStartOffset);
case Format21ih:
return instruction21ih(opcode, reader);
return new DexBackedInstruction21ih(dexBuf, opcode, instructionStartOffset);
case Format21lh:
return instruction21lh(opcode, reader);
return new DexBackedInstruction21lh(dexBuf, opcode, instructionStartOffset);
case Format21s:
return instruction21s(opcode, reader);
return new DexBackedInstruction21s(dexBuf, opcode, instructionStartOffset);
case Format21t:
return instruction21t(opcode, reader);
return new DexBackedInstruction21t(dexBuf, opcode, instructionStartOffset);
case Format22b:
return instruction22b(opcode, reader);
return new DexBackedInstruction22b(dexBuf, opcode, instructionStartOffset);
case Format22c:
return instruction22c(opcode, reader);
return new DexBackedInstruction22c(dexBuf, opcode, instructionStartOffset);
case Format22s:
return instruction22s(opcode, reader);
return new DexBackedInstruction22s(dexBuf, opcode, instructionStartOffset);
case Format22t:
return instruction22t(opcode, reader);
return new DexBackedInstruction22t(dexBuf, opcode, instructionStartOffset);
case Format22x:
return instruction22x(opcode, reader);
return new DexBackedInstruction22x(dexBuf, opcode, instructionStartOffset);
case Format23x:
return instruction23x(opcode, reader);
return new DexBackedInstruction23x(dexBuf, opcode, instructionStartOffset);
case Format30t:
return instruction30t(opcode, reader);
return new DexBackedInstruction30t(dexBuf, opcode, instructionStartOffset);
case Format31c:
return instruction31c(opcode, reader);
return new DexBackedInstruction31c(dexBuf, opcode, instructionStartOffset);
case Format31i:
return instruction31i(opcode, reader);
return new DexBackedInstruction31i(dexBuf, opcode, instructionStartOffset);
case Format31t:
return instruction31t(opcode, reader);
return new DexBackedInstruction31t(dexBuf, opcode, instructionStartOffset);
case Format32x:
return instruction32x(opcode, reader);
return new DexBackedInstruction32x(dexBuf, opcode, instructionStartOffset);
case Format35c:
return instruction35c(opcode, reader);
return new DexBackedInstruction35c(dexBuf, opcode, instructionStartOffset);
case Format3rc:
return instruction3rc(opcode, reader);
return new DexBackedInstruction3rc(dexBuf, opcode, instructionStartOffset);
case Format51l:
return instruction51l(opcode, reader);
return new DexBackedInstruction51l(dexBuf, opcode, instructionStartOffset);
case PackedSwitchPayload:
return packedSwitchPayload(reader);
return new DexBackedPackedSwitchPayload(dexBuf, instructionStartOffset);
case SparseSwitchPayload:
return sparseSwitchPayload(reader);
return new DexBackedSparseSwitchPayload(dexBuf, instructionStartOffset);
case ArrayPayload:
return arrayPayload(reader);
//TODO: temporary, until we get all instructions implemented
return new DexBackedArrayPayload(dexBuf, instructionStartOffset);
//TODO: temporary, until we get all instructions implemented
default:
throw new ExceptionWithContext("Unexpected opcode format: %s", opcode.format.toString());
}
}
@Nonnull
private static Instruction10t instruction10t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int offset = reader.readByte();
return new ImmutableInstruction10t(opcode, offset);
}
@Nonnull
private static Instruction10x instruction10x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte();
return new ImmutableInstruction10x(opcode);
}
@Nonnull
private static Instruction11n instruction11n(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int literal = NibbleUtils.extractHighSignedNibble(b);
return new ImmutableInstruction11n(opcode, registerA, literal);
}
@Nonnull
private static Instruction11x instruction11x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
return new ImmutableInstruction11x(opcode, registerA);
}
@Nonnull
private static Instruction12x instruction12x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
return new ImmutableInstruction12x(opcode, registerA, registerB);
}
@Nonnull
private static Instruction20t instruction20t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte();
int offset = reader.readShort();
return new ImmutableInstruction20t(opcode, offset);
}
@Nonnull
private static Instruction21c instruction21c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
DexBuffer dexBuf = reader.getDexBuffer();
int registerA = reader.readUbyte();
int referenceIndex = reader.readUshort();
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
return new ImmutableInstruction21c(opcode, registerA, reference);
}
@Nonnull
private static Instruction21ih instruction21ih(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int literalHat = reader.readShort();
return new ImmutableInstruction21ih(opcode, registerA, literalHat << 16);
}
@Nonnull
private static Instruction21lh instruction21lh(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int literalHat = reader.readShort();
return new ImmutableInstruction21lh(opcode, registerA, ((long)literalHat) << 48);
}
@Nonnull
private static Instruction21s instruction21s(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int literal = reader.readShort();
return new ImmutableInstruction21s(opcode, registerA, literal);
}
@Nonnull
private static Instruction21t instruction21t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int offset = reader.readShort();
return new ImmutableInstruction21t(opcode, registerA, offset);
}
@Nonnull
private static Instruction22b instruction22b(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int registerB = reader.readUbyte();
int literal = reader.readByte();
return new ImmutableInstruction22b(opcode, registerA, registerB, literal);
}
@Nonnull
private static Instruction22c instruction22c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
DexBuffer dexBuf = reader.getDexBuffer();
int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
int referenceIndex = reader.readUshort();
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
return new ImmutableInstruction22c(opcode, registerA, registerB, reference);
}
@Nonnull
private static Instruction22s instruction22s(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
int literal = reader.readShort();
return new ImmutableInstruction22s(opcode, registerA, registerB, literal);
}
@Nonnull
private static Instruction22t instruction22t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int b = reader.readUbyte();
int registerA = NibbleUtils.extractLowUnsignedNibble(b);
int registerB = NibbleUtils.extractHighUnsignedNibble(b);
int offset = reader.readShort();
return new ImmutableInstruction22t(opcode, registerA, registerB, offset);
}
@Nonnull
private static Instruction22x instruction22x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int registerB = reader.readUshort();
return new ImmutableInstruction22x(opcode, registerA, registerB);
}
@Nonnull
private static Instruction23x instruction23x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int registerB = reader.readUbyte();
int registerC = reader.readUbyte();
return new ImmutableInstruction23x(opcode, registerA, registerB, registerC);
}
@Nonnull
private static Instruction30t instruction30t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte();
int offset = reader.readInt();
return new ImmutableInstruction30t(opcode, offset);
}
@Nonnull
private static Instruction31c instruction31c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
DexBuffer dexBuf = reader.getDexBuffer();
int registerA = reader.readUbyte();
int referenceIndex = reader.readSmallUint();
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
return new ImmutableInstruction31c(opcode, registerA, reference);
}
@Nonnull
private static Instruction31i instruction31i(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int literal = reader.readInt();
return new ImmutableInstruction31i(opcode, registerA, literal);
}
@Nonnull
private static Instruction31t instruction31t(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
int offset = reader.readInt();
return new ImmutableInstruction31t(opcode, registerA, offset);
}
@Nonnull
private static Instruction32x instruction32x(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
reader.skipByte();
int registerA = reader.readUshort();
int registerB = reader.readUshort();
return new ImmutableInstruction32x(opcode, registerA, registerB);
}
@Nonnull
private static Instruction35c instruction35c(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
DexBuffer dexBuf = reader.getDexBuffer();
int b = reader.readUbyte();
int registerCount = NibbleUtils.extractHighUnsignedNibble(b);
int registerG = NibbleUtils.extractLowUnsignedNibble(b);
int referenceIndex = reader.readUshort();
b = reader.readUbyte();
int registerC = NibbleUtils.extractLowUnsignedNibble(b);
int registerD = NibbleUtils.extractHighUnsignedNibble(b);
b = reader.readUbyte();
int registerE = NibbleUtils.extractLowUnsignedNibble(b);
int registerF = NibbleUtils.extractHighUnsignedNibble(b);
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
return new ImmutableInstruction35c(opcode, registerCount, registerC, registerD, registerE, registerF,
registerG, reference);
}
@Nonnull
private static Instruction3rc instruction3rc(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
DexBuffer dexBuf = reader.getDexBuffer();
int registerCount = reader.readUbyte();
int referenceIndex = reader.readUshort();
int startRegister = reader.readUshort();
Reference reference = DexBackedReference.makeReference(dexBuf, opcode.referenceType, referenceIndex);
return new ImmutableInstruction3rc(opcode, startRegister, registerCount, reference);
}
@Nonnull
private static Instruction51l instruction51l(@Nonnull Opcode opcode, @Nonnull DexReader reader) {
int registerA = reader.readUbyte();
long literal = reader.readLong();
return new ImmutableInstruction51l(opcode, registerA, literal);
}
@Nonnull
private static DexBackedPackedSwitchPayload packedSwitchPayload(@Nonnull DexReader reader) {
// the reader is currently positioned after the 2-byte "opcode"
int instructionStartOffset = reader.getOffset() - 2;
DexBackedPackedSwitchPayload instruction =
new DexBackedPackedSwitchPayload(reader.getDexBuffer(), instructionStartOffset);
reader.setOffset(instructionStartOffset + instruction.getCodeUnits() * 2);
return instruction;
}
@Nonnull
private static DexBackedSparseSwitchPayload sparseSwitchPayload(@Nonnull DexReader reader) {
// the reader is currently positioned after the 2-byte "opcode"
int instructionStartOffset = reader.getOffset() - 2;
DexBackedSparseSwitchPayload instruction =
new DexBackedSparseSwitchPayload(reader.getDexBuffer(), instructionStartOffset);
reader.setOffset(instructionStartOffset + instruction.getCodeUnits() * 2);
return instruction;
}
@Nonnull
private static DexBackedArrayPayload arrayPayload(@Nonnull DexReader reader) {
// the reader is currently positioned after the 2-byte "opcode"
int instructionStartOffset = reader.getOffset() - 2;
DexBackedArrayPayload instruction = new DexBackedArrayPayload(reader.getDexBuffer(), instructionStartOffset);
reader.setOffset(instructionStartOffset + instruction.getCodeUnits() * 2);
return instruction;
}
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction10t;
import javax.annotation.Nonnull;
public class DexBackedInstruction10t extends DexBackedInstruction implements Instruction10t {
public DexBackedInstruction10t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getCodeOffset() { return dexBuf.readByte(instructionStart + 1); }
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction10x;
import javax.annotation.Nonnull;
public class DexBackedInstruction10x extends DexBackedInstruction implements Instruction10x {
public DexBackedInstruction10x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction11n;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction11n extends DexBackedInstruction implements Instruction11n {
public DexBackedInstruction11n(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override
public int getRegisterA() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override
public int getNarrowLiteral() {
return NibbleUtils.extractHighSignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override public long getWideLiteral() { return getNarrowLiteral(); }
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction11x;
import javax.annotation.Nonnull;
public class DexBackedInstruction11x extends DexBackedInstruction implements Instruction11x {
public DexBackedInstruction11x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
}

View File

@ -0,0 +1,57 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction12x;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction12x extends DexBackedInstruction implements Instruction12x {
public DexBackedInstruction12x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override
public int getRegisterA() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override
public int getRegisterB() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction20t;
import javax.annotation.Nonnull;
public class DexBackedInstruction20t extends DexBackedInstruction implements Instruction20t {
public DexBackedInstruction20t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getCodeOffset() { return dexBuf.readShort(instructionStart + 2); }
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.formats.Instruction21c;
import org.jf.dexlib2.iface.reference.Reference;
import javax.annotation.Nonnull;
public class DexBackedInstruction21c extends DexBackedInstruction implements Instruction21c {
public DexBackedInstruction21c(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Nonnull
@Override
public Reference getReference() {
return DexBackedReference.makeReference(dexBuf, opcode.referenceType, dexBuf.readUshort(instructionStart + 2));
}
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction21ih;
import javax.annotation.Nonnull;
public class DexBackedInstruction21ih extends DexBackedInstruction implements Instruction21ih {
public DexBackedInstruction21ih(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getNarrowLiteral() { return getHatLiteral() << 16; }
@Override public long getWideLiteral() { return getNarrowLiteral(); }
@Override public short getHatLiteral() { return (short)dexBuf.readShort(instructionStart + 2); }
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction21lh;
import javax.annotation.Nonnull;
public class DexBackedInstruction21lh extends DexBackedInstruction implements Instruction21lh {
public DexBackedInstruction21lh(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public long getWideLiteral() { return ((long)getHatLiteral()) << 48; }
@Override public short getHatLiteral() { return (short)dexBuf.readShort(instructionStart + 2); }
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction21s;
import javax.annotation.Nonnull;
public class DexBackedInstruction21s extends DexBackedInstruction implements Instruction21s {
public DexBackedInstruction21s(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getNarrowLiteral() { return dexBuf.readShort(instructionStart + 2); }
@Override public long getWideLiteral() { return getNarrowLiteral(); }
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction21t;
import javax.annotation.Nonnull;
public class DexBackedInstruction21t extends DexBackedInstruction implements Instruction21t {
public DexBackedInstruction21t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getCodeOffset() { return dexBuf.readShort(instructionStart + 2); }
}

View File

@ -0,0 +1,51 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction22b;
import javax.annotation.Nonnull;
public class DexBackedInstruction22b extends DexBackedInstruction implements Instruction22b {
public DexBackedInstruction22b(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getRegisterB() { return dexBuf.readUbyte(instructionStart + 2); }
@Override public int getNarrowLiteral() { return dexBuf.readByte(instructionStart + 3); }
@Override public long getWideLiteral() { return getNarrowLiteral(); }
}

View File

@ -0,0 +1,65 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.formats.Instruction22c;
import org.jf.dexlib2.iface.reference.Reference;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction22c extends DexBackedInstruction implements Instruction22c {
public DexBackedInstruction22c(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override
public int getRegisterA() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override
public int getRegisterB() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Nonnull
@Override
public Reference getReference() {
return DexBackedReference.makeReference(dexBuf, opcode.referenceType, dexBuf.readUshort(instructionStart + 2));
}
}

View File

@ -0,0 +1,60 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction22s;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction22s extends DexBackedInstruction implements Instruction22s {
public DexBackedInstruction22s(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override
public int getRegisterA() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override
public int getRegisterB() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override public int getNarrowLiteral() { return dexBuf.readShort(instructionStart + 2); }
@Override public long getWideLiteral() { return getNarrowLiteral(); }
}

View File

@ -0,0 +1,59 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction22t;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction22t extends DexBackedInstruction implements Instruction22t {
public DexBackedInstruction22t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override
public int getRegisterA() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override
public int getRegisterB() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readByte(instructionStart + 1));
}
@Override public int getCodeOffset() { return dexBuf.readShort(instructionStart + 2); }
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction22x;
import javax.annotation.Nonnull;
public class DexBackedInstruction22x extends DexBackedInstruction implements Instruction22x {
public DexBackedInstruction22x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getRegisterB() { return dexBuf.readUshort(instructionStart + 2); }
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction23x;
import javax.annotation.Nonnull;
public class DexBackedInstruction23x extends DexBackedInstruction implements Instruction23x {
public DexBackedInstruction23x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getRegisterB() { return dexBuf.readUbyte(instructionStart + 2); }
@Override public int getRegisterC() { return dexBuf.readUbyte(instructionStart + 3); }
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction30t;
import javax.annotation.Nonnull;
public class DexBackedInstruction30t extends DexBackedInstruction implements Instruction30t {
public DexBackedInstruction30t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getCodeOffset() { return dexBuf.readInt(instructionStart + 2); }
}

View File

@ -0,0 +1,57 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.formats.Instruction31c;
import org.jf.dexlib2.iface.reference.Reference;
import javax.annotation.Nonnull;
public class DexBackedInstruction31c extends DexBackedInstruction implements Instruction31c {
public DexBackedInstruction31c(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Nonnull
@Override
public Reference getReference() {
return DexBackedReference.makeReference(dexBuf, opcode.referenceType,
dexBuf.readSmallUint(instructionStart + 2));
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction31i;
import javax.annotation.Nonnull;
public class DexBackedInstruction31i extends DexBackedInstruction implements Instruction31i {
public DexBackedInstruction31i(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getNarrowLiteral() { return dexBuf.readInt(instructionStart + 2); }
@Override public long getWideLiteral() { return getNarrowLiteral(); }
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction31t;
import javax.annotation.Nonnull;
public class DexBackedInstruction31t extends DexBackedInstruction implements Instruction31t {
public DexBackedInstruction31t(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public int getCodeOffset() { return dexBuf.readInt(instructionStart + 2); }
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction32x;
import javax.annotation.Nonnull;
public class DexBackedInstruction32x extends DexBackedInstruction implements Instruction32x {
public DexBackedInstruction32x(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUshort(instructionStart + 2); }
@Override public int getRegisterB() { return dexBuf.readUshort(instructionStart + 4); }
}

View File

@ -0,0 +1,86 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.formats.Instruction35c;
import org.jf.dexlib2.iface.reference.Reference;
import org.jf.util.NibbleUtils;
import javax.annotation.Nonnull;
public class DexBackedInstruction35c extends DexBackedInstruction implements Instruction35c {
public DexBackedInstruction35c(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterCount() {
//TODO: make sure dalvik verifies that this is in the correct range
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readUbyte(instructionStart + 1));
}
@Override
public int getRegisterC() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readUbyte(instructionStart + 4));
}
@Override
public int getRegisterD() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readUbyte(instructionStart + 4));
}
@Override
public int getRegisterE() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readUbyte(instructionStart + 5));
}
@Override
public int getRegisterF() {
return NibbleUtils.extractHighUnsignedNibble(dexBuf.readUbyte(instructionStart + 5));
}
@Override
public int getRegisterG() {
return NibbleUtils.extractLowUnsignedNibble(dexBuf.readUbyte(instructionStart + 1));
}
@Nonnull
@Override
public Reference getReference() {
return DexBackedReference.makeReference(dexBuf, opcode.referenceType,
dexBuf.readUshort(instructionStart + 2));
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.dexbacked.reference.DexBackedReference;
import org.jf.dexlib2.iface.instruction.formats.Instruction3rc;
import org.jf.dexlib2.iface.reference.Reference;
import javax.annotation.Nonnull;
public class DexBackedInstruction3rc extends DexBackedInstruction implements Instruction3rc {
public DexBackedInstruction3rc(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterCount() {
return dexBuf.readUbyte(instructionStart + 1);
}
@Override
public int getStartRegister() {
return dexBuf.readUshort(instructionStart + 4);
}
@Nonnull
@Override
public Reference getReference() {
return DexBackedReference.makeReference(dexBuf, opcode.referenceType,
dexBuf.readUshort(instructionStart + 2));
}
}

View File

@ -0,0 +1,49 @@
/*
* Copyright 2012, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib2.dexbacked.instruction;
import org.jf.dexlib2.Opcode;
import org.jf.dexlib2.dexbacked.DexBuffer;
import org.jf.dexlib2.iface.instruction.formats.Instruction51l;
import javax.annotation.Nonnull;
public class DexBackedInstruction51l extends DexBackedInstruction implements Instruction51l {
public DexBackedInstruction51l(@Nonnull DexBuffer dexBuf,
@Nonnull Opcode opcode,
int instructionStart) {
super(dexBuf, opcode, instructionStart);
}
@Override public int getRegisterA() { return dexBuf.readUbyte(instructionStart + 1); }
@Override public long getWideLiteral() { return dexBuf.readLong(instructionStart + 2); }
}

View File

@ -40,12 +40,7 @@ import org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload;
import javax.annotation.Nonnull;
import java.util.List;
public class DexBackedPackedSwitchPayload implements PackedSwitchPayload {
public static final Opcode OPCODE = Opcode.PACKED_SWITCH_PAYLOAD;
@Nonnull public final DexBuffer dexBuf;
private final int instructionOffset;
public class DexBackedPackedSwitchPayload extends DexBackedInstruction implements PackedSwitchPayload {
public final int elementCount;
private static final int ELEMENT_COUNT_OFFSET = 2;
@ -53,17 +48,16 @@ public class DexBackedPackedSwitchPayload implements PackedSwitchPayload {
private static final int TARGETS_OFFSET = 8;
public DexBackedPackedSwitchPayload(@Nonnull DexBuffer dexBuf,
int instructionOffset) {
this.dexBuf = dexBuf;
this.instructionOffset = instructionOffset;
int instructionStart) {
super(dexBuf, Opcode.PACKED_SWITCH_PAYLOAD, instructionStart);
this.elementCount = dexBuf.readUshort(instructionOffset + ELEMENT_COUNT_OFFSET);
elementCount = dexBuf.readUshort(instructionStart + ELEMENT_COUNT_OFFSET);
}
@Nonnull
@Override
public List<? extends SwitchElement> getSwitchElements() {
final int firstKey = dexBuf.readInt(instructionOffset + FIRST_KEY_OFFSET);
final int firstKey = dexBuf.readInt(instructionStart + FIRST_KEY_OFFSET);
return new FixedSizeList<SwitchElement>() {
@Nonnull
@Override
@ -76,7 +70,7 @@ public class DexBackedPackedSwitchPayload implements PackedSwitchPayload {
@Override
public int getOffset() {
return dexBuf.readInt(instructionOffset + TARGETS_OFFSET + index*4);
return dexBuf.readInt(instructionStart + TARGETS_OFFSET + index*4);
}
};
}
@ -86,5 +80,4 @@ public class DexBackedPackedSwitchPayload implements PackedSwitchPayload {
}
@Override public int getCodeUnits() { return 4 + elementCount*2; }
@Override public Opcode getOpcode() { return OPCODE; }
}

View File

@ -40,23 +40,17 @@ import org.jf.dexlib2.iface.instruction.formats.SparseSwitchPayload;
import javax.annotation.Nonnull;
import java.util.List;
public class DexBackedSparseSwitchPayload implements SparseSwitchPayload {
public static final Opcode OPCODE = Opcode.SPARSE_SWITCH_PAYLOAD;
@Nonnull public final DexBuffer dexBuf;
private final int instructionOffset;
public class DexBackedSparseSwitchPayload extends DexBackedInstruction implements SparseSwitchPayload {
public final int elementCount;
private static final int ELEMENT_COUNT_OFFSET = 2;
private static final int KEYS_OFFSET = 4;
public DexBackedSparseSwitchPayload(@Nonnull DexBuffer dexBuf,
int instructionOffset) {
this.dexBuf = dexBuf;
this.instructionOffset = instructionOffset;
int instructionStart) {
super(dexBuf, Opcode.SPARSE_SWITCH_PAYLOAD, instructionStart);
this.elementCount = dexBuf.readUshort(instructionOffset + ELEMENT_COUNT_OFFSET);
elementCount = dexBuf.readUshort(instructionStart + ELEMENT_COUNT_OFFSET);
}
@Nonnull
@ -69,12 +63,12 @@ public class DexBackedSparseSwitchPayload implements SparseSwitchPayload {
return new SwitchElement() {
@Override
public int getKey() {
return dexBuf.readInt(instructionOffset + KEYS_OFFSET + index*4);
return dexBuf.readInt(instructionStart + KEYS_OFFSET + index*4);
}
@Override
public int getOffset() {
return dexBuf.readInt(instructionOffset + KEYS_OFFSET + elementCount*4 + index*4);
return dexBuf.readInt(instructionStart + KEYS_OFFSET + elementCount*4 + index*4);
}
};
}
@ -84,5 +78,4 @@ public class DexBackedSparseSwitchPayload implements SparseSwitchPayload {
}
@Override public int getCodeUnits() { return 2 + elementCount*4; }
@Override public Opcode getOpcode() { return OPCODE; }
}