Skip to content

Instantly share code, notes, and snippets.

@dneprDroid
Created June 10, 2024 19:59
Show Gist options
  • Save dneprDroid/43f2e020a50401504353b7c736ea8ee5 to your computer and use it in GitHub Desktop.
Save dneprDroid/43f2e020a50401504353b7c736ea8ee5 to your computer and use it in GitHub Desktop.
lldb-plugin.py
import lldb
"""
in lldb shell: command script import ~/Desktop/safari-debug/scripts/mylldb.py
"""
def __lldb_init_module(debugger, internal_dict):
# debugger.HandleCommand('b CC_SHA1_Update')
debugger.HandleCommand('breakpoint set -n CC_SHA1_Update '
'--breakpoint-name CC_SHA1_Update')
debugger.HandleCommand('breakpoint command add --python-function '
'mylldb.on__CC_SHA1_Update '
'--stop-on-error true CC_SHA1_Update')
debugger.HandleCommand('breakpoint set -n CC_SHA1_Final '
'--breakpoint-name CC_SHA1_Final')
debugger.HandleCommand('breakpoint command add --python-function '
'mylldb.on__CC_SHA1_Final '
'--stop-on-error true CC_SHA1_Final')
def on__CC_SHA1_Final(frame, bp_loc, internal_dict):
context = frame.register["x1"].unsigned
print(f"----------- CC_SHA1_Final -----------")
print(context)
return False
def on__CC_SHA1_Update(frame, bp_loc, internal_dict):
process = frame.thread.process
ok, errorMsg = _readFrameData(process, frame, frame.GetFunctionName())
if not ok:
print('error: ', errorMsg)
return False
def _toHexStr(bdata):
return ''.join([('\\x%x' % x) for x in bdata])
def _readFrameData(process, frame, functionName):
context = frame.register["x0"].unsigned
my_address = frame.register["x1"].unsigned
my_data_size = frame.register["x2"].unsigned
print(f"----------- {functionName} -----------")
print(context)
if my_data_size <= 0:
return False, "Invalid data size: %i" % my_data_size
error_ref = lldb.SBError()
buffer = process.ReadMemory(my_address, my_data_size, error_ref)
if error_ref.Success():
print(" Raw: ", buffer)
print(" Hex: ", _toHexStr(buffer))
return True, None
return False, str(error_ref)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment