ProxyClassLoader.java
4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.granite.crypto.internal;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProxyClassLoader
extends ClassLoader {
private static final String PACKAGE_COM_RSA = "com.rsa";
private static final String PREFIX_CLASS_COM_RSA = "com.rsa.";
private static final String PREFIX_RESOURCE_COM_RSA = "com.rsa.".replace('.', '/');
private final Logger log;
private final ClassLoader delegatee;
public ProxyClassLoader(ClassLoader delegatee) {
this.log = LoggerFactory.getLogger(this.getClass());
this.delegatee = delegatee;
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if (this.isRsaClass(name)) {
this.log.debug("loadClass: Not loading class {} through parent class loader", (Object)name);
throw new ClassNotFoundException(name);
}
try {
Class c = this.delegatee.loadClass(name);
this.log.debug("loadClass: Loaded class {} through parent class loader", (Object)name);
return c;
}
catch (ClassNotFoundException cnfe) {
this.log.debug("loadClass: Class {} not found through parent class loader", (Object)name);
throw cnfe;
}
catch (Throwable t) {
this.log.debug("loadClass: Error loading class " + name + " through parent class loader", t);
if (t instanceof Error) {
throw (Error)t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException)t;
}
throw new IllegalStateException("Unexpected failure: " + t, t);
}
}
@Override
public URL getResource(String name) {
if (this.isRsaResource(name)) {
this.log.debug("getResource({}) --> null (forced from internal)", (Object)name);
return null;
}
URL res = super.getResource(name);
this.log.debug("getResource({}) --> {}", (Object)name, (Object)res);
return res;
}
@Override
public Enumeration<URL> getResources(String name) throws IOException {
if (this.isRsaResource(name)) {
this.log.debug("getResources({}) --> empty (forced from internal)", (Object)name);
return Collections.enumeration(Collections.emptyList());
}
Enumeration<URL> res = super.getResources(name);
Object[] arrobject = new Object[3];
arrobject[0] = name;
arrobject[1] = res;
arrobject[2] = res.hasMoreElements() ? "has resources" : "empty";
this.log.debug("getResources({}) --> {} ({})", arrobject);
return res;
}
@Override
protected Package getPackage(String name) {
if (this.isRsaPackage(name)) {
this.log.debug("getPackage({}) --> null (forced from internal)", (Object)name);
return null;
}
Package res = super.getPackage(name);
this.log.debug("getPackage({}) --> {}", new Object[]{name, res});
return res;
}
@Override
protected Package[] getPackages() {
Package[] res = super.getPackages();
this.log.debug("getPackages() --> {} packages", (Object)res.length);
for (Package tstPkg : res) {
if (!this.isRsaPackage(tstPkg.getName())) continue;
ArrayList<Package> pkgList = new ArrayList<Package>(res.length);
for (Package pkg : pkgList) {
if (!this.isRsaPackage(pkg.getName())) {
this.log.debug("getPackages() --> add {}", (Object)pkg);
pkgList.add(pkg);
continue;
}
this.log.debug("getPackages() --> remove {}", (Object)pkg);
}
res = pkgList.toArray(new Package[pkgList.size()]);
break;
}
this.log.debug("getPackages() --> {} packages", (Object)res.length);
return res;
}
private boolean isRsaClass(String className) {
return className.startsWith("com.rsa.");
}
private boolean isRsaResource(String resName) {
return resName.startsWith(PREFIX_RESOURCE_COM_RSA);
}
private boolean isRsaPackage(String pkgName) {
return pkgName.startsWith("com.rsa.") || pkgName.equals("com.rsa");
}
}