Need I still provide rt.jar
even if I specify the version of JavaLanguage
above 8?
#725
Unanswered
skyleaworlder
asked this question in
Q&A
Replies: 3 comments 5 replies
-
I tried to search in issues and discussions. I think I cannot find any similar discussions. |
Beta Was this translation helpful? Give feedback.
2 replies
-
you can copy some code from |
Beta Was this translation helpful? Give feedback.
1 reply
-
val classLocation = JavaClassPathAnalysisInputLocation(jarFile.toPath().toAbsolutePath().toString())
val jrtLocation = JrtFileSystemAnalysisInputLocation()
val language = JavaLanguage(17)
val project = JavaProject.builder(language)
.addInputLocation(classLocation)
.addInputLocation(jrtLocation)
.build()
val idFact = project.getIdentifierFactory()
val view = project.createView()
val cha: CallGraphAlgorithm = ClassHierarchyAnalysisAlgorithm(view)
val mainClassType = idFact.getClassType(mainClassName)
val mainClass = view.getClass(mainClassType).takeIf { it.isPresent() }?.get() ?: run {
throw IOException("${mainClassType.toString()} not existed")
}
val allMethodsInMainClass = mainClass.methods.also { methods -> methods.forEach { println(it.toString()) } }
val jsm = mainClass.getMethod(idFact.getMethodSubSignature(
"main",
VoidType.getInstance(),
Collections.singletonList(ArrayType(idFact.getClassType("java.lang.String"), 1))
)).takeIf { it.isPresent() }?.get() ?: run { throw IOException("method not existed") } I add
If I remove the val classLocation = JavaClassPathAnalysisInputLocation(jarFile.toPath().toAbsolutePath().toString())
val jrtLocation = JrtFileSystemAnalysisInputLocation()
val language = JavaLanguage(17)
val project = JavaProject.builder(language)
.addInputLocation(classLocation)
// .addInputLocation(jrtLocation)
.build()
val idFact = project.getIdentifierFactory()
val view = project.createView()
val cha: CallGraphAlgorithm = ClassHierarchyAnalysisAlgorithm(view)
val mainClassType = idFact.getClassType(mainClassName)
val mainClass = view.getClass(mainClassType).takeIf { it.isPresent() }?.get() ?: run {
throw IOException("${mainClassType.toString()} not existed")
}
val allMethodsInMainClass = mainClass.methods.also { methods -> methods.forEach { println(it.toString()) } }
val jsm = mainClass.getMethod(idFact.getMethodSubSignature(
"main",
VoidType.getInstance(),
Collections.singletonList(ArrayType(idFact.getClassType("java.lang.String"), 1))
)).takeIf { it.isPresent() }?.get() ?: run { throw IOException("method not existed") }
val entryMethodSig = idFact.getMethodSignature(
mainClassType,
idFact.getMethodSubSignature(
"main",
VoidType.getInstance(),
Collections.singletonList(ArrayType(idFact.getClassType("java.lang.String"), 1))
)
)
val sm: SootMethod = view.getMethod(entryMethodSig).takeIf { it.isPresent() }?.get() ?: run {
throw IOException("${entryMethodSig.toString()} not existed")
}
val body = if (sm.hasBody()) sm.body else {
throw IOException("${entryMethodSig.toString()} no body")
}
val cg = cha.initialize(mutableListOf(entryMethodSig))
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As titled.
I use SootUp as follows:
Stacktrace:
I want to know if there are some special handling done for Java 9 or above?
Beta Was this translation helpful? Give feedback.
All reactions