Skip to content

Commit 0f47135

Browse files
committed
WIP
1 parent b928318 commit 0f47135

File tree

10 files changed

+6625
-29
lines changed

10 files changed

+6625
-29
lines changed

.idea/compiler.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/MiniJar_Getting_Started.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out.jar

-3.58 KB
Binary file not shown.

seenClasses.txt

Lines changed: 2480 additions & 0 deletions
Large diffs are not rendered by default.

seenNOFLOWClasses.txt

Lines changed: 4005 additions & 0 deletions
Large diffs are not rendered by default.

seenReflectiveClasses.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Application,Lorg/jboss/resteasy/microprofile/config/FilterConfigSourceImpl>
2+
<Application,Lorg/jboss/resteasy/microprofile/config/ServletContextConfigSourceImpl>
3+
<Application,Lorg/jboss/resteasy/microprofile/config/ServletConfigSourceImpl>
4+
<Primordial,Lsun/security/provider/Sun>
5+
<Primordial,Lsun/security/rsa/SunRsaSign>
6+
<Primordial,Lsun/security/util/ObjectIdentifier>
7+
<Primordial,Ljava/util/Date>
8+
<Primordial,Ljava/lang/String>
9+
<Primordial,Lsun/security/x509/CertificateExtensions>
10+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
11+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
12+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
13+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
14+
<Primordial,Lapple/security/AppleProvider>
15+
<Primordial,Lmodule-info>
16+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
17+
<Primordial,Ljava/lang/invoke/MethodHandleImpl>
18+
<Primordial,Lsun/net/spi/DefaultProxySelector>
19+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
20+
<Application,Lorg/jboss/resteasy/core/providerfactory/ResteasyProviderFactoryImpl>
21+
<Primordial,Ljava/nio/DirectByteBufferR>
22+
<Primordial,Ljava/nio/DirectByteBuffer>
23+
<Primordial,Lsun/nio/ch/FileChannelImpl>

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
*/
99

1010
rootProject.name = 'minijar'
11-
include('lib')
11+

src/main/java/minijar/MiniJar.java

Lines changed: 92 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77
package minijar;
88

9-
import java.io.File;
10-
import java.io.IOException;
9+
import java.io.*;
1110
import java.nio.charset.StandardCharsets;
1211
import java.util.ArrayList;
1312
import java.util.HashSet;
@@ -17,21 +16,18 @@
1716

1817
import com.google.common.collect.Sets;
1918
import com.google.common.io.Files;
20-
import com.ibm.wala.classLoader.IMethod;
19+
import com.ibm.wala.analysis.reflection.ClassFactoryContextInterpreter;
20+
import com.ibm.wala.analysis.reflection.ClassFactoryContextSelector;
21+
import com.ibm.wala.analysis.reflection.JavaTypeContext;
22+
import com.ibm.wala.classLoader.*;
2123
import com.ibm.wala.core.java11.Java9AnalysisScopeReader;
2224
import com.ibm.wala.core.util.warnings.Warnings;
23-
import com.ibm.wala.ipa.callgraph.AnalysisCache;
24-
import com.ibm.wala.ipa.callgraph.AnalysisCacheImpl;
25-
import com.ibm.wala.ipa.callgraph.AnalysisOptions;
26-
import com.ibm.wala.ipa.callgraph.AnalysisScope;
27-
import com.ibm.wala.ipa.callgraph.CGNode;
28-
import com.ibm.wala.ipa.callgraph.CallGraph;
29-
import com.ibm.wala.ipa.callgraph.CallGraphBuilder;
30-
import com.ibm.wala.ipa.callgraph.CallGraphBuilderCancelException;
31-
import com.ibm.wala.ipa.callgraph.Entrypoint;
25+
import com.ibm.wala.ipa.callgraph.*;
26+
import com.ibm.wala.ipa.callgraph.impl.ContextInsensitiveSelector;
3227
import com.ibm.wala.ipa.callgraph.impl.Everywhere;
3328
import com.ibm.wala.ipa.callgraph.impl.Util;
3429
import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
30+
import com.ibm.wala.ipa.callgraph.propagation.PropagationCallGraphBuilder;
3531
import com.ibm.wala.ipa.cha.ClassHierarchyException;
3632
import com.ibm.wala.ipa.cha.ClassHierarchyFactory;
3733
import com.ibm.wala.ipa.cha.IClassHierarchy;
@@ -42,6 +38,8 @@
4238
import com.ibm.wala.shrike.shrikeCT.ConstantPoolParser;
4339
import com.ibm.wala.types.MethodReference;
4440
import com.ibm.wala.util.collections.HashMapFactory;
41+
import com.ibm.wala.util.config.FileOfClasses;
42+
import com.ibm.wala.util.intset.IntSet;
4543

4644
public class MiniJar {
4745
private static final String USAGE =
@@ -127,7 +125,7 @@ public static void main(String[] args) throws Exception {
127125

128126
String[] mClasses = new String[mainClasses.size()];
129127
Set<String> cg = cw.getReachableMethods(mainClasses.toArray(mClasses), scopeFileData, entryClass, entrypointMethods, includedPaths);
130-
128+
131129
while ((ci = instrumenter.nextClass()) != null) {
132130
try {
133131
cw.processClass(ci, cg, includedPaths);
@@ -231,6 +229,7 @@ private Set<String> getReachableMethods(String[] mainClasses, String scopeFileDa
231229
AnalysisScope scope = new Java9AnalysisScopeReader().readJavaScope(scopeFileData, null, MiniJar.class.getClassLoader());
232230

233231
IClassHierarchy cha = ClassHierarchyFactory.make(scope);
232+
addDefaultExclusions(scope);
234233
System.out.println(cha.getNumberOfClasses() + " classes");
235234
System.out.println(Warnings.asString());
236235
Warnings.clear();
@@ -252,16 +251,70 @@ private Set<String> getReachableMethods(String[] mainClasses, String scopeFileDa
252251
}
253252

254253
// you can dial down reflection handling if you like
255-
//options.setReflectionOptions(AnalysisOptions.ReflectionOptions.NO_FLOW_TO_CASTS);
256254
options.setReflectionOptions(AnalysisOptions.ReflectionOptions.NO_FLOW_TO_CASTS);
255+
//options.setReflectionOptions(AnalysisOptions.ReflectionOptions.NONE);
257256
AnalysisCache cache = new AnalysisCacheImpl();
258-
259-
CallGraphBuilder<InstanceKey> builder = Util.makeRTABuilder(options, cache, cha, scope);
260-
//CallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);
257+
258+
//CallGraphBuilder builder = Util.makeZeroOneCFABuilder(Language.JAVA, options, cache, cha, scope);
259+
260+
//CallGraphBuilder<InstanceKey> builder = Util.makeRTABuilder(options, cache, cha, scope);
261+
CallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope);
261262
//CallGraphBuilder builder = Util.makeNCFABuilder(2, options, cache, cha, scope);
262263
//CallGraphBuilder builder = Util.makeVanillaNCFABuilder(2, options, cache, cha, scope);
263264
//CallGraphBuilder builder = Util.makeZeroOneContainerCFABuilder(options, cache, cha, scope);
264-
265+
266+
options.setSelector(new ClassTargetSelector() {
267+
ClassTargetSelector base = options.getClassTargetSelector();
268+
Set<IClass> seen = new HashSet<>();
269+
FileWriter log = new FileWriter("seenNOFLOWClasses.txt");
270+
271+
@Override
272+
public IClass getAllocatedTarget(CGNode caller, NewSiteReference site) {
273+
IClass baseC = base.getAllocatedTarget(caller, site);
274+
275+
if (!seen.contains(baseC)) {
276+
seen.add(baseC);
277+
try {
278+
log.write("**** SEEN: " + baseC + "\n");
279+
log.flush();
280+
} catch (IOException e) {
281+
System.err.println(e);
282+
}
283+
284+
}
285+
return baseC;
286+
}
287+
});
288+
289+
PropagationCallGraphBuilder propBuilder = ((PropagationCallGraphBuilder) builder);
290+
291+
propBuilder.setContextSelector(new ContextSelector() {
292+
ContextSelector base = propBuilder.getContextSelector();
293+
ClassFactoryContextSelector fac = new ClassFactoryContextSelector();
294+
FileWriter log = new FileWriter("seenReflectiveClasses.txt");
295+
296+
@Override
297+
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] actualParameters) {
298+
Context con = fac.getCalleeTarget(caller, site, callee, actualParameters);
299+
if (con instanceof JavaTypeContext) {
300+
JavaTypeContext javaCon = (JavaTypeContext) con;
301+
try {
302+
log.write(javaCon.getType().getType().toString() + "\n");
303+
log.flush();
304+
} catch (IOException e) {
305+
System.err.println(e);
306+
}
307+
}
308+
return base.getCalleeTarget(caller, site, callee, actualParameters);
309+
}
310+
311+
@Override
312+
public IntSet getRelevantParameters(CGNode caller, CallSiteReference site) {
313+
return base.getRelevantParameters(caller, site);
314+
}
315+
});
316+
317+
265318
System.out.println("building call graph...");
266319
CallGraph cg = builder.makeCallGraph(options, null);
267320
System.out.println("done! " + cg.getNumberOfNodes());
@@ -283,7 +336,7 @@ private static void processMethod(Set<String> allMethods, CGNode n, IClassHierar
283336
allMethods.addAll(MethodUtil.getSuperMethods(m,cha));
284337

285338
// Process for call sites
286-
n.iterateCallSites().forEachRemaining(call -> {
339+
/*n.iterateCallSites().forEachRemaining(call -> {
287340
if (call.getDeclaredTarget().equals(MethodReference.JavaLangClassNewInstance)) {
288341
Set<CGNode> targets = cg.getPossibleTargets(n, call);
289342
if (targets.isEmpty()) {
@@ -305,10 +358,29 @@ private static void processMethod(Set<String> allMethods, CGNode n, IClassHierar
305358
}
306359
307360
});
361+
*/
362+
308363

309364
}
310365

311-
366+
private static final String EXCLUSIONS = "java\\/awt\\/.*\n" +
367+
"javax\\/swing\\/.*\n" +
368+
"sun\\/awt\\/.*\n" +
369+
"sun\\/swing\\/.*\n" +
370+
"com\\/sun\\/.*\n" +
371+
"sun\\/.*\n" +
372+
"org\\/netbeans\\/.*\n" +
373+
"org\\/openide\\/.*\n" +
374+
"com\\/ibm\\/crypto\\/.*\n" +
375+
"com\\/ibm\\/security\\/.*\n" +
376+
"org\\/apache\\/xerces\\/.*\n" +
377+
"java\\/security\\/.*\n" +
378+
"jdk\\/.*\n" +
379+
"";
380+
381+
public static void addDefaultExclusions(AnalysisScope scope) throws UnsupportedEncodingException, IOException {
382+
scope.setExclusions(new FileOfClasses(new ByteArrayInputStream(EXCLUSIONS.getBytes("UTF-8"))));
383+
}
312384

313385

314386
}

0 commit comments

Comments
 (0)