use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class Main method processClass.
/**
* 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 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 (args.multiDex && // Never switch to the next dex if current dex is already empty
(outputDex.getClassDefs().items().size() > 0) && ((maxMethodIdsInDex > args.maxNumberOfIdxPerDex) || (maxFieldIdsInDex > args.maxNumberOfIdxPerDex))) {
DexFile completeDex = outputDex;
createDexFile();
assert (completeDex.getMethodIds().items().size() <= numMethodIds + MAX_METHOD_ADDED_DURING_DEX_CREATION) && (completeDex.getFieldIds().items().size() <= numFieldIds + MAX_FIELD_ADDED_DURING_DEX_CREATION);
}
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.incrementAndGet();
return false;
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class BlockDumper method dump.
/**
* 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);
// Force parsing to happen.
classFile.getMagic();
// Next, reparse it and observe the process.
DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse());
liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
liveCf.setObserver(this);
// Force parsing to happen.
liveCf.getMagic();
}
use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.
the class DotDumper method run.
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);
// Force parsing to happen.
classFile.getMagic();
// Next, reparse it and observe the process.
DirectClassFile liveCf = new DirectClassFile(ba, filePath, strictParse);
liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
liveCf.setObserver(this);
// Force parsing to happen.
liveCf.getMagic();
}
Aggregations