Initialize local project and fix ranch growth synchronization
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
"""Small AMF3 reader for the client's zlib-compressed resource tables."""
|
||||
import struct
|
||||
|
||||
|
||||
class Reader:
|
||||
def __init__(self, data):
|
||||
self.data, self.pos = data, 0
|
||||
self.strings, self.objects, self.traits = [], [], []
|
||||
|
||||
def take(self, n):
|
||||
value = self.data[self.pos:self.pos + n]
|
||||
if len(value) != n:
|
||||
raise ValueError("Truncated AMF data")
|
||||
self.pos += n
|
||||
return value
|
||||
|
||||
def u29(self):
|
||||
value = 0
|
||||
for _ in range(3):
|
||||
b = self.take(1)[0]
|
||||
if b < 128:
|
||||
return value << 7 | b
|
||||
value = value << 7 | b & 127
|
||||
return value << 8 | self.take(1)[0]
|
||||
|
||||
def string(self):
|
||||
h = self.u29()
|
||||
if not h & 1:
|
||||
return self.strings[h >> 1]
|
||||
value = self.take(h >> 1).decode("utf-8")
|
||||
if value:
|
||||
self.strings.append(value)
|
||||
return value
|
||||
|
||||
def read(self):
|
||||
kind = self.take(1)[0]
|
||||
if kind in (0, 1):
|
||||
return None
|
||||
if kind in (2, 3):
|
||||
return kind == 3
|
||||
if kind == 4:
|
||||
n = self.u29()
|
||||
return n - (1 << 29) if n & (1 << 28) else n
|
||||
if kind == 5:
|
||||
return struct.unpack(">d", self.take(8))[0]
|
||||
if kind == 6:
|
||||
return self.string()
|
||||
if kind in (7, 8, 9, 10, 11, 12):
|
||||
h = self.u29()
|
||||
if not h & 1:
|
||||
return self.objects[h >> 1]
|
||||
if kind == 8:
|
||||
value = struct.unpack(">d", self.take(8))[0]
|
||||
self.objects.append(value)
|
||||
return value
|
||||
if kind in (7, 11, 12):
|
||||
value = self.take(h >> 1)
|
||||
self.objects.append(value)
|
||||
return value
|
||||
if kind == 9:
|
||||
associative, dense = {}, []
|
||||
result = associative if not h >> 1 else dense
|
||||
self.objects.append(result)
|
||||
while (name := self.string()):
|
||||
associative[name] = self.read()
|
||||
for _ in range(h >> 1):
|
||||
dense.append(self.read())
|
||||
if dense and associative:
|
||||
raise ValueError("Mixed AMF array unsupported")
|
||||
return result
|
||||
if not h & 2:
|
||||
external, dynamic, names = self.traits[h >> 2]
|
||||
else:
|
||||
self.string()
|
||||
external, dynamic = bool(h & 4), bool(h & 8)
|
||||
names = [self.string() for _ in range(h >> 4)]
|
||||
self.traits.append((external, dynamic, names))
|
||||
if external:
|
||||
raise ValueError("Externalizable AMF object unsupported")
|
||||
result = {}
|
||||
self.objects.append(result)
|
||||
for name in names:
|
||||
result[name] = self.read()
|
||||
if dynamic:
|
||||
while (name := self.string()):
|
||||
result[name] = self.read()
|
||||
return result
|
||||
raise ValueError(f"Unsupported AMF3 marker {kind}")
|
||||
Reference in New Issue
Block a user