public int getModifiers() { int mod = Modifier.FINAL; try { mod |= getComponentType().getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | Modifier.PRIVATE); } catch (NotFoundException e) {} return mod; }
@Override public int getModifiers() { int mod = Modifier.FINAL; try { mod |= getComponentType().getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC | Modifier.PRIVATE); } catch (NotFoundException e) {} return mod; }
/** * Creates a new annotation. * If there already exists a class/interface with the same name, * the new interface overwrites that previous one. * * @param name a fully-qualified interface name. * Or null if the annotation has no super interface. * @throws RuntimeException if the existing interface is frozen. * @since 3.19 */ public CtClass makeAnnotation(String name) throws RuntimeException { try { CtClass cc = makeInterface(name, get("java.lang.annotation.Annotation")); cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); return cc; } catch (NotFoundException e) { // should never happen. throw new RuntimeException(e.getMessage(), e); } }
private void ensureNewInstance(CtClass cc) throws NotFoundException, CannotCompileException { CtMethod ccms[] = cc.getDeclaredMethods(); if( !javassist.Modifier.isAbstract(cc.getModifiers()) && !hasExisting("newInstance", "()Lwater/Freezable;", ccms) ) { cc.addMethod(CtNewMethod.make( "public water.Freezable newInstance() {\n" + " return new " +cc.getName()+"();\n" + "}", cc)); } }
@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(); }
/** * Creates a new annotation. * If there already exists a class/interface with the same name, * the new interface overwrites that previous one. * * @param name a fully-qualified interface name. * Or null if the annotation has no super interface. * @throws RuntimeException if the existing interface is frozen. * @since 3.19 */ public CtClass makeAnnotation(String name) throws RuntimeException { try { CtClass cc = makeInterface(name, get("java.lang.annotation.Annotation")); cc.setModifiers(cc.getModifiers() | Modifier.ANNOTATION); return cc; } catch (NotFoundException e) { // should never happen. throw new RuntimeException(e.getMessage(), e); } }
CtClass ctcs = mSuperClass == null ? null : mPool.get(mSuperClass); if (mClassName == null) { mClassName = (mSuperClass == null || javassist.Modifier.isPublic(ctcs.getModifiers()) ? ClassGenerator.class.getName() : mSuperClass + "$sc") + id;
CtClass ctcs = mSuperClass == null ? null : mPool.get(mSuperClass); if (mClassName == null) { mClassName = (mSuperClass == null || javassist.Modifier.isPublic(ctcs.getModifiers()) ? ClassGenerator.class.getName() : mSuperClass + "$sc") + id;
private void ensureType(CtClass cc) throws NotFoundException, CannotCompileException { CtMethod ccms[] = cc.getDeclaredMethods(); if( !javassist.Modifier.isAbstract(cc.getModifiers()) && !hasExisting("frozenType", "()I", ccms) ) { // Build a simple field & method returning the type token cc.addField(new CtField(CtClass.intType, "_frozen$type", cc)); cc.addMethod(CtNewMethod.make("public int frozenType() {" + " return _frozen$type == 0 ? (_frozen$type=water.TypeMap.onIce(\""+cc.getName()+"\")) : _frozen$type;" + "}",cc)); } }
int classMods = clazz.getModifiers(); if ((classMods & Modifier.INTERFACE) != 0) if (methods.length > 0)
if (isNeedInsertClass(ctClass.getName())) { ctClass.setModifiers(AccessFlag.setPublic(ctClass.getModifiers())); if (ctClass.isInterface() || ctClass.getDeclaredMethods().length < 1) {
private CtClass produceProxyClass(CtClass orgclass, Class orgRtClass) throws CannotCompileException, NotFoundException int modify = orgclass.getModifiers(); if (Modifier.isAbstract(modify) || Modifier.isNative(modify) || !Modifier.isPublic(modify))
CtClass ctcs = mSuperClass == null ? null : mPool.get(mSuperClass); if (mClassName == null) mClassName = (mSuperClass == null || javassist.Modifier.isPublic(ctcs.getModifiers()) ? TccClassGenerator.class.getName() : mSuperClass + "$sc") + id; mCtc = mPool.makeClass(mClassName);
return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try {
private CtClass produceProxyClass(CtClass orgclass, Class<?> orgRtClass) throws CannotCompileException, NotFoundException int modify = orgclass.getModifiers(); if (Modifier.isAbstract(modify) || Modifier.isNative(modify) || !Modifier.isPublic(modify))
private void ensureVersion(CtClass cc) throws NotFoundException, CannotCompileException, BadBytecode { CtMethod ccms[] = cc.getDeclaredMethods(); if (!javassist.Modifier.isAbstract(cc.getModifiers())) { String gsig = cc.getGenericSignature(); ClassSignature csig = SignatureAttribute.toClassSignature(gsig); // Warning: this is not doing proper parent (superclass/interfaces) traversal TypeArgument ta = getTypeArg(csig.getSuperClass().getTypeArguments(), "Lwater/api/rest/Version"); if (ta!=null && !hasExisting("getVersion", "()"+ta.getType().encode(), ccms) ) { String typeName = ta.toString(); String valueName = getValueFromType(typeName); //cc.addMethod(CtNewMethod.make("public "+typeName+" getVersion() {" + cc.addMethod(CtNewMethod.make("public water.api.rest.Version getVersion() {" + " return "+valueName+";" + "}",cc)); } } } private String getValueFromType(String typeName) {
bytecode.addInvokespecial(targetClass, mname, desc); else { if (!Modifier.isPublic(declClass.getModifiers()) || declClass.isInterface() != targetClass.isInterface()) declClass = targetClass;
CtClass addSerializationMethods( CtClass cc ) throws CannotCompileException, NotFoundException { if( cc.subclassOf(_enum) ) exposeRawEnumArray(cc); if( cc.subclassOf(_iced) ) ensureAPImethods(cc); if( cc.subclassOf(_iced) || cc.subclassOf(_dtask)|| cc.subtypeOf(_freezable)) { cc.setModifiers(javassist.Modifier.setPublic(cc.getModifiers())); ensureSerMethods(cc); ensureNullaryCtor(cc); ensureNewInstance(cc); ensureType(cc); } return cc; }
bytecode.addInvokespecial(targetClass, mname, desc); else { if (!Modifier.isPublic(declClass.getModifiers()) || declClass.isInterface() != targetClass.isInterface()) declClass = targetClass;
return maybe; int mod = clazz.getModifiers(); boolean isIntf = Modifier.isInterface(mod); try {