Created
January 13, 2024 15:59
-
-
Save diaowinner/07246be2671325962ce56bb373f7b83c to your computer and use it in GitHub Desktop.
(Buggy) kbitx glyph reader
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
import base64 | |
def readLeb(m): | |
a = m.encode() | |
n = base64.b64decode(a+b'==') | |
v=0 | |
s=0 | |
for i in range(len(n)): | |
b=n[i] | |
v |= (b & 0x7F) << s | |
if ((b & 0x80) == 0): | |
break | |
s += 7 | |
return v | |
def readWib(m): | |
# Doesn't work | |
a = m.encode() | |
n = base64.b64decode(a+b'==') | |
repeatData = None | |
repeatCount = 0 | |
eof = False | |
i = 0 | |
l = [] | |
while i < len(n): | |
if eof: | |
l.append(-1) | |
elif repeatCount > 0: | |
repeatCount -= 1 | |
if repeatData == None: | |
i += 1 | |
data = n[i] | |
if data < 0: | |
eof = True | |
l.append(data) | |
else: | |
l.append(repeatData) | |
i += 1 | |
if i >= len(n): | |
return l | |
data = n[i] | |
if data > 0: | |
eof = True | |
l.append(data) | |
repeatCount = data & 0x1F | |
if (data & 0x20) != 0: | |
repeatCount <<= 5 | |
match data & 0xC0: | |
case 0x00: | |
repeatData = 0x00 | |
case 0x40: | |
repeatData = 0xFF | |
case 0x80: | |
i += 1 | |
data = n[i] | |
if data < 0: | |
eof = True | |
l.append(data) | |
repeatData = data | |
case 0xC0: | |
repeatData = None | |
return l | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment