Skip to content

Instantly share code, notes, and snippets.

@mimi89999
Created September 21, 2020 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimi89999/98df99d9fbbbeb6bf62f82c8bfe9bb84 to your computer and use it in GitHub Desktop.
Save mimi89999/98df99d9fbbbeb6bf62f82c8bfe9bb84 to your computer and use it in GitHub Desktop.
sb_data = b''
with open(signed_apk, 'rb') as unsigned:
unsigned.seek(-6, 2) # From file end, 2 byte comment length, 4 byte offset of CD
cd_start = 0
for i in reversed(unsigned.read(4)):
cd_start *= (0xff + 1)
cd_start += i
print('cd_start:', cd_start)
unsigned.seek(cd_start - 16 - 8, 0) # 16 byte magic, uint64 size
sb_size = 0
for i in reversed(unsigned.read(8)):
sb_size *= (0xff + 1)
sb_size += i
print('sb_size:', sb_size)
sb_start = cd_start - sb_size - 8 # sb_size excludes first sb_size field
print('sb_start:', sb_start)
unsigned.seek(sb_start, 0)
sb_data = unsigned.read(sb_size + 8)
print(sb_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment