mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-06-23 16:05:30 +00:00
missing 3 functions, but otherwise correct
This commit is contained in:
parent
21f1a81aa3
commit
2365f4d697
92
parser.py
92
parser.py
@ -75,11 +75,17 @@ in_text = False
|
|||||||
# Mark if we should end parsing
|
# Mark if we should end parsing
|
||||||
end_parse = False
|
end_parse = False
|
||||||
|
|
||||||
|
# Initialize address of last bctr instruction to 0
|
||||||
|
bctr_addr = '00000000'
|
||||||
|
|
||||||
# Initialize address of last blr instruction to 0
|
# Initialize address of last blr instruction to 0
|
||||||
blr_addr = '00000000'
|
blr_addr = '00000000'
|
||||||
|
|
||||||
# Initialize address of last bctr instruction to 0
|
# Initialize address of last 'End of function' comment to 0
|
||||||
bctr_addr = '00000000'
|
eof_addr = '00000000'
|
||||||
|
|
||||||
|
# Initialize address of last restgprlr instruction to 0
|
||||||
|
restgprlr_addr = '00000000'
|
||||||
|
|
||||||
# Initialize address of last padding to 0
|
# Initialize address of last padding to 0
|
||||||
pad_addr = 0
|
pad_addr = 0
|
||||||
@ -103,8 +109,8 @@ with open(ida_html, 'r') as file:
|
|||||||
|
|
||||||
# If this is not the first function being added
|
# If this is not the first function being added
|
||||||
if num_functs > 0:
|
if num_functs > 0:
|
||||||
# If last address had padding, then this function was already added
|
# If last address had padding or restgprlr instruction, then this function was already added
|
||||||
if curr_addr_int-4 == pad_addr:
|
if curr_addr_int-4 == pad_addr or curr_addr_int-4 == restgprlr_addr:
|
||||||
# Set function type for start address
|
# Set function type for start address
|
||||||
functs[num_functs-1][3] = 'sub'
|
functs[num_functs-1][3] = 'sub'
|
||||||
else:
|
else:
|
||||||
@ -130,59 +136,31 @@ with open(ida_html, 'r') as file:
|
|||||||
curr_funct = functs[num_functs-1]
|
curr_funct = functs[num_functs-1]
|
||||||
# If previous address was a blr instruction
|
# If previous address was a blr instruction
|
||||||
if curr_addr_int-4 == int(blr_addr, 16):
|
if curr_addr_int-4 == int(blr_addr, 16):
|
||||||
# If last added function is a subroutine and has no nested functions
|
# If previous address had an 'End of function' comment or if there was a bctr with the comment
|
||||||
if curr_funct[3] == 'sub' and not curr_funct[2]:
|
if blr_addr == eof_addr or bctr_addr == eof_addr:
|
||||||
xref_idx = line.find('XREF: sub_')
|
# Find a XREF pointing to a .text address
|
||||||
# If XREF is a subroutine
|
xref_idx = line.find('XREF: .text:')
|
||||||
if xref_idx > -1:
|
if xref_idx > -1:
|
||||||
xref = line[xref_idx+10:xref_idx+18]
|
underscore_idx = line.find('_', xref_idx)
|
||||||
# If the XREF is equivalent to the last function's start address
|
if underscore_idx > -1:
|
||||||
if int(xref, 16) == curr_funct[0]:
|
xref = line[underscore_idx+1:underscore_idx+9]
|
||||||
# Store as nested function in latest function
|
|
||||||
functs[num_functs-1][2].append(xref)
|
|
||||||
# If not, add this address as a new function
|
|
||||||
else:
|
else:
|
||||||
add_function(curr_addr_int, curr_addr_int, 'loc')
|
xref = line[xref_idx+12:xref_idx+20]
|
||||||
# If not, add this address as new function
|
|
||||||
else:
|
else:
|
||||||
|
xref = None
|
||||||
|
|
||||||
|
# Couldn't find XREF pointing to .text address or the XREF is after this address
|
||||||
|
if xref == None or int(xref, 16) > curr_addr_int:
|
||||||
|
# Add as new function
|
||||||
add_function(curr_addr_int, curr_addr_int, 'loc')
|
add_function(curr_addr_int, curr_addr_int, 'loc')
|
||||||
|
|
||||||
# If last added function is not a subroutine or has nested functions:
|
|
||||||
else:
|
|
||||||
# Check for XREF to subroutine
|
|
||||||
xref_idx = line.find('XREF: sub_')
|
|
||||||
if xref_idx > -1:
|
|
||||||
xref = line[xref_idx+10:xref_idx+18]
|
|
||||||
# If not found, check for XREF to .text address
|
|
||||||
else:
|
|
||||||
xref_idx = line.find('XREF: .text:')
|
|
||||||
if xref_idx > -1:
|
|
||||||
underscore_idx = line.find('_', xref_idx)
|
|
||||||
# If referencing sub_, loc_, etc.
|
|
||||||
if underscore_idx > -1:
|
|
||||||
xref = line[underscore_idx+1:underscore_idx+9]
|
|
||||||
# Else, there's only the address after .text
|
|
||||||
else:
|
|
||||||
xref = line[xref_idx+12:xref_idx+20]
|
|
||||||
else:
|
|
||||||
xref = '-1'
|
|
||||||
|
|
||||||
# If XREF points to subroutine or .text address before current address
|
|
||||||
if int(xref, 16) < curr_addr_int:
|
|
||||||
# Store as nested function
|
|
||||||
functs[num_functs-1][2].append(xref)
|
|
||||||
# If not, add this address as new funciton
|
|
||||||
else:
|
|
||||||
add_function(curr_addr_int, curr_addr_int, 'loc')
|
|
||||||
|
|
||||||
# If not, store as nested function in latest function
|
|
||||||
else:
|
else:
|
||||||
# Find address of function that references this
|
# Find address of function that references this
|
||||||
xref_idx = line.find('XREF: sub_')
|
xref_idx = line.find('CODE XREF: sub_')
|
||||||
# If it was found
|
# If it was found
|
||||||
if xref_idx > -1:
|
if xref_idx > -1:
|
||||||
# Store as nested function in latest function
|
# Store as nested function in latest function
|
||||||
functs[num_functs-1][2].append(line[xref_idx+10:xref_idx+18])
|
functs[num_functs-1][2].append(line[xref_idx+15:xref_idx+23])
|
||||||
|
|
||||||
# Check if this line is padding
|
# Check if this line is padding
|
||||||
elif num_functs > 0 and re.search('<span class="c[0-9]*">\.long </span><span class="c[0-9]*">0$', line):
|
elif num_functs > 0 and re.search('<span class="c[0-9]*">\.long </span><span class="c[0-9]*">0$', line):
|
||||||
@ -196,9 +174,27 @@ with open(ida_html, 'r') as file:
|
|||||||
pad_addr = curr_addr_int
|
pad_addr = curr_addr_int
|
||||||
|
|
||||||
# Check for blr instruction
|
# Check for blr instruction
|
||||||
elif re.search('<span class="c[0-9]*">blr', line):
|
elif re.search('<span class="c[0-9]*">blr$', line):
|
||||||
blr_addr = curr_addr
|
blr_addr = curr_addr
|
||||||
|
|
||||||
|
# Check for 'End of function' comment
|
||||||
|
elif re.search('End of function ', line):
|
||||||
|
eof_addr = curr_addr
|
||||||
|
|
||||||
|
# Check for bctr instruction
|
||||||
|
elif re.search('<span class="c[0-9]*">bctr$', line):
|
||||||
|
bctr_addr = curr_addr
|
||||||
|
|
||||||
|
# Check for restgprlr instruction
|
||||||
|
elif re.search('<span class="c[0-9]*">b </span><span class="c[0-9]*">__restgprlr_[0-9][0-9]$', line):
|
||||||
|
# Convert current address to integer
|
||||||
|
curr_addr_int = int(curr_addr, 16)
|
||||||
|
|
||||||
|
# Add a new function at the line after restgprlr instruction, and end the current function at this address
|
||||||
|
add_function(curr_addr_int+4, curr_addr_int, None)
|
||||||
|
|
||||||
|
restgprlr_addr = curr_addr_int
|
||||||
|
|
||||||
# If not in .text
|
# If not in .text
|
||||||
else:
|
else:
|
||||||
# If .text section header found
|
# If .text section header found
|
||||||
|
Loading…
x
Reference in New Issue
Block a user