Seperate out execute-inline and execute-inline/range into seperate 35mi and 3rmi formats

This commit is contained in:
Ben Gruver
2011-11-09 16:28:26 -08:00
committed by Ben Gruver
parent bda056b7b0
commit b0c62b9781
15 changed files with 382 additions and 38 deletions

View File

@ -28,10 +28,10 @@
package org.jf.dexlib.Code.Analysis;
import org.jf.dexlib.Code.Format.Instruction35ms;
import org.jf.dexlib.Code.Format.Instruction3rms;
import org.jf.dexlib.Code.Format.Instruction35mi;
import org.jf.dexlib.Code.Format.Instruction3rmi;
import org.jf.dexlib.Code.OdexedInvokeInline;
import org.jf.dexlib.Code.OdexedInvokeVirtual;
import org.jf.dexlib.MethodIdItem;
import static org.jf.dexlib.Code.Analysis.DeodexUtil.Static;
import static org.jf.dexlib.Code.Analysis.DeodexUtil.Virtual;
@ -143,16 +143,16 @@ abstract class InlineMethodResolver {
@Override
public DeodexUtil.InlineMethod resolveExecuteInline(AnalyzedInstruction analyzedInstruction) {
assert analyzedInstruction.instruction instanceof OdexedInvokeVirtual;
assert analyzedInstruction.instruction instanceof OdexedInvokeInline;
OdexedInvokeVirtual instruction = (OdexedInvokeVirtual)analyzedInstruction.instruction;
int methodIndex = instruction.getVtableIndex();
OdexedInvokeInline instruction = (OdexedInvokeInline)analyzedInstruction.instruction;
int inlineIndex = instruction.getInlineIndex();
if (methodIndex < 0 || methodIndex >= inlineMethods.length) {
throw new RuntimeException("Invalid method index: " + methodIndex);
if (inlineIndex < 0 || inlineIndex >= inlineMethods.length) {
throw new RuntimeException("Invalid method index: " + inlineIndex);
}
if (methodIndex == 4) {
if (inlineIndex == 4) {
int parameterCount = getParameterCount(instruction);
if (parameterCount == 2) {
return indexOfIMethod;
@ -161,7 +161,7 @@ abstract class InlineMethodResolver {
} else {
throw new RuntimeException("Could not determine the correct inline method to use");
}
} else if (methodIndex == 5) {
} else if (inlineIndex == 5) {
int parameterCount = getParameterCount(instruction);
if (parameterCount == 3) {
return indexOfIIMethod;
@ -172,14 +172,14 @@ abstract class InlineMethodResolver {
}
}
return inlineMethods[methodIndex];
return inlineMethods[inlineIndex];
}
private int getParameterCount(OdexedInvokeVirtual instruction) {
if (instruction instanceof Instruction35ms) {
return ((Instruction35ms)instruction).getRegCount();
private int getParameterCount(OdexedInvokeInline instruction) {
if (instruction instanceof Instruction35mi) {
return ((Instruction35mi)instruction).getRegCount();
} else {
return ((Instruction3rms)instruction).getRegCount();
return ((Instruction3rmi)instruction).getRegCount();
}
}
};

View File

@ -252,11 +252,13 @@ public class MethodAnalyzer {
case Format22cs:
objectRegisterNumber = ((Instruction22cs)instruction.instruction).getRegisterB();
break;
case Format35mi:
case Format35ms:
objectRegisterNumber = ((Instruction35ms)instruction.instruction).getRegisterD();
objectRegisterNumber = ((FiveRegisterInstruction)instruction.instruction).getRegisterD();
break;
case Format3rmi:
case Format3rms:
objectRegisterNumber = ((Instruction3rms)instruction.instruction).getStartRegister();
objectRegisterNumber = ((RegisterRangeInstruction)instruction.instruction).getStartRegister();
break;
default:
continue;
@ -3338,13 +3340,13 @@ public class MethodAnalyzer {
throw new ValidationException("Cannot analyze an odexed instruction unless we are deodexing");
}
Instruction35ms instruction = (Instruction35ms)analyzedInstruction.instruction;
Instruction35mi instruction = (Instruction35mi)analyzedInstruction.instruction;
DeodexUtil.InlineMethod inlineMethod = deodexUtil.lookupInlineMethod(analyzedInstruction);
MethodIdItem inlineMethodIdItem = inlineMethod.getMethodIdItem();
if (inlineMethodIdItem == null) {
throw new ValidationException(String.format("Cannot load inline method with index %d",
instruction.getVtableIndex()));
instruction.getInlineIndex()));
}
Opcode deodexedOpcode = null;
@ -3376,13 +3378,13 @@ public class MethodAnalyzer {
throw new ValidationException("Cannot analyze an odexed instruction unless we are deodexing");
}
Instruction3rms instruction = (Instruction3rms)analyzedInstruction.instruction;
Instruction3rmi instruction = (Instruction3rmi)analyzedInstruction.instruction;
DeodexUtil.InlineMethod inlineMethod = deodexUtil.lookupInlineMethod(analyzedInstruction);
MethodIdItem inlineMethodIdItem = inlineMethod.getMethodIdItem();
if (inlineMethodIdItem == null) {
throw new ValidationException(String.format("Cannot load inline method with index %d",
instruction.getVtableIndex()));
instruction.getInlineIndex()));
}
Opcode deodexedOpcode = null;

View File

@ -56,8 +56,10 @@ public enum Format {
Format32x(Instruction32x.Factory, 6),
Format35c(Instruction35c.Factory, 6),
Format35s(Instruction35s.Factory, 6),
Format35mi(Instruction35mi.Factory, 6),
Format35ms(Instruction35ms.Factory, 6),
Format3rc(Instruction3rc.Factory, 6),
Format3rmi(Instruction3rmi.Factory, 6),
Format3rms(Instruction3rms.Factory, 6),
Format51l(Instruction51l.Factory, 10),
ArrayData(null, -1, true),

View File

@ -0,0 +1,136 @@
/*
* Copyright 2011, 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.dexlib.Code.Format;
import org.jf.dexlib.Code.*;
import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.NumberUtils;
public class Instruction35mi extends Instruction implements FiveRegisterInstruction, OdexedInvokeInline {
public static final InstructionFactory Factory = new Factory();
private byte regCount;
private byte regA;
private byte regD;
private byte regE;
private byte regF;
private byte regG;
private short inlineIndex;
public Instruction35mi(Opcode opcode, int regCount, byte regD, byte regE, byte regF, byte regG,
byte regA, int inlineIndex) {
super(opcode);
if (regCount > 5) {
throw new RuntimeException("regCount cannot be greater than 5");
}
if (regD >= 1 << 4 ||
regE >= 1 << 4 ||
regF >= 1 << 4 ||
regG >= 1 << 4 ||
regA >= 1 << 4) {
throw new RuntimeException("All register args must fit in 4 bits");
}
if (inlineIndex >= 1 << 16) {
throw new RuntimeException("The method index must be less than 65536");
}
this.regCount = (byte)regCount;
this.regA = regA;
this.regD = regD;
this.regE = regE;
this.regF = regF;
this.regG = regG;
this.inlineIndex = (short)inlineIndex;
}
private Instruction35mi(Opcode opcode, byte[] buffer, int bufferIndex) {
super(opcode);
this.regCount = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 1]);
this.regA = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 1]);
this.regD = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 4]);
this.regE = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 4]);
this.regF = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 5]);
this.regG = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 5]);
this.inlineIndex = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 2);
}
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
out.writeByte(opcode.value);
out.writeByte((regCount << 4) | regA);
out.writeShort(inlineIndex);
out.writeByte((regE << 4) | regD);
out.writeByte((regG << 4) | regF);
}
public Format getFormat() {
return Format.Format35ms;
}
public byte getRegCount() {
return regCount;
}
public byte getRegisterA() {
return regA;
}
public byte getRegisterD() {
return regD;
}
public byte getRegisterE() {
return regE;
}
public byte getRegisterF() {
return regF;
}
public byte getRegisterG() {
return regG;
}
public int getInlineIndex() {
return inlineIndex & 0xFFFF;
}
private static class Factory implements InstructionFactory {
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
return new Instruction35mi(opcode, buffer, bufferIndex);
}
}
}

View File

@ -0,0 +1,107 @@
/*
* Copyright 2011, 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.dexlib.Code.Format;
import org.jf.dexlib.Code.*;
import org.jf.dexlib.DexFile;
import org.jf.dexlib.Util.AnnotatedOutput;
import org.jf.dexlib.Util.NumberUtils;
public class Instruction3rmi extends Instruction implements RegisterRangeInstruction, OdexedInvokeInline {
public static final InstructionFactory Factory = new Factory();
private byte regCount;
private short startReg;
private short inlineIndex;
public Instruction3rmi(Opcode opcode, short regCount, int startReg, int inlineIndex) {
super(opcode);
if (regCount >= 1 << 8) {
throw new RuntimeException("regCount must be less than 256");
}
if (regCount < 0) {
throw new RuntimeException("regCount cannot be negative");
}
if (startReg >= 1 << 16) {
throw new RuntimeException("The beginning register of the range must be less than 65536");
}
if (startReg < 0) {
throw new RuntimeException("The beginning register of the range cannot be negative");
}
if (inlineIndex >= 1 << 16) {
throw new RuntimeException("The method index must be less than 65536");
}
this.regCount = (byte)regCount;
this.startReg = (short)startReg;
this.inlineIndex = (short)inlineIndex;
}
private Instruction3rmi(Opcode opcode, byte[] buffer, int bufferIndex) {
super(opcode);
this.regCount = (byte)NumberUtils.decodeUnsignedByte(buffer[bufferIndex + 1]);
this.inlineIndex = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 2);
this.startReg = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 4);
}
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
out.writeByte(opcode.value);
out.writeByte(regCount);
out.writeShort(inlineIndex);
out.writeShort(startReg);
}
public Format getFormat() {
return Format.Format3rms;
}
public short getRegCount() {
return (short)(regCount & 0xFF);
}
public int getStartRegister() {
return startReg & 0xFFFF;
}
public int getInlineIndex() {
return inlineIndex & 0xFFFF;
}
private static class Factory implements InstructionFactory {
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
return new Instruction3rmi(opcode, buffer, bufferIndex);
}
}
}

View File

@ -0,0 +1,36 @@
/*
* Copyright 2011, 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.dexlib.Code;
public interface OdexedInvokeInline {
int getInlineIndex();
}

View File

@ -264,8 +264,8 @@ public enum Opcode
SPUT_WIDE_VOLATILE((byte)0xeb, "sput-wide-volatile", ReferenceType.field, Format.Format21c, Opcode.ODEX_ONLY | Opcode.ODEXED_STATIC_VOLATILE | Opcode.CAN_THROW | Opcode.CAN_CONTINUE),
THROW_VERIFICATION_ERROR((byte)0xed, "throw-verification-error", ReferenceType.none, Format.Format20bc, Opcode.ODEX_ONLY | Opcode.CAN_THROW),
EXECUTE_INLINE((byte)0xee, "execute-inline", ReferenceType.none, Format.Format35ms, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
EXECUTE_INLINE_RANGE((byte)0xef, "execute-inline/range", ReferenceType.none, Format.Format3rms, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
EXECUTE_INLINE((byte)0xee, "execute-inline", ReferenceType.none, Format.Format35mi, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
EXECUTE_INLINE_RANGE((byte)0xef, "execute-inline/range", ReferenceType.none, Format.Format3rmi, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
INVOKE_DIRECT_EMPTY((byte)0xf0, "invoke-direct-empty", ReferenceType.method, Format.Format35s, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
IGET_QUICK((byte)0xf2, "iget-quick", ReferenceType.none, Format.Format22cs, Opcode.ODEX_ONLY | Opcode.ODEXED_INSTANCE_QUICK | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
IGET_WIDE_QUICK((byte)0xf3, "iget-wide-quick", ReferenceType.none, Format.Format22cs, Opcode.ODEX_ONLY | Opcode.ODEXED_INSTANCE_QUICK | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER | Opcode.SETS_WIDE_REGISTER),