diff options
Diffstat (limited to 'src/cuchaz/enigma/bytecode/ClassPublifier.java')
| -rw-r--r-- | src/cuchaz/enigma/bytecode/ClassPublifier.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassPublifier.java b/src/cuchaz/enigma/bytecode/ClassPublifier.java new file mode 100644 index 0000000..dbefd42 --- /dev/null +++ b/src/cuchaz/enigma/bytecode/ClassPublifier.java | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.bytecode; | ||
| 12 | |||
| 13 | import javassist.CtBehavior; | ||
| 14 | import javassist.CtClass; | ||
| 15 | import javassist.CtField; | ||
| 16 | import javassist.bytecode.AccessFlag; | ||
| 17 | import javassist.bytecode.InnerClassesAttribute; | ||
| 18 | |||
| 19 | |||
| 20 | public class ClassPublifier { | ||
| 21 | |||
| 22 | public static CtClass publify(CtClass c) { | ||
| 23 | |||
| 24 | // publify all the fields | ||
| 25 | for (CtField field : c.getDeclaredFields()) { | ||
| 26 | field.setModifiers(publify(field.getModifiers())); | ||
| 27 | } | ||
| 28 | |||
| 29 | // publify all the methods and constructors | ||
| 30 | for (CtBehavior behavior : c.getDeclaredBehaviors()) { | ||
| 31 | behavior.setModifiers(publify(behavior.getModifiers())); | ||
| 32 | } | ||
| 33 | |||
| 34 | // publify all the inner classes | ||
| 35 | InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute(InnerClassesAttribute.tag); | ||
| 36 | if (attr != null) { | ||
| 37 | for (int i=0; i<attr.tableLength(); i++) { | ||
| 38 | attr.setAccessFlags(i, publify(attr.accessFlags(i))); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | return c; | ||
| 43 | } | ||
| 44 | |||
| 45 | private static int publify(int flags) { | ||
| 46 | if (AccessFlag.isPrivate(flags) || AccessFlag.isProtected(flags)) { | ||
| 47 | flags = AccessFlag.setPublic(flags); | ||
| 48 | } | ||
| 49 | return flags; | ||
| 50 | } | ||
| 51 | } | ||