Closed paulo-raca closed 7 years ago
Did you call setModifiers on every subclass one by one? You have to do so.
Yes.
My code basically lists every .class file in the classpath, removes the .class
suffix and replaces /
with .
to get a list of every class it needs to check.
It will process each of these classes independently, ignoring whenever it's a subclass or not.
It processes Outer
and Outer$Inner
, but the visibility is only updated on Outer
.
I also apply some other changes using ctMethod.instrument()
, and these work fine both for Outer and Inner classes.
I've been investigating it a little, and I guess that since "outer" classes can only be public or package-visible, those are the only values mapped on CtClass.getModifiers()
.
If the class should by private
, the resulting modifier actually says PUBLIC
.
If the class should by protected
, the resulting modifier actually indicates "PACKAGE-VISIBLE"
.
I've also tested a few other modifiers (static, final, abstract) and these seem to work fine.
Another weird observation.
I'm now using ctClass.setModifiers( Modifier.setPublic(ctClass.getModifiers()));
to update the classes.
Javassist and javap
both see the modified classes as public.
AndroidStudio and the Fernflower decompiler do not, and show the unmodified visibility.
The only thing I can think of is that the access modifier is being stored in redundant places.
Ah, yes, you also have to update the InnerClasses attribute of the inner classes.
How do I do that?
javassist.bytecode.InnerClassesAttribute#setAccessFlags
Thank you!
Would it make sense to use InnerClassesAttribute automatically on CtClass.getModifiers()
/ CtClass.setModifiers()
?
I've modified CtClass.setModifiers() to do so.
Thanks a lot!
I'm trying to make every class in a package public.
Basically, for every CtClass:
ctClass.setModifiers( Modifier.setPublic(ctClass.getModifiers()));
This works fine for upper-level classes, but seems to have no effect on Subclasses.
(A few other manipulations work on subclasses just fine)