• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Dex类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.android.dex.Dex的典型用法代码示例。如果您正苦于以下问题:Java Dex类的具体用法?Java Dex怎么用?Java Dex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Dex类属于com.android.dex包,在下文中一共展示了Dex类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: mergeDexes

import com.android.dex.Dex; //导入依赖的package包/类
private Dex mergeDexes() throws IOException {
    mergeStringIds();
    mergeTypeIds();
    mergeTypeLists();
    mergeProtoIds();
    mergeFieldIds();
    mergeMethodIds();
    mergeAnnotations();
    unionAnnotationSetsAndDirectories();
    mergeClassDefs();

    // write the header
    contentsOut.header.off = 0;
    contentsOut.header.size = 1;
    contentsOut.fileSize = dexOut.getLength();
    contentsOut.computeSizesFromOffsets();
    contentsOut.writeHeader(headerOut);
    contentsOut.writeMap(mapListOut);

    // generate and write the hashes
    dexOut.writeHashes();

    return dexOut;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:25,代码来源:DexMerger.java


示例2: transformClassDef

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * Reads a class_def_item beginning at {@code in} and writes the index and
 * data.
 */
private void transformClassDef(Dex in, ClassDef classDef, IndexMap indexMap) {
    idsDefsOut.assertFourByteAligned();
    idsDefsOut.writeInt(classDef.getTypeIndex());
    idsDefsOut.writeInt(classDef.getAccessFlags());
    idsDefsOut.writeInt(classDef.getSupertypeIndex());
    idsDefsOut.writeInt(classDef.getInterfacesOffset());

    int sourceFileIndex = indexMap.adjustString(classDef.getSourceFileIndex());
    idsDefsOut.writeInt(sourceFileIndex);

    int annotationsOff = classDef.getAnnotationsOffset();
    idsDefsOut.writeInt(indexMap.adjustAnnotationDirectory(annotationsOff));

    int classDataOff = classDef.getClassDataOffset();
    if (classDataOff == 0) {
        idsDefsOut.writeInt(0);
    } else {
        idsDefsOut.writeInt(classDataOut.getPosition());
        ClassData classData = in.readClassData(classDef);
        transformClassData(in, classData, indexMap);
    }

    int staticValuesOff = classDef.getStaticValuesOffset();
    idsDefsOut.writeInt(indexMap.adjustStaticValues(staticValuesOff));
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:30,代码来源:DexMerger.java


示例3: transformClassData

import com.android.dex.Dex; //导入依赖的package包/类
private void transformClassData(Dex in, ClassData classData, IndexMap indexMap) {
    contentsOut.classDatas.size++;

    ClassData.Field[] staticFields = classData.getStaticFields();
    ClassData.Field[] instanceFields = classData.getInstanceFields();
    ClassData.Method[] directMethods = classData.getDirectMethods();
    ClassData.Method[] virtualMethods = classData.getVirtualMethods();

    classDataOut.writeUleb128(staticFields.length);
    classDataOut.writeUleb128(instanceFields.length);
    classDataOut.writeUleb128(directMethods.length);
    classDataOut.writeUleb128(virtualMethods.length);

    transformFields(indexMap, staticFields);
    transformFields(indexMap, instanceFields);
    transformMethods(in, indexMap, directMethods);
    transformMethods(in, indexMap, virtualMethods);
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:19,代码来源:DexMerger.java


示例4: transformMethods

import com.android.dex.Dex; //导入依赖的package包/类
private void transformMethods(Dex in, IndexMap indexMap, ClassData.Method[] methods) {
    int lastOutMethodIndex = 0;
    for (ClassData.Method method : methods) {
        int outMethodIndex = indexMap.adjustMethod(method.getMethodIndex());
        classDataOut.writeUleb128(outMethodIndex - lastOutMethodIndex);
        lastOutMethodIndex = outMethodIndex;

        classDataOut.writeUleb128(method.getAccessFlags());

        if (method.getCodeOffset() == 0) {
            classDataOut.writeUleb128(0);
        } else {
            codeOut.alignToFourBytesWithZeroFill();
            classDataOut.writeUleb128(codeOut.getPosition());
            transformCode(in, in.readCode(method), indexMap);
        }
    }
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:19,代码来源:DexMerger.java


示例5: IndexMap

import com.android.dex.Dex; //导入依赖的package包/类
public IndexMap(Dex target, TableOfContents tableOfContents) {
    this.target = target;
    this.stringIds = new int[tableOfContents.stringIds.size];
    this.typeIds = new short[tableOfContents.typeIds.size];
    this.protoIds = new short[tableOfContents.protoIds.size];
    this.fieldIds = new short[tableOfContents.fieldIds.size];
    this.methodIds = new short[tableOfContents.methodIds.size];
    this.typeListOffsets = new HashMap<Integer, Integer>();
    this.annotationOffsets = new HashMap<Integer, Integer>();
    this.annotationSetOffsets = new HashMap<Integer, Integer>();
    this.annotationSetRefListOffsets = new HashMap<Integer, Integer>();
    this.annotationDirectoryOffsets = new HashMap<Integer, Integer>();
    this.staticValuesOffsets = new HashMap<Integer, Integer>();

    /*
     * A type list, annotation set, annotation directory, or static value at
     * offset 0 is always empty. Always map offset 0 to 0.
     */
    this.typeListOffsets.put(0, 0);
    this.annotationSetOffsets.put(0, 0);
    this.annotationDirectoryOffsets.put(0, 0);
    this.staticValuesOffsets.put(0, 0);
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:24,代码来源:IndexMap.java


示例6: mergeLibraryDexBuffers

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * Merges the dex files in library jars. If multiple dex files define the
 * same type, this fails with an exception.
 */
private static byte[] mergeLibraryDexBuffers(byte[] outArray) throws IOException {
    for (byte[] libraryDex : libraryDexBuffers) {
        if (outArray == null) {
            outArray = libraryDex;
            continue;
        }

        Dex a = new Dex(outArray);
        Dex b = new Dex(libraryDex);
        Dex ab = new DexMerger(a, b, CollisionPolicy.FAIL).merge();
        outArray = ab.getBytes();
    }

    return outArray;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:20,代码来源:Main.java


示例7: findAssignableTypes

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * Returns the set of types that can be assigned to {@code typeIndex}.
 */
private Set<Integer> findAssignableTypes(Dex dex, int typeIndex) {
    Set<Integer> assignableTypes = new HashSet<Integer>();
    assignableTypes.add(typeIndex);

    for (ClassDef classDef : dex.classDefs()) {
        if (assignableTypes.contains(classDef.getSupertypeIndex())) {
            assignableTypes.add(classDef.getTypeIndex());
            continue;
        }

        for (int implemented : classDef.getInterfaces()) {
            if (assignableTypes.contains(implemented)) {
                assignableTypes.add(classDef.getTypeIndex());
                break;
            }
        }
    }

    return assignableTypes;
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:24,代码来源:FindUsages.java


示例8: defineClass

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        DexOptions dexOptions = new DexOptions();
        DexFile dexFile = new DexFile(dexOptions);
        DirectClassFile classFile = new DirectClassFile(data, name.replace('.', '/') + ".class", true);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        classFile.getMagic();
        dexFile.add(CfTranslator.translate(classFile, null, new CfOptions(), dexOptions, dexFile));
        Dex dex = new Dex(dexFile.toDex(null, false));
        Dex oldDex = getLastDex();
        if (oldDex != null) {
            dex = new DexMerger(new Dex[]{dex, oldDex}, CollisionPolicy.KEEP_FIRST).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:23,代码来源:BaseAndroidClassLoader.java


示例9: loadClass

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * Try to load a class. This will search all defined classes, all loaded jars and the parent class loader.
 *
 * @param name    the name of the class to load
 * @param resolve ignored
 * @return the class
 * @throws ClassNotFoundException if the class could not be found in any of the locations
 */
@Override
public Class<?> loadClass(String name, boolean resolve)
        throws ClassNotFoundException {
    Class<?> loadedClass = findLoadedClass(name);
    if (loadedClass == null) {
        Dex dex = getLastDex();
        if (dex != null) {
            loadedClass = loadClass(dex, name);
        }
        if (loadedClass == null) {
            loadedClass = getParent().loadClass(name);
        }
    }
    return loadedClass;
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:24,代码来源:BaseAndroidClassLoader.java


示例10: mergeDexes

import com.android.dex.Dex; //导入依赖的package包/类
private Dex mergeDexes() throws IOException {
    mergeStringIds();
    mergeTypeIds();
    mergeTypeLists();
    mergeProtoIds();
    mergeFieldIds();
    mergeMethodIds();
    mergeAnnotations();
    unionAnnotationSetsAndDirectories();
    mergeClassDefs();

    // write the header
    contentsOut.header.off = 0;
    contentsOut.header.size = 1;
    contentsOut.fileSize = dexOut.getLength();
    contentsOut.computeSizesFromOffsets();
    contentsOut.writeHeader(headerOut, mergeApiLevels());
    contentsOut.writeMap(mapListOut);

    // generate and write the hashes
    dexOut.writeHashes();

    return dexOut;
}
 
开发者ID:johnlee175,项目名称:dex,代码行数:25,代码来源:DexMerger.java


示例11: loadFromClassFile

import com.android.dex.Dex; //导入依赖的package包/类
private static Dex loadFromClassFile(File file) throws IOException, DecodeException {
	File outFile = File.createTempFile("jadx-tmp-", System.nanoTime() + ".jar");
	outFile.deleteOnExit();
	FileOutputStream out = null;
	JarOutputStream jo = null;
	try {
		out = new FileOutputStream(outFile);
		jo = new JarOutputStream(out);
		String clsName = AsmUtils.getNameFromClassFile(file);
		if (clsName == null) {
			throw new IOException("Can't read class name from file: " + file);
		}
		FileUtils.addFileToJar(jo, file, clsName + ".class");
	} finally {
		if (jo != null) {
			jo.close();
		}
		if (out != null) {
			out.close();
		}
	}
	return loadFromJar(outFile);
}
 
开发者ID:niranjan94,项目名称:show-java,代码行数:24,代码来源:InputFile.java


示例12: processDexEntry

import com.android.dex.Dex; //导入依赖的package包/类
private void processDexEntry(ZipFile zip, ZipEntry entry) throws IOException {
  String filename = entry.getName();
  checkState(filename.endsWith(".class.dex"),
      "%s isn't a dex archive: %s", zip.getName(), filename);
  checkState(entry.getMethod() == ZipEntry.STORED, "Expect to process STORED: %s", filename);
  try (InputStream entryStream = zip.getInputStream(entry)) {
    // We don't want to use the Dex(InputStream) constructor because it closes the stream,
    // which will break the for loop, and it has its own bespoke way of reading the file into
    // a byte buffer before effectively calling Dex(byte[]) anyway.
    // TODO(kmb) since entry is stored, mmap content and give to Dex(ByteBuffer) and output zip
    byte[] content = new byte[(int) entry.getSize()];
    ByteStreams.readFully(entryStream, content); // throws if file is smaller than expected
    checkState(entryStream.read() == -1,
        "Too many bytes in jar entry %s, expected %s", entry, entry.getSize());

    Dex dexFile = new Dex(content);
    if (tracker.track(dexFile)) {
      nextShard();
      tracker.track(dexFile);
    }
    curOut.writeAsync(entry, content);
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:24,代码来源:DexFileSplitter.java


示例13: processDexFiles

import com.android.dex.Dex; //导入依赖的package包/类
private static void processDexFiles(
    ZipFile zip, Iterable<ZipEntry> filesToProcess, HashSet<String> seen, DexFileAggregator out)
    throws IOException {
  for (ZipEntry entry : filesToProcess) {
    String filename = entry.getName();
    checkState(filename.endsWith(".dex"), "Input shouldn't contain .class files: %s", filename);
    if (!seen.add(filename)) {
      continue;  // pick first occurrence of each file to match how JVM treats dupes on classpath
    }
    try (InputStream content = zip.getInputStream(entry)) {
      // We don't want to use the Dex(InputStream) constructor because it closes the stream,
      // which will break the for loop, and it has its own bespoke way of reading the file into
      // a byte buffer before effectively calling Dex(byte[]) anyway.
      out.add(new Dex(ByteStreams.toByteArray(content)));
    }
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:18,代码来源:DexFileMerger.java


示例14: testMultidex_underLimitWritesOneShard

import com.android.dex.Dex; //导入依赖的package包/类
@Test
public void testMultidex_underLimitWritesOneShard() throws Exception {
  DexFileAggregator dexer =
      new DexFileAggregator(
          new DxContext(),
          dest,
          newDirectExecutorService(),
          MultidexStrategy.BEST_EFFORT,
          /*forceJumbo=*/ false,
          DEX_LIMIT,
          WASTE,
          DexFileMergerTest.DEX_PREFIX);
  Dex dex2 = DexFiles.toDex(convertClass(ByteStreams.class));
  dexer.add(dex);
  dexer.add(dex2);
  verify(dest, times(0)).addFile(any(ZipEntry.class), any(Dex.class));
  dexer.close();
  verify(dest).addFile(any(ZipEntry.class), written.capture());
  assertThat(Iterables.size(written.getValue().classDefs())).isEqualTo(2);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:21,代码来源:DexFileAggregatorTest.java


示例15: testMultidex_overLimitWritesSecondShard

import com.android.dex.Dex; //导入依赖的package包/类
@Test
public void testMultidex_overLimitWritesSecondShard() throws Exception {
  DexFileAggregator dexer =
      new DexFileAggregator(
          new DxContext(),
          dest,
          newDirectExecutorService(),
          MultidexStrategy.BEST_EFFORT,
          /*forceJumbo=*/ false,
          2 /* dex has more than 2 methods and fields */,
          WASTE,
          DexFileMergerTest.DEX_PREFIX);
  Dex dex2 = DexFiles.toDex(convertClass(ByteStreams.class));
  dexer.add(dex);   // classFile is already over limit but we take anything in empty shard
  dexer.add(dex2);  // this should start a new shard
  // Make sure there was one file written and that file is dex
  verify(dest).addFile(any(ZipEntry.class), written.capture());
  assertThat(written.getValue()).isSameAs(dex);
  dexer.close();
  verify(dest).addFile(any(ZipEntry.class), eq(dex2));
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:22,代码来源:DexFileAggregatorTest.java


示例16: testMonodex_alwaysWritesSingleShard

import com.android.dex.Dex; //导入依赖的package包/类
@Test
public void testMonodex_alwaysWritesSingleShard() throws Exception {
  DexFileAggregator dexer =
      new DexFileAggregator(
          new DxContext(),
          dest,
          newDirectExecutorService(),
          MultidexStrategy.OFF,
          /*forceJumbo=*/ false,
          2 /* dex has more than 2 methods and fields */,
          WASTE,
          DexFileMergerTest.DEX_PREFIX);
  Dex dex2 = DexFiles.toDex(convertClass(ByteStreams.class));
  dexer.add(dex);
  dexer.add(dex2);
  verify(dest, times(0)).addFile(any(ZipEntry.class), any(Dex.class));
  dexer.close();
  verify(dest).addFile(any(ZipEntry.class), written.capture());
  assertThat(Iterables.size(written.getValue().classDefs())).isEqualTo(2);
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:21,代码来源:DexFileAggregatorTest.java


示例17: mergeUnsorted

import com.android.dex.Dex; //导入依赖的package包/类
/**
 * Merges unsorted sections by reading them completely into memory and
 * sorting in memory.
 */
public final void mergeUnsorted() {
    getSection(contentsOut).off = out.getPosition();

    List<UnsortedValue> all = new ArrayList<UnsortedValue>();
    for (Dex d : dexs) {
        all.addAll(readUnsortedValues(d, indexMaps.get(d)));
    }
    Collections.sort(all);

    int outCount = 0;
    for (int i = 0; i < all.size(); ) {
        UnsortedValue e1 = all.get(i++);
        updateIndex(e1.offset, e1.indexMap, e1.index, outCount - 1);

        while (i < all.size() && e1.compareTo(all.get(i)) == 0) {
            UnsortedValue e2 = all.get(i++);
            updateIndex(e2.offset, e2.indexMap, e2.index, outCount - 1);
        }

        write(e1.value);
        outCount++;
    }

    getSection(contentsOut).size = outCount;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:30,代码来源:DexMerger.java


示例18: testMergeConflict

import com.android.dex.Dex; //导入依赖的package包/类
public void testMergeConflict() throws IOException {
    Dex a = resourceToDexBuffer("/testdata/A.dex");
    Dex b = resourceToDexBuffer("/testdata/B.dex");

    // a and b don't overlap; this should succeed
    Dex ab = new DexMerger(ImmutableList.of(a, b), CollisionPolicy.FAIL).merge();

    // a and ab overlap; this should fail
    DexMerger dexMerger = new DexMerger(ImmutableList.of(a, ab), CollisionPolicy.FAIL);
    try {
        dexMerger.merge();
        fail();
    } catch (DexException expected) {
        assertEquals("Multiple dex files define Ltestdata/A;", expected.getMessage());
    }
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:17,代码来源:MergeConflictTest.java


示例19: loadStaticValues

import com.android.dex.Dex; //导入依赖的package包/类
private void loadStaticValues(ClassDef cls, List<FieldNode> staticFields) throws DecodeException {
	for (FieldNode f : staticFields) {
		if (f.getAccessFlags().isFinal()) {
			f.addAttr(FieldInitAttr.NULL_VALUE);
		}
	}
	int offset = cls.getStaticValuesOffset();
	if (offset == 0) {
		return;
	}
	Dex.Section section = dex.openSection(offset);
	StaticValuesParser parser = new StaticValuesParser(dex, section);
	parser.processFields(staticFields);

	// process const fields
	root().getConstValues().processConstFields(this, staticFields);
}
 
开发者ID:skylot,项目名称:jadx,代码行数:18,代码来源:ClassNode.java


示例20: loadFromJar

import com.android.dex.Dex; //导入依赖的package包/类
private static Dex loadFromJar(File jarFile) throws DecodeException {
	JavaToDex j2d = new JavaToDex();
	try {
		LOG.info("converting to dex: {} ...", jarFile.getName());
		byte[] ba = j2d.convert(jarFile.getAbsolutePath());
		if (ba.length == 0) {
			throw new JadxException("Empty dx output");
		}
		return new Dex(ba);
	} catch (Exception e) {
		throw new DecodeException("java class to dex conversion error:\n " + e.getMessage(), e);
	} finally {
		if (j2d.isError()) {
			LOG.warn("dx message: {}", j2d.getDxErrors());
		}
	}
}
 
开发者ID:skylot,项目名称:jadx,代码行数:18,代码来源:InputFile.java



注:本文中的com.android.dex.Dex类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Util类代码示例发布时间:2022-05-22
下一篇:
Java BeforeScenario类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap