forked from 0xrumble/BytecodeScreen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassUtil.java
More file actions
48 lines (45 loc) · 1.68 KB
/
ClassUtil.java
File metadata and controls
48 lines (45 loc) · 1.68 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
package tools;
import basic_class.ClassFile;
import java.io.File;
import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ClassUtil {
public static List<ClassFile> getAllClassesFromJars(List<String> jarPathList,
boolean runtime) throws FileNotFoundException {
Set<ClassFile> classFileSet = new HashSet<>();
if (runtime) {
getRuntime(classFileSet);
}
for (String jarPath : jarPathList) {
classFileSet.addAll(JarUtil.resolveNormalJarFile(jarPath));
}
return new ArrayList<>(classFileSet);
}
public static List<ClassFile> getAllClassesFormfolder(List<String> jarPathList,boolean runtime) throws FileNotFoundException {
Set<ClassFile> classFileSet = new HashSet<>();
if (runtime) {
getRuntime(classFileSet);
}
for (String jarPath : jarPathList) {
classFileSet.addAll(JarUtil.resolveNormalfolderFile(jarPath));
}
return new ArrayList<>(classFileSet);
}
private static void getRuntime(Set<ClassFile> classFileSet) {
String rtJarPath = System.getenv("JAVA_HOME") +
File.separator + "jre" +
File.separator + "lib" +
File.separator + "rt.jar";
Path rtPath = Paths.get(rtJarPath);
if (!Files.exists(rtPath)) {
throw new RuntimeException("rt.jar not exists");
}
classFileSet.addAll(JarUtil.resolveNormalJarFile(rtJarPath));
}
}