Skip to content

Commit

Permalink
feat: rip-lib and unsigned
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Nov 20, 2022
1 parent 81d7029 commit 2dd57eb
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Release
on:
workflow_dispatch:
workflow_call:
push:
branches:
- main
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/sync_upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Sync upstream
on:
workflow_dispatch:
schedule:
- cron: "0 15 * * *"

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: sync
id: sync
shell: bash
run: |
git config --global user.name 'j-hc'
git config --global user.email 'j-hc@users.noreply.github.com'
if [[ $(git log | grep Author | head -1) == *"semantic"* ]]; then
git reset --hard HEAD~1
fi
git remote add upstream https://github.com/revanced/revanced-cli
C=$(git rev-list --left-right --count origin/main...remotes/upstream/main | awk '{print$2}')
echo "ahead $C commits"
if [ "$C" -gt 0 ]; then
echo "rebasing"
git tag -d $(git tag -l)
git fetch upstream --tags -f
git rebase -X ours upstream/main
git push --tags -f
git push -f https://${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git
echo ::set-output name=SYNC::1
else
echo "in sync"
echo ::set-output name=SYNC::0
fi
outputs:
SYNC: ${{ steps.sync.outputs.SYNC }}

build:
needs: check
uses: ./.github/workflows/release.yml
if: ${{ needs.check.outputs.SYNC == 1 }}
12 changes: 8 additions & 4 deletions src/main/kotlin/app/revanced/cli/command/MainCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ private class CLIVersionProvider : IVersionProvider {
}

@Command(
name = "ReVanced-CLI",
mixinStandardHelpOptions = true,
versionProvider = CLIVersionProvider::class
name = "ReVanced-CLI", mixinStandardHelpOptions = true, versionProvider = CLIVersionProvider::class
)
internal object MainCommand : Runnable {
val logger = DefaultCliLogger()
Expand Down Expand Up @@ -119,8 +117,14 @@ internal object MainCommand : Runnable {
)
var clean: Boolean = false

@Option(names = ["--rip-lib"], description = ["Rips the lib (arm64-v8a etc.) from the APK"])
var ripLibs = arrayOf<String>()

@Option(names = ["--custom-aapt2-binary"], description = ["Path to custom aapt2 binary"])
var aaptPath: String = ""

@Option(names = ["--unsigned"], description = ["Disable signing of the final apk"])
var unsigned: Boolean = false
}

override fun run() {
Expand Down Expand Up @@ -163,7 +167,7 @@ internal object MainCommand : Runnable {
Aligning.align(patchedFile, alignedFile)

// sign the file
val finalFile = if (!pArgs.mount) {
val finalFile = if (!pArgs.mount && !pArgs.unsigned) {
val signedOutput = cacheDirectory.resolve("${outputFile.nameWithoutExtension}_signed.apk")
Signing.sign(
alignedFile,
Expand Down
15 changes: 12 additions & 3 deletions src/main/kotlin/app/revanced/cli/patcher/Patcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import java.nio.file.Files

internal object Patcher {
internal fun start(
patcher: app.revanced.patcher.Patcher,
output: File,
allPatches: List<Class<out Patch<Context>>>
patcher: app.revanced.patcher.Patcher, output: File, allPatches: List<Class<out Patch<Context>>>
) {
val inputFile = args.inputFile

Expand Down Expand Up @@ -47,6 +45,17 @@ internal object Patcher {
}
}

args.patchArgs?.patchingArgs?.let { args ->
args.ripLibs.forEach {
logger.info("Ripping $it libs")
try {
outputFileSystem.deleteRecursively("lib/$it")
} catch (e: Exception) {
logger.warn("Failed to rip $it libs: $e")
}
}
}

result.doNotCompress?.let { outputFileSystem.uncompress(*it.toTypedArray()) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ internal class ZipFileSystemUtils(

private fun Path.getRelativePath(path: Path): Path = zipFileSystem.getPath(path.relativize(this).toString())

internal fun deleteRecursively(path: String) = zipFileSystem.getPath(path).deleteRecursively()

// TODO: figure out why the file system is uncompressed by default and how to fix it
internal fun uncompress(vararg paths: String) =
paths.forEach { Files.setAttribute(zipFileSystem.getPath(it), "zip:method", ZipEntry.STORED) }
Expand Down

0 comments on commit 2dd57eb

Please sign in to comment.