Commit graph

307 commits

Author SHA1 Message Date
Giovanni
c17881ba2f
Initialize RzAnalysisOp properly. (#4350) 2024-03-10 18:26:10 +08:00
Giovanni
c7ddd77546
Remove rz_list_get_top/bottom & rz_list_get_head/tail_data (#4348) 2024-03-09 18:24:23 +08:00
wargio
d47ceedbd3 Merge rz_asm and rz_analysis into one library but keep deprecated apis.
The tms320c64x has been merged into tms320.
2024-03-07 18:38:49 +08:00
Huzaifa
58f7032f26
Add C API rz_debug_switch_to_first_thread() (#4287) 2024-02-26 21:13:33 +08:00
Rot127
a6c7864198
Fix mismatch 'rz_cons_break_push' and 'rz_cons_break_pop' calls. (#4289)
If a function calls 'rz_cons_break_push()' but never calls 'rz_cons_break_pop()' before return,
the stack count of 'RzConsContext->break_stack' contains too many elements (each time one too much).

This in turn will lead to not resetting 'RzConsContext->breaked' flag.
Because the flag is only set to false, if 'rz_stack_is_empty(context->break_stack) == true'
(in 'rz_cons_context_break_push()').

This wasn't a problem so far, because 'RzConsContext->breaked' is simply never set to true
(exceptions are some timeout cases as far as I can see).
Also these cases when 'rz_cons_break_pop()' was forgetten to be called, were edge error cases.
So not often hit.

But if Rizin is usd by Cutter 'RzConsContext->breaked' is set to 'true',
if an `AnalysisTask` interrupt is handled (in 'AnalysisTask::interrupt()').
This interrupt is triggered for example, when the introduction dialog is closed
and the main Cutter window opens (after the optional 'aaa').

Now, if the binary file was analysed with 'aaa', and a lot of error cases were hit,
those error cases sometimes never called 'rz_cons_break_pop()' before returning from their function.
Although, of course, they should have to the `RzConsContext->break_stack` is in a proper state.

This means, when the main Cutter window opens binary files which trigger many error edge cases,
the `RzConsContext->break_stack` is not empty
(because of the not executed 'rz_cons_break_pop()').

This also means, that the last thing done, was setting 'RzConsContext->breaked = true'
(by 'AnalysisTask::interrupt()').

If Cutter wants to show some disassembly, it calls 'rz_core_print_disasm()' which checks
'RzConsContext == false' via 'rz_cons_is_breaked()'. This condition is never true, because
the flag was not reset to `false` because the stack was never empty.
So it returns before anything was disassembled.

Hence Cutter gets no disassembly text.

Fixes https://github.com/rizinorg/cutter/issues/2552
Fixes https://github.com/rizinorg/cutter/issues/3275
2024-02-23 23:50:11 +08:00
Giovanni
2886608d59
Rewrite how rz_cons_pipe_open/close behave to remove globals (#4223) 2024-02-14 09:05:17 +08:00
Giovanni
29b2093650
Fix Windows compilation warnings (#4209)
* Fix 'bool' differs in levels of indirection from 'void *'
* Fix function declaration.
2024-02-12 14:28:04 +08:00
Anton Kochkov
25fd417a28
Add user pointer to RzListComparator (#4204) 2024-02-11 13:28:33 +08:00
Anton Kochkov
85ffa899ec
Remove sdb_fmt() calls in RzDebug (#4135) 2024-01-21 23:24:52 +08:00
billow
5b36c7c6e0
Patch for windows debugger to load libraries (#4113) 2024-01-16 13:55:10 +08:00
billow
acace32cad
Fix windows debug plugin (#4099) 2024-01-13 08:16:38 +08:00
Giovanni
8fba9b4189
Force usage of RzList methods instead of direct access of the fields (#4036) 2023-12-18 21:05:57 +08:00
Riccardo Schirone
3b903caa96
librz: add some initial documentation (#3782) 2023-10-13 13:46:19 +08:00
Riccardo Schirone
a1cb888f95
core/cmd: fix some leftover of ?i command (#3911) 2023-10-05 21:31:21 +08:00
Florian Märkl
f3469946c5 Add specifiable size for watchpoints and tests
rz_bp_size_at() is not always the right size for a watchpoint, so we add
the possibility to specify the size as an extra argument to dmw.
2023-09-16 22:35:20 +08:00
David CARLIER
285ea07ab5
bsd_generate_corefile for FreeBSD adjust version since the feature is available in the 13.2 serie (#3820) 2023-09-03 19:38:40 +08:00
Khairul Azhar Kasmiran
681a6b04b8
Fix #3806: fuzzy dbt checks for CALL indirect on x86 (#3809) 2023-08-31 11:02:28 +08:00
Anton Kochkov
3278ec77d0
ci: use clang-format from LLVM 16 (#3696)
Co-authored-by: wargio <wargio@libero.it>
2023-08-01 09:11:26 +08:00
Giovanni
8efdb3d3a3
Refactoring debug plugin and cleanup output (#3634) 2023-07-04 10:42:41 +08:00
billow
6eb14128ad
Adding tricore support for rz_debug_plugin_gdb (#3557) 2023-06-06 12:53:51 +08:00
billow
73c546ddc0
Fix compile warnings (#3522) 2023-05-23 09:52:47 +08:00
Riccardo Schirone
65e4e9ebd1
Fix few sscanf issues reported by @yeggor (#3428) 2023-03-22 18:36:54 +08:00
Riccardo Schirone
d6196703d8 Fix conversion from GDB register profile to rizin profile 2023-03-14 11:41:29 +01:00
Anton Kochkov
e307b32c6d Fix Linux native debugger compilation for ARM64 2023-02-27 17:03:37 +08:00
Anton Kochkov
c2ecb289ef
Coverity fixes - memory leaks, UAFs (#3335)
* Fix CID 404596 - memory leak

* Fix CID 404594 - memory leak

* Fix CID 404595 - memory leak

* Fix CID 404593 - memory leak

* Fix CID 404592 - memory leak

* Fix CID 404349 - memory leak

* Fix CID 404021 - memory leak

* Fix CID 403816 - memory leak

* Fix CID 403733 - memory leak

* Fix CID 403587 - use after free

* Fix CID 403585 - memory leak

* Fix CID 402981 - memory leak

* Fix CID 402915 - memory leak

* Fix CID 402914 - memory leak

* Fix CID 402911 - memory leak

* Fix CID 402910 - memory leak

* Fix CID 401662 - memory leak

* Fix CID 401542 - resource leak

* Fix CID 400949 - memory leak

* Fix CID 400948 - memory leak
2023-02-02 08:59:07 +08:00
rizan21
cc18d675e6 Use clang-format 15 instead of 14 2023-01-25 22:02:26 +08:00
Riccardo Schirone
e933003b5b
librz: do not duplicate plugins (#3313)
* librz: do not duplicate plugins

Plugins structures are statically defined at the file scope and not
dynamically allocated. Plugins should not allocate them either as
RzLibPlugin keeps a reference to them anyway.
2023-01-23 12:51:09 +00:00
Riccardo Schirone
c4767cf1ac
Fix plugin removal and clean code (#3277)
* cmd: Fix summary of few "L" sub-commands
* util: start decluttering plugins handling

- Add Doxygen docs
- Remove unused API functions and make others internal only
- Use RzLibType enum for plugin type instead of int

* util: move dlopen/dlsym/dlclose to rz_sys
* util: make rz_lib_open/close return bool
* util: simplify rz_lib_add_handler and rz_lib_open*
* libs: implement rz_*_plugin_del to remove a plugin
* core: remove commands from RzCmd when removing plugins
* librz: call plugins 'fini' method when removing a plugin
* core/cmd: do not fail if the hashmap removal fails

When removing a group command, the inner command might have the same
name, thus it would result in trying to remove the same name twice.
Ignore it, as it is fine.

* librz: make RzCrypto plugins handling like the others
* librz/crypto: add rz_crypto_reset and use it
* librz: allocate the plugin structures before adding them
2023-01-16 13:32:46 +01:00
Florian Märkl
0acc7f11a1 Set dbg->bits in debug_dmp
This fixes the last tests in db/formats/dmp on OpenBSD/sparc64.
2023-01-15 19:01:18 +01:00
Florian Märkl
e40d9a6cf3 Fix dmp reg profile depending on host bitness
dbg->bits was checked in reg/windows_arm64.h, but when returning the reg
profile from the dmp plugin, this (deprecated) variable held the host
value when 64 was expected.
So it is better to move this check to the respective points where the
profile file is included.
2023-01-15 19:01:18 +01:00
Florian Märkl
1b4385e224
Make xnu reg profile depend on cpu type instead of RzDebug.bits (#3270)
RzDebug.bits often has nonsensical contents set from all kinds of
places. Specifically, when debugging fat binaries on arm64, it had a
value not matching the debuggee when the reg profile was loaded,
resulting in the arm32 profile being used.
The right way to determine the profile is to do it after attach, when
the cpu type of the debuggee is known.
2023-01-07 17:43:41 +01:00
Giovanni
55e690990b
Fix endianness for win pagedump and winkd (#3204) 2022-12-09 11:41:28 +01:00
wargio
1165b20ee7 arch name is always set in debug native even when the arch is unknown 2022-12-06 10:07:38 +08:00
wargio
bc5eb09782 Removed rzbochs 2022-12-04 16:53:58 +01:00
wargio
a3b8ed48b7 Remove esil debugger since it is a big todo 2022-12-04 16:53:58 +01:00
wargio
f137f983a7 Remove unimplemented methods in debug 2022-12-04 16:53:58 +01:00
wargio
18a4cb5582 Rewrite of bochs debugger and io plugin 2022-12-04 16:53:58 +01:00
wargio
47e674acb6 Adds sync_registers in debug plugin and cleanup brainfuck debugger 2022-12-04 16:53:58 +01:00
Khairul Azhar Kasmiran
0493acc8b8
Fix up rz_debug_trace_ins_after() (#3216) 2022-11-30 23:38:26 +08:00
Khairul Azhar Kasmiran
10858a6f10
rz_debug_trace_ins_after: Downgrade dbg->cur_op guard (#3206) 2022-11-29 19:08:33 +08:00
Khairul Azhar Kasmiran
fc77223448
Print err msgs if rz_debug_trace_ins_before() fails (#3203) 2022-11-27 07:15:26 +08:00
Anton Kochkov
4a037c2f2a
Convert dk commands to the rzshell (#3078) 2022-10-11 18:02:52 +08:00
Anton Kochkov
87e369b9a7
Convert de commands to the rzshell (#3083) 2022-10-10 22:10:48 +08:00
Anton Kochkov
4bf6b67212
Convert dd commands to rzshell (#3049)
* Convert `dd` command to rzshell
* Remove unimplemented `dH` command
* Remove `ddt` command
* Move `date` command to the "shell" category
2022-09-29 08:24:50 +08:00
Anton Kochkov
d0bd24cf26
Convert dp commands to the rzshell (#3047) 2022-09-27 01:21:25 +08:00
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
4e5857cacf
Meson refactor: collect modules in dict and centralize config (#2945)
Duplicated code for pkg-config and cmake configuration is avoided by
letting every rizin module register itself in a global dictionary
called "modules" which is then iterated in one place to perform any
shared logic, inspired by how qemu handles multiple targets in its meson
build system.

This is an almost pure refactor, so the resulting .pc/.cmake files
should be identical with the following exceptions:
- rz_reg.pc does not have plugindir anymore as rz_reg has no plugins.
- Some other modules have their dependencies in .pc files altered to be
  consistent with cmake.
2022-08-20 19:59:27 +02:00
wargio
a73e8ecd4d Add references and flags to constant pointers to data maps 2022-08-13 22:52:24 +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
Florian Märkl
1d88af3c56
Refactor and replace .dm* calls with pure C (#2847)
This fixes the following minor issues:
* Errors like "Cannot create flag (...) because there is already (...)
  flag" during debug startup
* Unnecessary seeks during .dm* causing io reads and e.g. delays of up
  to 5s on x86 macOS during debug startup
* Flags are now created in the "maps" flagspace, rather than globally,
  making them easier to clean up later
* Flags now have the same size as the maps and not +1
2022-07-28 13:40:44 +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
Riccardo Schirone
a689f0a86e librz: refactor a bit how plugins are built
Rely on RZ_ARRAY_SIZE to add librz plugins instead of NULL terminators.
2022-07-20 22:04:02 +02: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
Riccardo Schirone
8939fdbd7d
Use add_global_arguments instead of passing cflags/ldflags all around (#2812)
See also 66a0e22293/docs/TESTING_WITH_SANITIZERS.md (clang)
2022-07-17 21:33:51 +08:00
Anton Kochkov
b2d9429129
Remove sdb json (#1118)
* Drop sdb_json in `librz/cons/grep.c`
* Do not print the JSON key in grep
* Use proper JSON paths in tests
* Use signed number in case of RzJson in tests
* Do not add quotes for sole RZ_JSON_STRING
2022-07-12 22:48:33 +08:00
Peiwei Hu
0fc9c9682e
Fix some checks of rz_analysis_op (#2755)
* Fix some checks of rz_analysis_op
* rm unreachable code
2022-07-01 18:12:14 +08:00
Riccardo Schirone
2987e035da hash: use RzHash in most hash APIs 2022-06-28 21:55:26 +08:00
Riccardo Schirone
9ea7c2fa5a RzHash: rename everything in librz/hash to RzHash prefix 2022-06-28 21:55:26 +08: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
Riccardo Schirone
ce6ac3e467 meson: use major/minor only in the lib soversion 2022-05-10 21:04:43 +02: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
Rot127
10bedc2b00
Add Hexagon register profile (#2490)
Although the reg profile was not really used yet it will be relevant for the RZIL uplifting.
Introduces:
* Double/quadruple registers now properly overlap with their counterparts.
* Registers have correct types assigned (vec, ctr, sys etc. Before, all regs were of type gbr)
* Consistent register names (asm name style: c3:2, r31 etc, alias style: lc1:sa1, lr etc.)
* Adds _tmp registers in the profile. Later used by uplifted instructions (think of .new registers).
2022-04-03 18:26:17 +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