use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.
the class ClassReferenceListBuilder method run.
public void run(String refClassName) throws IOException {
classNames.add(refClassName);
while (true) {
Set<String> temp = getUnAnalyzeClasses();
if (temp.isEmpty()) {
break;
}
for (String tempName : temp) {
alreadyAnalyzedClasses.add(tempName);
refcname = tempName;
// System.out.println("scan:---------->" + refcname);
for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
String name = entry.getName();
currentName = name;
if (name.endsWith(CLASS_EXTENSION) && shouldScan(name)) {
DirectClassFile classFile;
try {
classFile = path.getClass(name);
} catch (FileNotFoundException e) {
throw new IOException("Class " + name + " is missing form original class path " + path, e);
}
// System.out.println("=====classname:" + name);
addDependencies(classFile.getConstantPool());
}
}
}
}
}
use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.
the class ClassReferenceListBuilder method addClassWithHierachy.
private void addClassWithHierachy(String classBinaryName) {
if (classNames.contains(classBinaryName) || !refcname.equals(classBinaryName + CLASS_EXTENSION)) {
return;
}
try {
DirectClassFile classFile = path.getClass(currentName);
classNames.add(currentName);
File entryFile = new File(patchDir + "/" + currentName);
entryFile.getParentFile().mkdirs();
if (!entryFile.exists()) {
entryFile.createNewFile();
// Iterable<ClassPathElement> elements = path.getElements();
// for (ClassPathElement element : elements) {
// InputStream in = element.open(currentName);
byte[] bytes = NuwaProcessor.referHackWhenInit(classFile.getBytes().makeDataInputStream());
// System.out.println(classFile.getFilePath() + ",size:" + bytes.length);
FileUtils.writeByteArrayToFile(entryFile, bytes);
// }
}
// NuwaProcessor.referHackWhenInit();
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) {
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.
the class Path method getClass.
synchronized DirectClassFile getClass(String path) throws FileNotFoundException {
DirectClassFile classFile = null;
for (ClassPathElement element : elements) {
try {
InputStream in = element.open(path);
try {
byte[] bytes = readStream(in, baos, readBuffer);
baos.reset();
classFile = new DirectClassFile(bytes, path, false);
classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
break;
} finally {
in.close();
}
} catch (IOException e) {
// search next element
}
}
if (classFile == null) {
throw new FileNotFoundException("File \"" + path + "\" not found");
}
return classFile;
}
use of com.android.dx.cf.direct.DirectClassFile in project buck by facebook.
the class ClassReferenceListBuilder method addClassWithHierarchy.
private void addClassWithHierarchy(String classBinaryName) {
if (classNames.contains(classBinaryName)) {
return;
}
try {
DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
if (CLASS_TO_CHECK != null && classBinaryName.contains(CLASS_TO_CHECK)) {
found();
}
classNames.add(classBinaryName);
CstType superClass = classFile.getSuperclass();
if (superClass != null) {
addClassWithHierarchy(superClass.getClassType().getClassName());
}
TypeList interfaceList = classFile.getInterfaces();
int interfaceNumber = interfaceList.size();
for (int i = 0; i < interfaceNumber; i++) {
addClassWithHierarchy(interfaceList.getType(i).getClassName());
}
} catch (FileNotFoundException e) {
// Ignore: The referenced type is not in the path it must be part of the libraries.
}
}
use of com.android.dx.cf.direct.DirectClassFile in project buck by facebook.
the class AnnotationLister method process.
/** Processes based on configuration specified in constructor. */
void process() {
for (String path : args.files) {
ClassPathOpener opener;
opener = new ClassPathOpener(path, true, new ClassPathOpener.Consumer() {
public boolean processFileBytes(String name, long lastModified, byte[] bytes) {
if (!name.endsWith(".class")) {
return true;
}
ByteArray ba = new ByteArray(bytes);
DirectClassFile cf = new DirectClassFile(ba, name, true);
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
AttributeList attributes = cf.getAttributes();
Attribute att;
String cfClassName = cf.getThisClass().getClassType().getClassName();
if (cfClassName.endsWith(PACKAGE_INFO)) {
att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitPackageAnnotation(cf, ann);
}
att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitPackageAnnotation(cf, ann);
}
} else if (isMatchingInnerClass(cfClassName) || isMatchingPackage(cfClassName)) {
printMatch(cf);
} else {
att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitClassAnnotation(cf, ann);
}
att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
for (; att != null; att = attributes.findNext(att)) {
BaseAnnotations ann = (BaseAnnotations) att;
visitClassAnnotation(cf, ann);
}
}
return true;
}
public void onException(Exception ex) {
throw new RuntimeException(ex);
}
public void onProcessArchiveStart(File file) {
}
});
opener.process();
}
}
Aggregations