Пример #1
0
def get_file(code, addr, defines, *args):
    pos0 = args[0]
    pos1 = code.find(b'\x00', pos0)
    string = code[pos0:pos1].decode(buriko_setup.senc)
    string = asdis.escape(string)
    lno = args[1]
    return (string, lno)
Пример #2
0
def get_file(code, addr, defines, *args):
    pos0 = args[0]
    pos1 = code.find(b'\x00', pos0)
    string = code[pos0:pos1].decode('cp932')
    string = asdis.escape(string)
    lno = args[1]
    return string, lno
Пример #3
0
def get_file(code, addr, defines, *args):
	pos0 = args[0]
	pos1 = code.find(b'\x00', pos0)
	string = code[pos0:pos1].decode('cp932')
	string = asdis.escape(string)
	lno = args[1]
	return string, lno
Пример #4
0
def get_string(code, addr, args):
    pos0 = addr + args
    pos1 = code.find(b'\x00', pos0)
    try:
        string = '>> ' + code[pos0:pos1].decode(bpconfig.senc)
    except Exception:
        string = '<< ' + code[pos0:pos1].decode(bpconfig.ienc)
    string = asdis.escape(string)
    return string
Пример #5
0
def get_string(code, addr, args):
    pos0 = addr + args
    pos1 = code.find(b'\x00', pos0)
    try:
        string = '>> ' + code[pos0:pos1].decode(bpconfig.senc)
    except Exception:
        string = '<< ' + code[pos0:pos1].decode(bpconfig.ienc)
    string = asdis.escape(string)
    return string
Пример #6
0
def parse(code):
    bgiop.clear_offsets()

    size = get_code_end(code)
    pos = 0
    texts = []
    strings = []
    while pos < size:
        addr = pos
        op, = struct.unpack('<I', code[addr:addr + 4])
        if op not in bgiop.ops:
            raise Exception('size unknown for op %02x @ offset %05x' %
                            (op, addr))
        pos += 4

        if op == 0x003:  # push_string
            fmt, _, _ = bgiop.ops[op]
            n = struct.calcsize(fmt)

            pos0 = struct.unpack(fmt, code[pos:pos + n])[0]
            s = get_string(code, addr, pos0)
            s = asdis.escape(s)
            strings.append(s)

            pos += n
        elif 0x140 <= op <= 0x160:  # msg_::f_
            if op == 0x140:  #or op == 0x143 or op == 0x151 or op == 0x150:
                if len(strings) == 1:
                    texts.append({
                        "name": None,
                        "text": strings[0],
                        "opcode": op
                    })
                elif len(strings) == 2:
                    texts.append({
                        "name": strings[0],
                        "text": strings[1],
                        "opcode": op
                    })
                else:
                    raise Exception("len(strings) = %d" % len(strings))
            # else:
            #     raise Exception("msg_op=0x%x" % op)
            strings.clear()
        else:
            strings.clear()
            fmt, _, _ = bgiop.ops[op]
            if fmt:
                n = struct.calcsize(fmt)
                pos += n

    return texts
Пример #7
0
def out(fo, inst, offsets, hdrtext, defines):
    if hdrtext:
        fo.write('#header "%s"\n\n' % asdis.escape(hdrtext))
    if defines:
        for offset in sorted(defines):
            fo.write('#define %s L%05x\n' % (defines[offset], offset))
        fo.write('\n')
    for addr in sorted(inst):
        if inst[addr].startswith('line('):
            fo.write('\n')
        if addr in offsets or addr in defines:
            if addr in defines:
                fo.write('\n%s:\n' % defines[addr])
            else:
                fo.write('\nL%05x:\n' % addr)
        fo.write('\t%s;\n' % inst[addr])
Пример #8
0
def out(fo, inst, offsets, hdrtext, defines):
	if hdrtext:
		fo.write('#header "%s"\n\n' % asdis.escape(hdrtext))
	if defines:
		for offset in sorted(defines):
			fo.write('#define %s L%05x\n' % (defines[offset], offset))
		fo.write('\n')
	for addr in sorted(inst):
		if inst[addr].startswith('line('):
			fo.write('\n')
		if addr in offsets or addr in defines:
			if addr in defines:
				fo.write('\n%s:\n' % defines[addr])
			else:
				fo.write('\nL%05x:\n' % addr)
		fo.write('\t%s;\n' % inst[addr])
Пример #9
0
def parse(code):
    bgiop.clear_offsets()

    size = get_code_end(code)
    pos = 0
    texts = []
    strings = []
    while pos < size:
        addr = pos
        op, = struct.unpack('<I', code[addr:addr+4])
        if op not in bgiop.ops:
            raise Exception('size unknown for op %02x @ offset %05x' % (op, addr))
        pos += 4

        if op == 0x003: # push_string
            fmt, _, _ = bgiop.ops[op]
            n = struct.calcsize(fmt)

            pos0 = struct.unpack(fmt, code[pos:pos+n])[0]
            s = get_string(code, addr, pos0)
            s = asdis.escape(s)
            strings.append(s)

            pos += n
        elif 0x140 <= op <= 0x160: # msg_::f_
            if op == 0x140: #or op == 0x143 or op == 0x151 or op == 0x150:
                if len(strings) == 1:
                    texts.append({ "name":None, "text":strings[0], "opcode":op })
                elif len(strings) == 2:
                    texts.append({ "name":strings[0], "text":strings[1], "opcode":op })
                else:
                    raise Exception("len(strings) = %d" % len(strings))
            # else:
            #     raise Exception("msg_op=0x%x" % op)
            strings.clear()
        else:
            strings.clear()
            fmt, _, _ = bgiop.ops[op]
            if fmt:
                n = struct.calcsize(fmt)
                pos += n

    return texts
Пример #10
0
def out(disasmoutfile, inst, offsets, hdrtext, defines):
    """
    Write to a text file buffer `disasmoutfile` using data gathered from parse()
    """
    if hdrtext:
        disasmoutfile.write('#header "%s"\n\n' % asdis.escape(hdrtext))
    if defines:
        for offset in sorted(defines):
            disasmoutfile.write('#define %s L%05x\n' %
                                (defines[offset], offset))
        disasmoutfile.write('\n')
    for addr in sorted(inst):
        if inst[addr].startswith('line('):
            disasmoutfile.write('\n')
        if addr in offsets or addr in defines:
            if addr in defines:
                disasmoutfile.write('\n%s:\n' % defines[addr])
            else:
                disasmoutfile.write('\nL%05x:\n' % addr)
        disasmoutfile.write('\t%s;\n' % inst[addr])
Пример #11
0
def get_string(code, addr, pos0):
    pos1 = code.find(b'\x00', pos0)
    string = code[pos0:pos1].decode('cp932')
    string = asdis.escape(string)
    return string
Пример #12
0
def get_string(code, addr, defines, *args):
    pos0 = args[0]
    pos1 = code.find(b'\x00', pos0)
    string = buriko_common.get_escaped_text(code[pos0:pos1]).decode(buriko_setup.senc)
    string = asdis.escape(string)
    return (string,)
Пример #13
0
def get_string(code, addr, *args):
	pos0 = addr + args[0]
	pos1 = code.find(b'\x00', pos0)
	string = code[pos0:pos1].decode('cp932')
	string = asdis.escape(string)
	return string