com.android.dx.cf.direct.DirectClassFile Java Examples
The following examples show how to use
com.android.dx.cf.direct.DirectClassFile.
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 File: AnnotationLister.java From buck with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example #2
Source File: BaseAndroidClassLoader.java From rhino-android with Apache License 2.0 | 6 votes |
/** * {@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 #3
Source File: ClassReferenceListBuilder.java From RocooFix with MIT License | 6 votes |
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); } } }
Example #4
Source File: ClassReferenceListBuilder.java From RocooFix with MIT License | 6 votes |
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); } } }
Example #5
Source File: ClassReferenceListBuilder.java From RocooFix with MIT License | 6 votes |
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())); } }
Example #6
Source File: ClassReferenceListBuilder.java From RocooFix with MIT License | 6 votes |
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. } }
Example #7
Source File: ClassDumper.java From Box with Apache License 2.0 | 6 votes |
/** * 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 #8
Source File: BlockDumper.java From Box with Apache License 2.0 | 6 votes |
/** * 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 #9
Source File: DotDumper.java From Box with Apache License 2.0 | 6 votes |
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 #10
Source File: ClassReferenceListBuilder.java From Box with Apache License 2.0 | 6 votes |
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. } }
Example #11
Source File: ClassReferenceListBuilder.java From Box with Apache License 2.0 | 6 votes |
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())); } }
Example #12
Source File: AnnotationLister.java From Box with Apache License 2.0 | 6 votes |
/** * 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; } } }
Example #13
Source File: AnnotationLister.java From Box with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example #14
Source File: AnnotationLister.java From Box with Apache License 2.0 | 6 votes |
/** * 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); } } }
Example #15
Source File: DotDumper.java From Box with Apache License 2.0 | 6 votes |
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 #16
Source File: BlockDumper.java From Box with Apache License 2.0 | 6 votes |
/** * 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 #17
Source File: ClassDumper.java From Box with Apache License 2.0 | 6 votes |
/** * 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 #18
Source File: ClassReferenceListBuilder.java From buck with Apache License 2.0 | 6 votes |
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. } }
Example #19
Source File: AnnotationLister.java From Box with Apache License 2.0 | 6 votes |
/** * 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; } } }
Example #20
Source File: ClassReferenceListBuilder.java From Box with Apache License 2.0 | 6 votes |
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())); } }
Example #21
Source File: ClassReferenceListBuilder.java From Box with Apache License 2.0 | 6 votes |
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. } }
Example #22
Source File: ClassDumper.java From buck with Apache License 2.0 | 6 votes |
/** * 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 #23
Source File: BlockDumper.java From buck with Apache License 2.0 | 6 votes |
/** * 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 #24
Source File: AnnotationLister.java From buck with Apache License 2.0 | 6 votes |
/** * 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; } } }
Example #25
Source File: AttributeTranslator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Gets the {@code AnnotationDefault} attributes out of a * given class, if any, reforming them as an * {@code AnnotationDefault} annotation. * * @param cf {@code non-null;} the class in question * @return {@code null-ok;} an appropriately-constructed * {@code AnnotationDefault} annotation, if there were any * annotation defaults in the class, or {@code null} if not */ private static Annotation translateAnnotationDefaults(DirectClassFile cf) { CstType thisClass = cf.getThisClass(); MethodList methods = cf.getMethods(); int sz = methods.size(); Annotation result = new Annotation(thisClass, AnnotationVisibility.EMBEDDED); boolean any = false; for (int i = 0; i < sz; i++) { Method one = methods.get(i); AttributeList attribs = one.getAttributes(); AttAnnotationDefault oneDefault = (AttAnnotationDefault) attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME); if (oneDefault != null) { NameValuePair pair = new NameValuePair( one.getNat().getName(), oneDefault.getValue()); result.add(pair); any = true; } } if (! any) { return null; } result.setImmutable(); return AnnotationUtils.makeAnnotationDefault(result); }
Example #26
Source File: MainActivity.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #27
Source File: Main.java From J2ME-Loader with Apache License 2.0 | 5 votes |
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 #28
Source File: AttributeTranslator.java From J2ME-Loader with Apache License 2.0 | 5 votes |
/** * Gets the annotations out of a given class, similar to {@link * #getAnnotations}, also including annotations for translations * of class-level attributes {@code EnclosingMethod} and * {@code InnerClasses}, if present. Additionally, if the * class is an annotation class, then this also includes a * representation of all the {@code AnnotationDefault} * values. * * @param cf {@code non-null;} the class in question * @param args {@code non-null;} the high-level options * @return {@code non-null;} the set of annotations, which may be empty */ public static Annotations getClassAnnotations(DirectClassFile cf, CfOptions args) { CstType thisClass = cf.getThisClass(); AttributeList attribs = cf.getAttributes(); Annotations result = getAnnotations(attribs); Annotation enclosingMethod = translateEnclosingMethod(attribs); try { Annotations innerClassAnnotations = translateInnerClasses(thisClass, attribs, enclosingMethod == null); if (innerClassAnnotations != null) { result = Annotations.combine(result, innerClassAnnotations); } } catch (Warning warn) { args.warn.println("warning: " + warn.getMessage()); } if (enclosingMethod != null) { result = Annotations.combine(result, enclosingMethod); } if (AccessFlags.isAnnotation(cf.getAccessFlags())) { Annotation annotationDefault = translateAnnotationDefaults(cf); if (annotationDefault != null) { result = Annotations.combine(result, annotationDefault); } } return result; }
Example #29
Source File: Main.java From J2ME-Loader with Apache License 2.0 | 5 votes |
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 #30
Source File: AttributeTranslator.java From buck with Apache License 2.0 | 5 votes |
/** * Gets the {@code AnnotationDefault} attributes out of a * given class, if any, reforming them as an * {@code AnnotationDefault} annotation. * * @param cf {@code non-null;} the class in question * @return {@code null-ok;} an appropriately-constructed * {@code AnnotationDefault} annotation, if there were any * annotation defaults in the class, or {@code null} if not */ private static Annotation translateAnnotationDefaults(DirectClassFile cf) { CstType thisClass = cf.getThisClass(); MethodList methods = cf.getMethods(); int sz = methods.size(); Annotation result = new Annotation(thisClass, AnnotationVisibility.EMBEDDED); boolean any = false; for (int i = 0; i < sz; i++) { Method one = methods.get(i); AttributeList attribs = one.getAttributes(); AttAnnotationDefault oneDefault = (AttAnnotationDefault) attribs.findFirst(AttAnnotationDefault.ATTRIBUTE_NAME); if (oneDefault != null) { NameValuePair pair = new NameValuePair( one.getNat().getName(), oneDefault.getValue()); result.add(pair); any = true; } } if (! any) { return null; } result.setImmutable(); return AnnotationUtils.makeAnnotationDefault(result); }