本文整理汇总了Java中com.android.dx.cf.direct.DirectClassFile类的典型用法代码示例。如果您正苦于以下问题:Java DirectClassFile类的具体用法?Java DirectClassFile怎么用?Java DirectClassFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DirectClassFile类属于com.android.dx.cf.direct包,在下文中一共展示了DirectClassFile类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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>");
}
}
示例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.
}
示例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.
}
示例4: visitClassAnnotation
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
/**
* Inspects a class annotation.
*
* @param cf {@code non-null;} class file
* @param ann {@code non-null;} annotation
*/
private void visitClassAnnotation(DirectClassFile cf,
BaseAnnotations ann) {
if (!args.eTypes.contains(ElementType.TYPE)) {
return;
}
for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
String annClassName
= anAnn.getType().getClassType().getClassName();
if (args.aclass.equals(annClassName)) {
printMatch(cf);
}
}
}
示例5: printMatch
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
/**
* Prints, or schedules for printing, elements related to a matching
* class.
*
* @param cf {@code non-null;} matching class
*/
private void printMatch(DirectClassFile cf) {
for (Main.PrintType pt : args.printTypes) {
switch (pt) {
case CLASS:
String classname;
classname =
cf.getThisClass().getClassType().getClassName();
classname = classname.replace('/','.');
System.out.println(classname);
break;
case INNERCLASS:
matchInnerClassesOf.add(
cf.getThisClass().getClassType().getClassName());
break;
case METHOD:
//TODO
break;
case PACKAGE:
break;
}
}
}
示例6: addClassWithHierachy
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
private void addClassWithHierachy(String classBinaryName) {
if (toKeep.contains(classBinaryName)) {
return;
}
String fileName = classBinaryName + CLASS_EXTENSION;
try {
DirectClassFile classFile = path.getClass(fileName);
toKeep.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
示例7: 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);
}
}
示例8: addSupperClass
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
public void addSupperClass(String name){
if (name.endsWith(CLASS_EXTENSION)) {
classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
}
if (name.endsWith(CLASS_EXTENSION)) {
DirectClassFile classFile;
try {
classFile = path.getClass(name);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
String superClassName=superClass.getClassType().getClassName();
classNames.add(superClassName);
}
} catch (FileNotFoundException e) {
// throw new IOException("Class " + name +
// " is missing form original class path " + path, e);
}
}
}
示例9: addRootsV2
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
public void addRootsV2(String name){
if (name.endsWith(CLASS_EXTENSION)) {
classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
}
if (name.endsWith(CLASS_EXTENSION)) {
DirectClassFile classFile;
try {
classFile = path.getClass(name);
addDependencies(classFile);
} catch (FileNotFoundException e) {
// throw new IOException("Class " + name +
// " is missing form original class path " + path, e);
}
}
}
示例10: addDependencies
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
private void addDependencies(DirectClassFile classFile) {
for (Constant constant : classFile.getConstantPool().getEntries()) {
if (constant instanceof CstType) {
checkDescriptor(((CstType) constant).getClassType().getDescriptor());
} else if (constant instanceof CstFieldRef) {
checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
} else if (constant instanceof CstBaseMethodRef) {
checkPrototype(((CstBaseMethodRef) constant).getPrototype());
}
}
FieldList fields = classFile.getFields();
int nbField = fields.size();
for (int i = 0; i < nbField; i++) {
checkDescriptor(fields.get(i).getDescriptor().getString());
}
MethodList methods = classFile.getMethods();
int nbMethods = methods.size();
for (int i = 0; i < nbMethods; i++) {
checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
}
}
示例11: addClassWithHierachy
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
示例12: addDependencies
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
private void addDependencies(DirectClassFile classFile) {
for (Constant constant : classFile.getConstantPool().getEntries()) {
if (constant instanceof CstType) {
checkDescriptor(((CstType) constant).getClassType().getDescriptor());
} else if (constant instanceof CstFieldRef) {
checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
} else if (constant instanceof CstBaseMethodRef) {
checkPrototype(((CstBaseMethodRef) constant).getPrototype());
}
}
FieldList fields = classFile.getFields();
int nbField = fields.size();
for (int i = 0; i < nbField; i++) {
checkDescriptor(fields.get(i).getDescriptor().getString());
}
MethodList methods = classFile.getMethods();
int nbMethods = methods.size();
for (int i = 0; i < nbMethods; i++) {
checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
}
}
示例13: addClassWithHierachy
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierachy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierachy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
示例14: getCode
import com.android.dx.cf.direct.DirectClassFile; //导入依赖的package包/类
/**
* Extracts the code block from the given method of the given class, or
* <code>null</code>, if method is native or abstract.
*/
private static DalvCode getCode(Method method, DirectClassFile classFile) {
boolean isNative = AccessFlags.isNative(method.getAccessFlags());
boolean isStatic = AccessFlags.isStatic(method.getAccessFlags());
boolean isAbstract = AccessFlags.isAbstract(method.getAccessFlags());
if (isNative || isAbstract) {
return null;
}
ConcreteMethod concrete = new ConcreteMethod(method, classFile, false, false);
TranslationAdvice advice = DexTranslationAdvice.THE_ONE;
RopMethod rmeth = Ropper.convert(concrete, advice);
CstMethodRef meth = new CstMethodRef(method.getDefiningClass(), method.getNat());
int paramSize = meth.getParameterWordCount(isStatic);
DalvCode code = RopTranslator.translate(rmeth, PositionList.NONE, null, paramSize);
DalvCode.AssignIndicesCallback callback = new DalvCode.AssignIndicesCallback() {
public int getIndex(Constant cst) {
// Everything is at index 0!
return 0;
}
};
code.assignIndices(callback);
return code;
}