forked from jeankalud/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vehicle Researcher
committed
Jan 17, 2018
1 parent
b773e27
commit 7ef3fd5
Showing
17 changed files
with
241 additions
and
33 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/* | ||
out/* |
Binary file not shown.
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env python2.7 | ||
|
||
import os | ||
import sys | ||
import glob | ||
import shutil | ||
import urllib2 | ||
import hashlib | ||
import subprocess | ||
|
||
|
||
EXTERNAL_PATH = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
if os.path.exists("/init.qcom.rc"): | ||
# android | ||
APKPATCH = os.path.join(EXTERNAL_PATH, 'tools/apkpatch_android') | ||
SIGNAPK = os.path.join(EXTERNAL_PATH, 'tools/signapk_android') | ||
else: | ||
APKPATCH = os.path.join(EXTERNAL_PATH, 'tools/apkpatch') | ||
SIGNAPK = os.path.join(EXTERNAL_PATH, 'tools/signapk') | ||
|
||
APKS = { | ||
'com.waze': { | ||
'src': 'https://apkcache.s3.amazonaws.com/com.waze_1021278.apk', | ||
'src_sha256': 'f00957e93e2389f9e30502ac54994b98ac769314b0963c263d4e8baa625ab0c2', | ||
'patch': 'com.waze.apkpatch', | ||
'out_sha256': '9ec8b0ea3c78c666342865b1bfb66e368a3f5c911df2ad12835206ec8b19f444' | ||
}, | ||
'com.spotify.music': { | ||
'src': 'https://apkcache.s3.amazonaws.com/com.spotify.music_24382006.apk', | ||
'src_sha256': '0610fea68ee7ba5f8e4e0732ad429d729dd6cbb8bc21222c4c99db6cb09fbff4', | ||
'patch': 'com.spotify.music.apkpatch', | ||
'out_sha256': '5a3d6f478c7e40403a98ccc8906d7e0ae12b06543b41f5df52149dd09c647c11' | ||
}, | ||
} | ||
|
||
def sha256_path(path): | ||
with open(path, 'rb') as f: | ||
return hashlib.sha256(f.read()).hexdigest() | ||
|
||
def remove(path): | ||
try: | ||
os.remove(path) | ||
except OSError: | ||
pass | ||
|
||
def process(download, patch): | ||
# clean up any junk apks | ||
for out_apk in glob.glob(os.path.join(EXTERNAL_PATH, 'out/*.apk')): | ||
app = os.path.basename(out_apk)[:-4] | ||
if app not in APKS: | ||
print "remove junk", out_apk | ||
remove(out_apk) | ||
|
||
complete = True | ||
for k,v in APKS.iteritems(): | ||
apk_path = os.path.join(EXTERNAL_PATH, 'out', k+'.apk') | ||
print "checking", apk_path | ||
if os.path.exists(apk_path) and sha256_path(apk_path) == v['out_sha256']: | ||
# nothing to do | ||
continue | ||
|
||
complete = False | ||
|
||
remove(apk_path) | ||
|
||
src_path = os.path.join(EXTERNAL_PATH, 'src', v['src_sha256']) | ||
if not os.path.exists(src_path) or sha256_path(src_path) != v['src_sha256']: | ||
if not download: | ||
continue | ||
|
||
print "downloading", v['src'], "to", src_path | ||
# download it | ||
resp = urllib2.urlopen(v['src']) | ||
data = resp.read() | ||
with open(src_path, 'wb') as src_f: | ||
src_f.write(data) | ||
|
||
if sha256_path(src_path) != v['src_sha256']: | ||
print "download was corrupted..." | ||
continue | ||
|
||
if not patch: | ||
continue | ||
|
||
# ignoring lots of TOCTTOU here... | ||
|
||
apk_temp = "/tmp/"+k+".patched" | ||
remove(apk_temp) | ||
apk_temp2 = "/tmp/"+k+".signed" | ||
remove(apk_temp2) | ||
|
||
try: | ||
print "patching", v['patch'] | ||
subprocess.check_call([APKPATCH, 'apply', src_path, apk_temp, os.path.join(EXTERNAL_PATH, v['patch'])]) | ||
print "signing", apk_temp | ||
subprocess.check_call([SIGNAPK, | ||
os.path.join(EXTERNAL_PATH, 'tools/certificate.pem'), os.path.join(EXTERNAL_PATH, 'tools/key.pk8'), | ||
apk_temp, apk_temp2]) | ||
|
||
out_sha256 = sha256_path(apk_temp2) if os.path.exists(apk_temp2) else None | ||
|
||
if out_sha256 == v['out_sha256']: | ||
print "done", apk_path | ||
shutil.move(apk_temp2, apk_path) | ||
else: | ||
print "patch was corrupted", apk_temp2, out_sha256 | ||
finally: | ||
remove(apk_temp) | ||
remove(apk_temp2) | ||
|
||
return complete | ||
|
||
if __name__ == "__main__": | ||
ret = True | ||
if len(sys.argv) == 2 and sys.argv[1] == "download": | ||
ret = process(True, False) | ||
elif len(sys.argv) == 2 and sys.argv[1] == "patch": | ||
ret = process(False, True) | ||
else: | ||
ret = process(True, True) | ||
sys.exit(0 if ret else 1) |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/system/bin/sh | ||
|
||
DIR="$(cd "$(dirname "$0")" && pwd)" | ||
|
||
export LD_LIBRARY_PATH=/system/lib64 | ||
export CLASSPATH="$DIR"/ApkPatch.android.jar | ||
exec app_process "$DIR" ApkPatch "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICtTCCAh4CCQDm79UqF+Dc5zANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMC | ||
SUQxEzARBgNVBAgTCkphd2EgQmFyYXQxEDAOBgNVBAcTB0JhbmR1bmcxEjAQBgNV | ||
BAoTCUxvbmRhdGlnYTETMBEGA1UECxMKQW5kcm9pZERldjEaMBgGA1UEAxMRTG9y | ||
ZW5zaXVzIFcuIEwuIFQxIzAhBgkqhkiG9w0BCQEWFGxvcmVuekBsb25kYXRpZ2Eu | ||
bmV0MB4XDTEwMDUwNTA5MjEzOFoXDTEzMDEyODA5MjEzOFowgZ4xCzAJBgNVBAYT | ||
AklEMRMwEQYDVQQIEwpKYXdhIEJhcmF0MRAwDgYDVQQHEwdCYW5kdW5nMRIwEAYD | ||
VQQKEwlMb25kYXRpZ2ExEzARBgNVBAsTCkFuZHJvaWREZXYxGjAYBgNVBAMTEUxv | ||
cmVuc2l1cyBXLiBMLiBUMSMwIQYJKoZIhvcNAQkBFhRsb3JlbnpAbG9uZGF0aWdh | ||
Lm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAy2oWtbdVXMHGiS6cA3qi | ||
3VfZt5Vz9jTlux+TEcGx5h18ZKwclyo+z2B0L/p5bYdnrTdFEiD7IxvX+h3lu0JV | ||
B9rdXZdyrzXNOw5YFrsn2k7hKvB8KEBaga1gZEwodlc6N14H3FbZdZkIA9V716Pu | ||
e5CWBZ2VqU03lUJmKnpH8c8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQBpNgXh8dw9 | ||
uMjZxzLUXovV5ptHd61jAcZlQlffqPsz6/2QNfIShVdGH9jkm0IudfKkbvvOKive | ||
a77t9c4sDh2Sat2L/rx6BfTuS1+y9wFr1Ee8Rrr7wGHhRkx2qqGrXGVWqXn8aE3E | ||
P6e7BTPF0ibS+tG8cdDPEisqGFxw36nTNQ== | ||
-----END CERTIFICATE----- |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/system/bin/sh | ||
|
||
DIR="$(cd "$(dirname "$0")" && pwd)" | ||
|
||
export LD_LIBRARY_PATH=/system/lib64 | ||
export CLASSPATH="$DIR"/signapk.android.jar | ||
exec app_process "$DIR" com.android.signapk.SignApk "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
|
||
# simple script to get a vehicle fingerprint. | ||
# keep this script running for few seconds: some messages are published every few seconds | ||
|
||
# Instructions: | ||
# - connect to a Panda | ||
# - run selfdrive/boardd/boardd | ||
# - launching this script | ||
# - since some messages are published at low frequency, keep this script running for few seconds, | ||
# until all messages are received at least once | ||
|
||
import zmq | ||
import selfdrive.messaging as messaging | ||
from selfdrive.services import service_list | ||
|
||
context = zmq.Context() | ||
logcan = messaging.sub_sock(context, service_list['can'].port) | ||
msgs = {} | ||
while True: | ||
lc = messaging.recv_sock(logcan, True) | ||
for c in lc.can: | ||
if c.src == 0: | ||
msgs[c.address] = len(c.dat) | ||
|
||
fingerprint = ', '.join("%d: %d" % v for v in sorted(msgs.items())) | ||
|
||
print "number of messages:", len(msgs) | ||
print "fingerprint", fingerprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters