com.android.dx.cf.direct.StdAttributeFactory Java Examples

The following examples show how to use com.android.dx.cf.direct.StdAttributeFactory. 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: Box   Author: lulululbj   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 readBytes = getReadBytes();
    if (readBytes != bytes.length) {
        parsed(ba, readBytes, bytes.length - readBytes, "<extra data at end of file>");
    }
}
 
Example #2
Source Project: Box   Author: lulululbj   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
}
 
Example #3
Source Project: Box   Author: lulululbj   File: DotDumper.java    License: Apache License 2.0 6 votes vote down vote up
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.
}
 
Example #4
Source Project: Box   Author: lulululbj   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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 readBytes = getReadBytes();
    if (readBytes != bytes.length) {
        parsed(ba, readBytes, bytes.length - readBytes, "<extra data at end of file>");
    }
}
 
Example #5
Source Project: Box   Author: lulululbj   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
}
 
Example #6
Source Project: Box   Author: lulululbj   File: DotDumper.java    License: Apache License 2.0 6 votes vote down vote up
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.
}
 
Example #7
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 #8
Source Project: buck   Author: facebook   File: ClassDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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>");
    }
}
 
Example #9
Source Project: buck   Author: facebook   File: BlockDumper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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.
}
 
Example #10
Source Project: buck   Author: facebook   File: DotDumper.java    License: Apache License 2.0 6 votes vote down vote up
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.
}
 
Example #11
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #12
Source Project: Box   Author: lulululbj   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #13
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 #14
Source Project: J2ME-Loader   Author: nikita36078   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #15
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 #16
Source Project: bazel   Author: bazelbuild   File: Dexing.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source Project: byte-buddy   Author: raphw   File: AndroidClassLoadingStrategy.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@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(DISPATCHER.translate(directClassFile,
            binaryRepresentation,
            dexCompilerOptions,
            dexFileOptions,
            new DexFile(dexFileOptions)));
}
 
Example #18
Source Project: buck   Author: facebook   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
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;
    }