-
Notifications
You must be signed in to change notification settings - Fork 0
/
webos-ipk-dump.py
114 lines (104 loc) · 3.34 KB
/
webos-ipk-dump.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
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
#-------------------------------------------------------------------------------
# Name: webos-ipk-dump
# Purpose: save all your devices' apps (ipks)
#
# Author: PrplHaz4
#
# Created: 24/10/2014
# Copyright: (c) PrplHaz4 2014
# Licence: Not responsible if something blows up
#-------------------------------------------------------------------------------
import os
import sys
import json
import urllib.request
import shutil
import codecs
global token, deviceId, inputFile
def main():
print("--------------------------")
if not os.path.exists(inputFile):
print(inputFile + " must exist in this directory!")
sys.exit(0)
apps = readIpkJson(inputFile)
if not os.path.exists('.\ipk'):
os.mkdir('.\ipk')
for app in apps:
ipkUrl = apps[app]['appLocation']
downloadIpk(token, deviceId, ipkUrl)
pass
def getAppFilename(ipkUrl):
return os.path.split(ipkUrl)[1]
def getRequestHeaders(token, deviceId):
return {"Auth-Token":token, \
"Device-Id":deviceId \
}
def downloadIpk(token, deviceId, ipkUrl):
ipkUrl = ipkUrl.replace("cdn.downloads.palm.com", "cdn.downloads.hpsvcs.com")
appFilename = getAppFilename(ipkUrl)
headers = getRequestHeaders(token, deviceId)
print(appFilename, end='')
sys.stdout.flush()
if not os.path.exists(".\\ipk\\" + appFilename):
r = urllib.request.Request(ipkUrl, None, headers)
try:
with urllib.request.urlopen(r, None) as response, open(".\\ipk\\" + appFilename, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
print(" ....saved!")
except urllib.error.URLError:
print(" ....Error downloading file")
print(ipkUrl)
e = sys.exc_info()[0]
print(e)
else:
print(" ...already exists.")
def readIpkJson(inputFilename):
f = None
try:
print("Trying UTF-8-sig...")
sys.stdout.flush()
f = json.load(codecs.open(inputFilename, 'r', 'utf_8_sig'))
return f
except:
e = sys.exc_info()[0]
print(e)
try:
print("Trying UTF-8...")
sys.stdout.flush()
f = json.load(codecs.open(inputFilename, 'r', 'utf8'))
return f
except:
e = sys.exc_info()[0]
print(e)
try:
print("Trying UTF-16...")
sys.stdout.flush()
f = json.load(codecs.open(inputFilename, 'r', 'utf16'))
return f
except:
e = sys.exc_info()[0]
print(e)
print("\nCan't read input file! Try saving it with UTF-8 encoding.")
sys.exit()
if __name__ == '__main__':
if len(sys.argv) < 3:
print("\nEmail these to yourself using Impostah from your webOS device.")
token = input(" Your Palm Profile token >> ")
deviceId = input(" Your Device Profile ndUid >> ")
inputFile = input(" Installed Apps json [ipkdump.json] >> ")
if token == "":
print("Need to enter a token!")
sys.exit(0)
if deviceId == "":
print("Need to enter a device ID!")
sys.exit(0)
if(inputFile) == "":
inputFile = "ipkdump.json"
else:
token = sys.argv[1]
deviceId = sys.argv[2]
try:
inputFile = sys.argv[3]
except IndexError:
inputFile = "ipkdump.json"
main()