summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/bytecode
diff options
context:
space:
mode:
authorGravatar Cuchaz2015-03-23 16:26:44 -0400
committerGravatar Cuchaz2015-03-23 16:26:44 -0400
commit902b1b519f8ae89910f6f0d9f077738711349324 (patch)
tree1ce8a1d05e8797a62ae0d5391ae5b3c951e19b5d /src/cuchaz/enigma/bytecode
parentrepackage for 0.10.3 beta (diff)
downloadenigma-fork-0.10.3_beta.tar.gz
enigma-fork-0.10.3_beta.tar.xz
enigma-fork-0.10.3_beta.zip
add protectifier! Muwahahaha!!!v0.10.3_beta
Diffstat (limited to '')
-rw-r--r--src/cuchaz/enigma/bytecode/ClassProtectifier.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/bytecode/ClassProtectifier.java b/src/cuchaz/enigma/bytecode/ClassProtectifier.java
new file mode 100644
index 0000000..49a6269
--- /dev/null
+++ b/src/cuchaz/enigma/bytecode/ClassProtectifier.java
@@ -0,0 +1,41 @@
1package cuchaz.enigma.bytecode;
2
3import javassist.CtBehavior;
4import javassist.CtClass;
5import javassist.CtField;
6import javassist.bytecode.AccessFlag;
7import javassist.bytecode.InnerClassesAttribute;
8
9
10public class ClassProtectifier {
11
12 public static CtClass protectify(CtClass c) {
13
14 // protectify all the fields
15 for (CtField field : c.getDeclaredFields()) {
16 field.setModifiers(protectify(field.getModifiers()));
17 }
18
19 // protectify all the methods and constructors
20 for (CtBehavior behavior : c.getDeclaredBehaviors()) {
21 behavior.setModifiers(protectify(behavior.getModifiers()));
22 }
23
24 // protectify all the inner classes
25 InnerClassesAttribute attr = (InnerClassesAttribute)c.getClassFile().getAttribute(InnerClassesAttribute.tag);
26 if (attr != null) {
27 for (int i=0; i<attr.tableLength(); i++) {
28 attr.setAccessFlags(i, protectify(attr.accessFlags(i)));
29 }
30 }
31
32 return c;
33 }
34
35 private static int protectify(int flags) {
36 if (AccessFlag.isPrivate(flags)) {
37 flags = AccessFlag.setProtected(flags);
38 }
39 return flags;
40 }
41}