-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.gradle
210 lines (183 loc) · 7 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import groovy.io.FileType
import javax.crypto.Cipher
import javax.crypto.SecretKey
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
ext {
// Whether the theme assets should be encrypted or not,
// this makes it harder for pirates and kangers! (DEFAULT: true)
SHOULD_ENCRYPT_ASSETS = false
// Whether this theme supports third party theme systems, we will not be able to help you debug
// your themes on external theming systems, so the team will NOT respond to external systems if
// there are issues with your theme (DEFAULT: false)
SUPPORTS_THIRD_PARTY_SYSTEMS = false
// Encryption values, do not touch as we generate a random key every time you compile!
byte[] key = new byte[16]
new Random().nextBytes(key)
KEY = key
byte[] iv = new byte[16]
new Random().nextBytes(iv)
IV_KEY = iv
}
android {
compileSdkVersion 27
android.applicationVariants.all { final variant ->
variant.outputs.all {
outputFileName = "yoru.-v${variant.versionCode}.apk"
}
}
defaultConfig {
// If you're planning to change up the package name, ensure you have read the readme
// thoroughly!
applicationId "com.ohayoubaka.yoru"
// We are only supporting Nougat and above, all new changes will incorporate Nougat changes
// to the substratum repo rather than anything lower. Keep targetSdkVersion the same.
minSdkVersion 28
targetSdkVersion 28
// Both versions must be changed to increment on Play Store/user's devices
versionCode 27
versionName "27-alpha2"
// Themers: Do not touch this, they will only formulate integrity structure of the core
// template
buildConfigField "boolean", "SUPPORTS_THIRD_PARTY_THEME_SYSTEMS", "" +
SUPPORTS_THIRD_PARTY_SYSTEMS
resValue "bool", "SUPPORTS_THIRD_PARTY_THEME_SYSTEMS", "" + SUPPORTS_THIRD_PARTY_SYSTEMS
resValue "string", "encryption_status", (shouldEncrypt() ? "onCompileVerify" : "false")
ndk {
moduleName "LoadingProcess"
abiFilters "armeabi-v7a", "arm64-v8a", "x86"
}
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
// When you compile an APK as release, your resources and IV keys will be safeguarded
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.github.javiersantos:PiracyChecker:1.1'
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version") {
transitive = true
}
}
// Themers, do not touch this! This is our function to help us encrypt your assets!
task encryptAssets {
if (!shouldEncrypt()) {
println("Skipping assets encryption...")
return
}
def tempAssets = new File(getProjectDir(), "/src/main/assets-temp")
if (!tempAssets.exists()) {
println("Encrypting duplicated assets, don't worry, your original assets are safe...")
def list = []
def dir = new File(getProjectDir(), "/src/main/assets")
dir.eachFileRecurse(FileType.FILES) { file ->
list << file
FileInputStream fis = new FileInputStream(file)
File fo = new File(file.getAbsolutePath().replace("assets", "assets-temp"))
fo.getParentFile().mkdirs()
FileOutputStream fos = new FileOutputStream(fo)
byte[] buffer = new byte[4096]
int n
while ((n = fis.read(buffer)) != -1) {
fos.write(buffer, 0, n)
}
fis.close()
fos.close()
}
list.each {
if (it.getAbsolutePath().contains("overlays")) {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding")
SecretKey secret = new SecretKeySpec(KEY, "AES")
IvParameterSpec iv = new IvParameterSpec(IV_KEY)
cipher.init(Cipher.ENCRYPT_MODE, secret, iv)
FileInputStream fis = new FileInputStream(it)
FileOutputStream fos = new FileOutputStream(it.getAbsolutePath() + ".enc")
byte[] input = new byte[64]
int bytesRead
while ((bytesRead = fis.read(input)) != -1) {
byte[] output = cipher.update(input, 0, bytesRead)
if (output != null) {
fos.write(output)
}
}
byte[] output = cipher.doFinal()
if (output != null) {
fos.write(output)
}
fis.close()
fos.flush()
fos.close()
it.delete()
}
}
} else {
throw new RuntimeException("Old temporary assets found! Try and do a clean project.")
}
}
task writeKeys {
def KEY_READY = String.valueOf("\"" + KEY + "\"")
.replace("\"", "")
.replace("[", "{")
.replace("]", "}")
def IV_KEY_READY = String.valueOf("\"" + IV_KEY + "\"")
.replace("\"", "")
.replace("[", "{")
.replace("]", "}")
def headerFile = new File(getProjectDir(), "src/main/jni/LoadingProcess.h")
headerFile.createNewFile()
headerFile.text = """
#include <jni.h>
jbyte DECRYPTION_KEY[] = ${KEY_READY};
jbyte IV_KEY[] = ${IV_KEY_READY};
"""
}
project.afterEvaluate {
preBuild.dependsOn encryptAssets
}
gradle.buildFinished {
def tempAssets = new File(getProjectDir(), "/src/main/assets-temp")
if (tempAssets.exists()) {
println("Cleaning duplicated encrypted assets, not your decrypted assets...")
def encryptedAssets = new File(getProjectDir(), "src/main/assets")
encryptedAssets.deleteDir()
tempAssets.eachFileRecurse(FileType.FILES) { file ->
FileInputStream fis = new FileInputStream(file)
File fo = new File(file.getAbsolutePath().replace("assets-temp", "assets"))
fo.getParentFile().mkdirs()
FileOutputStream fos = new FileOutputStream(fo)
byte[] buffer = new byte[4096]
int n
while ((n = fis.read(buffer)) != -1) {
fos.write(buffer, 0, n)
}
fis.close()
fos.close()
}
tempAssets.deleteDir()
}
}
boolean shouldEncrypt() {
ArrayList<String> tasks = project.gradle.startParameter.taskNames
return SHOULD_ENCRYPT_ASSETS && Arrays.toString(tasks).toLowerCase().contains("release")
}
repositories {
mavenCentral()
}