Example #1
0
def main():
    usage = "usage: %prog address label"
    parser = OptionParser(usage)
    (options, args) = parser.parse_args()
    if len(args) == 1:
        print "usage: python pretty_text.py address label"
        args.append("UnnamedText_" + (args[0].replace("0x", "")))
    elif len(args) != 2:
        parser.error("we need both an address and a label")
    address = int(args[0], 16)
    label = args[1]

    text_pretty_printer_at(address, label)
Example #2
0
def insert_text(address, label, apply=False, try_fixing=True):
    "inserts a text script (but not $8s)"
    start_address = address

    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping text at " + hex(
            start_address) + " with address " + label
        return "skip"

    #another reason to skip is if the interval is 0
    processed_incbin = analyze_incbins.processed_incbins[line_number]
    if processed_incbin["interval"] == 0:
        print "skipping text at " + hex(
            start_address
        ) + " with address " + label + " because the interval is 0"
        return "skip"

    text_asm, byte_count = text_pretty_printer_at(start_address, label)
    end_address = start_address + byte_count
    newlines = split_incbin_line_into_three(line_number, start_address,
                                            byte_count)

    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", "$")  #where does this keep coming from??

    #Char52 doesn't work yet
    newlines = newlines.replace("Char52", "$52")

    diff = generate_diff_insert(line_number, newlines)
    print diff
    if apply:
        return apply_diff(diff, try_fixing=try_fixing)
    else:  #simulate a successful insertion
        return True
def insert_text(address, label, apply=False, try_fixing=True):
    "inserts a text script (but not $8s)"
    start_address = address

    line_number = find_incbin_to_replace_for(start_address)
    if line_number == None:
        print "skipping text at " + hex(start_address) + " with address " + label
        return "skip"

    #another reason to skip is if the interval is 0
    processed_incbin = analyze_incbins.processed_incbins[line_number]
    if processed_incbin["interval"] == 0:
        print "skipping text at " + hex(start_address) + " with address " + label + " because the interval is 0"
        return "skip"

    text_asm, byte_count = text_pretty_printer_at(start_address, label)
    end_address = start_address + byte_count
    newlines = split_incbin_line_into_three(line_number, start_address, byte_count)

    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", "$") #where does this keep coming from??

    #Char52 doesn't work yet
    newlines = newlines.replace("Char52", "$52")

    diff = generate_diff_insert(line_number, newlines)
    print diff
    if apply:
        return apply_diff(diff, try_fixing=try_fixing)
    else: #simulate a successful insertion
        return True