/** * Generates a dex file and returns its bytes. */ public byte[] generate() { if (outputDex == null) { DexOptions options = new DexOptions(); options.minSdkVersion = DexFormat.API_NO_EXTENDED_OPCODES; outputDex = new DexFile(options); } for (TypeDeclaration typeDeclaration : types.values()) { outputDex.add(typeDeclaration.toClassDefItem()); } try { return outputDex.toDex(null, false); } catch (IOException e) { throw new RuntimeException(e); } }
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(); 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.writeInt(file.getFileSize()); out.writeInt(SizeOf.HEADER_ITEM); out.writeInt(DexFormat.ENDIAN_TAG); file.getStringIds().writeHeaderPart(out); file.getTypeIds().writeHeaderPart(out); file.getProtoIds().writeHeaderPart(out); file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out); file.getClassDefs().writeHeaderPart(out);
TypeIdsSection typeIds = file.getTypeIds(); MixedItemSection byteData = file.getByteData(); MixedItemSection wordData = file.getWordData(); MixedItemSection typeLists = file.getTypeLists(); StringIdsSection stringIds = file.getStringIds(); MixedItemSection classDataSection = file.getClassData(); classDataSection.add(classData);
/** {@inheritDoc} */ public void addContents(DexFile file) { MixedItemSection byteData = file.getByteData(); TypeIdsSection typeIds = file.getTypeIds(); if (code.hasPositions() || code.hasLocals()) { debugInfo = new DebugInfoItem(code, isStatic, ref); byteData.add(debugInfo); } if (code.hasAnyCatches()) { for (Type type : code.getCatchTypes()) { typeIds.intern(type); } catches = new CatchStructs(code); } for (Constant c : code.getInsnConstants()) { file.internIfAppropriate(c); } }
calcSignature(barr); calcChecksum(barr); getStatistics().writeAnnotation(out); out.finishAnnotating();
outputDex.toDex(null, false); dumpMethod(outputDex, args.methodToDump, humanOutWriter); } else { outArray = outputDex.toDex(humanOutWriter, args.verboseDump); context.out.println(outputDex.getStatistics().toHuman());
/** {@inheritDoc} */ public void addContents(DexFile file) { FieldIdsSection fieldIds = file.getFieldIds(); MixedItemSection wordData = file.getWordData(); fieldIds.intern(field); annotations = wordData.intern(annotations); }
cf.getMagic(); int numMethodIds = outputDex.getMethodIds().items().size(); int numFieldIds = outputDex.getFieldIds().items().size(); int constantPoolSize = cf.getConstantPool().size(); && (outputDex.getClassDefs().items().size() > 0) && ((maxMethodIdsInDex > args.maxNumberOfIdxPerDex) || (maxFieldIdsInDex > args.maxNumberOfIdxPerDex))) { DexFile completeDex = outputDex; createDexFile(); assert (completeDex.getMethodIds().items().size() <= numMethodIds + MAX_METHOD_ADDED_DURING_DEX_CREATION) && (completeDex.getFieldIds().items().size() <= numFieldIds + MAX_FIELD_ADDED_DURING_DEX_CREATION); CfTranslator.translate(cf, bytes, args.cfOptions, args.dexOptions, outputDex); synchronized (outputDex) { outputDex.add(clazz);
try { DexFile file = new DexFile(dex_options); DirectClassFile cf = new DirectClassFile(bytes, name + ".class", cf_options.strictNameCheck); cf.getMagic(); file.add(CfTranslator.translate(cf, bytes, cf_options, dex_options, file)); if (dexFile.exists()) dexFile.delete(); fos = new FileOutputStream(dexFile); file.writeTo(fos, null, false); if (log.isTraceEnabled()) log.trace(String.format("Wrote class [%s] to cache: %s", name, dexFile.getAbsolutePath()));
private void createDexFile() { outputDex = new DexFile(args.dexOptions); if (args.dumpWidth != 0) { outputDex.setDumpWidth(args.dumpWidth); } }
/** * {@inheritDoc} */ public void register(String name, byte[] binaryRepresentation) { DirectClassFile directClassFile = new DirectClassFile(binaryRepresentation, name.replace('.', '/') + CLASS_FILE_EXTENSION, NON_STRICT); directClassFile.setAttributeFactory(new StdAttributeFactory()); dexFile.add(CfTranslator.translate(directClassFile, binaryRepresentation, dexCompilerOptions, dexFileOptions, new DexFile(dexFileOptions))); }
numMethodIds = outputDex.getMethodIds().items().size(); numFieldIds = outputDex.getFieldIds().items().size(); } else if (outputDex.getClassDefs().items().size() > 0) { numMethodIds = outputDex.getMethodIds().items().size(); numFieldIds = outputDex.getFieldIds().items().size();
public EvalResult evaluate(String scriptText) throws IOException, IllegalAccessException, InstantiationException, ClassNotFoundException { long sd = System.nanoTime(); final Set<String> classNames = new LinkedHashSet<String>(); final DexFile dexFile = new DexFile(dexOptions); CompilerConfiguration config = new CompilerConfiguration(); config.setBytecodePostprocessor(new BytecodeProcessor() { gcl.parseClass(scriptText); byte[] dalvikBytecode = new byte[0]; dalvikBytecode = dexFile.toDex(new OutputStreamWriter(new ByteArrayOutputStream()), false);
private boolean addClassToDex(ClassDefItem clazz) { synchronized (outputDex) { outputDex.add(clazz); } return true; }
DexFile getDexFile() { if (outputDex == null) { DexOptions options = new DexOptions(); options.minSdkVersion = DexFormat.API_NO_EXTENDED_OPCODES; outputDex = new DexFile(options); } return outputDex; }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { FieldIdsSection fieldIds = file.getFieldIds(); fieldIds.intern(field); }
@Override public int getIndex(Constant cst) { IndexedItem item = file.findItemOrNull(cst); if (item == null) { return -1; } return item.getIndex(); } });
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { MixedItemSection byteData = file.getByteData(); int size = items.length; for (int i = 0; i < size; i++) { items[i] = byteData.intern(items[i]); } }
/** {@inheritDoc} */ @Override public void addContents(DexFile file) { CstCallSite callSite = invokeDynamicRef.getCallSite(); CallSiteIdsSection callSiteIds = file.getCallSiteIds(); CallSiteItem callSiteItem = callSiteIds.getCallSiteItem(callSite); if (callSiteItem == null) { MixedItemSection byteData = file.getByteData(); callSiteItem = new CallSiteItem(callSite); byteData.add(callSiteItem); callSiteIds.addCallSiteItem(callSite, callSiteItem); } this.data = callSiteItem; }
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(); 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.writeInt(file.getFileSize()); out.writeInt(SizeOf.HEADER_ITEM); out.writeInt(DexFormat.ENDIAN_TAG); file.getStringIds().writeHeaderPart(out); file.getTypeIds().writeHeaderPart(out); file.getProtoIds().writeHeaderPart(out); file.getFieldIds().writeHeaderPart(out); file.getMethodIds().writeHeaderPart(out); file.getClassDefs().writeHeaderPart(out);