private void growBufferIfNeeded(int minSize) { if (minSize > size) { if (minSize > buf.length) { int newSize = getNewBufferSize(buf.length, minSize); if (newSize < minSize) throw new IndexOutOfBoundsException(); buf = Arrays.copyOf(buf, newSize); } size = minSize; } }
@Test public void testAnnotationElementOrder() { // Elements are out of order wrt to the element name ImmutableSet<ImmutableAnnotationElement> elements = ImmutableSet.of(new ImmutableAnnotationElement("zabaglione", ImmutableNullEncodedValue.INSTANCE), new ImmutableAnnotationElement("blah", ImmutableNullEncodedValue.INSTANCE)); ImmutableAnnotation annotation = new ImmutableAnnotation(AnnotationVisibility.RUNTIME, "Lorg/test/anno;", elements); ImmutableClassDef classDef = new ImmutableClassDef("Lorg/test/blah;", 0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); try { DexPool.writeTo(dataStore, new ImmutableDexFile(Opcodes.getDefault(), ImmutableSet.of(classDef))); } catch (IOException ex) { throw new RuntimeException(ex); } DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef); Annotation dbAnnotation = Iterables.getFirst(dbClassDef.getAnnotations(), null); Assert.assertNotNull(dbAnnotation); List<AnnotationElement> dbElements = Lists.newArrayList(dbAnnotation.getElements()); // Ensure that the elements were written out in sorted order Assert.assertEquals(2, dbElements.size()); Assert.assertEquals("blah", dbElements.get(0).getName()); Assert.assertEquals("zabaglione", dbElements.get(1).getName()); }
static byte[] toBytecode(DexFile dexFile) throws IOException { MemoryDataStore dataStore = new MemoryDataStore(); DexPool.writeTo(dataStore, dexFile); return dataStore.getData(); }
public List<MemoryDataStore> asMemory() { final List<MemoryDataStore> stores = new ArrayList<>(2); try { writeTo(dexNum -> { MemoryDataStore m = new MemoryDataStore(); stores.add(m); return m; }); } catch (IOException ex) { ex.printStackTrace(); } return stores; }
final MemoryDataStore m = new MemoryDataStore(dex.header.file_size_ + 512); DexPool.writeTo(m, d); m.writeTo(jos); classesIdx = String.valueOf(++i); jos.closeEntry();
MemoryDataStore dataStore = new MemoryDataStore(); DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.forApi(apiLevel), dataStore.getBuffer());
MemoryDataStore dataStore = new MemoryDataStore(); DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.forApi(apiLevel), dataStore.getBuffer());
private void growBufferIfNeeded(int minSize) { if (minSize > size) { if (minSize > buf.length) { int newSize = getNewBufferSize(buf.length, minSize); if (newSize < minSize) throw new IndexOutOfBoundsException(); buf = Arrays.copyOf(buf, newSize); } size = minSize; } }
0, "Ljava/lang/Object;", null, null, ImmutableSet.of(annotation), null, null); MemoryDataStore dataStore = new MemoryDataStore(); DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dataStore.getBuffer()); ClassDef dbClassDef = Iterables.getFirst(dexFile.getClasses(), null); Assert.assertNotNull(dbClassDef);
methodImpl))); MemoryDataStore dexStore = new MemoryDataStore(); dexBuilder.writeTo(dexStore); DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexStore.getBuffer());
methodBuilder.getMethodImplementation()))); MemoryDataStore dexStore = new MemoryDataStore(); dexBuilder.writeTo(dexStore); DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexStore.getBuffer());
MemoryDataStore dataStore = new MemoryDataStore(); DexPool dexPool = new DexPool(Opcodes.getDefault()); dexPool.internClass(class1); dexPool.reset(); dexPool.writeTo(dataStore); dexFile1 = new RawDexFile(Opcodes.getDefault(), dataStore.getBuffer()); MemoryDataStore dataStore = new MemoryDataStore(); DexPool dexPool = new DexPool(Opcodes.getDefault()); dexPool.internClass(class1); dexPool.writeTo(dataStore); dexFile2 = new RawDexFile(Opcodes.getDefault(), dataStore.getBuffer());