Skip to content

Instantly share code, notes, and snippets.

@EkriirkE
Last active February 12, 2026 10:09
Show Gist options
  • Select an option

  • Save EkriirkE/92ecb76817e6559d0dab08879135d013 to your computer and use it in GitHub Desktop.

Select an option

Save EkriirkE/92ecb76817e6559d0dab08879135d013 to your computer and use it in GitHub Desktop.
Android app storing settings in a binary format. I don't know the name of this format but this is what I deduced and worked for me
#Android app was storing settings in a binary format. I don't know the name of this format but this is what I deduced and worked for my usecase
prefs={}
with open("shared_preferences.preferences_pb","rb") as x:
while True:
if len(x.read(1))<1: break#0A
l=x.read(1)[0]
if l & 0x80: l=(l&0x7F)|(x.read(1)[0]<<7)
t=x.read(l)
if len(t)<1: break
p=2+t[1]
n=t[2:p].decode()
p+=1 #12
while t[p] & 0x80: p+=1
p+=1
b=None
match t[p]:
case 0x05:#UInt32
b=struct.unpack('I',t[p+1:p+5])[0]
p+=4
case 0x08:#Bool
b=t[p+1]!=0
case 0x15:#Float32
b=struct.unpack('f',t[p+1:p+5])[0]
p+=4
case 0x18:#Byte
b=t[p+1]
case 0x20:#Packed Integer
p+=1
lc=1
b=t[p]&0x7F
while t[p] & 0x80:
p+=1
b|=(t[p]&0x7F)<<(lc*7)
lc+=1
case 0x2A:#String
p+=1
lc=1
l=t[p]&0x7F
while t[p] & 0x80:
p+=1
l|=(t[p]&0x7F)<<(lc*7)
lc+=1
p+=1
b=t[p:p+l].decode()
#case _: print(f"Unknown {hex(t[p])}")
#print(f"{n}={b}")
prefs.update({n:b})
print(f"{prefs=}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment