Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when debugging a binary in relative path #681

Open
negasora opened this issue Dec 18, 2024 · 0 comments
Open

Crash when debugging a binary in relative path #681

negasora opened this issue Dec 18, 2024 · 0 comments
Assignees
Milestone

Comments

@negasora
Copy link
Member

python3 dbg.py a -> works
python3 dbg.py $(pwd)/a -> works
python3 dbg.py ../a -> crashes
python3 dbg.py pls/a -> crashes

dbg3.py:

#For Testing Binary Ninja Debugger

import binaryninja
from binaryninja.debugger import DebugAdapterType
import getopt
import sys

from binaryninja.debugger import DebuggerController,  DebuggerEventType

# Parse command line arguments
opts, args = getopt.getopt(sys.argv[1:], "")

if len(args) < 1:
    print("Usage: python test_debugger.py <path_to_binary>")
    sys.exit(1)

binary_path = args[0]
bv = binaryninja.load(binary_path)

# Ensure analysis is complete
bv.update_analysis_and_wait()

dc = DebuggerController(bv)
dc.adapter_type = 'LLDB'


# Define a callback to capture stdout messages
def stdout_listener(event):
    #how do we get stderr?!?
    print("Event Type: %s" % event.type)
    if event.type in [DebuggerEventType.BackendMessageEventType]:
        print(f"Backend: {event.data.message_data.message}")
    elif event.type in [DebuggerEventType.LaunchFailureEventType]:
        print(f"ErrorMessage: {event.data.error_data.error}")
    elif event.type in [DebuggerEventType.StdoutMessageEventType, ]:
        print(f"Program Output: {event.data.message_data.message}")

# Register the callback
dc.register_event_callback(stdout_listener)

dc.cmd_line = "hi testarg"

# Launch the target
if dc.launch_and_wait():
    pass
    #print("Launch successful.")
    # Resume execution and wait for the target to stop
    stop_reason = dc.go_and_wait()
    # After the target has stopped
    print(f"Stop Reason: {dc.stop_reason_str}")    
else:
    print("Failed to launch the target.")
    
import time

dc.remove_event_callback(stdout_listener)
time.sleep(1)
#Cleanup
del dc
print("Done!")

print("Sleeping")
time.sleep(1)

import sys
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant