Skip to content

Commit 5ea7470

Browse files
committed
Add test for obfuscated native Kotlin APK analysis
1 parent 88b6462 commit 5ea7470

5 files changed

Lines changed: 23 additions & 9 deletions

File tree

.idea/compiler.xml

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

data/src/main/kotlin/com/theapache64/stackzy/data/repo/ApkAnalyzerRepo.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class ApkAnalyzerRepo @Inject constructor() {
3232
private val APP_LABEL_MANIFEST_REGEX by lazy { "<application.+?label=\"(.+?)\"".toRegex() }
3333
private val USER_PERMISSION_REGEX by lazy { "<uses-permission (?:android:)?name=\"(?<permission>.+?)\"/>".toRegex() }
3434
private val PACKAGE_FROM_DIR_REGEX by lazy { ".+\\/smali.*?\\/(.+)".toRegex() }
35+
private val OBF_REGEX by lazy { "^[a-z][a-z0-9]?\\.[0-9]$".toRegex() }
3536
}
3637

3738
/**
@@ -353,7 +354,7 @@ class ApkAnalyzerRepo @Inject constructor() {
353354
val appLib = allLibraries.find { dirPackageName.contains(it.packageName) }
354355
if (appLib != null) {
355356
appLibs.add(appLib)
356-
} else if (dirPackageName.contains(".")) {
357+
} else if (dirPackageName.contains(".") && !dirPackageName.matches(OBF_REGEX)) {
357358
// to avoid obfuscated package names
358359
untrackedLibs.add(dirPackageName)
359360
}

src/test/kotlin/com/theapache64/stackzy/data/repo/ApkAnalyzerRepoTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,22 @@ class ApkAnalyzerRepoTest {
106106
}
107107
}
108108

109+
@Test
110+
fun `Analysis Report - Obf Native`() = runBlockingUnitTest {
111+
// First, lets decompile a native kotlin apk file
112+
librariesRepo.loadLibs { libs ->
113+
Arbor.d("Starting test... ;)")
114+
getCachedDecompiledApk(NATIVE_OBF_KOTLIN_APK_FILE_NAME) { nativeApkFile, decompiledDir ->
115+
val report = apkAnalyzerRepo.analyze(NATIVE_OBF_KOTLIN_PACKAGE_NAME, nativeApkFile, decompiledDir, libs)
116+
report.appName.should.equal(NATIVE_OBF_KOTLIN_APP_NAME)
117+
report.platform.should.instanceof(Platform.NativeKotlin::class.java)
118+
report.libraries.size.should.above(0)
119+
report.untrackedLibraries.should.not.contain("lm.1")
120+
report.untrackedLibraries.should.not.contain("z.1")
121+
}
122+
}
123+
}
124+
109125
@Test
110126
fun `Analysis Report - Flutter`() = runBlockingUnitTest {
111127
librariesRepo.loadLibs { libs ->

src/test/kotlin/com/theapache64/stackzy/test/Utils.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const val NATIVE_KOTLIN_APP_NAME = "TopCorn"
1313
const val NATIVE_KOTLIN_PACKAGE_NAME = "com.theapache64.topcorn"
1414
const val NATIVE_KOTLIN_APK_FILE_NAME = "com.theapache64.topcorn_kotlin_android.apk"
1515

16+
const val NATIVE_OBF_KOTLIN_APP_NAME = "JioHotstar"
17+
const val NATIVE_OBF_KOTLIN_PACKAGE_NAME = "in.startv.hotstar"
18+
const val NATIVE_OBF_KOTLIN_APK_FILE_NAME = "in.startv.hotstar.apk"
19+
1620
const val CORDOVA_APP_NAME = "FinC Financial Calculators"
1721
const val CORDOVA_PACKAGE_NAME = "com.swot.emicalculator"
1822
const val CORDOVA_APK_FILE_NAME = "com.swot.emicalculator_cordova.apk"
26 MB
Binary file not shown.

0 commit comments

Comments
 (0)