Commit graph

28596 commits

Author SHA1 Message Date
Rizan
bbc5457b7a
Use compiler intrinsics for rz_swap_* functions (#3300)
* Using `__builtin_swap*()` whenever available instead of `rz_swap*()`
* Moved `test_endian()` from test_utils.c to test_endian.h
* Added test cases
2023-01-22 21:30:21 +08:00
Florian Märkl
9703de3099
Set up srht builds to trigger through hottub (#3312)
hottub_trigger is a key added in our hottub fork.
2023-01-21 19:25:33 +01:00
Florian Märkl
b1277a7dc8 Reduce requested op info in go analysis
BASIC supplies all needed info in these cases and is slightly less
expensive than DISASM.
2023-01-21 18:26:11 +01:00
Florian Märkl
b6c9b6ad01 Skip filling IL in x86 if not requested
If not requested, building the IL is an unnecessary overhead.
2023-01-21 18:26:11 +01:00
Florian Märkl
3f4570cd7a
Fix string flag sizes after aar (Fix #3305) (#3307)
Regression from 7af1353166, but most
likely already broken before and only made visible by it: String flags
set from bin had their size set to how many bytes the string takes, but
were overwritten to a size of 1 after running aar.
2023-01-21 15:28:05 +01:00
Giovanni
7af1353166
Use proper methods to detect strings in analysis loop. (#3284) 2023-01-20 12:02:10 +08:00
Giovanni
a13a724550
Fix #3128 - Add overflow checks on dyldcache bin values. (#3303) 2023-01-20 12:01:34 +08:00
Giovanni
907e0981c5
Fix English in docs files and updated/removed some tips (#3299) 2023-01-17 19:49:38 +01:00
Florian Märkl
8f1fdc91d6
Limit op cache in type matching (#3297)
Reduces the peak memory usage of the corkami virtgap.exe test from
1.177GB to 241.9MB (measured with massif).
2023-01-17 15:54:37 +08:00
Riccardo Schirone
30f4d77088
ci: add CI for rz-bindgen (#3285) 2023-01-17 07:02:15 +08: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
7c6579a614 Fix asm.bits-dependent open tests
Passing arch and bits as args instead of commands ensures they take
effect earlier. This fixes these tests on platforms where the default
asm.bits is 32.
2023-01-15 19:01:18 +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
953a81afc0
Make afs respect the cc (Fix #3291) (#3292)
Applying a function signature with afs to a function was using a
combination of the existing args and wrong stack addresses to apply the
args to function variables. This generally resulted in incorrect
locations. Instead, we now use the info from the cc.
2023-01-15 13:40:14 +01:00
Peter B
ca3c77e981
Set refptr for Xtensa l32r opcode for better disassembly output (#3289) 2023-01-15 09:32:37 +08:00
Giovanni
4a9740d11d
Fix pxj output (#3290) 2023-01-14 14:14:34 +08:00
Riccardo Schirone
48ece26787 librz: remove non existing functions 2023-01-12 08:55:58 +01:00
Giovanni
3edb12c2d2
Temporary fix for the meta strings (#3283)
* Temporary fix for the meta strings
* Fix unit test
* Added test for Csl with raw binary
2023-01-11 12:31:49 +08:00
Florian Märkl
70c1a3e109
Fix some tests for platforms without native debugger (#3278) 2023-01-09 17:57:39 +01:00
Florian Märkl
01a82490d7 Raise timeout for some aez tests
On some platforms, the rizin startup itself takes multiple seconds,
which can make these tests timeout even if they would otherwise work.
2023-01-09 10:26:30 +08: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
Florian Märkl
de5aa96af9 Patch Mach-O chained ptrs into sparse overlay RzBuffer
Patching the chained ptrs on the fly during every read as before turned
out to be a major bottleneck on larger binaries. So now we patch
everything once into a sparse overlay buffer, like it is already done in
ELF and classic Mach-O relocs.
2023-01-07 11:04:22 +08:00
Florian Märkl
29adadc2b8 Speed up ppc64 IL tests by not loading hashes 2023-01-07 10:18:57 +08:00
Florian Märkl
d4932d3d2c Avoid syncing regs in between multiple IL steps
When stepping multiple times in the analysis RzIL vm, it is not
necessary to sync the regs from and to RzReg between every instruction,
but only at the beginning and at the end.
The conditions for stepping until an addr and fixed-count stepping are
handled as callbacks inside rz_analysis_il_vm_step_while(), so the sync
logic does not have to be exposed to the caller.
2023-01-07 10:18:57 +08:00
Florian Märkl
d6bd4a57b0
Remove temporary type string conversion in DWARF integration (#3266)
Due to the DWARF parsing having been implemented before proper RzTypes,
it was still generating C-like strings that we then parsed into RzType.
This is fragile and was identified to be a major performance bottleneck
on OpenBSD/sparc64. Instead, we now generate RzTypes directly where
possible.
There are still cases left where strings have to be generated
from those types to be stored in an SDB. This should be changed in the
future too.

rz_type_pointer_of_type() is now also always creating a pointer type of
the given type. Before, it would have failed when the pointee was an
identifier that did not exist in the database. But this may be a valid
case e.g. while still building the database from DWARF and such
sanitization goes beyond what one would expect from
rz_type_pointer_of_type().
2023-01-05 19:14:59 +01:00
Riccardo Schirone
572c26ea6a core/cmd: fix 'sleep' command to consider whole arg 2023-01-05 17:55:18 +01:00
Giovanni
d1ad5b5051
Added missing help for Vb modes in V? (#3265) 2023-01-04 20:56:13 +08:00
Florian Märkl
fa15d2fbab Fix type bitsizes for struct/union member loops
Even if the case is nonsensical in practice, we can't rule out the
possibility that a struct or union may contain itself as a member
(optionally through multiple recursion steps). This must be caught when
calculating the size of the type in order to not recurse infinitely.
Structs containing pointers to itself are not meant by this, as that is
perfectly valid and the size is determined without recursion.
However typedefs and arrays must be taken into account.
2023-01-04 09:39:10 +08:00
Florian Märkl
5a229ca6a7 Fix rz_type_db_get_bitsize() without specifier and add tests 2023-01-04 09:39:10 +08:00
Giovanni
2c91585125
Fix wrong subvar in json (#3263) 2023-01-03 16:53:03 +01:00
Florian Märkl
d9950f7479
Replace bp/sp-vars by generic stack-based ones (#3167)
Variables on the stack are not identified by bp/sp+<offset> anymore, but
by their address from the bottom of the stack frame (RzStackAddr),
independent of how they are accessed.
So now there are only two kinds of variables: stack and register.

This required some major refactoring and other changes:
* RzAnalysisVar.isarg was removed. Whether a variable is an argument is
  now specified implicitly by its storage location.
* Varsub of struct fields had to be rewritten so fields can be queried
  by arbitrary stack addresses using the recently introduced sp
  tracking, as the old approach to fill a list with all fields would not
  work anymore.
* analysis.vars.stackname was removed, new behavior is more similar to
  this being true before.
* Variables will not be created at stack+0 now, because the return
  address is there. Before, vars were only created sometimes in such
  cases.
* Variables created from bp offsets in x86 are not deleted anymore if
  the function's bp_frame is false (see removed
  rz_analysis_function_delete_vars_by_kind(fcn,
  RZ_ANALYSIS_VAR_KIND_BPV); calls). This may lead to some
  false-positive detected variables. Whether this really is a practical
  issue is yet to be seen. At least there are no meaningful tests that
  are broken by this.
* Applying variables from dwarf needed some fixes for determining the
  correct stack locations of variables in order to write meaningful
  tests. The handling is still not entirely correct for all
  possibilities of dwarf info, but at least the changed/added test cases
  are right and serve as a reference for future changes.
* Projects version 11 is introduced.
* afvb commands have been removed, afvs now handles all stack vars.
2023-01-02 11:36:21 +08:00
Dhruv Maroo
3c109be4dc
Fix Coverity defects for RzSubprocess PTY changes (#3260)
* Use the PTY free function
* Pass the pointer, so that the function can modify it
* Also check for NULL before writing out the `new_pty`
* Free the allocated PTY in `init_pipes` before failing
* Add NULL checks for proc before accessing master and slave fd
2023-01-01 15:55:32 +08:00
Dhruv Maroo
61e8ace32a
Fixing some Coverity issues (#3261)
* Use signed long long for `src_readlen`, so we can check for -1

    * Fixes Coverity defect 396947 and 356103

* Replace Unicode quotes with ASCII

* Ue signed structure in case -1 is returned (CID 396933)

* Need signed to check negative (CID 395560)

* Fix memleaks in `test_autocmplt_global`

    * Related CIDs: 356309, 356307

* Set initial value of `ret` to false
2022-12-31 16:57:19 +08:00
Dhruv Maroo
d20f68d7ab
Add *pty API (#3221)
* Initial function signatur and struct for `RzPty` API

* Change type annotation to borrow

* Implement `rz_subprocess_login_tty`

* Add fork mode enum and move pty struct; restructure ifdef guards

* Add rough implementation of forkpty

  * Add `rz_sys` versions for `forkpty` family of functions

* Add forkpty code; Make changes according to review

* Implement forkpty properly and add unit test

  * Add `test_interactive_pty`

* Add documentation

* Remove const in function argument

  * Apparently, MacOS as non-const arguments for `openpty` and `forkpty`

* Add more tests for subprocess forkin using forkpty

  * `test_interactive_pipe_pty`: Create pipes between the slave's PTY
    and master and use them
  * `test_interactive_custom_pty`: Use a custom PTY for the slave

* Add PTY functions exist checks for unit tests

* Move terminal param code inside the forkpty branch

* Add comment about why we need to check `n_bytes = 0` in `subprocess_wait`

* Remove forkpty with a specified `RzPTY`

  * Also, no piping done in forkpty

* Add checks to disallow using `forkpty` with piping

* Make changes according to review

  * No need to check proc file descriptors for -1 in `forkpty` mode, since
    they *will* be -1
  * No need to check `n_bytes == 0` in for `std{out,err}_pty`

* Extract pipe initialization code in `init_pipes` function

* Allow using custom PTY for `rz_subprocess_forkpty`

* Remove const qualifiers for termios and winsize arguments

  * This makes the build pass on MacOS, which does accepts non-const
    arguments

* Change `pid_t` to int so that it compiles on Windows

* Add empty implementation for PTY API for Windows

  * Update function signature for `rz_subprocess_start_opt` for Windows
  * Re-add `#define` for `pid_t` in `librz/socket/run.c`

* Move functions to remove duplicate definitions

* Allow specifying piping options even in `forkpty` mode

    * Only expose the master fd for the streams which have pipe create
      as their piping option

* Add comment about not using `master_fd` directly

* Fix types in definition for Windows

* Free the allocated `RzPTY` object

* Add const qualifiers for `RzPTY` argument

* Assign `fork_mode` and `pty` in all instances of subprocess opt start

    * for good measure

* Compare master fd with -1, not 0

* Remove stray file

* Add second comment about the terminal attribute

* Overhaul the whole PTY implementation

    * Now the caller can either use a pipe or PTY to send and receive
      data from any of the streams
    * Extra option `make_raw` to use the slave PTY in raw mode
    * Add documentation for all the new functions

* Fix UAF bug

* Add error handling for `tcgetattr`

* Move the term param setting code

* Add documentation for the subprocess API and sys API

* Format according to clang-format
2022-12-29 20:38:39 +08:00
Peiwei Hu
276306b587
Add search.case_sensitive for grep case-sensitive/insensitive (#3241) 2022-12-28 09:38:32 +08:00
Peiwei Hu
1938890035
Fix: grep(~) will change the original result when ignores case (#3259) 2022-12-25 08:01:06 +08:00
Florian Märkl
13cd3942d1
Rewrite stack pointer tracking and storage (#3207)
The stack pointer was previously already tracked during analysis for
variables and their accesses, but not stored in any sensible form for
further use. RzAnalysisBlock.stackptr and parent_stackptr were used in
some places, but they had no evident meaning.
Now we store the sp at the entry of a basic block and the difference
from that for every instruction inside the block to allow for efficient
querying of the sp value at arbitrary analyzed addresses.
RzAnalysisFunction.stackptr is now deprecated as its previous use was
primarily as a temporary accumulator, which is now handled locally, but
full removal of it would go beyond the scope here.

asm.stackptr visualizes both the absolute sp value and the delta of each
instruction in disassembly.

Changes in librz/analysis/p fix some test cases with the new tracking.

Introduces project version v10 with sp_entry/sp_delta instead of
stackptr/parent_stackptr.
2022-12-23 15:01:15 +01:00
Rot127
4d9652f331
Add instructions introduced in Hexagon v70, v70t and v73. (#3258) 2022-12-22 21:49:23 +08:00
Dhruv Maroo
a3ebd3fa99
Dalvik disassembly should not throw error for single opcode (#3255) 2022-12-20 22:36:56 +05:30
Riccardo Schirone
f64ef48277 test: fix 'core: ' message in help log error 2022-12-19 11:46:18 +01:00
Riccardo Schirone
efa5598e5e test/unit: Add small unit test for rz_log 2022-12-19 11:46:18 +01:00
Riccardo Schirone
3b685b3f46 core: Users do not care too much about error being 'core' or not 2022-12-19 11:46:18 +01:00
Riccardo Schirone
0ae1ee23a7 util: fix logging of long strings by using RzStrBuf 2022-12-19 11:46:18 +01:00
Anton Kochkov
1d3fbac74a
Add Nord color theme (#3250) 2022-12-18 11:48:15 +08:00
Anton Kochkov
dcaf3ecd69
Add Mars color theme (#3252) 2022-12-17 20:25:41 +08:00
Anton Kochkov
8ec9529a09
Enable trivial-auto-var-init and unsigned-char GCC flags (#3232) 2022-12-17 15:27:15 +08:00
Khairul Azhar Kasmiran
80fb4303a8
gdb_to_rz_profile: Check whether groups exist (#3253) 2022-12-17 13:07:32 +08:00
Dhruv Maroo
f8f042f818
Fix searching for strings in rz-bin when the file format is invalid (#3245)
* Fix searching for strings in `rz-bin` when the file format is invalid

  * Always try with "any" bin plugin before giving up searching a file
  * Add a test in `db/tools/rz_bin` for this

* Remove `EXPECT_ERR` from `rz-bin broken MZ` test
2022-12-15 23:08:48 +08:00
Riccardo Schirone
adf8b0717e
bin/formats/elf: consider stripped bins without sections (#3248)
Backport radare2 commit https://github.com/radareorg/radare2/pull/20864
2022-12-15 20:29:19 +08:00