Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import idaapi
import idc
# by http://reverseengineering.stackexchange.com/users/2318/w-s
def apply_dif_file(dif_file_name):
print "Applying " + dif_file_name + " to database."
f = open(dif_file_name, "r")
for l in f:
if l.find(":") == -1:
continue
splitted = l.split()
off_in_file = splitted[0].replace(":", "")
initial_byte = splitted[1]
new_byte = splitted[2]
#Converting offset to integer
#After that converting it to the ea
offset = int(off_in_file, 16)
ea = idaapi.get_fileregion_ea(offset)
#converting new byte
new_byte_num = int(new_byte, 16)
log = "Patching 0x" + initial_byte + " to 0x" + new_byte + " at " + "0x%X" % offset + " (ea " + "0x%X" % ea + ")..."
if Byte(ea) == new_byte_num:
print log + " Already patched"
continue
elif Byte(ea) != int(initial_byte, 16):
print log + " Wrong byte " + "0x%X" % Byte(ea) + " detected, aborting!!!"
return
print log
idc.PatchByte(ea, new_byte_num)
f.close()
print "Done patching"
def apply_dif():
f = idc.AskFile(0, "*.dif", "Select .dif file")
if f is None:
print "No file selected"
return
apply_dif_file(f)
apply_dif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.