forked from ma1co/Sony-PMCA-RE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmca-console.py
78 lines (72 loc) · 4.21 KB
/
pmca-console.py
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
#!/usr/bin/env python3
"""A command line application to install apps on Android-enabled Sony cameras"""
import argparse
from pmca.commands.market import *
from pmca.commands.usb import *
from pmca import spk
if getattr(sys, 'frozen', False):
from frozenversion import version
else:
version = None
def main():
"""Command line main"""
parser = argparse.ArgumentParser()
if version:
parser.add_argument('--version', action='version', version=version)
subparsers = parser.add_subparsers(dest='command', title='commands')
info = subparsers.add_parser('info', description='Display information about the camera connected via USB')
info.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver')
install = subparsers.add_parser('install', description='Installs an apk file on the camera connected via USB. The connection can be tested without specifying a file.')
install.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver')
install.add_argument('-o', dest='outFile', type=argparse.FileType('w'), help='write the output to this file')
install.add_argument('-l', dest='local', action='store_true', help='local only (don\'t send statistics)')
installMode = install.add_mutually_exclusive_group()
installMode.add_argument('-f', dest='apkFile', type=argparse.FileType('rb'), help='install an apk file')
installMode.add_argument('-a', dest='appPackage', help='the package name of an app from the app list')
installMode.add_argument('-i', dest='appInteractive', action='store_true', help='select an app from the app list (interactive)')
market = subparsers.add_parser('market', description='Download apps from the official Sony app store')
market.add_argument('-t', dest='token', help='Specify an auth token')
apk2spk = subparsers.add_parser('apk2spk', description='Convert apk to spk')
apk2spk.add_argument('inFile', metavar='app.apk', type=argparse.FileType('rb'), help='the apk file to convert')
apk2spk.add_argument('outFile', metavar='app' + spk.constants.extension, type=argparse.FileType('wb'), help='the output spk file')
spk2apk = subparsers.add_parser('spk2apk', description='Convert spk to apk')
spk2apk.add_argument('inFile', metavar='app' + spk.constants.extension, type=argparse.FileType('rb'), help='the spk file to convert')
spk2apk.add_argument('outFile', metavar='app.apk', type=argparse.FileType('wb'), help='the output apk file')
firmware = subparsers.add_parser('firmware', description='Update the firmware')
firmware.add_argument('-f', dest='datFile', type=argparse.FileType('rb'), required=True, help='the firmware file')
firmware.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver')
updaterShell = subparsers.add_parser('updatershell', description='Launch firmware updater debug shell')
updaterShell.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver')
updaterShellMode = updaterShell.add_mutually_exclusive_group()
updaterShellMode.add_argument('-f', dest='fdatFile', type=argparse.FileType('rb'), help='firmware file')
updaterShellMode.add_argument('-m', dest='model', help='model name')
gps = subparsers.add_parser('gps', description='Update GPS assist data')
gps.add_argument('-d', dest='driver', choices=['libusb', 'native'], help='specify the driver')
gps.add_argument('-f', dest='file', type=argparse.FileType('rb'), help='assistme.dat file')
args = parser.parse_args()
if args.command == 'info':
infoCommand(args.driver)
elif args.command == 'install':
if args.appInteractive:
pkg = appSelectionCommand()
if not pkg:
return
else:
pkg = args.appPackage
installCommand(args.driver, args.apkFile, pkg, args.outFile, args.local)
elif args.command == 'market':
marketCommand(args.token)
elif args.command == 'apk2spk':
args.outFile.write(spk.dump(args.inFile.read()))
elif args.command == 'spk2apk':
args.outFile.write(spk.parse(args.inFile.read()))
elif args.command == 'firmware':
firmwareUpdateCommand(args.datFile, args.driver)
elif args.command == 'updatershell':
updaterShellCommand(args.model, args.fdatFile, args.driver)
elif args.command == 'gps':
gpsUpdateCommand(args.file, args.driver)
else:
parser.print_usage()
if __name__ == '__main__':
main()