Skip to content

Commit db807fa

Browse files
committed
Added logging & traceability, refactoring & restructuring
1 parent 2fc6df8 commit db807fa

28 files changed

+695
-281
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -241,4 +241,6 @@ gradle-app.setting
241241
# End of https://www.gitignore.io/api/macos,gradle,intellij,androidstudio
242242
/.vscode/
243243

244-
site
244+
site
245+
246+
.kotlin

.idea/deploymentTargetSelector.xml

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

antipiracy/build.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ android {
7373
* */
7474
dependencies {
7575
// Kotlin dependencies
76-
compileOnly "androidx.annotation:annotation:1.7.1"
76+
compileOnly "androidx.annotation:annotation:1.8.0"
7777
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
78-
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
78+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1"
7979

8080
// Testing dependencies
8181
testImplementation "junit:junit:4.13.2"
8282
testImplementation "androidx.test:core:1.5.0"
83-
testImplementation "org.mockito:mockito-core:5.9.0"
84-
testImplementation "com.google.truth:truth:1.4.0"
85-
testImplementation "org.robolectric:robolectric:4.11.1"
83+
testImplementation "org.mockito:mockito-core:5.12.0"
84+
testImplementation "com.google.truth:truth:1.4.2"
85+
testImplementation "org.robolectric:robolectric:4.12.2"
8686
}
8787

8888

antipiracy/src/main/kotlin/com/kevlar/antipiracy/attestator/AntipiracyAttestator.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import android.content.Context
2323
import android.content.pm.ApplicationInfo
2424
import android.content.pm.PackageManager
2525
import com.kevlar.antipiracy.dsl.settings.AntipiracySettings
26-
import com.kevlar.antipiracy.dataset.DatasetEntry
26+
import com.kevlar.antipiracy.dataset.ScanEntry
2727
import com.kevlar.antipiracy.detection.vectors.InputVector
2828
import com.kevlar.antipiracy.detection.vectors.OutputVector
2929
import com.kevlar.antipiracy.detection.vectors.specter.OutputSpecter
@@ -72,12 +72,12 @@ internal object AntipiracyAttestator {
7272
outputSpecters: List<OutputSpecter>,
7373
index: Int
7474
): AntipiracyAttestation {
75-
val detectedDatasetEntries: Set<DatasetEntry> = outputSpecters
75+
val detectedDatasetEntries: Set<ScanEntry> = outputSpecters
7676
.asSequence()
7777
.filter { it.matchingVectors.any(OutputVector::isNotEmpty) }
7878
.map(OutputSpecter::matchingVectors)
7979
.flatten()
80-
.mapNotNull(OutputVector::matchingDataset)
80+
.mapNotNull(OutputVector::scanEntry)
8181
.toSet()
8282

8383
return when {

antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/DatasetEntry.kt

-60
This file was deleted.

antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/MatchableDatasetEntry.kt antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/ScanEntry.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15+
*
1516
*/
1617

1718
package com.kevlar.antipiracy.dataset
1819

19-
/**
20-
* Parent class for [MatchableAlphabetDatasetEntry] and [MatchableHeuristicDatasetEntry]
21-
* */
22-
internal abstract class MatchableDatasetEntry {
23-
abstract val datasetEntry: DatasetEntry
24-
}
20+
public data class ScanEntry (
21+
public val threat: Threat,
22+
public val packageName: String,
23+
public val detectionLog: String
24+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Designed and developed by Kevlar Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@file:Suppress("SpellCheckingInspection")
18+
19+
package com.kevlar.antipiracy.dataset
20+
21+
/**
22+
* Synthetizes a targetable software, along with its essential metadata.
23+
* */
24+
public enum class Threat(public val type: ThreatType, public val softwareName: String) {
25+
// Pirate apps
26+
ACTION_LAUNCHER_PATCHER(ThreatType.PIRATE_APP, "Action Launcher Patcher"),
27+
AGK(ThreatType.PIRATE_APP, "AGK App Killer"),
28+
APP_SARA(ThreatType.PIRATE_APP, "App Sara"),
29+
CGD(ThreatType.PIRATE_APP, "Content Guard Disabler"),
30+
CREEPLAYS_PATCHER(ThreatType.PIRATE_APP, "Creeplays Patcher"),
31+
CREE_HACK(ThreatType.PIRATE_APP, "Cree Hack"),
32+
FREEDOM(ThreatType.PIRATE_APP, "Freedom"),
33+
HIDE_ROOT(ThreatType.PIRATE_APP, "Hide Root"),
34+
GAME_HACKER(ThreatType.PIRATE_APP, "Game Hacker"),
35+
GAME_KILLER(ThreatType.PIRATE_APP, "Game Killer Cheats"),
36+
LEO_PLAYCARDS(ThreatType.PIRATE_APP, "Leo Playcards"),
37+
LUCKY_PATCHER(ThreatType.PIRATE_APP, "Lucky Patcher"),
38+
ROOT_CLOAK(ThreatType.PIRATE_APP, "Root Cloak"),
39+
URET_PATCHER(ThreatType.PIRATE_APP, "Uret Patcher"),
40+
XMG(ThreatType.PIRATE_APP, "XModGames"),
41+
42+
// Pirate stores
43+
AC_MARKET(ThreatType.PIRATE_STORE, "AC Market"),
44+
AIOD(ThreatType.PIRATE_STORE, "All In One Downloader"),
45+
APP_CAKE(ThreatType.PIRATE_STORE, "App Cake"),
46+
APTOIDE(ThreatType.PIRATE_STORE, "Aptoide"),
47+
BLACK_MART(ThreatType.PIRATE_STORE, "Black Mart"),
48+
GET_APK(ThreatType.PIRATE_STORE, "Get Apk"),
49+
GET_JAR(ThreatType.PIRATE_STORE, "Get Jar"),
50+
HAPPYMOD(ThreatType.PIRATE_STORE, "Happymod"),
51+
MOBILISM(ThreatType.PIRATE_STORE, "Mobilism"),
52+
MOB_GENIE(ThreatType.PIRATE_STORE, "Mobogenie"),
53+
ONE_MOBILE(ThreatType.PIRATE_STORE, "1Mobile"),
54+
SLIDE_ME(ThreatType.PIRATE_STORE, "Slide Me"),
55+
Z_MARKET(ThreatType.PIRATE_STORE, "Z Market"),
56+
57+
// Whitelisting / Blacklisting
58+
BLACKLIST(ThreatType.PIRATE_APP, "Manual Blacklist")
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Designed and developed by Kevlar Contributors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.kevlar.antipiracy.dataset
18+
19+
/**
20+
* Parent class for [com.kevlar.antipiracy.detection.vectors.heuristic.HeuristicThreatDetectionSuite] and [com.kevlar.antipiracy.detection.vectors.alphabet.AlphabetThreatDetectionSuite]
21+
* */
22+
internal abstract class ThreatDetectionSuite {
23+
abstract val threat: Threat
24+
}

antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/DatasetType.kt antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/ThreatType.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ package com.kevlar.antipiracy.dataset
1919
/**
2020
* Differentiates functionalities between different data set targets (pirate software).
2121
* */
22-
public enum class DatasetType {
22+
public enum class ThreatType {
2323
PIRATE_APP, PIRATE_STORE;
2424
}

antipiracy/src/main/kotlin/com/kevlar/antipiracy/detection/vectors/OutputVector.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
package com.kevlar.antipiracy.detection.vectors
1818

19-
import com.kevlar.antipiracy.dataset.DatasetEntry
19+
import com.kevlar.antipiracy.dataset.ScanEntry
2020

2121
/**
2222
* Output abstraction for vector operations
2323
* */
2424
internal data class OutputVector(
25-
val matchingDataset: DatasetEntry?
25+
val scanEntry: ScanEntry?
2626
) {
27-
fun isEmpty() = matchingDataset == null
28-
fun isNotEmpty() = matchingDataset != null
27+
fun isEmpty() = scanEntry == null
28+
fun isNotEmpty() = scanEntry != null
2929
}

antipiracy/src/main/kotlin/com/kevlar/antipiracy/detection/vectors/alphabet/AlphabetDataset.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616

1717
package com.kevlar.antipiracy.detection.vectors.alphabet
1818

19-
import com.kevlar.antipiracy.dataset.DatasetEntry
19+
import com.kevlar.antipiracy.dataset.Threat
2020
import com.kevlar.antipiracy.detection.vectors.alphabet.units.AlphabetUnit
2121

2222
/**
2323
* Contains all abstract alphabet entries in kevlar's dataset.
2424
* */
2525
internal object AlphabetDataset {
2626
val nonIdentifiable = arrayOf(
27-
MatchableAlphabetDatasetEntry(
28-
DatasetEntry.LUCKY_PATCHER,
27+
AlphabetThreatDetectionSuite(
28+
Threat.LUCKY_PATCHER,
2929
listOf(
3030
AlphabetUnit.L, AlphabetUnit.U, AlphabetUnit.C, AlphabetUnit.K, AlphabetUnit.Y,
3131
AlphabetUnit.SEPARATOR,

antipiracy/src/main/kotlin/com/kevlar/antipiracy/detection/vectors/alphabet/MatchableAlphabetDatasetEntry.kt antipiracy/src/main/kotlin/com/kevlar/antipiracy/detection/vectors/alphabet/AlphabetThreatDetectionSuite.kt

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
package com.kevlar.antipiracy.detection.vectors.alphabet
1818

19-
import com.kevlar.antipiracy.dataset.DatasetEntry
20-
import com.kevlar.antipiracy.dataset.MatchableDatasetEntry
19+
import com.kevlar.antipiracy.dataset.Threat
20+
import com.kevlar.antipiracy.dataset.ThreatDetectionSuite
2121
import com.kevlar.antipiracy.detection.vectors.alphabet.units.AlphabetUnit
2222

2323
/**
2424
* Single abstract alphabet string.
2525
*
2626
* It is composed of a list of [AlphabetUnit]s, which
27-
* model single alphabet letters, and a [DatasetEntry]
27+
* model single alphabet letters, and a [Threat]
2828
* associated with the given label.
2929
* */
30-
internal data class MatchableAlphabetDatasetEntry (
31-
override val datasetEntry: DatasetEntry,
32-
val labelAlphabetUnits: List<AlphabetUnit>
33-
) : MatchableDatasetEntry()
30+
internal data class AlphabetThreatDetectionSuite (
31+
override val threat: Threat,
32+
val associatedAlphabetizedLabel: List<AlphabetUnit>
33+
) : ThreatDetectionSuite()
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.kevlar.antipiracy.detection.vectors.alphabet
22

33
import android.content.pm.ApplicationInfo
4+
import com.kevlar.antipiracy.dataset.ScanEntry
45
import com.kevlar.antipiracy.detection.vectors.AntipiracyVector
56
import com.kevlar.antipiracy.detection.vectors.InputVector
67
import com.kevlar.antipiracy.detection.vectors.OutputVector
@@ -10,20 +11,26 @@ import com.kevlar.antipiracy.detection.vectors.alphabet.units.isContainedIn
1011

1112
internal class AlphabetVector(inputVector: InputVector) : AntipiracyVector(inputVector) {
1213
override suspend fun probe(applicationInfo: ApplicationInfo): OutputVector {
13-
val label: CharSequence? = applicationInfo.nonLocalizedLabel
14+
val appLabel: CharSequence? = applicationInfo.nonLocalizedLabel
1415

1516
AlphabetDataset.nonIdentifiable.forEach {
1617
// Android labels can be null
17-
if (label != null) {
18-
val reduced: List<AlphabetUnit> = AlphabetUnitProducer.convertString(label)
19-
val targetLabel: List<AlphabetUnit> = it.labelAlphabetUnits
18+
if (appLabel != null) {
19+
val reduced: List<AlphabetUnit> = AlphabetUnitProducer.convertString(appLabel)
20+
val targetLabel: List<AlphabetUnit> = it.associatedAlphabetizedLabel
2021

2122
if (reduced.isContainedIn(targetLabel)) {
22-
return OutputVector(matchingDataset = it.datasetEntry)
23+
return OutputVector(
24+
scanEntry = ScanEntry(
25+
threat = it.threat,
26+
packageName = applicationInfo.packageName,
27+
detectionLog = "Detected [appLabel=$appLabel] masked as [target=$reduced], app package is [packageName=${applicationInfo.packageName}]"
28+
)
29+
)
2330
}
2431
}
2532
}
2633

27-
return OutputVector(matchingDataset = null)
34+
return OutputVector(scanEntry = null)
2835
}
2936
}

antipiracy/src/main/kotlin/com/kevlar/antipiracy/detection/vectors/alphabet/units/AlphabetUnit.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.kevlar.antipiracy.detection.vectors.alphabet.units
1818

1919
/**
20-
* Models an abstract alphabet element (unit).
20+
* Models a discrete, abstract alphabet element (unit).
2121
* */
2222
internal enum class AlphabetUnit(val asciiLower: Char, val asciiUpper: Char) {
2323
A('a', 'A'),

0 commit comments

Comments
 (0)