Skip to content

Instantly share code, notes, and snippets.

@mikezucc
Last active October 9, 2018 01:12
Show Gist options
  • Save mikezucc/c60abd90c7948b694cd61726b9dd3314 to your computer and use it in GitHub Desktop.
Save mikezucc/c60abd90c7948b694cd61726b9dd3314 to your computer and use it in GitHub Desktop.
Stop debugger by loosely matching a stack frame
import lldb
"""
NOTE:
LLDB print adds a bunch of other stuff to the string like in this example
(lldb) script
-- ENTERED PYTHON REPL
>>> print lldb.frame.GetDisplayFunctionName()
::-[ASLayoutTransition applySubnodeInsertionsAndMoves]()
"""
"""
REMEMBER: This is the FILO callstack. It should match the same visual order
that you see in the debugger.
"""
matchingCallStack = [
'-[_ASDisplayLayer layoutSublayers]'
]
initializedParams = False
def stop_matching_stack(debugger, command, result, internal_dict):
global matchingCallStack
global initializedParams
if not initializedParams:
debugger.HandleCommand('expr BOOL $matchedStack = 0x0')
target = debugger.GetSelectedTarget()
process = target.GetProcess()
thread = process.GetSelectedThread()
callStack = [frame.GetFunctionName() for frame in thread.frames]
print callStack
matchingCallStackCopy = list(matchingCallStack)
matchedSignatures = 0
for signature in callStack:
found = False
for requirement in matchingCallStackCopy:
if requirement in signature:
found = True
break
if found:
matchingCallStackCopy = matchingCallStackCopy[1:]
matchedSignatures = matchedSignatures + 1
if matchedSignatures == len(matchingCallStack):
print "Stack Matcher: Matched Stack!"
debugger.HandleCommand('expr $matchedStack = 0x1')
return True
elif matchedSignatures > 0:
print "Stack Matcher: Partial Match: " + str(matchedSignatures)
print process
debugger.HandleCommand('expr $matchedStack = 0x0')
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add -f stackpoint.stop_matching_stack stop_matching_stack')
print 'The "stop_matching_stack" python command has been installed and is ready for use.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment