Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对结果中的导出和非导出组件进行过滤 #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/kotlin/net/bytedance/security/app/RuleData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ data class RuleData(

val targetSdk: String = "", // 规则适用的targetSdk版本
val runtimeSdk: String = "", // 规则适用的运行时系统版本

val exportedCompos: Boolean? = null, // 是否过滤导出组件
)

val defaultSourceReturn = SourceReturn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import net.bytedance.security.app.Log
import net.bytedance.security.app.PLUtils
import net.bytedance.security.app.PreAnalyzeContext
import net.bytedance.security.app.android.AndroidUtils
import net.bytedance.security.app.android.ComponentDescription
import net.bytedance.security.app.getConfig
import net.bytedance.security.app.result.model.*
import net.bytedance.security.app.rules.AbstractRule
import net.bytedance.security.app.util.Json
import net.bytedance.security.app.util.TaskQueue
import net.bytedance.security.app.util.profiler
Expand Down Expand Up @@ -151,6 +153,23 @@ object OutputSecResults {
return map.values.toList()
}

/**
* filter results based on "exportedCompos" field
*/
private fun filterExportedCompos(securityVulnerabilityItems: List<SecurityVulnerabilityItem>):
List<SecurityVulnerabilityItem> {
return securityVulnerabilityItems.filter {
it.details?.get("Manifest")?.let { manifest ->
val exported = (manifest as ComponentDescription).exported
when ((it.rule as AbstractRule).exportedCompos) {
true -> exported
false -> !exported
null -> true
}
} ?: false
}
}

/**
* group the results by the category
*/
Expand Down Expand Up @@ -196,7 +215,7 @@ object OutputSecResults {
insertPerm()
insertMani()
addManifest(ctx)
groupResult(removeDup())
groupResult(filterExportedCompos(removeDup()))
val jsonName =
"results_" + AndroidUtils.PackageName + "_" + java.lang.Long.toHexString(System.nanoTime() + (Math.random() * 100).toLong())
val outputPath = getConfig().outPath + "/results.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ import net.bytedance.security.app.RuleData
import net.bytedance.security.app.RuleDescription

abstract class AbstractRule(override val name: String, ruleData: RuleData) : IRule {
final override val desc: RuleDescription

init {
desc = ruleData.desc
}
}
final override val desc: RuleDescription = ruleData.desc
val exportedCompos: Boolean? = ruleData.exportedCompos
}
Loading