Skip to content

Commit

Permalink
Added logging & traceability, refactoring & restructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
cioccarellia committed Jun 23, 2024
1 parent 2fc6df8 commit db807fa
Show file tree
Hide file tree
Showing 28 changed files with 695 additions and 281 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,6 @@ gradle-app.setting
# End of https://www.gitignore.io/api/macos,gradle,intellij,androidstudio
/.vscode/

site
site

.kotlin
29 changes: 29 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions antipiracy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ android {
* */
dependencies {
// Kotlin dependencies
compileOnly "androidx.annotation:annotation:1.7.1"
compileOnly "androidx.annotation:annotation:1.8.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.1"

// Testing dependencies
testImplementation "junit:junit:4.13.2"
testImplementation "androidx.test:core:1.5.0"
testImplementation "org.mockito:mockito-core:5.9.0"
testImplementation "com.google.truth:truth:1.4.0"
testImplementation "org.robolectric:robolectric:4.11.1"
testImplementation "org.mockito:mockito-core:5.12.0"
testImplementation "com.google.truth:truth:1.4.2"
testImplementation "org.robolectric:robolectric:4.12.2"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import com.kevlar.antipiracy.dsl.settings.AntipiracySettings
import com.kevlar.antipiracy.dataset.DatasetEntry
import com.kevlar.antipiracy.dataset.ScanEntry
import com.kevlar.antipiracy.detection.vectors.InputVector
import com.kevlar.antipiracy.detection.vectors.OutputVector
import com.kevlar.antipiracy.detection.vectors.specter.OutputSpecter
Expand Down Expand Up @@ -72,12 +72,12 @@ internal object AntipiracyAttestator {
outputSpecters: List<OutputSpecter>,
index: Int
): AntipiracyAttestation {
val detectedDatasetEntries: Set<DatasetEntry> = outputSpecters
val detectedDatasetEntries: Set<ScanEntry> = outputSpecters
.asSequence()
.filter { it.matchingVectors.any(OutputVector::isNotEmpty) }
.map(OutputSpecter::matchingVectors)
.flatten()
.mapNotNull(OutputVector::matchingDataset)
.mapNotNull(OutputVector::scanEntry)
.toSet()

return when {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package com.kevlar.antipiracy.dataset

/**
* Parent class for [MatchableAlphabetDatasetEntry] and [MatchableHeuristicDatasetEntry]
* */
internal abstract class MatchableDatasetEntry {
abstract val datasetEntry: DatasetEntry
}
public data class ScanEntry (
public val threat: Threat,
public val packageName: String,
public val detectionLog: String
)
59 changes: 59 additions & 0 deletions antipiracy/src/main/kotlin/com/kevlar/antipiracy/dataset/Threat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Designed and developed by Kevlar Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

@file:Suppress("SpellCheckingInspection")

package com.kevlar.antipiracy.dataset

/**
* Synthetizes a targetable software, along with its essential metadata.
* */
public enum class Threat(public val type: ThreatType, public val softwareName: String) {
// Pirate apps
ACTION_LAUNCHER_PATCHER(ThreatType.PIRATE_APP, "Action Launcher Patcher"),
AGK(ThreatType.PIRATE_APP, "AGK App Killer"),
APP_SARA(ThreatType.PIRATE_APP, "App Sara"),
CGD(ThreatType.PIRATE_APP, "Content Guard Disabler"),
CREEPLAYS_PATCHER(ThreatType.PIRATE_APP, "Creeplays Patcher"),
CREE_HACK(ThreatType.PIRATE_APP, "Cree Hack"),
FREEDOM(ThreatType.PIRATE_APP, "Freedom"),
HIDE_ROOT(ThreatType.PIRATE_APP, "Hide Root"),
GAME_HACKER(ThreatType.PIRATE_APP, "Game Hacker"),
GAME_KILLER(ThreatType.PIRATE_APP, "Game Killer Cheats"),
LEO_PLAYCARDS(ThreatType.PIRATE_APP, "Leo Playcards"),
LUCKY_PATCHER(ThreatType.PIRATE_APP, "Lucky Patcher"),
ROOT_CLOAK(ThreatType.PIRATE_APP, "Root Cloak"),
URET_PATCHER(ThreatType.PIRATE_APP, "Uret Patcher"),
XMG(ThreatType.PIRATE_APP, "XModGames"),

// Pirate stores
AC_MARKET(ThreatType.PIRATE_STORE, "AC Market"),
AIOD(ThreatType.PIRATE_STORE, "All In One Downloader"),
APP_CAKE(ThreatType.PIRATE_STORE, "App Cake"),
APTOIDE(ThreatType.PIRATE_STORE, "Aptoide"),
BLACK_MART(ThreatType.PIRATE_STORE, "Black Mart"),
GET_APK(ThreatType.PIRATE_STORE, "Get Apk"),
GET_JAR(ThreatType.PIRATE_STORE, "Get Jar"),
HAPPYMOD(ThreatType.PIRATE_STORE, "Happymod"),
MOBILISM(ThreatType.PIRATE_STORE, "Mobilism"),
MOB_GENIE(ThreatType.PIRATE_STORE, "Mobogenie"),
ONE_MOBILE(ThreatType.PIRATE_STORE, "1Mobile"),
SLIDE_ME(ThreatType.PIRATE_STORE, "Slide Me"),
Z_MARKET(ThreatType.PIRATE_STORE, "Z Market"),

// Whitelisting / Blacklisting
BLACKLIST(ThreatType.PIRATE_APP, "Manual Blacklist")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Designed and developed by Kevlar Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.kevlar.antipiracy.dataset

/**
* Parent class for [com.kevlar.antipiracy.detection.vectors.heuristic.HeuristicThreatDetectionSuite] and [com.kevlar.antipiracy.detection.vectors.alphabet.AlphabetThreatDetectionSuite]
* */
internal abstract class ThreatDetectionSuite {
abstract val threat: Threat
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ package com.kevlar.antipiracy.dataset
/**
* Differentiates functionalities between different data set targets (pirate software).
* */
public enum class DatasetType {
public enum class ThreatType {
PIRATE_APP, PIRATE_STORE;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.kevlar.antipiracy.detection.vectors

import com.kevlar.antipiracy.dataset.DatasetEntry
import com.kevlar.antipiracy.dataset.ScanEntry

/**
* Output abstraction for vector operations
* */
internal data class OutputVector(
val matchingDataset: DatasetEntry?
val scanEntry: ScanEntry?
) {
fun isEmpty() = matchingDataset == null
fun isNotEmpty() = matchingDataset != null
fun isEmpty() = scanEntry == null
fun isNotEmpty() = scanEntry != null
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

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

import com.kevlar.antipiracy.dataset.DatasetEntry
import com.kevlar.antipiracy.dataset.Threat
import com.kevlar.antipiracy.detection.vectors.alphabet.units.AlphabetUnit

/**
* Contains all abstract alphabet entries in kevlar's dataset.
* */
internal object AlphabetDataset {
val nonIdentifiable = arrayOf(
MatchableAlphabetDatasetEntry(
DatasetEntry.LUCKY_PATCHER,
AlphabetThreatDetectionSuite(
Threat.LUCKY_PATCHER,
listOf(
AlphabetUnit.L, AlphabetUnit.U, AlphabetUnit.C, AlphabetUnit.K, AlphabetUnit.Y,
AlphabetUnit.SEPARATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

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

import com.kevlar.antipiracy.dataset.DatasetEntry
import com.kevlar.antipiracy.dataset.MatchableDatasetEntry
import com.kevlar.antipiracy.dataset.Threat
import com.kevlar.antipiracy.dataset.ThreatDetectionSuite
import com.kevlar.antipiracy.detection.vectors.alphabet.units.AlphabetUnit

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

import android.content.pm.ApplicationInfo
import com.kevlar.antipiracy.dataset.ScanEntry
import com.kevlar.antipiracy.detection.vectors.AntipiracyVector
import com.kevlar.antipiracy.detection.vectors.InputVector
import com.kevlar.antipiracy.detection.vectors.OutputVector
Expand All @@ -10,20 +11,26 @@ import com.kevlar.antipiracy.detection.vectors.alphabet.units.isContainedIn

internal class AlphabetVector(inputVector: InputVector) : AntipiracyVector(inputVector) {
override suspend fun probe(applicationInfo: ApplicationInfo): OutputVector {
val label: CharSequence? = applicationInfo.nonLocalizedLabel
val appLabel: CharSequence? = applicationInfo.nonLocalizedLabel

AlphabetDataset.nonIdentifiable.forEach {
// Android labels can be null
if (label != null) {
val reduced: List<AlphabetUnit> = AlphabetUnitProducer.convertString(label)
val targetLabel: List<AlphabetUnit> = it.labelAlphabetUnits
if (appLabel != null) {
val reduced: List<AlphabetUnit> = AlphabetUnitProducer.convertString(appLabel)
val targetLabel: List<AlphabetUnit> = it.associatedAlphabetizedLabel

if (reduced.isContainedIn(targetLabel)) {
return OutputVector(matchingDataset = it.datasetEntry)
return OutputVector(
scanEntry = ScanEntry(
threat = it.threat,
packageName = applicationInfo.packageName,
detectionLog = "Detected [appLabel=$appLabel] masked as [target=$reduced], app package is [packageName=${applicationInfo.packageName}]"
)
)
}
}
}

return OutputVector(matchingDataset = null)
return OutputVector(scanEntry = null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.kevlar.antipiracy.detection.vectors.alphabet.units

/**
* Models an abstract alphabet element (unit).
* Models a discrete, abstract alphabet element (unit).
* */
internal enum class AlphabetUnit(val asciiLower: Char, val asciiUpper: Char) {
A('a', 'A'),
Expand Down
Loading

0 comments on commit db807fa

Please sign in to comment.