Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
a250e2b5
Commit
a250e2b5
authored
Jun 17, 2022
by
vvb2060
Committed by
John Wu
Jun 17, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set version comment in apk
parent
cd964548
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
3 deletions
+52
-3
Codegen.kt
buildSrc/src/main/java/Codegen.kt
+0
-2
Setup.kt
buildSrc/src/main/java/Setup.kt
+52
-1
testkey.pk8
tools/keys/testkey.pk8
+0
-0
testkey.x509.pem
tools/keys/testkey.x509.pem
+0
-0
No files found.
buildSrc/src/main/java/Codegen.kt
View file @
a250e2b5
...
...
@@ -64,8 +64,6 @@ fun genKeyData(keysDir: File, outSrc: File) {
it
.
println
(
"package com.topjohnwu.magisk.signing;"
)
it
.
println
(
"public final class KeyData {"
)
it
.
byteField
(
"testCert"
,
File
(
keysDir
,
"testkey.x509.pem"
).
readBytes
())
it
.
byteField
(
"testKey"
,
File
(
keysDir
,
"testkey.pk8"
).
readBytes
())
it
.
byteField
(
"verityCert"
,
File
(
keysDir
,
"verity.x509.pem"
).
readBytes
())
it
.
byteField
(
"verityKey"
,
File
(
keysDir
,
"verity.pk8"
).
readBytes
())
...
...
buildSrc/src/main/java/Setup.kt
View file @
a250e2b5
import
com.android.build.gradle.BaseExtension
import
com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import
com.android.builder.internal.packaging.IncrementalPackager
import
com.android.builder.model.SigningConfig
import
com.android.tools.build.apkzlib.sign.SigningExtension
import
com.android.tools.build.apkzlib.sign.SigningOptions
import
com.android.tools.build.apkzlib.zfile.ZFiles
import
com.android.tools.build.apkzlib.zip.ZFileOptions
import
org.apache.tools.ant.filters.FixCrLfFilter
import
org.gradle.api.Action
import
org.gradle.api.JavaVersion
...
...
@@ -16,6 +21,8 @@ import java.io.ByteArrayInputStream
import
java.io.ByteArrayOutputStream
import
java.io.File
import
java.io.PrintStream
import
java.security.KeyStore
import
java.security.cert.X509Certificate
import
java.util.*
import
java.util.zip.*
...
...
@@ -55,6 +62,37 @@ fun Project.setupCommon() {
}
}
private
fun
SigningConfig
.
getPrivateKey
():
KeyStore
.
PrivateKeyEntry
{
val
keyStore
=
KeyStore
.
getInstance
(
storeType
?:
KeyStore
.
getDefaultType
())
storeFile
!!
.
inputStream
().
use
{
keyStore
.
load
(
it
,
storePassword
!!
.
toCharArray
())
}
val
keyPwdArray
=
keyPassword
!!
.
toCharArray
()
val
entry
=
keyStore
.
getEntry
(
keyAlias
!!
,
KeyStore
.
PasswordProtection
(
keyPwdArray
))
return
entry
as
KeyStore
.
PrivateKeyEntry
}
private
fun
addComment
(
apkPath
:
File
,
signConfig
:
SigningConfig
,
minSdk
:
Int
,
eocdComment
:
String
)
{
val
privateKey
=
signConfig
.
getPrivateKey
()
val
signingOptions
=
SigningOptions
.
builder
()
.
setMinSdkVersion
(
minSdk
)
.
setV1SigningEnabled
(
true
)
.
setV2SigningEnabled
(
true
)
.
setKey
(
privateKey
.
privateKey
)
.
setCertificates
(
privateKey
.
certificate
as
X509Certificate
)
.
setValidation
(
SigningOptions
.
Validation
.
ASSUME_INVALID
)
.
build
()
val
options
=
ZFileOptions
().
apply
{
noTimestamps
=
true
autoSortFiles
=
true
}
ZFiles
.
apk
(
apkPath
,
options
).
use
{
SigningExtension
(
signingOptions
).
register
(
it
)
it
.
eocdComment
=
eocdComment
.
toByteArray
()
it
.
get
(
IncrementalPackager
.
APP_METADATA_ENTRY_PATH
)
?.
delete
()
}
}
private
fun
Project
.
setupAppCommon
()
{
setupCommon
()
...
...
@@ -91,6 +129,19 @@ private fun Project.setupAppCommon() {
includeInApk
=
false
}
}
android
.
applicationVariants
.
all
{
val
projectName
=
project
.
name
.
toLowerCase
(
Locale
.
ROOT
)
val
variantCapped
=
name
.
capitalize
(
Locale
.
ROOT
)
val
variant
=
name
.
toLowerCase
(
Locale
.
ROOT
)
tasks
.
getByPath
(
":$projectName:package$variantCapped"
).
doLast
{
val
apkDir
=
if
(
properties
[
"android.injected.invoked.from.ide"
]
==
"true"
)
"intermediates"
else
"outputs"
val
apk
=
File
(
buildDir
,
"${apkDir}/apk/${variant}/$projectName-${variant}.apk"
)
val
comment
=
"${Config.versionCode}"
addComment
(
apk
,
signingConfig
,
android
.
defaultConfig
.
minSdk
!!
,
comment
)
}
}
}
fun
Project
.
setupApp
()
{
...
...
tools/keys/testkey.pk8
deleted
100644 → 0
View file @
cd964548
This diff was suppressed by a .gitattributes entry.
tools/keys/testkey.x509.pem
deleted
100644 → 0
View file @
cd964548
This diff was suppressed by a .gitattributes entry.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment