Exemple #1
0
def read_ast_from_file(raw_contents):
    # .rpyc files are just zlib compressed pickles of a tuple of some data and the actual AST of the file
    if raw_contents.startswith("RENPY RPC2"):
        # parse the archive structure
        position = 10
        chunks = {}
        while True:
            slot, start, length = struct.unpack("III", raw_contents[position: position + 12])
            if slot == 0:
                break
            position += 12

            chunks[slot] = raw_contents[start: start + length]

        raw_contents = chunks[1]
    raw_contents = raw_contents.decode('zlib')
    data, stmts = magic.safe_loads(raw_contents, factory, {"_ast", "collections"})
    return stmts
Exemple #2
0
def read_ast_from_file(in_file):
    # .rpyc files are just zlib compressed pickles of a tuple of some data and the actual AST of the file
    raw_contents = in_file.read()
    if raw_contents.startswith("RENPY RPC2"):
        # parse the archive structure
        position = 10
        chunks = {}
        while True:
            slot, start, length = struct.unpack("III", raw_contents[position: position + 12])
            if slot == 0:
                break
            position += 12

            chunks[slot] = raw_contents[start: start + length]

        raw_contents = chunks[1]
    raw_contents = raw_contents.decode('zlib')
    data, stmts = magic.safe_loads(raw_contents, factory, ("_ast",))
    return stmts
Exemple #3
0
def read_ast_from_file(raw_contents):
    data, stmts = magic.safe_loads(raw_contents, factory, {"_ast", "collections"})
    return stmts
Exemple #4
0
def read_ast_from_file(in_file):
    # .rpyc files are just zlib compressed pickles of a tuple of some data and the actual AST of the file
    raw_contents = in_file.read().decode('zlib')
    data, stmts = magic.safe_loads(raw_contents, factory, ("_ast",))
    return stmts