Skip to content

Commit

Permalink
Fix project test
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf101 committed Jun 25, 2024
1 parent 9fa33f2 commit 8561d6a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.jacodb.panda.dynamic.ark.base
import org.jacodb.api.common.cfg.CommonAssignInst
import org.jacodb.api.common.cfg.CommonInst
import org.jacodb.api.common.cfg.CommonInstLocation
import org.jacodb.api.common.cfg.CommonReturnInst
import org.jacodb.panda.dynamic.ark.model.ArkMethod

data class ArkInstLocation(
Expand Down Expand Up @@ -115,11 +116,11 @@ interface ArkTerminatingStmt : ArkStmt

data class ArkReturnStmt(
override val location: ArkInstLocation,
val arg: ArkEntity?,
) : ArkTerminatingStmt {
override val returnValue: ArkValue?,
) : ArkTerminatingStmt, CommonReturnInst {
override fun toString(): String {
return if (arg != null) {
"return $arg"
return if (returnValue != null) {
"return $returnValue"
} else {
"return"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,28 @@ class ArkMethodBuilder(
arg = convertToArkFieldRef(stmt.arg),
)

is ReturnStmtDto -> ArkReturnStmt(
location = loc(),
arg = convertToArkEntity(stmt.arg),
)
is ReturnStmtDto -> {
val arkEntity = convertToArkEntity(stmt.arg)
val arkValue = if (arkEntity is ArkValue) {
arkEntity
} else {
val newLocal = ArkLocal("_tmp${freeLocal++}", ArkUnknownType)
currentStmts += ArkAssignStmt(
location = loc(),
lhv = newLocal,
rhv = arkEntity,
)
newLocal
}
ArkReturnStmt(
location = loc(),
returnValue = arkValue,
)
}

is ReturnVoidStmtDto -> ArkReturnStmt(
location = loc(),
arg = null,
returnValue = null,
)

is ThrowStmtDto -> ArkThrowStmt(
Expand Down Expand Up @@ -534,10 +548,12 @@ fun convertToArkClass(clazz: ClassDto): ArkClass {
}

fun convertToArkFile(file: ArkFileDto): ArkFile {
val classes = file.classes.map { convertToArkClass(it) }
val classesFromNamespaces = file.namespaces.flatMap { it.classes }
val allClasses = file.classes + classesFromNamespaces
val convertedClasses = allClasses.map { convertToArkClass(it) }
return ArkFile(
name = file.name,
path = file.absoluteFilePath,
classes = classes,
classes = convertedClasses,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ private object StmtGetOperands : ArkStmt.Visitor<Sequence<ArkEntity>> {
}

override fun visit(stmt: ArkReturnStmt): Sequence<ArkEntity> = sequence {
if (stmt.arg != null) {
yield(stmt.arg)
if (stmt.returnValue != null) {
yield(stmt.returnValue)
}
}

Expand Down
16 changes: 3 additions & 13 deletions jacodb-panda-dynamic/src/test/kotlin/ark/ArkProjectAnalysis.kt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class ArkProjectAnalysis {
logger.info { "Processing '$filename'" }
val project = loadProjectForSample(filename)
val startTime = System.currentTimeMillis()
runAnalysis(project, filename)
runAnalysis(project)
val endTime = System.currentTimeMillis()
analysisTime += (endTime - startTime).milliseconds
tsLinesSuccess += fileLines
Expand All @@ -135,25 +135,15 @@ class ArkProjectAnalysis {
}
}

private fun runAnalysis(project: ArkFile, filename: String) {
private fun runAnalysis(project: ArkFile) {
val graph = ArkApplicationGraph(project)
val unitResolver = UnitResolver<ArkMethod> { SingletonUnit }
val manager = TaintManager(
graph = graph,
unitResolver = unitResolver,
getConfigForMethod = { method -> getConfigForMethod(method, rules) },
)

var methods = project.classes.flatMap { it.methods }
if (filename == "base/account/AccountManager") {
val methodNames = setOf(
"getDeviceIdListWithCursor",
"requestGet",
"taintRun",
"taintSink"
)
methods = methods.filter { it.name in methodNames }
}
val methods = project.classes.flatMap { it.methods }
val sinks = manager.analyze(methods, timeout = 10.seconds)
totalPathEdges += manager.runnerForUnit.values.sumOf { it.getPathEdges().size }
totalSinks += sinks
Expand Down

0 comments on commit 8561d6a

Please sign in to comment.