当前位置: 首页>>代码示例>>Java>>正文


Java DirectClassFile.getMagic方法代码示例

本文整理汇总了Java中com.android.dx.cf.direct.DirectClassFile.getMagic方法的典型用法代码示例。如果您正苦于以下问题:Java DirectClassFile.getMagic方法的具体用法?Java DirectClassFile.getMagic怎么用?Java DirectClassFile.getMagic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.dx.cf.direct.DirectClassFile的用法示例。


在下文中一共展示了DirectClassFile.getMagic方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dump

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    DirectClassFile cf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.setObserver(this);
    cf.getMagic(); // Force parsing to happen.

    int at = getAt();
    if (at != bytes.length) {
        parsed(ba, at, bytes.length - at, "<extra data at end of file>");
    }
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:19,代码来源:ClassDumper.java

示例2: dump

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Does the dumping.
 */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, getFilePath(), getStrictParse());
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:23,代码来源:BlockDumper.java

示例3: run

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
private void run() {
    ByteArray ba = new ByteArray(bytes);

    /*
     * First, parse the file completely, so we can safely refer to
     * attributes, etc.
     */
    classFile = new DirectClassFile(ba, filePath, strictParse);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    classFile.getMagic(); // Force parsing to happen.

    // Next, reparse it and observe the process.
    DirectClassFile liveCf =
        new DirectClassFile(ba, filePath, strictParse);
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    liveCf.getMagic(); // Force parsing to happen.
}
 
开发者ID:JLLK,项目名称:multidex-maker,代码行数:19,代码来源:DotDumper.java

示例4: defineClass

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的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

示例5: parseClass

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
private static DirectClassFile parseClass(String name, byte[] bytes) {

        DirectClassFile cf = new DirectClassFile(bytes, name,
                args.cfOptions.strictNameCheck);
        cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
        cf.getMagic(); // triggers the actual parsing
        return cf;
    }
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:9,代码来源:Dexer.java

示例6: translate0

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 * @param filePath {@code non-null;} the file path for the class,
 * excluding any base directory specification
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(String filePath, byte[] bytes,
        CfOptions cfOptions, DexOptions dexOptions) {
    DirectClassFile cf =
        new DirectClassFile(bytes, filePath, cfOptions.strictNameCheck);

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();

    OptimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations);
    }

    processFields(cf, out);
    processMethods(cf, cfOptions, dexOptions, out);

    return out;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:45,代码来源:CfTranslator.java

示例7: parseClassFile

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
public static DirectClassFile parseClassFile(byte[] classfile, String classfilePath) {
  DirectClassFile result = new DirectClassFile(
      new ByteArray(classfile), classfilePath, /*strictParse*/ false);
  result.setAttributeFactory(StdAttributeFactory.THE_ONE);
  result.getMagic(); // triggers the parsing
  return result;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:8,代码来源:Dexing.java

示例8: parseClass

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
private DirectClassFile parseClass(String name, byte[] bytes) {

        DirectClassFile cf = new DirectClassFile(bytes, name,
            args.cfOptions.strictNameCheck);
        cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
        cf.getMagic(); // triggers the actual parsing
        return cf;
    }
 
开发者ID:facebook,项目名称:buck,代码行数:9,代码来源:Main.java

示例9: parseClass

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
private DirectClassFile parseClass(String name, byte[] bytes) {
    DirectClassFile cf = new DirectClassFile(bytes, name, cfOptions.strictNameCheck);
    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();
    return cf;
}
 
开发者ID:imkiva,项目名称:Krine,代码行数:7,代码来源:DexConverter.java

示例10: analyze

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Performs the hierarchy analysis and returns the result.
 */
public TypeHierarchy analyze() {
    // Extract all class files.
    UniversalFile library = UniversalFileCreator.createDirectory(null, libraryPath);
    UniversalFile[] classes = library.listFilesRecursively(new UniversalFileFilter() {
        @Override
        public boolean accept(UniversalFile file) {
            return file.getName().toLowerCase().endsWith(".class");
        }
    });
    System.out.println("Getting type hierarchy for " + classes.length + " classes.");

    TypeHierarchy result = new TypeHierarchy();
    final String basePath = library.getAbsolutePath();
    for (UniversalFile clazz : classes) {
        String fileName = clazz.getRelativePath(basePath).replace('\\', '.');
        DirectClassFile classFile = new DirectClassFile(clazz.getFileAsBytes(), fileName, false);
        classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        try {
            classFile.getMagic();
        } catch (ParseException ex) {
            continue;
        }

        final int DOT_CLASS_LENGTH = ".class".length();
        String className = fileName.substring(0, fileName.length() - DOT_CLASS_LENGTH).replace(
                '/', '.');

        // Super-class.
        if (classFile.getSuperclass() != null) {
            String superClassName = Util.parseClassName(
                    classFile.getSuperclass().getClassType().getClassName()).toString();
            result.addDirectSubType(className, superClassName);
        }

        // Interfaces
        TypeList interfaces = classFile.getInterfaces();
        if (interfaces != null) {
            for (int i = 0; i < interfaces.size(); i++) {
                String interfaceName = Util
                        .parseClassName(interfaces.getType(i).getClassName()).toString();
                result.addDirectSubType(className, interfaceName);
            }
        }
    }
    return result;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:50,代码来源:HierarchyAnalyzer.java

示例11: getAllDependencies

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Adds all dependencies of the given class to classDeps.
 */
private static void getAllDependencies(byte[] bytes, String relativePath,
        Dependencies.ClassDeps classDeps) {

    Log.debug(TAG, relativePath);
    DirectClassFile classFile = new DirectClassFile(bytes, relativePath, false);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    try {
        classFile.getMagic();
    } catch (ParseException ex) {
        Log.warn(TAG, "Put to red-list as it couldn't be parsed: " + relativePath);
        BAD_CLASSES.add(classDeps.getClassName());
        return;
    }

    String superClassName = "";
    // This can happen for java.lang.Object.
    if (classFile.getSuperclass() != null) {
        superClassName = Util.parseClassName(
                classFile.getSuperclass().getClassType().getClassName()).toString();
    }

    // Super Class
    if (!superClassName.isEmpty()) {
        Set<String> superClass = new HashSet<String>();
        superClass.add(superClassName.replace('/', '.'));
        classDeps.getMethodDeps("SUPER").addDependency(superClassName.replace('/', '.'), "");
    }

    // Interfaces
    TypeList interfaces = classFile.getInterfaces();
    if (interfaces.size() > 0) {
        Set<String> interfaceList = new HashSet<String>();
        for (int i = 0; i < interfaces.size(); ++i) {
            interfaceList.add(Util.parseClassName(interfaces.getType(i).getClassName())
                    .toString());
            classDeps.getMethodDeps("INTERFACES").addDependency(
                    Util.parseClassName(interfaces.getType(i).getClassName()).toString(), "");
        }
    }

    // Methods
    MethodList methods = classFile.getMethods();
    for (int i = 0; i < methods.size(); i++) {
        Method method = methods.get(i);
        // CstMethodRef methodRef = new
        // CstMethodRef(method.getDefiningClass(), method.getNat());
        // We shouldn't need to go through the signature. If the class is
        // not used in the code block, we can ignore it.
        // processSignature(methodRef, dependencies);
        processCode(getCode(method, classFile),
                classDeps.getMethodDeps(method.getName().toHuman()));
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:57,代码来源:JDKAnalyzer.java

示例12: processClass

import com.android.dx.cf.direct.DirectClassFile; //导入方法依赖的package包/类
/**
 * Processes one classfile.
 *
 * @param name {@code non-null;} name of the file, clipped such that it
 * <i>should</i> correspond to the name of the class it contains
 * @param bytes {@code non-null;} contents of the file
 * @return whether processing was successful
 */
private boolean processClass(String name, byte[] bytes) {
    if (! args.coreLibrary) {
        checkClassName(name);
    }

    DirectClassFile cf =
        new DirectClassFile(bytes, name, args.cfOptions.strictNameCheck);

    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();

    int numMethodIds = outputDex.getMethodIds().items().size();
    int numFieldIds = outputDex.getFieldIds().items().size();
    int numTypeIds = outputDex.getTypeIds().items().size();
    int constantPoolSize = cf.getConstantPool().size();

    if (args.multiDex && ((numMethodIds + constantPoolSize > args.maxNumberOfIdxPerDex) ||
        (numFieldIds + constantPoolSize > args.maxNumberOfIdxPerDex) ||
        (numTypeIds + constantPoolSize
                /* annotation added by dx are not counted in numTypeIds */
                + AnnotationUtils.DALVIK_ANNOTATION_NUMBER
                > args.maxNumberOfIdxPerDex))) {
      createDexFile();
    }

    try {
        ClassDefItem clazz =
            CfTranslator.translate(cf, bytes, args.cfOptions, args.dexOptions, args.optimizerOptions, outputDex);
        synchronized (outputDex) {
            outputDex.add(clazz);
        }
        return true;

    } catch (ParseException ex) {
        dxConsole.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(dxConsole.err);
        } else {
            ex.printContext(dxConsole.err);
        }
    }
    errors++;
    return false;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:53,代码来源:Main.java


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