Esempio n. 1
0
def main():
    args = parse_args()
    scriptutils.configure_logging(args)

    logger = logging.getLogger(__name__)

    script_file_path = args.input
    output_xml_path = args.output
    build_dir = args.build_dir

    opcode_list = opcodes.load_opcode_list()

    logger.debug("Loading script file: %s", script_file_path)
    with open(script_file_path, "r") as script_file:
        result_chunky_file = parse_and_assemble(script_file, opcode_list, args.verbose)

    # Generate chunky file XML
    chunky_file_xml = chunkyfilexml.chunky_file_to_xml(result_chunky_file, build_dir)

    if output_xml_path:
        logger.debug("Writing XML file: %s", output_xml_path)
        with open(output_xml_path, "w") as output_xml_file:
            output_xml_file.write(chunky_file_xml)
    else:
        print(chunky_file_xml)
Esempio n. 2
0
def main():
    args = parse_args()
    configure_logging(args)

    try:
        hwnd = msg.find_window(args.window_class)
        print(f"hWnd: 0x{hwnd:x}")

        def print_visitor(level, parent_gid, gid, type_tag):
            prefix = level * '-' + ' ' if level > 0 else ''
            print(f"{prefix}0x{gid:x}: {type_tag}")

        print("Dumping tree:")
        msg.walk_gob_tree(hwnd, print_visitor)
    except msg.WindowNotFoundException:
        logger.error("Could not find 3DMM/CW2 window")
Esempio n. 3
0
def main():
    args = parse_args()
    scriptutils.configure_logging(args)

    logger = logging.getLogger(__name__)

    filename = args.file
    logger.info(f"Loading file: {filename}")
    with open(filename, "rb") as chunky_file_handle:
        this_chunky_file = loader.load_from_file(chunky_file_handle)
        logger.info(f"Loaded: {this_chunky_file}")
        script_chunks = [
            c for c in this_chunky_file.chunks
            if c.chunk_id.tag in SCRIPT_CHUNK_TAGS
        ]
        string_table_chunks = [
            c for c in this_chunky_file.chunks
            if c.chunk_id.tag in STRING_TABLE_TAGS
        ]

        if len(script_chunks) > 0:
            logger.info(f"Found {len(script_chunks)} script chunks")
            fmt = formatter.TextScriptFormatter()

            for c in script_chunks:
                script = disassembler.disassemble_script(
                    io.BytesIO(c.decoded_data))
                print(
                    fmt.format_script(script,
                                      chunk_id=c.chunk_id,
                                      chunk_name=c.name,
                                      file_name=filename))

        if len(string_table_chunks) > 0:
            for c in string_table_chunks:
                logger.info(f"Dumping string table: {c.chunk_id} {c.name}")

                try:
                    strings = stringtable.StringTable.from_buffer(
                        c.decoded_data)

                    for k, v in strings.items():
                        logger.info(f"    0x{k:x} - {v}")
                except:
                    logger.exception("failed to load string table")
Esempio n. 4
0
def main():
    args = parse_args()
    configure_logging(args)

    minimum_multiplier = 0.0001

    if args.multiplier < minimum_multiplier:
        logger.error(f"Invalid multiplier: must be >= {minimum_multiplier}")
    else:
        try:
            hwnd = msg.find_window(args.window_class)
            logger.info(f"hWnd: 0x{hwnd:x}")

            if msg.set_time_scale(hwnd, args.multiplier) != 0:
                logger.info(f"Clock set to {args.multiplier}x")
            else:
                logger.error("Failed to set clock")

        except msg.WindowNotFoundException:
            logger.error("Could not find 3DMM/CW2 window")
Esempio n. 5
0
def main():
    args = parse_args()
    scriptutils.configure_logging(args)

    logger = logging.getLogger(__name__)

    if args.chunk_data_dir:
        chunk_data_dir = args.chunk_data_dir.absolute()
        logger.info("Writing chunk data to: %s", chunk_data_dir)
    else:
        chunk_data_dir = None

    with open(args.input, "rb") as movie_file:
        this_file = loader.load_from_file(movie_file)
        output_file_path = pathlib.Path(args.output).absolute()

        this_file_xml = chunky_file_to_xml(this_file, chunk_data_dir)

        with open(output_file_path, "w") as outfile:
            outfile.write(this_file_xml)

        if args.stdout:
            print(this_file_xml)
Esempio n. 6
0
def main():
    args = parse_args()
    configure_logging(args)

    if args.template:
        logger.info("Loading template file: %s" % args.template.absolute())
        # Load existing chunky file as a template
        with open(args.template, "rb") as template_file:
            chunky_file = loader.load_from_file(template_file)
    else:
        # Create an empty chunky file
        chunky_file = model.ChunkyFile(model.Endianness.LittleEndian,
                                       model.CharacterSet.ANSI,
                                       file_type=EMPTY_FILE)

    for input_file in args.input:
        logger.info("Processing: %s" % input_file)
        xml_to_chunky_file(chunky_file, input_file)

    logger.info("Generating: %s" % args.output)
    with open(args.output, "wb") as output_file:
        writer.write_to_file(chunky_file, output_file)

    logger.info("Complete")