add playstore apk puller

master
Florian Schrofner 2023-08-01 12:22:20 +02:00
parent 6c066b442c
commit 227333cb14
2 changed files with 67 additions and 0 deletions

47
playstore-apk-puller/pap.clj Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env bb
(require
'[clojure.tools.cli :refer [parse-opts]]
'[clojure.string :as string])
(def cli-options
[["-b" "--bundle BUNDLE" "The bundle id"]])
;;executes shell command but throws exception on error
(defn- safe-sh [& commands]
(as-> (apply shell/sh commands) $
(if (= (:exit $) 0) $ (throw (Exception. (:err $))))))
;;gets the working directory, but removes the new line in the end
(def wd (as-> (:out (safe-sh "pwd")) $
(subs $ 0 (- (count $) 1))))
(def options (:options (parse-opts *command-line-args* cli-options)))
(if-let [bundle (:bundle options)]
(do
(def packages (->>
(safe-sh "adb" "shell" "pm" "path" bundle)
:out
(string/split-lines)
(map #(last (re-find #"package:(.*)$" %)))))
(println (str "found " (count packages) " packages, pulling.."))
(doseq [package packages]
(safe-sh "adb" "pull" package wd))
(println "successfully pulled packages.")
(println "install them to the currently connected device? (y/n): ")
(def file-names (map #(str wd fs/file-separator (.getName (io/file %))) packages))
(let [answer (read-line)]
(when (= answer "y")
(if (< 1 (count file-names))
(apply safe-sh "adb" "install-multiple" file-names)
(safe-sh "adb" "install" (first file-names))))))
(println "error: you need to provide a bundle id with -b [BUNDLE]"))

View File

@ -0,0 +1,20 @@
# Playstore APK Puller
A script that extracts the installed APKs for the provided bundle id from the currently connected device via adb.
APKs are downloaded to the current working dir when executing the script.
Optionally you can also directly install the downloaded APKs to another device (by disconnecting the device you've pulled the APKs from and launching an emulator, for example).
## Example Usage
```bash
pap.clj -b com.example.app
```
### Fish
You can create a fish function to easily use the script from any directory.
```
function pap
PATH_TO_SCRIPT/pap.clj $argv
end
funcsave pap
```