Skip to content

Commit 3e2f6b5

Browse files
author
wuerror
committed
Optimize: Strategy A - Pre-load Exclusions & Cleanup
1 parent 156c242 commit 3e2f6b5

3 files changed

Lines changed: 51 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ All notable changes to this project will be documented in this file.
3636
- This architecture prevents crashes and significantly improves stability when analyzing complex third-party libraries (e.g., `com.itextpdf`, `org.bouncycastle`).
3737
- Spring Boot `BOOT-INF/classes` is automatically treated as Target.
3838

39+
### Optimized
40+
- **Call Graph Generation (Strategy A)**:
41+
- Optimized `SootManager` to apply strict exclusions *before* loading classes.
42+
- Extended the default exclusion list to filter out massive frameworks (Spring internals, AWS/Azure SDKs, Netty, etc.) from analysis scope.
43+
- Significantly reduced `wjtp` phase execution time and memory usage.
44+
3945
### Fixed
4046
- **NPE in RuleManager**: Fixed `NullPointerException` when processing CallGraph edges where `target()` method is null during Backward Reachability Analysis.
4147
- **DiscoveryEngine Compilation**: Fixed variable reference error (`appJars` -> `targetAppJars`).

src/main/java/com/jbytescanner/core/SootManager.java

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@
1616
public class SootManager {
1717
private static final Logger logger = LoggerFactory.getLogger(SootManager.class);
1818

19+
private static final List<String> DEFAULT_EXCLUDES = java.util.Arrays.asList(
20+
// JDK & Android
21+
"java.", "javax.", "sun.", "jdk.", "android.", "dalvik.", "com.sun.", "org.xml.", "org.w3c.",
22+
23+
// Logging
24+
"org.slf4j.", "org.apache.commons.logging.", "org.log4j.", "org.apache.logging.", "ch.qos.logback.",
25+
26+
// Common Utils & JSON
27+
"com.google.", "org.apache.commons.", "com.fasterxml.jackson.", "com.alibaba.fastjson.", "com.google.gson.",
28+
"org.json.", "net.minidev.json.", "org.yaml.",
29+
30+
// Spring & Frameworks (We only want to analyze the application code, not the framework internals unless needed)
31+
"org.springframework.", "org.hibernate.", "org.mybatis.", "org.thymeleaf.", "freemarker.",
32+
"org.jboss.", "org.apache.tomcat.", "org.apache.catalina.", "org.eclipse.jetty.", "io.undertow.",
33+
34+
// Network & Async
35+
"io.netty.", "io.grpc.", "io.reactivex.", "rx.", "okhttp3.", "org.apache.http.",
36+
37+
// Cloud SDKs (Huge bloat)
38+
"com.amazonaws.", "software.amazon.awssdk.", "com.azure.", "com.microsoft.", "com.oracle.bmc.",
39+
40+
// Database Drivers
41+
"org.postgresql.", "com.mysql.", "oracle.jdbc.", "com.microsoft.sqlserver.", "org.h2.", "org.hsqldb.",
42+
"org.mongodb.", "redis.clients.", "com.zaxxer.hikari.",
43+
44+
// Crypto & Security
45+
"org.bouncycastle.", "com.nimbusds.", "io.jsonwebtoken.",
46+
47+
// Languages
48+
"scala.", "kotlin.", "groovy.", "clojure.",
49+
50+
// Testing
51+
"junit.", "org.junit.", "org.testng.", "org.mockito.", "net.bytebuddy.", "org.objenesis.",
52+
53+
// Others
54+
"com.aspose.", "com.itextpdf.", "org.dom4j.", "org.jsoup."
55+
);
56+
1957
public static void initSoot(List<String> appJars, List<String> libJars, boolean wholeProgram, List<String> scanPackages) {
2058
G.reset();
2159

@@ -36,7 +74,7 @@ public static void initSoot(List<String> appJars, List<String> libJars, boolean
3674

3775
Options.v().set_soot_classpath(cpBuilder.toString());
3876

39-
// ONLY App jars go to process-dir
77+
// ONLY App jars go to process_dir
4078
Options.v().set_process_dir(appJars);
4179

4280
// 3. Phase Options
@@ -46,42 +84,17 @@ public static void initSoot(List<String> appJars, List<String> libJars, boolean
4684
// Strict Isolation: Only generate bodies for included packages
4785
Options.v().set_no_bodies_for_excluded(true);
4886

49-
// 3.1 Whitelist (Include)
87+
// 3.1 Whitelist (Include) - CRITICAL for Speed
5088
if (scanPackages != null && !scanPackages.isEmpty()) {
5189
logger.info("Applying strict inclusion scope: {}", scanPackages);
5290
Options.v().set_include(scanPackages);
5391
}
5492

55-
// 3.2 Blacklist (Exclude)
56-
List<String> excludes = new ArrayList<>();
57-
// Standard excludes
58-
excludes.add("java.");
59-
excludes.add("javax.");
60-
excludes.add("sun.");
61-
excludes.add("jdk.");
62-
excludes.add("android.");
63-
// Common libs that cause trouble (bloated or complex)
64-
excludes.add("org.slf4j.");
65-
excludes.add("org.apache.");
66-
excludes.add("com.google.");
67-
excludes.add("net.minidev.");
68-
excludes.add("com.fasterxml.jackson.");
69-
excludes.add("org.springframework."); // We only analyze business logic, usually don't need deep spring bodies
70-
excludes.add("org.hibernate.");
71-
excludes.add("io.netty.");
72-
73-
// Phase 6.3 Enhanced Exclusion List (Based on log analysis)
74-
excludes.add("org.bouncycastle."); // Fix crash
75-
excludes.add("com.sheca."); // Fix crash
76-
excludes.add("com.aspose.");
77-
excludes.add("com.itextpdf.");
78-
excludes.add("oracle.");
79-
excludes.add("dm.jdbc.");
80-
excludes.add("jj2000.");
81-
excludes.add("com.github.jaiimageio.");
82-
excludes.add("com.claymoresystems.");
83-
84-
Options.v().set_exclude(excludes);
93+
// 3.2 Blacklist (Exclude) - Optimized List
94+
// Using set_exclude allows us to explicitly block these even if they are in process_dir (partially)
95+
// or if they are pulled in by dependencies.
96+
logger.info("Applying comprehensive exclude list ({} prefixes)...", DEFAULT_EXCLUDES.size());
97+
Options.v().set_exclude(DEFAULT_EXCLUDES);
8598
}
8699

87100
// 4. Load

src/main/java/com/jbytescanner/graph/CallGraphBuilder.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,10 @@ public CallGraph build() {
2424
Options.v().setPhaseOption("cg.cha", "enabled:true");
2525

2626
// Exclusions are now handled globally in SootManager.initSoot
27-
// configureExclusions();
2827

2928
logger.info("Running Soot Packs (wjtp)... This may take a while.");
3029
PackManager.v().runPacks();
3130

3231
return Scene.v().getCallGraph();
3332
}
34-
35-
private void configureExclusions() {
36-
// Exclude standard libraries and common frameworks
37-
List<String> excludeList = new ArrayList<>();
38-
excludeList.add("java.");
39-
excludeList.add("javax.");
40-
excludeList.add("sun.");
41-
excludeList.add("jdk.");
42-
excludeList.add("org.slf4j.");
43-
excludeList.add("org.apache.commons.logging.");
44-
45-
// Convert to Options format if necessary or use Scene.v().addBasicClass for phantom
46-
// Soot has -exclude option.
47-
// Since we already loaded Scene in SootManager, we rely on Options set there OR set them here if not too late.
48-
// Actually, exclude options should be set BEFORE loadNecessaryClasses.
49-
// We will need to move exclusion logic to SootManager in the next refactor.
50-
// For now, PackManager run will use whatever was loaded.
51-
}
5233
}

0 commit comments

Comments
 (0)