Пример #1
0
def insert_08_asm(map_id, text_id, line_id=0):
    map2 = extract_maps.map_headers[map_id]
    base_label = map_name_cleaner(map2["name"], None)[:-2]
    label = base_label + "Text" + str(text_id)

    start_address = all_texts[map_id][text_id][line_id]["start_address"]

    (text_asm, end_address) = text_asm_pretty_printer(label, start_address)
    print "end address is: " + hex(end_address)

    #find where to insert the assembly
    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping text label for a $08 on map_id=" + str(
            map_id) + " text_id=" + str(
                text_id) + " because the address is taken"
        return

    #also do a name check
    if 1 <= ("\n".join(analyze_incbins.asm)).count("\n" + label + ":"):
        print "skipping text label for a $08 on map_id=" + str(
            map_id) + " text_id=" + str(
                text_id
            ) + " because the label is already taken (" + label + ":)"
        return

    newlines = split_incbin_line_into_three(line_number, start_address,
                                            end_address - start_address)

    newlines = newlines.split("\n")
    if len(newlines) == 2: index = 0  #replace the 1st line with new content
    elif len(newlines) == 3: index = 1  #replace the 2nd line with new content

    newlines[index] = text_asm

    if len(newlines) == 3 and newlines[2][-2:] == "$0":
        #get rid of the last incbin line if it is only including 0 bytes
        del newlines[2]
        #note that this has to be done after adding in the new asm
    newlines = "\n".join(line for line in newlines)

    newlines = newlines.replace("$x", "$")

    diff = generate_diff_insert(line_number, newlines)
    print "working on map_id=" + str(map_id) + " text_id=" + str(text_id)
    print diff
    result = apply_diff(diff)

    if result == False:
        failed_attempts[len(failed_attempts.keys())] = {
            "map_id": map_id,
            "text_id": text_id
        }
def insert_08_asm(map_id, text_id, line_id=0):
    map2 = extract_maps.map_headers[map_id]
    base_label = map_name_cleaner(map2["name"], None)[:-2]
    label = base_label + "Text" + str(text_id)

    start_address = all_texts[map_id][text_id][line_id]["start_address"]

    (text_asm, end_address) = text_asm_pretty_printer(label, start_address)
    print "end address is: " + hex(end_address)

    #find where to insert the assembly
    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping text label for a $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " because the address is taken"
        return

    #also do a name check
    if 1 <= ("\n".join(analyze_incbins.asm)).count("\n" + label + ":"):
        print "skipping text label for a $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " because the label is already taken (" + label + ":)"
        return
    
    newlines = split_incbin_line_into_three(line_number, start_address, end_address - start_address )
    
    newlines = newlines.split("\n")
    if len(newlines) == 2: index = 0 #replace the 1st line with new content
    elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
    
    newlines[index] = text_asm

    if len(newlines) == 3 and newlines[2][-2:] == "$0":
        #get rid of the last incbin line if it is only including 0 bytes
        del newlines[2]
        #note that this has to be done after adding in the new asm
    newlines = "\n".join(line for line in newlines)

    newlines = newlines.replace("$x", "$")

    diff = generate_diff_insert(line_number, newlines)
    print "working on map_id=" + str(map_id) + " text_id=" + str(text_id)
    print diff
    result = apply_diff(diff)

    if result == False:
        failed_attempts[len(failed_attempts.keys())] = {"map_id": map_id, "text_id": text_id}
Пример #3
0
def insert_asm(start_address, label, text_asm=None, end_address=None):
    if text_asm == None and end_address == None:
        (text_asm, end_address) = text_asm_pretty_printer(label,
                                                          start_address,
                                                          include_08=False)
        print "end address is: " + hex(end_address)

    #find where to insert the assembly
    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping asm because the address is taken"
        return False

    #name check
    if (label + ":") in "\n".join(analyze_incbins.asm):
        print "skipping asm because the label is taken"
        return False

    newlines = split_incbin_line_into_three(line_number, start_address,
                                            end_address - start_address)

    newlines = newlines.split("\n")
    if len(newlines) == 2: index = 0  #replace the 1st line with new content
    elif len(newlines) == 3: index = 1  #replace the 2nd line with new content

    newlines[index] = text_asm

    if len(newlines) == 3 and newlines[2][-2:] == "$0":
        #get rid of the last incbin line if it is only including 0 bytes
        del newlines[2]
        #note that this has to be done after adding in the new asm
    newlines = "\n".join(line for line in newlines)

    newlines = newlines.replace("$x", "$")

    diff = generate_diff_insert(line_number, newlines)
    print diff
    result = apply_diff(diff, try_fixing=True)
    return True
def insert_asm(start_address, label, text_asm=None, end_address=None):
    if text_asm == None and end_address == None:
        (text_asm, end_address) = text_asm_pretty_printer(label, start_address, include_08=False)
        print "end address is: " + hex(end_address)

    #find where to insert the assembly
    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping asm because the address is taken"
        return False

    #name check
    if (label + ":") in "\n".join(analyze_incbins.asm):
        print "skipping asm because the label is taken"
        return False

    newlines = split_incbin_line_into_three(line_number, start_address, end_address - start_address )
    
    newlines = newlines.split("\n")
    if len(newlines) == 2: index = 0 #replace the 1st line with new content
    elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
    
    newlines[index] = text_asm

    if len(newlines) == 3 and newlines[2][-2:] == "$0":
        #get rid of the last incbin line if it is only including 0 bytes
        del newlines[2]
        #note that this has to be done after adding in the new asm
    newlines = "\n".join(line for line in newlines)

    newlines = newlines.replace("$x", "$")

    diff = generate_diff_insert(line_number, newlines)
    print diff
    result = apply_diff(diff, try_fixing=True)
    return True