use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.
the class RopToDop method dopFor.
/**
* Returns the dalvik opcode appropriate for the given register-based
* instruction.
*
* @param insn {@code non-null;} the original instruction
* @return the corresponding dalvik opcode; one of the constants in
* {@link Dops}
*/
public static Dop dopFor(Insn insn) {
Rop rop = insn.getOpcode();
/*
* First, just try looking up the rop in the MAP of easy
* cases.
*/
Dop result = MAP.get(rop);
if (result != null) {
return result;
}
switch(rop.getOpcode()) {
case RegOps.MOVE_EXCEPTION:
return Dops.MOVE_EXCEPTION;
case RegOps.INVOKE_STATIC:
return Dops.INVOKE_STATIC;
case RegOps.INVOKE_VIRTUAL:
return Dops.INVOKE_VIRTUAL;
case RegOps.INVOKE_SUPER:
return Dops.INVOKE_SUPER;
case RegOps.INVOKE_DIRECT:
return Dops.INVOKE_DIRECT;
case RegOps.INVOKE_INTERFACE:
return Dops.INVOKE_INTERFACE;
case RegOps.NEW_ARRAY:
return Dops.NEW_ARRAY;
case RegOps.FILLED_NEW_ARRAY:
return Dops.FILLED_NEW_ARRAY;
case RegOps.FILL_ARRAY_DATA:
return Dops.FILL_ARRAY_DATA;
case RegOps.MOVE_RESULT:
{
RegisterSpec resultReg = insn.getResult();
if (resultReg == null) {
return Dops.NOP;
} else {
switch(resultReg.getBasicType()) {
case Type.BT_INT:
case Type.BT_FLOAT:
case Type.BT_BOOLEAN:
case Type.BT_BYTE:
case Type.BT_CHAR:
case Type.BT_SHORT:
return Dops.MOVE_RESULT;
case Type.BT_LONG:
case Type.BT_DOUBLE:
return Dops.MOVE_RESULT_WIDE;
case Type.BT_OBJECT:
return Dops.MOVE_RESULT_OBJECT;
default:
{
throw new RuntimeException("Unexpected basic type");
}
}
}
}
case RegOps.GET_FIELD:
{
CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
int basicType = ref.getBasicType();
switch(basicType) {
case Type.BT_BOOLEAN:
return Dops.IGET_BOOLEAN;
case Type.BT_BYTE:
return Dops.IGET_BYTE;
case Type.BT_CHAR:
return Dops.IGET_CHAR;
case Type.BT_SHORT:
return Dops.IGET_SHORT;
case Type.BT_INT:
return Dops.IGET;
}
break;
}
case RegOps.PUT_FIELD:
{
CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
int basicType = ref.getBasicType();
switch(basicType) {
case Type.BT_BOOLEAN:
return Dops.IPUT_BOOLEAN;
case Type.BT_BYTE:
return Dops.IPUT_BYTE;
case Type.BT_CHAR:
return Dops.IPUT_CHAR;
case Type.BT_SHORT:
return Dops.IPUT_SHORT;
case Type.BT_INT:
return Dops.IPUT;
}
break;
}
case RegOps.GET_STATIC:
{
CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
int basicType = ref.getBasicType();
switch(basicType) {
case Type.BT_BOOLEAN:
return Dops.SGET_BOOLEAN;
case Type.BT_BYTE:
return Dops.SGET_BYTE;
case Type.BT_CHAR:
return Dops.SGET_CHAR;
case Type.BT_SHORT:
return Dops.SGET_SHORT;
case Type.BT_INT:
return Dops.SGET;
}
break;
}
case RegOps.PUT_STATIC:
{
CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
int basicType = ref.getBasicType();
switch(basicType) {
case Type.BT_BOOLEAN:
return Dops.SPUT_BOOLEAN;
case Type.BT_BYTE:
return Dops.SPUT_BYTE;
case Type.BT_CHAR:
return Dops.SPUT_CHAR;
case Type.BT_SHORT:
return Dops.SPUT_SHORT;
case Type.BT_INT:
return Dops.SPUT;
}
break;
}
case RegOps.CONST:
{
Constant cst = ((ThrowingCstInsn) insn).getConstant();
if (cst instanceof CstType) {
return Dops.CONST_CLASS;
} else if (cst instanceof CstString) {
return Dops.CONST_STRING;
}
break;
}
}
throw new RuntimeException("unknown rop: " + rop);
}
use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.
the class MemberListParser method parse.
/**
* Does the actual parsing.
*/
private void parse() {
int attributeContext = getAttributeContext();
int count = getCount();
// Skip the count.
int at = offset + 2;
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
if (observer != null) {
observer.parsed(bytes, offset, 2, humanName() + "s_count: " + Hex.u2(count));
}
for (int i = 0; i < count; i++) {
try {
int accessFlags = bytes.getUnsignedShort(at);
int nameIdx = bytes.getUnsignedShort(at + 2);
int descIdx = bytes.getUnsignedShort(at + 4);
CstString name = (CstString) pool.get(nameIdx);
CstString desc = (CstString) pool.get(descIdx);
if (observer != null) {
observer.startParsingMember(bytes, at, name.getString(), desc.getString());
observer.parsed(bytes, at, 0, "\n" + humanName() + "s[" + i + "]:\n");
observer.changeIndent(1);
observer.parsed(bytes, at, 2, "access_flags: " + humanAccessFlags(accessFlags));
observer.parsed(bytes, at + 2, 2, "name: " + name.toHuman());
observer.parsed(bytes, at + 4, 2, "descriptor: " + desc.toHuman());
}
at += 6;
AttributeListParser parser = new AttributeListParser(cf, attributeContext, at, attributeFactory);
parser.setObserver(observer);
at = parser.getEndOffset();
StdAttributeList attributes = parser.getList();
attributes.setImmutable();
CstNat nat = new CstNat(name, desc);
Member member = set(i, accessFlags, nat, attributes);
if (observer != null) {
observer.changeIndent(-1);
observer.parsed(bytes, at, 0, "end " + humanName() + "s[" + i + "]\n");
observer.endParsingMember(bytes, at, name.getString(), desc.getString(), member);
}
} catch (ParseException ex) {
ex.addContext("...while parsing " + humanName() + "s[" + i + "]");
throw ex;
} catch (RuntimeException ex) {
ParseException pe = new ParseException(ex);
pe.addContext("...while parsing " + humanName() + "s[" + i + "]");
throw pe;
}
}
endOffset = at;
}
use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.
the class StdAttributeFactory method signature.
/**
* Parses a {@code Signature} attribute.
*/
private Attribute signature(DirectClassFile cf, int offset, int length, ParseObserver observer) {
if (length != 2) {
throwBadLength(2);
}
ByteArray bytes = cf.getBytes();
ConstantPool pool = cf.getConstantPool();
int idx = bytes.getUnsignedShort(offset);
CstString cst = (CstString) pool.get(idx);
Attribute result = new AttSignature(cst);
if (observer != null) {
observer.parsed(bytes, offset, 2, "signature: " + cst);
}
return result;
}
use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.
the class InsnFormat method cstString.
/**
* Helper method to return the constant string for a {@link CstInsn}
* in human form.
*
* @param insn {@code non-null;} a constant-bearing instruction
* @return {@code non-null;} the human string form of the contained
* constant
*/
protected static String cstString(DalvInsn insn) {
CstInsn ci = (CstInsn) insn;
Constant cst = ci.getConstant();
return cst instanceof CstString ? ((CstString) cst).toQuoted() : cst.toHuman();
}
use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.
the class Form31c method isCompatible.
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
if (!(insn instanceof CstInsn)) {
return false;
}
RegisterSpecList regs = insn.getRegisters();
RegisterSpec reg;
switch(regs.size()) {
case 1:
{
reg = regs.get(0);
break;
}
case 2:
{
/*
* This format is allowed for ops that are effectively
* 2-arg but where the two args are identical.
*/
reg = regs.get(0);
if (reg.getReg() != regs.get(1).getReg()) {
return false;
}
break;
}
default:
{
return false;
}
}
if (!unsignedFitsInByte(reg.getReg())) {
return false;
}
CstInsn ci = (CstInsn) insn;
Constant cst = ci.getConstant();
return (cst instanceof CstType) || (cst instanceof CstFieldRef) || (cst instanceof CstString);
}
Aggregations