com.android.dx.dex.cf.CfTranslator Java Examples

The following examples show how to use com.android.dx.dex.cf.CfTranslator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: rhino-android   Author: F43nd1r   File: BaseAndroidClassLoader.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@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();
        DxContext context = new DxContext();
        dexFile.add(CfTranslator.translate(context, 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, context).merge();
        }
        return loadClass(dex, name);
    } catch (IOException | ClassNotFoundException e) {
        throw new FatalLoadingException(e);
    }
}
 
Example #2
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
Example #3
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
Example #4
Source Project: lua-for-android   Author: qtiuto   File: MainActivity.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DexFile generateDexFile(List<byte[]> classByteCodes){
    DxContext dxContext=new DxContext();
    DexOptions dexOptions=new DexOptions();
    CfOptions cfOptions=new CfOptions();
    DexFile dexFile=new DexFile(dexOptions);
    for (byte[] cls:classByteCodes){
        DirectClassFile directClassFile=new DirectClassFile(cls,"",false);
        directClassFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
        directClassFile.getMagic();
        dexFile.add(CfTranslator.translate(dxContext,directClassFile,cls,cfOptions,dexOptions,dexFile));
    }
    return dexFile;
}
 
Example #5
Source Project: J2ME-Loader   Author: nikita36078   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
                args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}
 
Example #6
Source Project: knopflerfish.org   Author: knopflerfish   File: Dexifier.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addToDexFile(DexFile dexFile, String name, byte[] bytes) {
  DirectClassFile cf = new DirectClassFile(bytes, name, cfOptions.strictNameCheck);
  cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
  cf.getMagic();

  int numMethodIds = dexFile.getMethodIds().items().size();
  int numFieldIds = dexFile.getFieldIds().items().size();
  int constantPoolSize = cf.getConstantPool().size();

  int maxMethodIdsInDex = numMethodIds + constantPoolSize + cf.getMethods().size() +
      MAX_METHOD_ADDED_DURING_DEX_CREATION;
  int maxFieldIdsInDex = numFieldIds + constantPoolSize + cf.getFields().size() +
      MAX_FIELD_ADDED_DURING_DEX_CREATION;

  if ((dexFile.getClassDefs().items().size() > 0)
      && ((maxMethodIdsInDex > MAX_NUMBER_OF_IDX_PER_DEX) ||
          (maxFieldIdsInDex > MAX_NUMBER_OF_IDX_PER_DEX))) {
    throw new RuntimeException("TODO multi dex!");
  }

  try {
    ClassDefItem clazz = CfTranslator.translate(cf, bytes, cfOptions , dexOptions, dexFile);
    synchronized (dexFile) {
      dexFile.add(clazz);
    }
  } catch (ParseException ex) {
    Main.exit("Parse error, " + name, ex);
  }
}
 
Example #7
Source Project: bazel   Author: bazelbuild   File: Dexing.java    License: Apache License 2.0 5 votes vote down vote up
public ClassDefItem addToDexFile(DexFile dest, DirectClassFile classFile) {
  ClassDefItem result = CfTranslator.translate(
      context,
      classFile,
      (byte[]) null /*ignored*/,
      cfOptions,
      dest.getDexOptions(),
      dest);
  dest.add(result);
  return result;
}
 
Example #8
Source Project: buck   Author: facebook   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private ClassDefItem translateClass(byte[] bytes, DirectClassFile cf) {
    try {
        return CfTranslator.translate(context, cf, bytes, args.cfOptions,
            args.dexOptions, outputDex);
    } catch (ParseException ex) {
        context.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(context.err);
        } else {
            ex.printContext(context.err);
        }
    }
    errors.incrementAndGet();
    return null;
}