Esempio n. 1
0
def gen5get(f):
    texts = []
    reader = binaryreader(f)
    
    numblocks = reader.read16()
    numentries = reader.read16()
    filesize = reader.read32()
    zero = reader.read32()
    blockoffsets = []
    for i in range(numblocks):
        blockoffsets.append(reader.read32())
    # filesize == len(f)-reader.pos()
    for i in range(numblocks):
        reader.seek(blockoffsets[i])
        size = reader.read32()
        tableoffsets = []
        charcounts = []
        textflags = []
        for j in range(numentries):
            tableoffsets.append(reader.read32())
            charcounts.append(reader.read16())
            textflags.append(reader.read16())
        for j in range(numentries):
            compressed = False
            encchars = []
            text = ""
            reader.seek(blockoffsets[i]+tableoffsets[j])
            for k in range(charcounts[j]):
                encchars.append(reader.read16())
            key = encchars[len(encchars)-1]^0xFFFF
            decchars = []
            while encchars:
                char = encchars.pop() ^ key
                key = ((key>>3)|(key<<13))&0xFFFF
                decchars.insert(0, char)
            if decchars[0] == 0xF100:
                compressed = True
                decchars.pop(0)
                newstring = []
                container = 0
                bit = 0
                while decchars:
                    container |= decchars.pop(0)<<bit
                    bit += 16
                    while bit >= 9:
                        bit -= 9
                        c = container&0x1FF
                        if c == 0x1FF:
                            newstring.append(0xFFFF)
                        else:
                            newstring.append(c)
                        container >>= 9
                decchars = newstring
            while decchars:
                c = decchars.pop(0)
                if c == 0xFFFF:
                    break
                elif c == 0xFFFE:
                    text += "\\n"
                elif c < 20 or c > 0xF000:
                    text += "\\x%04X"%c
                elif c == 0xF000:
                    try:
                        kind = decchars.pop(0)
                        count = decchars.pop(0)
                        if kind == 0xbe00 and count == 0:
                            text += "\\f"
                            continue
                        if kind == 0xbe01 and count == 0:
                            text += "\\r"
                            continue
                        text += "VAR("
                        args = [kind]
                        for k in range(count):
                            args.append(decchars.pop(0))
                    except IndexError:
                        break
                    text += ", ".join(map(str, args))
                    text += ")"
                else:
                    text += unichr(c)
            e = "%i_%i"%(i, j)
            flag = ""
            val = textflags[j]
            c = 65
            while val:
                if val&1:
                    flag += chr(c)
                c += 1
                val >>= 1
            if compressed:
                flag += "c"
            e += flag
            texts.append([e, text])
    return texts
Esempio n. 2
0
def gen5get(f):
    texts = []
    reader = binaryreader(f)

    numblocks = reader.read16()
    numentries = reader.read16()
    filesize = reader.read32()
    zero = reader.read32()
    blockoffsets = []
    for i in range(numblocks):
        blockoffsets.append(reader.read32())
    # filesize == len(f)-reader.pos()
    for i in range(numblocks):
        reader.seek(blockoffsets[i])
        size = reader.read32()
        tableoffsets = []
        charcounts = []
        textflags = []
        for j in range(numentries):
            tableoffsets.append(reader.read32())
            charcounts.append(reader.read16())
            textflags.append(reader.read16())
        for j in range(numentries):
            compressed = False
            encchars = []
            text = ""
            reader.seek(blockoffsets[i] + tableoffsets[j])
            for k in range(charcounts[j]):
                encchars.append(reader.read16())
            key = encchars[len(encchars) - 1] ^ 0xFFFF
            decchars = []
            while encchars:
                char = encchars.pop() ^ key
                key = ((key >> 3) | (key << 13)) & 0xFFFF
                decchars.insert(0, char)
            if decchars[0] == 0xF100:
                compressed = True
                decchars.pop(0)
                newstring = []
                container = 0
                bit = 0
                while decchars:
                    container |= decchars.pop(0) << bit
                    bit += 16
                    while bit >= 9:
                        bit -= 9
                        c = container & 0x1FF
                        if c == 0x1FF:
                            newstring.append(0xFFFF)
                        else:
                            newstring.append(c)
                        container >>= 9
                decchars = newstring
            while decchars:
                c = decchars.pop(0)
                if c == 0xFFFF:
                    break
                elif c == 0xFFFE:
                    text += "\\n"
                elif c < 20 or c > 0xF000:
                    text += "\\x%04X" % c
                elif c == 0xF000:
                    try:
                        kind = decchars.pop(0)
                        count = decchars.pop(0)
                        if kind == 0xbe00 and count == 0:
                            text += "\\f"
                            continue
                        if kind == 0xbe01 and count == 0:
                            text += "\\r"
                            continue
                        text += "VAR("
                        args = [kind]
                        for k in range(count):
                            args.append(decchars.pop(0))
                    except IndexError:
                        break
                    text += ", ".join(map(str, args))
                    text += ")"
                else:
                    text += unichr(c)
            e = "%i_%i" % (i, j)
            flag = ""
            val = textflags[j]
            c = 65
            while val:
                if val & 1:
                    flag += chr(c)
                c += 1
                val >>= 1
            if compressed:
                flag += "c"
            e += flag
            texts.append([e, text])
    return texts
Esempio n. 3
0
def gen4get(f):
    texts = []
    reader = binaryreader(f)
    
    num = reader.read16()
    seed = reader.read16()
    hasComments = False
    if seed & 0xFF == 0xFF: # PPRE Seed
        if seed & 0x100:
            hasComments = True
    offsets = []
    sizes = []
    for i in range(num):
        tmp = ((((seed*0x2FD)&0xFFFF)*(i+1))&0xFFFF)
        key = tmp | (tmp << 16)
        offsets.append(reader.read32() ^ key)
        sizes.append(reader.read32() ^ key)
    if hasComments:
        tmp = ((((seed*0x2FD)&0xFFFF)*(i+1))&0xFFFF)
        key = tmp | (tmp << 16)
        commentOfs = reader.read32() ^ key
        term = reader.read32() ^ key
        if term != 0xFFFF:
            print("Erroneous comment offset terminator: %X"%term)
    for i in range(num):
        reader.seek(offsets[i])
        compressed = False
        offset = offsets[i]
        size = sizes[i]
        key = (0x91BD3*(i+1))&0xFFFF
        string = []
        for j in range(size):
            string.append(reader.read16() ^ key)
            key = (key+0x493D)&0xFFFF
        if string[0] == 0xF100:
            compressed = True
            string.pop(0)
            newstring = []
            container = 0
            bit = 0
            while string:
                container |= string.pop(0)<<bit
                bit += 15
                while bit >= 9:
                    bit -= 9
                    c = container&0x1FF
                    if c == 0x1FF:
                        newstring.append(0xFFFF)
                    else:
                        newstring.append(c)
                    container >>= 9
            string = newstring
        text = ""
        while string:
            char = string.pop(0)
            if char == 0xFFFF:
                break
            elif char == 0xFFFE:
                try:
                    kind = string.pop(0)
                    count = string.pop(0)
                    text += "VAR("
                    args = [kind]
                    for k in range(count):
                        args.append(string.pop(0))
                except IndexError:
                    break
                text += ", ".join(map(str, args))
                text += ")"
            elif char == 0xE000:
                text += "\\n"
            elif char == 0x25BC:
                text += "\\r"
            elif char == 0x25BD:
                text += "\\f"
            else:
                try:
                    text += unicodeparser.tb[char]
                except:
                    text += "\\x%04X"%char
        e = "0_%i"%i
        if compressed:
            e += "c" # 0_2c = ....
        texts.append([e, text])
    if hasComments:
        reader.seek(commentOfs)
        num = reader.read16()
        for i in range(num):
            commentid = reader.read16()
            text = ""
            c = 0
            while True:
                c = reader.read16()
                if c == 0xFFFF:
                    break
                text += unichr(c)
            e = "Comment_%i"%commentid
            texts.append([e, text])
    return sorted(texts, cmp=sortTextKeys)
Esempio n. 4
0
def gen4get(f):
    texts = []
    reader = binaryreader(f)

    num = reader.read16()
    seed = reader.read16()
    hasComments = False
    if seed & 0xFF == 0xFF:  # PPRE Seed
        if seed & 0x100:
            hasComments = True
    offsets = []
    sizes = []
    for i in range(num):
        tmp = ((((seed * 0x2FD) & 0xFFFF) * (i + 1)) & 0xFFFF)
        key = tmp | (tmp << 16)
        offsets.append(reader.read32() ^ key)
        sizes.append(reader.read32() ^ key)
    if hasComments:
        tmp = ((((seed * 0x2FD) & 0xFFFF) * (i + 1)) & 0xFFFF)
        key = tmp | (tmp << 16)
        commentOfs = reader.read32() ^ key
        term = reader.read32() ^ key
        if term != 0xFFFF:
            print("Erroneous comment offset terminator: %X" % term)
    for i in range(num):
        reader.seek(offsets[i])
        compressed = False
        offset = offsets[i]
        size = sizes[i]
        key = (0x91BD3 * (i + 1)) & 0xFFFF
        string = []
        for j in range(size):
            string.append(reader.read16() ^ key)
            key = (key + 0x493D) & 0xFFFF
        if string[0] == 0xF100:
            compressed = True
            string.pop(0)
            newstring = []
            container = 0
            bit = 0
            while string:
                container |= string.pop(0) << bit
                bit += 15
                while bit >= 9:
                    bit -= 9
                    c = container & 0x1FF
                    if c == 0x1FF:
                        newstring.append(0xFFFF)
                    else:
                        newstring.append(c)
                    container >>= 9
            string = newstring
        text = ""
        while string:
            char = string.pop(0)
            if char == 0xFFFF:
                break
            elif char == 0xFFFE:
                try:
                    kind = string.pop(0)
                    count = string.pop(0)
                    text += "VAR("
                    args = [kind]
                    for k in range(count):
                        args.append(string.pop(0))
                except IndexError:
                    break
                text += ", ".join(map(str, args))
                text += ")"
            elif char == 0xE000:
                text += "\\n"
            elif char == 0x25BC:
                text += "\\r"
            elif char == 0x25BD:
                text += "\\f"
            else:
                try:
                    text += unicodeparser.tb[char]
                except:
                    text += "\\x%04X" % char
        e = "0_%i" % i
        if compressed:
            e += "c"  # 0_2c = ....
        texts.append([e, text])
    if hasComments:
        reader.seek(commentOfs)
        num = reader.read16()
        for i in range(num):
            commentid = reader.read16()
            text = ""
            c = 0
            while True:
                c = reader.read16()
                if c == 0xFFFF:
                    break
                text += unichr(c)
            e = "Comment_%i" % commentid
            texts.append([e, text])
    return sorted(texts, cmp=sortTextKeys)