-
-
Save jvns/7f1eff7cdda26412cc8df280a1641fd4 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 | |
import os | |
import json | |
def format_variable(variable): | |
data = variable.GetData() | |
as_bytes = list(data.uint8) | |
return { | |
"name": variable.name, | |
"address": variable.address_of.value, | |
"size": variable.size, | |
"data": as_bytes, | |
"type": variable.GetType().GetName(), | |
"value": variable.value, | |
} | |
def format_variables(frame): | |
variables = frame.GetVariables(True, True, True, True) | |
return [format_variable(v) for v in variables] | |
def run(filename): | |
debugger = lldb.SBDebugger.Create() | |
debugger.SetAsync(False) | |
target = debugger.CreateTarget(filename) | |
target.BreakpointCreateByName("main") | |
process = target.LaunchSimple(None, None, os.getcwd()) | |
while process.GetState() == lldb.eStateStopped: | |
thread = process.GetSelectedThread() | |
frame = thread.GetSelectedFrame() | |
line_number = frame.GetLineEntry().GetLine() | |
if line_number > 100000: | |
break | |
yield { | |
"line_number": line_number, | |
"variables": format_variables(frame), | |
} | |
thread.StepOver() | |
process.Kill() | |
def main(): | |
filename = os.environ["BINARY_NAME"] | |
lines = list(run(filename)) | |
print(json.dumps(lines)) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment