Exemplo n.º 1
0
def create_patchers_from_file(file):
    """Create patchers from a file."""
    raw_data = GameConfigObj(file)

    binary = raw_data.pop(Key.BINARY, None)
    if binary is not None:
        binary = Key.as_str(manager, binary)

    srv_check = Key.as_bool(manager, raw_data.pop(Key.SRV_CHECK, "True"))

    # Parse patcher data
    patcher_data = parse_data(manager, raw_data, (
        (Key.BINARY, Key.as_str, binary if binary is not None else NO_DEFAULT),
        (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
        (Key.OFFSET, Key.as_int, 0),
        (Key.LEVEL, Key.as_int, 0),
        (Key.SRV_CHECK, Key.as_bool, srv_check),
        (Key.SIZE, Key.as_int, NO_DEFAULT),
        ("op_codes", Key.as_identifier, None),
    ))

    # Create the patchers
    return Patchers({
        name: Patcher(get_pointer(*data[:5]), *data[5:])
        for name, data in patcher_data
    })
Exemplo n.º 2
0
def get_pointer_from_dict(raw_data, manager=manager):
    pointer_dict = dict()

    binary = raw_data.pop(Key.BINARY, None)
    if binary is not None:
        binary = Key.as_str(manager, binary)

    srv_check = Key.as_bool(manager, raw_data.pop(Key.SRV_CHECK, "True"))

    # Prepare binary pointers
    ptrs = parse_data(manager, raw_data.pop("binary_pointer", {}),
                      ((Key.BINARY, Key.as_str,
                        binary if binary is not None else NO_DEFAULT),
                       (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
                       (Key.OFFSET, Key.as_int, NO_DEFAULT),
                       (Key.LEVEL, Key.as_int, 0),
                       (Key.SRV_CHECK, Key.as_bool, srv_check)))

    # Create the pointers
    for name, data in ptrs:
        pointer_dict[name] = get_pointer(*data)

    # Prepare pointers
    ptrs = parse_data(manager, raw_data,
                      ((Key.BINARY, Key.as_str,
                        binary if binary is not None else NO_DEFAULT),
                       (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
                       (Key.OFFSET, Key.as_int, NO_DEFAULT),
                       (Key.LEVEL, Key.as_int, 0),
                       (Key.SRV_CHECK, Key.as_bool, srv_check)))

    # Create the pointers
    for name, data in ptrs:
        pointer_dict[name] = get_pointer(*data)

    return pointer_dict
Exemplo n.º 3
0
def get_data_from_dict(raw_data):
    data_dict = dict()

    binary = raw_data.get(Key.BINARY, None)
    if binary is not None:
        binary = Key.as_str(manager, binary)

    srv_check = Key.as_bool(manager, raw_data.get(Key.SRV_CHECK, "True"))

    for method_name in ("instance_attribute", "pointer_attribute",
                        "static_instance_array", "dynamic_instance_array",
                        "static_pointer_array", "dynamic_pointer_array",
                        "virtual_function"):
        offsets_data = parse_data(manager, raw_data.get(method_name, {}),
                                  ((Key.OFFSET, Key.as_int, NO_DEFAULT), ))

        for name, data in offsets_data:
            data_dict[name] = data[0]

    pointers_data = parse_data(manager, raw_data.get(
        "function", {}), ((Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
                          (Key.BINARY, Key.as_str,
                           binary if binary is not None else NO_DEFAULT),
                          (Key.SRV_CHECK, Key.as_bool, srv_check)))

    for name, data in pointers_data:
        data_dict[name] = find_binary(*data[1:]).find_address(data[0]).address

    for method_name in ("binary_attribute", "binary_array"):
        offsets_data = parse_data(
            manager, raw_data.get(method_name, {}),
            ((Key.BINARY, Key.as_str,
              binary if binary is not None else NO_DEFAULT),
             (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
             (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
             (Key.SRV_CHECK, Key.as_bool, srv_check)))

        for name, data in offsets_data:
            data_dict[name] = get_offset(*data)

    offsets_data = parse_data(manager,
                              raw_data.get("binary_virtual_function", {}),
                              ((Key.BINARY, Key.as_str,
                                binary if binary is not None else NO_DEFAULT),
                               (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
                               (Key.OFFSET, Key.as_int, NO_DEFAULT),
                               (Key.SIZE, Key.as_int, 4),
                               (Key.SRV_CHECK, Key.as_bool, srv_check)))

    for name, data in offsets_data:
        data_dict[name] = get_offset(*data) // 4

    pointers_data = parse_data(
        manager, raw_data.get("binary_absolute_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.LEVEL, Key.as_int, 1),
         (Key.SRV_CHECK, Key.as_bool, srv_check)))

    for name, data in pointers_data:
        data_dict[name] = get_pointer(*data).address

    pointers_data = parse_data(
        manager, raw_data.get("binary_relative_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check)))

    for name, data in pointers_data:
        data_dict[name] = get_relative_pointer(*data).address

    pointers_data = parse_data(
        manager, raw_data.get("binary_pointer", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.LEVEL, Key.as_int, 0),
         (Key.SRV_CHECK, Key.as_bool, srv_check)))

    for name, data in pointers_data:
        data_dict[name] = get_pointer(*data).address

    return data_dict
Exemplo n.º 4
0
def get_type_from_dict(raw_data, manager=manager):
    type_dict = dict()

    binary = raw_data.get(Key.BINARY, None)
    if binary is not None:
        binary = Key.as_str(manager, binary)
        type_dict["_binary"] = binary

    srv_check = raw_data.get(Key.SRV_CHECK, None)
    if srv_check is not None:
        srv_check = Key.as_bool(manager, srv_check)
        type_dict["_srv_check"] = srv_check
    else:
        srv_check = True

    size = raw_data.get(Key.SIZE, None)
    if size is not None:
        type_dict["_size"] = Key.as_int(manager, size)

    # Prepare pointer and instance attributes
    for method in (manager.instance_attribute, manager.pointer_attribute):
        attributes = parse_data(
            manager, raw_data.get(method.__name__, {}),
            ((Key.TYPE_NAME, Key.as_attribute_type, NO_DEFAULT),
             (Key.OFFSET, Key.as_int, NO_DEFAULT),
             (Key.DOC, Key.as_str, None)))

        # Create the attributes
        for name, data in attributes:
            type_dict[name] = method(*data)

    # Prepare arrays
    for method in (manager.static_instance_array,
                   manager.dynamic_instance_array,
                   manager.static_pointer_array,
                   manager.dynamic_pointer_array):
        arrays = parse_data(
            manager, raw_data.get(method.__name__, {}),
            ((Key.TYPE_NAME, Key.as_attribute_type, NO_DEFAULT),
             (Key.OFFSET, Key.as_int, NO_DEFAULT),
             (Key.LENGTH, Key.as_int, None), (Key.DOC, Key.as_str, None)))

        # Create the arrays
        for name, data in arrays:
            type_dict[name] = method(*data)

    # Prepare virtual functions
    vfuncs = parse_data(
        manager, raw_data.get("virtual_function", {}),
        ((Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.ARGS, Key.as_args_tuple,
                                                ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.THISCALL),
         (Key.DOC, Key.as_str, None)))

    # Create the virtual functions
    for name, data in vfuncs:
        type_dict[name] = manager.virtual_function(*data)

    # Prepare functions
    funcs = parse_data(
        manager, raw_data.get("function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.SRV_CHECK, Key.as_bool, srv_check),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.ARGS, Key.as_args_tuple,
          ()), (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.THISCALL),
         (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        ptr = find_binary(*data[:2]).find_address(data[2])
        type_dict[name] = manager.function_pointer(ptr, *data[3:])

    # Via binary.

    # Prepare binary attributes
    attributes = parse_data(
        manager, raw_data.get("binary_attribute", {}),
        (("method", Key.as_str, "instance_attribute"),
         (Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check),
         (Key.TYPE_NAME, Key.as_attribute_type, NO_DEFAULT),
         (Key.DOC, Key.as_str, None)))

    # Create the attributes
    for name, data in attributes:
        method = getattr(manager, data[0])
        offset = get_offset(*data[1:6])
        type_dict[name] = method(data[6], offset, data[7])

    # Prepare binary arrays
    arrays = parse_data(
        manager, raw_data.get("binary_array", {}),
        (("method", Key.as_str, "static_instance_array"),
         (Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check),
         (Key.TYPE_NAME, Key.as_attribute_type, NO_DEFAULT),
         (Key.LENGTH, Key.as_int, None), (Key.DOC, Key.as_str, None)))

    # Create the arrays
    for name, data in arrays:
        method = getattr(manager, data[0])
        offset = get_offset(*data[1:6])
        type_dict[name] = method(data[6], offset, data[7], data[8])

    # Prepare binary virtual functions
    vfuncs = parse_data(
        manager, raw_data.get("binary_virtual_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.ARGS, Key.as_args_tuple,
                                                   ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.THISCALL),
         (Key.DOC, Key.as_str, None)))

    # Create the virtual functions
    for name, data in vfuncs:
        index = get_offset(*data[:5]) // 4
        type_dict[name] = manager.virtual_function(index, *data[5:])

    # Prepare binary absolute functions
    funcs = parse_data(
        manager, raw_data.get("binary_absolute_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.LEVEL, Key.as_int, 1),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.ARGS, Key.as_args_tuple,
                                                   ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.THISCALL),
         (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        ptr = get_pointer(*data[:5])
        type_dict[name] = manager.function_pointer(ptr, *data[5:])

    # Prepare binary relative functions
    funcs = parse_data(
        manager, raw_data.get("binary_relative_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.ARGS, Key.as_args_tuple,
                                                   ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.THISCALL),
         (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        ptr = get_relative_pointer(*data[:5])
        type_dict[name] = manager.function_pointer(ptr, *data[5:])

    # Prepare binary pointers
    ptrs = parse_data(manager, raw_data.get("binary_pointer", {}),
                      ((Key.BINARY, Key.as_str,
                        binary if binary is not None else NO_DEFAULT),
                       (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
                       (Key.OFFSET, Key.as_int, NO_DEFAULT),
                       (Key.LEVEL, Key.as_int, 0),
                       (Key.SRV_CHECK, Key.as_bool, srv_check)))

    # Create the pointers
    for name, data in ptrs:
        type_dict[name] = get_pointer(*data)

    return type_dict
Exemplo n.º 5
0
def get_function_from_dict(raw_data, manager=manager):
    function_dict = dict()

    binary = raw_data.pop(Key.BINARY, None)
    if binary is not None:
        binary = Key.as_str(manager, binary)

    srv_check = Key.as_bool(manager, raw_data.pop(Key.SRV_CHECK, "True"))

    # Prepare functions
    funcs = parse_data(
        manager, raw_data.pop("function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.ARGS, Key.as_args_tuple,
          ()), (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.CDECL),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        function_dict[name] = manager.pipe_function(*data)

    # Prepare binary absolute functions
    funcs = parse_data(
        manager, raw_data.pop("binary_absolute_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.LEVEL, Key.as_int, 1),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.ARGS, Key.as_args_tuple,
                                                   ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.CDECL),
         (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        ptr = get_pointer(*data[:5])
        function_dict[name] = manager.pipe_function_pointer(ptr, *data[5:])

    # Prepare binary relative functions
    funcs = parse_data(
        manager, raw_data.pop("binary_relative_function", {}),
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.OFFSET, Key.as_int, NO_DEFAULT), (Key.SIZE, Key.as_int, 4),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.ARGS, Key.as_args_tuple,
                                                   ()),
         (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.CDECL),
         (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        ptr = get_relative_pointer(*data[:5])
        function_dict[name] = manager.pipe_function_pointer(ptr, *data[5:])

    # Prepare functions
    funcs = parse_data(
        manager, raw_data,
        ((Key.BINARY, Key.as_str,
          binary if binary is not None else NO_DEFAULT),
         (Key.IDENTIFIER, Key.as_identifier, NO_DEFAULT),
         (Key.ARGS, Key.as_args_tuple,
          ()), (Key.RETURN_TYPE, Key.as_return_type, DataType.VOID),
         (Key.CONVENTION, Key.as_convention, Convention.CDECL),
         (Key.SRV_CHECK, Key.as_bool, srv_check), (Key.DOC, Key.as_str, None)))

    # Create the functions
    for name, data in funcs:
        function_dict[name] = manager.pipe_function(*data)

    return function_dict