mirror of
https://github.com/revanced/smali.git
synced 2025-06-12 04:17:36 +02:00
Use Format 35c for invoke-direct-empty, and get rid of Format 35s
This commit is contained in:
@ -3463,7 +3463,7 @@ public class MethodAnalyzer {
|
||||
}
|
||||
|
||||
private void analyzeInvokeDirectEmpty(AnalyzedInstruction analyzedInstruction) {
|
||||
Instruction35s instruction = (Instruction35s)analyzedInstruction.instruction;
|
||||
Instruction35c instruction = (Instruction35c)analyzedInstruction.instruction;
|
||||
|
||||
Instruction35c deodexedInstruction = new Instruction35c(Opcode.INVOKE_DIRECT, instruction.getRegCount(),
|
||||
instruction.getRegisterD(), instruction.getRegisterE(), instruction.getRegisterF(),
|
||||
|
@ -55,7 +55,6 @@ public enum Format {
|
||||
Format31t(Instruction31t.Factory, 6),
|
||||
Format32x(Instruction32x.Factory, 6),
|
||||
Format35c(Instruction35c.Factory, 6),
|
||||
Format35s(Instruction35s.Factory, 6),
|
||||
Format35mi(Instruction35mi.Factory, 6),
|
||||
Format35ms(Instruction35ms.Factory, 6),
|
||||
Format3rc(Instruction3rc.Factory, 6),
|
||||
|
@ -66,23 +66,19 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi
|
||||
throw new RuntimeException("All register args must fit in 4 bits");
|
||||
}
|
||||
|
||||
checkItem(opcode, referencedItem, regCount);
|
||||
|
||||
this.regCount = (byte)regCount;
|
||||
this.regA = regA;
|
||||
this.regD = regD;
|
||||
this.regE = regE;
|
||||
this.regF = regF;
|
||||
this.regG = regG;
|
||||
|
||||
checkItem(opcode, referencedItem, regCount);
|
||||
}
|
||||
|
||||
protected Instruction35c(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
|
||||
super(dexFile, opcode, buffer, bufferIndex);
|
||||
|
||||
if (getRegCount() > 5) {
|
||||
throw new RuntimeException("regCount cannot be greater than 5");
|
||||
}
|
||||
|
||||
this.regCount = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 1]);
|
||||
this.regA = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 1]);
|
||||
this.regD = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 4]);
|
||||
@ -90,6 +86,10 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi
|
||||
this.regF = NumberUtils.decodeLowUnsignedNibble(buffer[bufferIndex + 5]);
|
||||
this.regG = NumberUtils.decodeHighUnsignedNibble(buffer[bufferIndex + 5]);
|
||||
|
||||
if (getRegCount() > 5) {
|
||||
throw new RuntimeException("regCount cannot be greater than 5");
|
||||
}
|
||||
|
||||
checkItem(opcode, getReferencedItem(), getRegCount());
|
||||
}
|
||||
|
||||
@ -148,7 +148,8 @@ public class Instruction35c extends InstructionWithReference implements FiveRegi
|
||||
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.value && opcode.value <= INVOKE_INTERFACE.value) {
|
||||
} else if (opcode.value >= INVOKE_VIRTUAL.value && opcode.value <= INVOKE_INTERFACE.value ||
|
||||
opcode == INVOKE_DIRECT_EMPTY) {
|
||||
//check data for invoke-* opcodes
|
||||
MethodIdItem methodIdItem = (MethodIdItem) item;
|
||||
int parameterRegisterCount = methodIdItem.getPrototype().getParameterRegisterCount();
|
||||
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* [The "BSD licence"]
|
||||
* Copyright (c) 2010 Ben Gruver (JesusFreke)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. 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.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.FiveRegisterInstruction;
|
||||
import org.jf.dexlib.Code.Instruction;
|
||||
import org.jf.dexlib.Code.InstructionWithReference;
|
||||
import org.jf.dexlib.Code.Opcode;
|
||||
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 Instruction35s extends InstructionWithReference implements FiveRegisterInstruction {
|
||||
public static final Instruction.InstructionFactory Factory = new Factory();
|
||||
private byte regCount;
|
||||
private byte regA;
|
||||
private byte regD;
|
||||
private byte regE;
|
||||
private byte regF;
|
||||
private byte regG;
|
||||
|
||||
public Instruction35s(Opcode opcode, int regCount, byte regD, byte regE, byte regF, byte regG,
|
||||
byte regA, Item referencedItem) {
|
||||
super(opcode, referencedItem);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
checkItem(opcode, referencedItem, regCount);
|
||||
|
||||
this.regCount = (byte)regCount;
|
||||
this.regA = regA;
|
||||
this.regD = regD;
|
||||
this.regE = regE;
|
||||
this.regF = regF;
|
||||
this.regG = regG;
|
||||
}
|
||||
|
||||
protected Instruction35s(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
|
||||
super(dexFile, opcode, buffer, bufferIndex);
|
||||
|
||||
if (getRegCount() > 5) {
|
||||
throw new RuntimeException("regCount cannot be greater than 5");
|
||||
}
|
||||
|
||||
checkItem(opcode, getReferencedItem(), getRegCount());
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
protected void writeInstruction(AnnotatedOutput out, int currentCodeAddress) {
|
||||
out.writeByte(opcode.value);
|
||||
out.writeByte((regCount << 4) | regA);
|
||||
out.writeShort(getReferencedItem().getIndex());
|
||||
out.writeByte((regE << 4) | regD);
|
||||
out.writeByte((regG << 4) | regF);
|
||||
}
|
||||
|
||||
public Format getFormat() {
|
||||
return Format.Format35s;
|
||||
}
|
||||
|
||||
public int 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;
|
||||
}
|
||||
|
||||
private static void checkItem(Opcode opcode, Item item, int regCount) {
|
||||
if (opcode == FILLED_NEW_ARRAY) {
|
||||
//check data for filled-new-array 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.value && opcode.value <= INVOKE_INTERFACE.value) {
|
||||
//check data for invoke-* opcodes
|
||||
MethodIdItem methodIdItem = (MethodIdItem) item;
|
||||
int parameterRegisterCount = methodIdItem.getPrototype().getParameterRegisterCount();
|
||||
if (opcode != INVOKE_STATIC) {
|
||||
parameterRegisterCount++;
|
||||
}
|
||||
if (parameterRegisterCount != regCount) {
|
||||
throw new RuntimeException("regCount does not match the number of arguments of the method");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class Factory implements Instruction.InstructionFactory {
|
||||
public Instruction makeInstruction(DexFile dexFile, Opcode opcode, byte[] buffer, int bufferIndex) {
|
||||
return new Instruction35s(dexFile, opcode, buffer, bufferIndex);
|
||||
}
|
||||
}
|
||||
}
|
@ -266,7 +266,7 @@ public enum Opcode
|
||||
THROW_VERIFICATION_ERROR((short)0xed, "throw-verification-error", ReferenceType.none, Format.Format20bc, Opcode.ODEX_ONLY | Opcode.CAN_THROW),
|
||||
EXECUTE_INLINE((short)0xee, "execute-inline", ReferenceType.none, Format.Format35mi, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
EXECUTE_INLINE_RANGE((short)0xef, "execute-inline/range", ReferenceType.none, Format.Format3rmi, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_DIRECT_EMPTY((short)0xf0, "invoke-direct-empty", ReferenceType.method, Format.Format35s, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_DIRECT_EMPTY((short)0xf0, "invoke-direct-empty", ReferenceType.method, Format.Format35c, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
INVOKE_OBJECT_INIT_RANGE((short)0xf0, "invoke-object-init/range", ReferenceType.method, Format.Format3rc, Opcode.ODEX_ONLY | Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_RESULT),
|
||||
IGET_QUICK((short)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((short)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),
|
||||
|
Reference in New Issue
Block a user