本文整理汇总了Java中javassist.bytecode.AccessFlag类的典型用法代码示例。如果您正苦于以下问题:Java AccessFlag类的具体用法?Java AccessFlag怎么用?Java AccessFlag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessFlag类属于javassist.bytecode包,在下文中一共展示了AccessFlag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertCode
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
@Override
protected void insertCode(List<CtClass> box, File jarFile) throws IOException, CannotCompileException {
ZipOutputStream outStream = new JarOutputStream(new FileOutputStream(jarFile));
//get every class in the box ,ready to insert code
for (CtClass ctClass : box) {
//change modifier to public ,so all the class in the apk will be public ,you will be able to access it in the patch
ctClass.setModifiers(AccessFlag.setPublic(ctClass.getModifiers()));
if (isNeedInsertClass(ctClass.getName()) && !(ctClass.isInterface() || ctClass.getDeclaredMethods().length < 1)) {
//only insert code into specific classes
zipFile(transformCode(ctClass.toBytecode(), ctClass.getName().replaceAll("\\.", "/")), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class");
} else {
zipFile(ctClass.toBytecode(), outStream, ctClass.getName().replaceAll("\\.", "/") + ".class");
}
}
outStream.close();
}
示例2: addDefaultConstructor
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
/**
* Declares a constructor that takes no parameter.
*
* @param classfile The class descriptor
*
* @throws CannotCompileException Indicates trouble with the underlying Javassist calls
*/
private void addDefaultConstructor(ClassFile classfile) throws CannotCompileException {
final ConstPool constPool = classfile.getConstPool();
final String constructorSignature = "()V";
final MethodInfo constructorMethodInfo = new MethodInfo( constPool, MethodInfo.nameInit, constructorSignature );
final Bytecode code = new Bytecode( constPool, 0, 1 );
// aload_0
code.addAload( 0 );
// invokespecial
code.addInvokespecial( BulkAccessor.class.getName(), MethodInfo.nameInit, constructorSignature );
// return
code.addOpcode( Opcode.RETURN );
constructorMethodInfo.setCodeAttribute( code.toCodeAttribute() );
constructorMethodInfo.setAccessFlags( AccessFlag.PUBLIC );
classfile.addMethod( constructorMethodInfo );
}
示例3: markBridges
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
public void markBridges(CtClass c) {
for (CtMethod method : c.getDeclaredMethods()) {
MethodEntry methodEntry = EntryFactory.getMethodEntry(method);
// is this a bridge method?
MethodEntry bridgedMethodEntry = m_jarIndex.getBridgedMethod(methodEntry);
if (bridgedMethodEntry != null) {
// it's a bridge method! add the bridge flag
int flags = method.getMethodInfo().getAccessFlags();
flags |= AccessFlag.BRIDGE;
method.getMethodInfo().setAccessFlags(flags);
}
}
}
示例4: updateInnerEntry
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private static void updateInnerEntry(int mod, String name, CtClass clazz, boolean outer) {
ClassFile cf = clazz.getClassFile2();
InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
InnerClassesAttribute.tag);
if (ica == null)
return;
int n = ica.tableLength();
for (int i = 0; i < n; i++)
if (name.equals(ica.innerClass(i))) {
int acc = ica.accessFlags(i) & AccessFlag.STATIC;
ica.setAccessFlags(i, mod | acc);
String outName = ica.outerClass(i);
if (outName != null && outer)
try {
CtClass parent = clazz.getClassPool().get(outName);
updateInnerEntry(mod, name, parent, false);
}
catch (NotFoundException e) {
throw new RuntimeException("cannot find the declaring class: "
+ outName);
}
break;
}
}
示例5: firstFrame
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private Frame firstFrame(MethodInfo method, int maxLocals, int maxStack) {
int pos = 0;
Frame first = new Frame(maxLocals, maxStack);
if ((method.getAccessFlags() & AccessFlag.STATIC) == 0) {
first.setLocal(pos++, Type.get(clazz));
}
CtClass[] parameters;
try {
parameters = Descriptor.getParameterTypes(method.getDescriptor(), clazz.getClassPool());
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < parameters.length; i++) {
Type type = zeroExtend(Type.get(parameters[i]));
first.setLocal(pos++, type);
if (type.getSize() == 2)
first.setLocal(pos++, Type.TOP);
}
return first;
}
示例6: markBridges
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
public void markBridges(CtClass c) {
for (CtMethod method : c.getDeclaredMethods()) {
MethodEntry methodEntry = EntryFactory.getMethodEntry(method);
// is this a bridge method?
MethodEntry bridgedMethodEntry = this.m_jarIndex.getBridgedMethod(methodEntry);
if (bridgedMethodEntry != null) {
// it's a bridge method! add the bridge flag
int flags = method.getMethodInfo().getAccessFlags();
flags |= AccessFlag.BRIDGE;
method.getMethodInfo().setAccessFlags(flags);
}
}
}
示例7: addDefaultConstructor
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
/**
* Declares a constructor that takes no parameter.
*
* @param classfile
* @throws CannotCompileException
*/
private void addDefaultConstructor(ClassFile classfile) throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
String cons_desc = "()V";
MethodInfo mi = new MethodInfo( cp, MethodInfo.nameInit, cons_desc );
Bytecode code = new Bytecode( cp, 0, 1 );
// aload_0
code.addAload( 0 );
// invokespecial
code.addInvokespecial( BulkAccessor.class.getName(), MethodInfo.nameInit, cons_desc );
// return
code.addOpcode( Opcode.RETURN );
mi.setCodeAttribute( code.toCodeAttribute() );
mi.setAccessFlags( AccessFlag.PUBLIC );
classfile.addMethod( mi );
}
示例8: addGetFieldHandlerMethod
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private void addGetFieldHandlerMethod(ClassFile classfile)
throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
GETFIELDHANDLER_METHOD_DESCRIPTOR);
/* local variable | this | */
Bytecode code = new Bytecode(cp, 2, 1);
// aload_0 // load this
code.addAload(0);
// getfield // get field "$JAVASSIST_CALLBACK" defined already
code.addOpcode(Opcode.GETFIELD);
int field_index = cp.addFieldrefInfo(this_class_index,
HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
code.addIndex(field_index);
// areturn // return the value of the field
code.addOpcode(Opcode.ARETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
classfile.addMethod(minfo);
}
示例9: addSetFieldHandlerMethod
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private void addSetFieldHandlerMethod(ClassFile classfile)
throws CannotCompileException {
ConstPool cp = classfile.getConstPool();
int this_class_index = cp.getThisClassInfo();
MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
SETFIELDHANDLER_METHOD_DESCRIPTOR);
/* local variables | this | callback | */
Bytecode code = new Bytecode(cp, 3, 3);
// aload_0 // load this
code.addAload(0);
// aload_1 // load callback
code.addAload(1);
// putfield // put field "$JAVASSIST_CALLBACK" defined already
code.addOpcode(Opcode.PUTFIELD);
int field_index = cp.addFieldrefInfo(this_class_index,
HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
code.addIndex(field_index);
// return
code.addOpcode(Opcode.RETURN);
minfo.setCodeAttribute(code.toCodeAttribute());
minfo.setAccessFlags(AccessFlag.PUBLIC);
classfile.addMethod(minfo);
}
示例10: addReadWriteMethods
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private void addReadWriteMethods(ClassFile classfile)
throws CannotCompileException {
List fields = classfile.getFields();
for (Iterator field_iter = fields.iterator(); field_iter.hasNext();) {
FieldInfo finfo = (FieldInfo) field_iter.next();
if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0
&& (!finfo.getName().equals(HANDLER_FIELD_NAME))) {
// case of non-static field
if (filter.handleRead(finfo.getDescriptor(), finfo
.getName())) {
addReadMethod(classfile, finfo);
readableFields.put(finfo.getName(), finfo
.getDescriptor());
}
if (filter.handleWrite(finfo.getDescriptor(), finfo
.getName())) {
addWriteMethod(classfile, finfo);
writableFields.put(finfo.getName(), finfo
.getDescriptor());
}
}
}
}
示例11: markBridges
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
public void markBridges(CtClass c)
{
for(CtMethod method : c.getDeclaredMethods())
{
MethodEntry methodEntry = EntryFactory.getMethodEntry(method);
// is this a bridge method?
MethodEntry bridgedMethodEntry =
m_jarIndex.getBridgedMethod(methodEntry);
if(bridgedMethodEntry != null)
{
// it's a bridge method! add the bridge flag
int flags = method.getMethodInfo().getAccessFlags();
flags |= AccessFlag.BRIDGE;
method.getMethodInfo().setAccessFlags(flags);
}
}
}
示例12: solveMethod
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
public SymbolReference<MethodDeclaration> solveMethod(String name, List<Type> argumentsTypes, boolean staticOnly) {
List<MethodDeclaration> candidates = new ArrayList<>();
Predicate<CtMethod> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers()));
for (CtMethod method : ctClass.getDeclaredMethods()) {
boolean isSynthetic = method.getMethodInfo().getAttribute(SyntheticAttribute.tag) != null;
boolean isNotBridge = (method.getMethodInfo().getAccessFlags() & AccessFlag.BRIDGE) == 0;
if (method.getName().equals(name) && !isSynthetic && isNotBridge && staticOnlyCheck.test(method)) {
candidates.add(new JavassistMethodDeclaration(method, typeSolver));
}
}
try {
CtClass superClass = ctClass.getSuperclass();
if (superClass != null) {
SymbolReference<MethodDeclaration> ref = new JavassistClassDeclaration(superClass, typeSolver).solveMethod(name, argumentsTypes, staticOnly);
if (ref.isSolved()) {
candidates.add(ref.getCorrespondingDeclaration());
}
}
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
return MethodResolutionLogic.findMostApplicable(candidates, name, argumentsTypes, typeSolver);
}
示例13: solveMethod
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly) {
List<ResolvedMethodDeclaration> candidates = new ArrayList<>();
Predicate<CtMethod> staticOnlyCheck = m -> !staticOnly || (staticOnly && Modifier.isStatic(m.getModifiers()));
for (CtMethod method : ctClass.getDeclaredMethods()) {
boolean isSynthetic = method.getMethodInfo().getAttribute(SyntheticAttribute.tag) != null;
boolean isNotBridge = (method.getMethodInfo().getAccessFlags() & AccessFlag.BRIDGE) == 0;
if (method.getName().equals(name) && !isSynthetic && isNotBridge && staticOnlyCheck.test(method)) {
candidates.add(new JavassistMethodDeclaration(method, typeSolver));
}
}
try {
CtClass superClass = ctClass.getSuperclass();
if (superClass != null) {
SymbolReference<ResolvedMethodDeclaration> ref = new JavassistClassDeclaration(superClass, typeSolver).solveMethod(name, argumentsTypes, staticOnly);
if (ref.isSolved()) {
candidates.add(ref.getCorrespondingDeclaration());
}
}
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
return MethodResolutionLogic.findMostApplicable(candidates, name, argumentsTypes, typeSolver);
}
示例14: getModifiers
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
@Override
public int getModifiers() {
//this code reimplements CtClassType.getModifiers() to circumvent a bug
int acc = this.cf.getAccessFlags();
acc = clear(acc, SUPER);
int inner = this.cf.getInnerAccessFlags();
if (inner != -1) {
if ((inner & STATIC) != 0) {
acc |= STATIC;
}
if (AccessFlag.isPublic(inner)) {
//seems that public nested classes already have the PUBLIC modifier set
//but we are paranoid and we set it again
acc = setPublic(acc);
} else if (AccessFlag.isProtected(inner)) {
acc = setProtected(acc);
} else if (AccessFlag.isPrivate(inner)) {
acc = setPrivate(acc);
} else { //package visibility
acc = setPackage(acc); //clear the PUBLIC modifier in case it is set
}
}
return AccessFlag.toModifier(acc);
}
示例15: getDeclaredFields
import javassist.bytecode.AccessFlag; //导入依赖的package包/类
private ArrayList<Signature> getDeclaredFields(boolean areStatic) {
if ((areStatic ? this.fieldsStatic : this.fieldsObject) == null) {
final ArrayList<Signature> fields = new ArrayList<Signature>();
@SuppressWarnings("unchecked")
final List<FieldInfo> fieldsJA = this.cf.getFields();
for (FieldInfo fld : fieldsJA) {
if (Modifier.isStatic(AccessFlag.toModifier(fld.getAccessFlags())) == areStatic) {
final Signature sig = new Signature(getClassName(), fld.getDescriptor(), fld.getName());
fields.add(sig);
}
}
if (areStatic) {
this.fieldsStatic = fields;
} else {
this.fieldsObject = fields;
}
}
return (areStatic ? this.fieldsStatic : this.fieldsObject);
}