mirror of
https://github.com/revanced/smali.git
synced 2025-06-12 04:17:36 +02:00
Add support for Format5rc
This commit is contained in:
@ -3402,7 +3402,7 @@ public class MethodAnalyzer {
|
||||
assert false;
|
||||
}
|
||||
|
||||
Instruction3rc deodexedInstruction = new Instruction3rc(deodexedOpcode, instruction.getRegCount(),
|
||||
Instruction3rc deodexedInstruction = new Instruction3rc(deodexedOpcode, (short)instruction.getRegCount(),
|
||||
instruction.getStartRegister(), inlineMethodIdItem);
|
||||
|
||||
analyzedInstruction.setDeodexedInstruction(deodexedInstruction);
|
||||
@ -3511,7 +3511,7 @@ public class MethodAnalyzer {
|
||||
opcode = Opcode.INVOKE_VIRTUAL_RANGE;
|
||||
}
|
||||
|
||||
deodexedInstruction = new Instruction3rc(opcode, instruction.getRegCount(),
|
||||
deodexedInstruction = new Instruction3rc(opcode, (short)instruction.getRegCount(),
|
||||
instruction.getStartRegister(), methodIdItem);
|
||||
} else {
|
||||
Instruction35ms instruction = (Instruction35ms)analyzedInstruction.instruction;
|
||||
|
@ -64,6 +64,7 @@ public enum Format {
|
||||
Format41c(Instruction41c.Factory, 8),
|
||||
Format51l(Instruction51l.Factory, 10),
|
||||
Format52c(Instruction52c.Factory, 10),
|
||||
Format5rc(Instruction5rc.Factory, 10),
|
||||
ArrayData(null, -1, true),
|
||||
PackedSwitchData(null, -1, true),
|
||||
SparseSwitchData(null, -1, true),
|
||||
|
@ -94,6 +94,10 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi
|
||||
}
|
||||
|
||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
|
||||
if(getReferencedItem().getIndex() > 0xFFFF) {
|
||||
throw new RuntimeException(String.format("%s index is too large. Use the %s/jumbo instruction instead.", opcode.referenceType.name(), opcode.name));
|
||||
}
|
||||
|
||||
out.writeByte(opcode.value);
|
||||
out.writeByte((regCount << 4) | regA);
|
||||
out.writeShort(getReferencedItem().getIndex());
|
||||
@ -105,7 +109,7 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi
|
||||
return Format.Format35c;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return regCount;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class Instruction35mi extends Instruction implements FiveRegisterInstruct
|
||||
return Format.Format35ms;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return regCount;
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class Instruction35ms extends Instruction implements FiveRegisterInstruct
|
||||
return Format.Format35ms;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return regCount;
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class Instruction35s extends InstructionWithReference implements FiveRegi
|
||||
return Format.Format35s;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return regCount;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,10 @@ public class Instruction3rc extends InstructionWithReference implements Register
|
||||
}
|
||||
|
||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
|
||||
if(getReferencedItem().getIndex() > 0xFFFF) {
|
||||
throw new RuntimeException(String.format("%s index is too large. Use the jumbo variant of the instruction instead.", opcode.referenceType.name()));
|
||||
}
|
||||
|
||||
out.writeByte(opcode.value);
|
||||
out.writeByte(regCount);
|
||||
out.writeShort(this.getReferencedItem().getIndex());
|
||||
@ -89,7 +93,7 @@ public class Instruction3rc extends InstructionWithReference implements Register
|
||||
return Format.Format3rc;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return (short)(regCount & 0xFF);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class Instruction3rmi extends Instruction implements RegisterRangeInstruc
|
||||
return Format.Format3rms;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return (short)(regCount & 0xFF);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class Instruction3rms extends Instruction implements RegisterRangeInstruc
|
||||
return Format.Format3rms;
|
||||
}
|
||||
|
||||
public short getRegCount() {
|
||||
public int getRegCount() {
|
||||
return (short)(regCount & 0xFF);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* 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.Instruction;
|
||||
import org.jf.dexlib.Code.InstructionWithReference;
|
||||
import org.jf.dexlib.Code.Opcode;
|
||||
import org.jf.dexlib.Code.RegisterRangeInstruction;
|
||||
import org.jf.dexlib.DexFile;
|
||||
import org.jf.dexlib.Item;
|
||||
import org.jf.dexlib.MethodIdItem;
|
||||
import org.jf.dexlib.TypeIdItem;
|
||||
import org.jf.dexlib.Util.AnnotatedOutput;
|
||||
import org.jf.dexlib.Util.NumberUtils;
|
||||
|
||||
import static org.jf.dexlib.Code.Opcode.*;
|
||||
|
||||
public class Instruction5rc extends InstructionWithJumboReference implements RegisterRangeInstruction {
|
||||
public static final InstructionFactory Factory = new Factory();
|
||||
private short regCount;
|
||||
private short startReg;
|
||||
|
||||
public Instruction5rc(Opcode opcode, int regCount, int startReg, Item referencedItem) {
|
||||
super(opcode, referencedItem);
|
||||
|
||||
if (regCount >= 1 << 16) {
|
||||
throw new RuntimeException("regCount must be less than 65536");
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
this.regCount = (short)regCount;
|
||||
this.startReg = (short)startReg;
|
||||
|
||||
checkItem(opcode, referencedItem, regCount);
|
||||
}
|
||||
|
||||
private Instruction5rc(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
|
||||
super(dexFile, opcode, buffer, bufferIndex);
|
||||
|
||||
this.regCount = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 6);
|
||||
this.startReg = (short)NumberUtils.decodeUnsignedShort(buffer, bufferIndex + 8);
|
||||
|
||||
checkItem(opcode, getReferencedItem(), getRegCount());
|
||||
}
|
||||
|
||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
|
||||
out.writeByte(0xff);
|
||||
out.writeByte(opcode.value);
|
||||
out.writeInt(this.getReferencedItem().getIndex());
|
||||
out.writeShort(regCount);
|
||||
out.writeShort(startReg);
|
||||
}
|
||||
|
||||
public Format getFormat() {
|
||||
return Format.Format5rc;
|
||||
}
|
||||
|
||||
public int getRegCount() {
|
||||
return regCount & 0xFFFF;
|
||||
}
|
||||
|
||||
public int getStartRegister() {
|
||||
return startReg & 0xFFFF;
|
||||
}
|
||||
|
||||
private static void checkItem(Opcode opcode, Item item, int regCount) {
|
||||
if (opcode == FILLED_NEW_ARRAY_JUMBO) {
|
||||
//check data for filled-new-array/jumbo opcode
|
||||
String type = ((TypeIdItem) item).getTypeDescriptor();
|
||||
if (type.charAt(0) != '[') {
|
||||
throw new RuntimeException("The type must be an array type");
|
||||
}
|
||||
if (type.charAt(1) == 'J' || type.charAt(1) == 'D') {
|
||||
throw new RuntimeException("The type cannot be an array of longs or doubles");
|
||||
}
|
||||
} else if (opcode.value >= INVOKE_VIRTUAL_JUMBO.value && opcode.value <= INVOKE_INTERFACE_JUMBO.value) {
|
||||
//check data for invoke-*/range opcodes
|
||||
MethodIdItem methodIdItem = (MethodIdItem) item;
|
||||
int parameterRegisterCount = methodIdItem.getPrototype().getParameterRegisterCount();
|
||||
if (opcode != INVOKE_STATIC_JUMBO) {
|
||||
parameterRegisterCount++;
|
||||
}
|
||||
if (parameterRegisterCount != regCount) {
|
||||
throw new RuntimeException("regCount does not match the number of arguments of the method");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Factory implements InstructionFactory {
|
||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
|
||||
return new Instruction5rc(dexFile, opcode, buffer, bufferIndex);
|
||||
}
|
||||
}
|
||||
}
|
@ -29,5 +29,5 @@
|
||||
package org.jf.dexlib.Code;
|
||||
|
||||
public interface InvokeInstruction {
|
||||
short getRegCount();
|
||||
int getRegCount();
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ public enum Opcode
|
||||
INSTANCE_OF_JUMBO((short)0xff02, "instance-of/jumbo", ReferenceType.type, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
|
||||
NEW_INSTANCE_JUMBO((short)0xff03, "new-instance/jumbo", ReferenceType.type, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
|
||||
NEW_ARRAY_JUMBO((short)0xff04, "new-array/jumbo", ReferenceType.type, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
|
||||
|
||||
FILLED_NEW_ARRAY_JUMBO((short)0xff05, "filled-new-array/jumbo", ReferenceType.type, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
IGET_JUMBO((short)0xff06, "iget/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
|
||||
IGET_WIDE_JUMBO((short)0xff07, "iget-wide/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER | Opcode.SETS_WIDE_REGISTER),
|
||||
IGET_OBJECT_JUMBO((short)0xff08, "iget-object/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER),
|
||||
@ -315,7 +315,12 @@ public enum Opcode
|
||||
SPUT_BOOLEAN_JUMBO((short)0xff1e, "sput-boolean/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE),
|
||||
SPUT_BYTE_JUMBO((short)0xff1f, "sput-byte/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE),
|
||||
SPUT_CHAR_JUMBO((short)0xff20, "sput-char/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE),
|
||||
SPUT_SHORT_JUMBO((short)0xff21, "sput-short/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE);
|
||||
SPUT_SHORT_JUMBO((short)0xff21, "sput-short/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE),
|
||||
INVOKE_VIRTUAL_JUMBO((short)0xff22, "invoke-virtual/jumbo", ReferenceType.method, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_SUPER_JUMBO((short)0xff23, "invoke-super/jumbo", ReferenceType.method, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_DIRECT_JUMBO((short)0xff24, "invoke-direct/jumbo", ReferenceType.method, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_STATIC_JUMBO((short)0xff25, "invoke-static/jumbo", ReferenceType.method, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_INTERFACE_JUMBO((short)0xff26, "invoke-interface/jumbo", ReferenceType.method, Format.Format5rc, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT);
|
||||
|
||||
private static Opcode[] opcodesByValue;
|
||||
private static Opcode[] expandedOpcodesByValue;
|
||||
|
Reference in New Issue
Block a user