use of com.android.dx.rop.cst.CstString in project J2ME-Loader by nikita36078.
the class Form21c 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;
int cpi = ci.getIndex();
Constant cst = ci.getConstant();
if (!unsignedFitsInShort(cpi)) {
return false;
}
return (cst instanceof CstType) || (cst instanceof CstFieldRef) || (cst instanceof CstString);
}
use of com.android.dx.rop.cst.CstString in project J2ME-Loader by nikita36078.
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);
}
use of com.android.dx.rop.cst.CstString in project J2ME-Loader by nikita36078.
the class AnnotationUtils method makeSignature.
/**
* Constructs a standard {@code Signature} annotation.
*
* @param signature {@code non-null;} the signature string
* @return {@code non-null;} the annotation
*/
public static Annotation makeSignature(CstString signature) {
Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);
/*
* Split the string into pieces that are likely to be common
* across many signatures and the rest of the file.
*/
String raw = signature.getString();
int rawLength = raw.length();
ArrayList<String> pieces = new ArrayList<String>(20);
for (int at = 0; at < rawLength; ) /*at*/
{
char c = raw.charAt(at);
int endAt = at + 1;
if (c == 'L') {
// Scan to ';' or '<'. Consume ';' but not '<'.
while (endAt < rawLength) {
c = raw.charAt(endAt);
if (c == ';') {
endAt++;
break;
} else if (c == '<') {
break;
}
endAt++;
}
} else {
// Scan to 'L' without consuming it.
while (endAt < rawLength) {
c = raw.charAt(endAt);
if (c == 'L') {
break;
}
endAt++;
}
}
pieces.add(raw.substring(at, endAt));
at = endAt;
}
int size = pieces.size();
CstArray.List list = new CstArray.List(size);
for (int i = 0; i < size; i++) {
list.set(i, new CstString(pieces.get(i)));
}
list.setImmutable();
result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
result.setImmutable();
return result;
}
use of com.android.dx.rop.cst.CstString in project J2ME-Loader by nikita36078.
the class HeaderItem method writeTo.
/**
* {@inheritDoc}
*/
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
int mapOff = file.getMap().getFileOffset();
Section firstDataSection = file.getFirstDataSection();
Section lastDataSection = file.getLastDataSection();
int dataOff = firstDataSection.getFileOffset();
int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
String magic = file.getDexOptions().getMagic();
if (out.annotates()) {
out.annotate(8, "magic: " + new CstString(magic).toQuoted());
out.annotate(4, "checksum");
out.annotate(20, "signature");
out.annotate(4, "file_size: " + Hex.u4(file.getFileSize()));
out.annotate(4, "header_size: " + Hex.u4(SizeOf.HEADER_ITEM));
out.annotate(4, "endian_tag: " + Hex.u4(DexFormat.ENDIAN_TAG));
out.annotate(4, "link_size: 0");
out.annotate(4, "link_off: 0");
out.annotate(4, "map_off: " + Hex.u4(mapOff));
}
// Write the magic number.
for (int i = 0; i < 8; i++) {
out.writeByte(magic.charAt(i));
}
// Leave space for the checksum and signature.
out.writeZeroes(24);
out.writeInt(file.getFileSize());
out.writeInt(SizeOf.HEADER_ITEM);
out.writeInt(DexFormat.ENDIAN_TAG);
/*
* Write zeroes for the link size and data, as the output
* isn't a staticly linked file.
*/
out.writeZeroes(8);
out.writeInt(mapOff);
// Write out each section's respective header part.
file.getStringIds().writeHeaderPart(out);
file.getTypeIds().writeHeaderPart(out);
file.getProtoIds().writeHeaderPart(out);
file.getFieldIds().writeHeaderPart(out);
file.getMethodIds().writeHeaderPart(out);
file.getClassDefs().writeHeaderPart(out);
if (out.annotates()) {
out.annotate(4, "data_size: " + Hex.u4(dataSize));
out.annotate(4, "data_off: " + Hex.u4(dataOff));
}
out.writeInt(dataSize);
out.writeInt(dataOff);
}
use of com.android.dx.rop.cst.CstString in project J2ME-Loader by nikita36078.
the class ProtoIdItem method makeShortForm.
/**
* Creates the short-form of the given prototype.
*
* @param prototype {@code non-null;} the prototype
* @return {@code non-null;} the short form
*/
private static CstString makeShortForm(Prototype prototype) {
StdTypeList parameters = prototype.getParameterTypes();
int size = parameters.size();
StringBuilder sb = new StringBuilder(size + 1);
sb.append(shortFormCharFor(prototype.getReturnType()));
for (int i = 0; i < size; i++) {
sb.append(shortFormCharFor(parameters.getType(i)));
}
return new CstString(sb.toString());
}
Aggregations