Commit graph

146 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
5a54787eee
Fix pdb.autoload crash (#2729) 2022-06-23 10:50:11 +02:00
GustavoLCR
3bc60f6800 WinKD: Add nullability/ownership markers to functions 2022-06-05 00:27:35 +08:00
GustavoLCR
951a33c490 WinKD/DMP: Use backtrace_generic() for dbt for arm and x86 2022-06-05 00:27:35 +08: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
GustavoLCR
953ffb47fb WinKD: Switch to current process and thread 2022-06-05 00:27:35 +08:00
GustavoLCR
cd1f5469ab WinKD: Use kernel module address from version packet 2022-06-05 00:27:35 +08:00
GustavoLCR
384cbe6c9d WinKD: Set dbg.bpinmaps to false 2022-06-05 00:27:35 +08:00
GustavoLCR
c8eb8e5082 WinKD: Get x64 frames 2022-06-05 00:27:35 +08:00
GustavoLCR
811a9a2819 WinKD: Fixes for packet sending/receiving
* Ignore resent packets
* Resend packet if we didn't get an ACK
* Break if Ctrl-C is pressed
* Always wait for a state change packet in debug event wait function
2022-06-05 00:27:35 +08:00
GustavoLCR
e63faa6005 WinKD: Fix incomplete register write
* Fix register read size
2022-06-05 00:27:35 +08:00
GustavoLCR
dbed351f19 DMP/WinKD: Basic memory mapping info 2022-06-05 00:27:35 +08:00
GustavoLCR
a73b845304 WinKD/DMP: Use cfgSetI core bind method 2022-05-10 10:22:49 +08:00
GustavoLCR
6b95dc16ae WinKD/DMP: Quote pdbpath for idp command 2022-05-10 10:22:49 +08:00
GustavoLCR
10990d9ce9 WinKD: Fix getting kernel address in early initialization
* Use saved kernel module info gotten from `DbgKdLoadSymbolsStateChange` packet
2022-05-10 10:22:49 +08:00
GustavoLCR
a9ea591ade WinKD: Keep a cache of current thread context 2022-05-10 10:22:49 +08:00
GustavoLCR
3cabf34561 WinKD: Remove winkd_lock_tryenter()
* Use `winkd_lock_enter()` and make it possible to break it through `RzCons`
2022-05-10 10:22:49 +08:00
GustavoLCR
f423a02129 WinKD/DMP: Add verbose logging to winkd_build_profile() 2022-05-10 10:22:49 +08:00
GustavoLCR
e9cffc0afa WinKD: Create profile dynamically if not found
* Download kernel module and PDB
* Load kernel PDB info
2022-05-10 10:22:49 +08:00
GustavoLCR
61235f02a0 WinKD: Fix pids/tids cache
* Fix double-free of name in debug modules list
2022-05-10 10:22:49 +08:00
GustavoLCR
7db85c9a69 WinKD: Disable unimplemented step function 2022-05-10 10:22:49 +08:00
GustavoLCR
10cfd66598 WinKD: Avoid unnecessary re-syncing 2022-05-10 10:22:49 +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
Frankenstein
9b618ca12f
Fixing compilation warnings on RISC-V (#2527) 2022-04-13 21:24:59 +08: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
0c4308d07e
Add module name to PDB flag name (#2435)
* Add PDB flags inside `symbols` flag space
* Use `rz_bin_get_baddr()` in `rz_core_pdb_load_info()`
* Fix tests
2022-03-29 12:49:34 +08:00
GustavoLCR
e945fb0e31 Introduce rz_file_dos_basename() API
Use it whenever we need to interact with paths that can contain `\` as a separator as well
2022-03-29 09:27:51 +08:00
Riccardo Schirone
230652aa98
Add -Wimplicit-fallthrough to meson file (#2438) 2022-03-24 08:27:18 +08:00
GustavoLCR
76c2b1f9f4
DMP: Fill in module->name (#2434) 2022-03-23 13:38:35 +08: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
GustavoLCR
f9568b74dc DMP: Fix using dL to initialize dmp debug plugin 2022-03-03 21:52:41 +08:00
GustavoLCR
cfbb860ddb DMP: Show physical pages if no process is selected
* Fix leak
2022-03-03 21:52:41 +08:00