Last active
September 29, 2018 01:28
-
-
Save mikezucc/87dc0692d45033548173bd5539c761fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [ | |
'-[CALayer 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 # this should pause the debugger | |
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 stack_match.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