Commit graph

78 commits

Author SHA1 Message Date
Dean
59b38e6efa
Add /*<type>*/ comments everywhere (#2986)
Adds /*<type>*/ comments and a linter check from rz-bindgen to enforce
their existence and consistency

Also includes the following fixes made when adding the annotations:
* removed unused intern_table arguments in pyc_dis.c, pyc_dis.h, asm_pyc.c
* removed unused classes argument from place_nodes in agraph.c
* removed unused recurse and recurse_bb functions in canalysis.c
* removed unused vars field from RzPrint struct
* removed unused RzAnalysisType* structs from rz_analysis.h
* removed unused list field from RzEgg struct
* fixed bug in bp_plugin.c where duplication-checking logic iterates over the wrong list
* removed unused q_regs field from RzDebug struct
* removed unused backtrace field from RzDebugPlugin struct
* removed unused classes_list field from RzBinNXOObj struct
* removed unused methods_list and classes_list fields from RzBinZimgObj struct
2022-09-11 13:04:53 +08:00
Anton Kochkov
6bdcbc5124
Fix unused variable warnings on MacOS ARM64 (#2980) 2022-08-24 18:16:39 +02:00
Florian Märkl
e893d2fb66 Fix arm64 register access in xnu debugger
ARM_THREAD_STATE64 fetches arm_thread_state64_t but our struct was
arm_unified_thread_state_t, which adds a header. The pc in the register
profile was hacked to account for the shift, but all the x-regs were
not, so x7 had the value of x8 for example. Now we just use the specific
state for 32 or 64.
2022-08-07 19:22:40 +02:00
Florian Märkl
8681cdc43b Use cpu_type_t for checking xnu debuggee's arch
This fixes basic single-stepping on macOS/arm64.
dbg->bits is affected by all kinds of things going on in rizin, in
particular it currently randomly switches to 16 when calling pd during
an arm64 debug session, causing the stepping code to break.
We now fetch the cpu type of the process once during attach, similar to
how lldb does it. They also use 0 for the "invalid" value, so we do that
as well.
2022-08-07 19:22:40 +02:00
Florian Märkl
aaa34e9281 Refactor global state of xnu debugger into RzXnuDebug struct
The chained_address in arm32 xnu_modify_trace_bit is left for now since
we don't test this platform yet.
2022-08-07 19:22:40 +02:00
GustavoLCR
d3446789c7 Windows: Various fixes
* Fix some XP incompatibility
* Use wide version of APIs
* Remove unused/unnecessary function pointers
2022-07-24 21:00:51 +08:00
Florian Märkl
97cc3ee4b7 Remove unused variable in xnu_debug.c 2022-07-17 20:31:32 +02:00
Florian Märkl
0d02fdd0c4 Fix rz_xnu_get_cur_thread() messing up the target's mappings
Getting the thread list with task_threads() allocates a mapping in the
caller's memory that should then be freed with vm_deallocate() later.
However rz_xnu_get_cur_thread() was passing the debuggee's task to the
deallocate rather than its own, meaning the thread list would probably
leak and the debuggee's maps would get broken if there was something at
that address.
2022-07-17 20:31:32 +02:00
Florian Märkl
f6664c2cee Fix detaching in XNU Debugger
PT_DETACH must always be called, even when killing the process.
2022-07-17 20:31:32 +02:00
Florian Märkl
e6ab93e4cc Fix attaching in XNU Debugger
ptrace with PT_ATTACHEXC will send a SIGSTOP to the process, which we then
sometimes received in the first mach_msg loop while waiting for hitting a
breakpoint, when having been already attached at this point.
See also bsd/kern/mach_process.c:287 in xnu-8020.121.3.

Correct attaching works like this, in exactly this order:
* posix_spawn the process with POSIX_SPAWN_START_SUSPENDED
* set up the Mach port for receiving exceptions
* ptrace(PT_ATTACHEXC) -> sends SIGSTOP
* wait on the Mach port until receiving the SIGSTOP msg
* call task_suspend
* reply to the msg

Then we have a beautiful process suspended right at the start in dyld.
2022-07-17 20:31:32 +02:00
Florian Märkl
584fb0e4e9 Improve logging for EXC_SOFTWARE on XNU, showing Unix signals 2022-07-17 20:31:32 +02:00
Florian Märkl
c90ebb6b68 De-include xnu_threads.c and xnu_excthreads.c
With XNU_USE_PTRACE removed, these source files can now be compiled as
standalone objects unconditionally.
2022-07-17 20:31:32 +02:00
Florian Märkl
c671083925 Remove XNU_USE_PTRACE
The ptrace-based backend is broken and has been disabled by default
since 2016.
2022-07-17 20:31:32 +02:00
GustavoLCR
8de1000532 Debug: Implement backtrace_generic() 2022-06-05 00:27:35 +08:00
GustavoLCR
aa8fb63b39 WinKD/Windows: Extract common parts to common_windows.c 2022-06-05 00:27:35 +08:00
GustavoLCR
f10e5d865a Debug: Allow dce in all platforms
* Used for `WinKD` and `Windows` debug
2022-06-05 00:27:35 +08:00
Theofilos Pechlivanis
d8ed585cba
Fix minor compiler warnings on i386 (#2585)
* Fix a `-Wpointer-to-int-cast` and a `-Wunused-variable` on i386
2022-05-03 22:23:14 +08:00
Florian Märkl
b40dde5fbf
Move DEBUGGER checks from C to meson.build (#2577)
Entire files are now avoided to be built by checking in meson rather
than using #if DEBUGGER. This now also includes bsd_debug.c, which
is currently slightly broken on OpenBSD/sparc64 and caused compile
errors even with -Ddebugger=false.
2022-05-02 11:22:35 +02:00
Anton Kochkov
b1e48a0c1c
Various Coverity fixes (#2499)
* Fix CID 390322 - memory leak
* Fix CID 390031 - memory leak
* Fix CID 390014 - memory leak
* Fix CID 389941 - memory leak
* Fix CID 389093 - memory leak
* Fix CID 389090 - memory leak
* Fix CID 379250 - memory leak
* Fix CID 378897 - unterminated string
* Fix CID 378854 - memory leak
* Fix CID 373736 - memory leak
* Fix CID 371126 - memory leak
* Fix CID 371089 - memory leak
2022-04-05 22:42:36 +02:00
Riccardo Schirone
962ffe2755 RzDebug/p/native: do not use ptrace with NT_X86_XSTATE if not supported
If the kernel/system where Rizin is currently run does not support
ptrace(PTRACE_GETREGSET, ..., NT_X86_XSTATE, ...), ENODEV is returned by
the kernel. In such cases, we print the error message once and never
execute the ptrace call again, assuming it is not supported.

Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
2022-04-05 14:14:35 +02:00
GustavoLCR
170ab3eb3b
Remove windows.h include from rz_types.h (#2410)
* Create `rz_windows.h`
* Move `RzThread` structure definitions to internal header
* Create and use `rz_th_get_user()` API to avoid exposing `RzThread` layout in external header
* Make `rz_th_self()` an IPI
* Use `_wmkdir()` in `rz_sys_mkdir()` on Windows
* Remove unused `winkd_break_read` function
* Remove `RzIORap` definition from `rz_io.h`
* Remove include of `Windows.h` from `rz_types.h`
* Use `rz_windows.h` when necessary
* Remove `RzCoreRtrHost` definition from `rz_core.h`
* Remove `rz_socket.h` include from `rz_core.h`
2022-03-16 13:54:41 +01:00
GustavoLCR
f4f9471d62
Fix OOB read in backtrace_windows_x64() (#2414) 2022-03-16 10:44:02 +01:00
GustavoLCR
dd81b6629a
Implement getting a backtrace from a Windows Kernel Dump for x64 (#2387)
* PE: Add header to mappings
* PE: Add temp defs for unknown `UNWIND_CODE_OPS`
* Core Bind: Add `RzCoreBinApplyInfo` binding
* DMP/WinKD: Always add kernel modules to mod list
* Implement Windows x64 SEH backtracing
* Fix `ompb` not prioritizing maps
* Optimize `rz_io_map_priorize()`
* DMP: Implement backtrace for x64
2022-03-15 10:45:02 +01:00
Florian Märkl
1d8a2d8871
Fix error reporting for Mach API (#2360)
These functions do not set errno, but indicate their errors through the
return value.
2022-02-23 13:46:03 +01:00
Florian Märkl
3b0b966b29 Remove dbg.bpsize and instead calculate when needed
In practice, dbg.bpsize was always automatically set to
rz_bp_size(core->dbg->bp, core->analysis->bits) whenever the global bits
changed. But this breaks as soon as different bits are needed for where
the breakpoint is supposed to be set vs. the current value of asm.bits
(for example for thumb/arm32).
So this removes the global bpsize and always calculates it for the
specific breakpoint address.
As a sidenote, dbg.bpsize was not even used for manual db (for dcu it
was though).
2022-01-26 17:12:26 +01:00
Florian Märkl
490fb69685 Refactor: Replace corebind by need-driven context in RzBreakpoint 2022-01-26 17:12:26 +01:00
Riccardo Schirone
d8cd049652
Windows on non-x86 arch was still using non-existing RZ_BP defines (#2112) 2021-12-17 19:09:59 +01:00
Dhruv Maroo
34d345d884 Format according to clang-format-13 2021-11-25 15:44:28 +08:00
GustavoLCR
53a7694631
Add support for Windows on ARM (#1502)
* Support building for Windows on ARM

* Fix usage of reserved function name on ARM
* Fix architecture dependent `CONTEXT` fields access

* Fixes for debugging on Windows on ARM

* Fix breakpoint behavior on windows on ARM
* Fix register profile when debugging
* Remove `drx` error message if not supported
* Add support for hardware breakpoints
* Disable support for hardware single-stepping

* Fix Windows Message breakpoints on ARM

* Fix software single-stepping on return instruction on ARM

* Consider link register as destination for return instructions

* Fix setting debug bits to 16

* Rename `r12` to `ip` for windows arm register profile

* Remove debug bits hardcoding on windows

* Add 32bit registers to Windows ARM64 register profile

* Fix software step breakpoint alignment when entering thumb mode

* Define `RZ_TEST_ARCH` for `arm` and `arm64`

* Use `StackWalk64` API for backtracing on Windows

* Fix software single-stepping ARM in thumb mode

* Sync `asm.bits` with debugger

* Cleanup windows_debug.c

* Add SPDX for cross-arm64-windows.txt

* Add floating point control register flags

* Fix Windows Arm register profile alignment

* Keep `drx` warning
2021-11-24 20:13:42 +08:00
David CARLIER
73fa2b30a5
debug: descriptors list netbsd and porting fixes on linux version. (#2018)
took from the linux version, files descriptors per process are stored
 in a similar fashion.
2021-11-24 08:35:01 +08:00
Dhruv Maroo
6da244eca7 Update db commands according to the new syntax after newshell port 2021-10-19 14:20:29 +08:00
Dhruv Maroo
afd1bab3c0
Port db commands to newshell (#1777)
* Add `db` commands in `cmd_debug.yaml`

* Use bool instead of int as return value

* Port `db` commands to newshell

* Fix integration tests. Use `db- <addr>`, instead of `db-<addr>`

* Fix `dbW` handler and update `rz_w32_add_winmsg_breakpoint`

* Remove checks for `argc` in `cmd_debug.c` (from review)

* Fix failing Windows tests

* Change control flow in conditional expressions

* Use `RzCmdStateOutput` in handler for `dbt` to print backtrace in various formats

* Use forward slash (/) instead of pipe (|) for command descriptions

* Use output modes for printing breakpoints in `db` handler

* Remove extra newline while printing breakpoints in JSON format

* Change description for `dbc` command

* Update descriptions and handlers; Remove <addr> argument wherever necessary

* Use `RZ_CMD_ARG_TYPE_CHOICES` for perm in `dbw`

* Add details for `dbC` and `dbw`

* Add quiet printing mode for breakpoints

* Remove unnecessary <addr> argument for `db` commands

 * Also add a quiet output mode for `dbl` and `dbt`

* Return if no breakpoint found in function `add_breakpoint`

* Update tests for new `db` commands

* Update `db` command descriptions

 * Remove `dbi.` redundant command
 * Add details for iterating through the list of breakpoints

* Extract `rz_debug_bp_add_noreturn_func` into `debug.c` as RZ_API

* Fix `dbil` handler and `dbg_bps` test

* Shift the noreturn function breakpoint to `cdebug.c`

* Format according to clang-format

* Fix failing integration tests

 * TODO: Find why `db- @@c:dblq` is failing, and fix the bug

* Update `db` commands

* Use `db- @@c:dblq` instead of `db-*`

 * This will also work as a test for command edits (see https://github.com/rizinorg/rizin/pull/1806)
2021-10-08 21:40:51 +05:30
Anton Kochkov
2b55fe560f Fix Windows building 2021-09-29 09:05:51 +08:00
Florian Märkl
c816630ae4
Fix some null derefs in Windows Debugger (#1748) 2021-09-25 16:58:31 +02:00
David CARLIER
5ec700715a
debug: handle signals on NetBSD and little build fix. (#1719) 2021-09-19 10:52:58 +08:00
DC
efee20738d debug: generate core dump for FreeBSD.
from the 14.x (next) release, since the snapshot update, interface is available
 and allows enough flexibility thus here we re trying to dump data as much
 as possible.
2021-09-09 14:14:26 +02:00
David CARLIER
c913107d91
debug: generate coredump on netbsd. (#1603)
Co-authored-by: Giovanni <561184+wargio@users.noreply.github.com>
2021-09-07 12:08:13 +08:00
Riccardo Schirone
6aef990eef Fix few clang-cl warnings 2021-09-04 12:06:07 +02:00
Riccardo Schirone
dd38e70964
Add some SPDX headers (#1469)
* Add copyright and license to all librz/include/*.h files in dep5

* SPDX headers for most include files except bin/arch/debug

* Add SPDX headers in asm/arch/{8051,arm}

* Add SPDX header for shlr/gdb include files

* Add SPDX header for shlr/bochs include files

* Add SPDX header for librz/reg

* Add SPDX header for librz/debug/p/native/xnu

* Add SPDX header for librz/debug/p/native/windows

* Add SPDX header for librz/debug/p/native/reg include files

* Add SPDX header for librz/debug/p/native/maps include files

* Add SPDX header for librz/debug/p/native/linux include files
2021-08-17 18:27:03 +02:00
GustavoLCR
56841703e1
Various debug fixes (#1359)
* Fix regression showing threads `rip` for `dpt` on Windows
* Improve `dpt` output
* Consider flags too when printing thread address
* Improve `RzCoreBind->getNameDelta` to use realname if `flags->realnames` is true
* Fix negative offsets
* Fix flagspace selection side-effects after calling `rz_core_bin_apply()` APIs
* Fix wrong register profile after attaching to a process with `dpa`
* Fix wrong base address when opening a process memory
* Fix wrong register profile after opening a process memory
* Implement `rz_debug_reg_profile_sync()`
* Fix diff tests
2021-07-27 15:03:08 +08:00
GustavoLCR
69611e103b
Remove RzDebug->user and use RzDebug->plugin_data instead (#1355)
* Remove doubled `rz_reg_set_profile_string()` call in `rz_debug_use()`
* Remove `RzDebug->user` and use `RzDebug->plugin_data` instead
* Fix crashes when switching between `native` and `windbg` debug plugins
2021-07-24 11:13:53 +02:00
GustavoLCR
885c45a699
Refactor Windows debug code (#1318)
* Fix some handle leaks
* Fix some memory leaks
* Re-use handles if possible
* Avoid allocations inside loops in `w32_desc_list()`
* Use debug plugin functions instead of reimplementing logic in io_debug.c and io_w32dbg.c to maintain state consistency
* Remove unneeded code
* Rename some functions
2021-07-19 18:22:54 +08:00
GustavoLCR
1ab628d83d
Fix some clang-cl warnings (#1298) 2021-07-15 12:15:17 +08:00
David CARLIER
168e713efd
Fix few build warnings on macOS (#1229) 2021-06-20 10:05:06 +00:00
Florian Märkl
78652caaf5 Add user pointer to RzDebug Plugins and Refactor GDB for it 2021-06-14 11:46:17 +02:00
Florian Märkl
6fa3bba0f2 Make w32dbg_wrap Init Lazy on Get instead of Execution Order-dependent 2021-06-14 11:46:17 +02:00
Florian Märkl
8e97bf218f Replace rz_buf_new() by rz_buf_new_with_bytes(NULL, 0) 2021-05-30 10:53:13 +02:00
Florian Märkl
0e00ade846
Fix FreeBSD Build for removed KF_TYPE_CRYPTO (#1023) 2021-04-14 23:15:57 +02:00
Khairul Azhar Kasmiran
d5aa6ecce9
Fix -Wstringop-truncation warnings in optimized asan build in rizin code (#794) 2021-03-08 21:12:18 +08:00
Riccardo Schirone
53bf5c497f SPDX Copyright text for all files based on history
- Add LICENSES directory
- Download additional licenses used
- Add .reuse directory
- Add doc about SPDX/reuse

Co-authored-by: Florian Märkl <info@florianmaerkl.de>
2021-03-05 19:39:15 +08:00