Commit graph

588 commits

Author SHA1 Message Date
Giovanni
d19fc9d0d8
Add N_THREAD_LIMIT to limit the max number of threads (upper limit). (#4510) 2024-05-24 16:12:08 +08:00
wargio
bce7bd76c1 Refactoring rz-test to use thread safe functions. 2024-05-22 22:27:41 +08:00
Khairul Azhar Kasmiran
84e63af3d2
rz_core_task_join: Return fine-grained error values (#4505) 2024-05-22 12:03:35 +08:00
pelijah
9c34738977
Remove SdbList (#4496) 2024-05-17 19:23:04 +08:00
pelijah
01203509ff
Add extended insert/update methods for HT (#4489)
* Return more info from HT insert/update methods

* Fix bug with tracking

* More doc comments

* Update tests

* Separate extented insert/update methods

* Reuse code

* Update docs

* Fix insert_update() usage

* Rehashing -> modification

* Trigger buckets reallocation

* Return enum
2024-05-17 18:06:01 +08:00
pelijah
706a6bf6c2
sdb: remove unused cas and expire features (#4487) 2024-05-12 18:27:54 +08:00
pelijah
f818ca4296
Refactor sdb_foreach and related APIs (#4471)
* Refactor sdb_foreach and related APIs
* Strengthen bounds check in sdb_dump_next()
* Switch to RzPVector
* Use length info in filter_noreturn()
* Fix cmp function
* Remove unused sdb_like() API
* Pass SdbKv to SdbForeachCallback
* Add sdbkv_dup_value() helper
2024-05-07 07:57:52 +08:00
Khairul Azhar Kasmiran
2efd34a305
rz_core_task_join: Return true on join (#4474) 2024-05-06 21:10:43 +08:00
pelijah
b5898d0203
Add rz_pvector_enumerate macro (#4462) 2024-04-27 11:07:06 +08:00
pelijah
c2e0348437
RzIL: add unit-tests for float cmp helpers (#4458)
* RzIL: add unit-tests for float cmp helpers
* Add NaN cases
2024-04-24 20:09:03 +08:00
Rot127
34f1a9e7b4
Add rz_log and rz_core_notify functions usable with not-formatted strings. (#4448) 2024-04-22 07:31:37 +08:00
pelijah
b8ebd5ac42
Add missing vector foreach macros to clang-format cfg (#4456)
* Add rz_vector_foreach to clang-format cfg
* Add other vector foreach macros
2024-04-22 07:16:46 +08:00
pelijah
11cb44af98
Remove ht_pp.h include from rz_list.h (#4441) 2024-04-18 13:39:49 +03:00
pelijah
f2d8e0db3d
Add HtSP, HtSS, HtSU, SetS (#4415)
- All `ht_*_new0()` are removed
- `freefn` field of HT options was renamed to `finiKV`
- `finiKV_user` fields was added to HT options
- Added `ht_*_new_opt_size` API
- `HtSP` and `HtUP` are created with `ValueFree` callback  that allows to reduce extra LOC and prevent bugs
- `SetP` replaced with `SetS` (based on `HtSP`)
- `rz_th_ht_*_new0()` and `rz_th_ht_*_new_opt()` are replaced with `rz_th_ht_*_new(HtXX *)`
2024-04-16 20:27:48 +08:00
Khairul Azhar Kasmiran
73d85d270a
rz_cmd_desc_get_arg: Remove unused cmd param (#4427) 2024-04-11 17:57:18 +08:00
Florian Märkl
eeda6b1b59 Remove RzFlag.base
The only place where this field was set to a non-zero value was the now
removed fb command, and it was never used for anything sensible. Thus it
is safe to remove.
2024-04-04 13:22:57 +02:00
Rot127
fb6efca4b5
[Hexagon] RzIL uplifiting (#3837)
Uplift Hexagon architecture to RzIL

The general structure is, that every (sub-)instruction has a getter for it's RzIL code.
Calling the getter will return the RzIL operation.
If RzIL for an instruction is requested, the plugin makes a decision. Because Hexagon only executes whole instruction packets. If the instruction is not the last instruction in a packet, it will simply return `EMPTY()`. If the RzIL for the last instruction in a packet is requested, it will get the RzIL operations for all instructions in the packet, shuffles them into the correct execution order (according to some rules) and returns the complete operation for the packet.

The RzIL code was entirely generated with the [rzil-compiler](https://github.com/Rot127/rzil-compiler/), using the semantic definition of the [QEMU Hexagon module](https://github.com/qemu/qemu/tree/master/target/hexagon).

Currently successful compile instructions (and tested):
```
[*] 1581/1733 standard instructions compiled.
[*] 431/643 HVX instructions compiled.
[*] In total: 2012/2376 instructions compiled.
```

It was tested with:
- (Semantic tests) `rz-tracetest` against the execution trace of the QEMU Hexagon test binaries.
- (Bug free and semi-semtantic test) Adding tests which simply execute the test binaries to ensure leak and segfault free execution. Also it is executed until a certain instruction is reached (end of `main` or `loc.pass` symbol), partially testing it executes correctly.

For the uplifting several changes and modernization had to be made:

- Enhance consistency of decoding
  - Allow to disassemble an instruction without copying the result. This is used if the given buffer of instruction bytes is larger than one instruction width. In this case, as many instructions as the buffer can hold are disassembled and buffered for later.
  - Generally enhance buffering of instructions.
  - Allow to mark a packet as valid before it is completely decoded (in case we know it must be valid, e.g. if it is a jump target of a valid packet).
- Fix (hopefully) all memory leaks of the Hexagon plugin.
- Changes to register getters, because RzIL needs finer control to translate alias or explicit register names to their real register.
  - Getter for register name is now done by table, so for future distinction between DSP version we can just select another table.
  - Translation functions from register alias or explicit name to their real register.
  - Each operand contains now it's variable ID (e.g. `d` for register `Rd`) as in the ISA (for mapping in the RzIL code).
- Ease debugging by tracking in more precision, if an instruction is added to a stale, active or new packet.
- Add registers `C20` - `C29` (not yet present in LLVM)
- Some renaming to make the code more readable.
2024-03-22 07:24:56 +00:00
pelijah
d43bb152df
buf_format(): parse format string only once (#4365) 2024-03-17 10:18:56 +08:00
Rockrid3r
b5a703fbc3 fix memory leaks in path_walker 2024-03-16 08:56:50 +00:00
Rockrid3r
6f1de19e04 Updated documentation for rz_type_parse_string_single. Removed remaining comments 2024-03-16 08:56:50 +00:00
Rockrid3r
12ddaa8a27 removed empty lines & comments 2024-03-16 08:56:50 +00:00
Rockrid3r
f64b2f3d26 removed unnecessary offset setup 2024-03-16 08:56:50 +00:00
Rockrid3r
ae0afa109c fix path_walker & add unit tests for offset_by_path 2024-03-16 08:56:50 +00:00
Giovanni
461a2fed87
Remove rz_pvector_index_ptr (#4351)
Unlike rz_vector_index_ptr, which is very important, there do not seem
to be any valid usages of rz_pvector_index_ptr in rizin, cutter or
rz-ghidra that could not be replaced by rz_pvector_at.
In case there will be a use-case for it in the future, it can also be
done by rz_pvector_data(...) + i.
2024-03-10 18:40:26 +01:00
Giovanni
c17881ba2f
Initialize RzAnalysisOp properly. (#4350) 2024-03-10 18:26:10 +08:00
Giovanni
ef0ed21d9f
Convert basic block into RzPVector (#4349)
Co-authored-by: HN026 <plancksconstant01@gmail.com>
2024-03-10 15:59:15 +08:00
Giovanni
64f8a5ae57
Move parse into arch. (#4342) 2024-03-07 23:50:22 +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
Florian Märkl
2a9f765582
Weaken f80 assertions in test_float for non-x86 (#4280)
OpenBSD/sparc64 uses 128-bit floats as long double by default while our
tests seeminly assumed either 64-bit or 80-bit, both of which produce
different results than 128 here. Since 80-bit is x86-specific, we check
only the bits we know will be identical between other architectures.
2024-02-21 15:02:05 +01:00
pelijah
cf62a870ab
Fix several memleaks in regex.c (#4274) 2024-02-20 11:29:59 +08:00
Dhruv Maroo
01c0159f6e Fix the test for ARM and Windows 2024-02-17 15:46:11 +08:00
Dhruv Maroo
87f889efa7 Fix conversion of 80-bit floats
* Add a new unit test for the same
2024-02-17 15:46:11 +08:00
Dhruv Maroo
70fb3be17f 80-bit float initialization works now
* Added a test in `test_float.c` for it
    * It is kind of unfortunate to deal with the idiosyncrasy of 80-bit
      float this way. There are cleaner ways, but they would require
      more refactor, and are probably not worth it since we wouldn't be
      modifying the float code that often.
2024-02-17 15:46:11 +08:00
billow
8026d94b56
rzil: add analysis and evaluation integration test (#4241)
* Try to refactor rz_core_analysis_bytes_il
* Add the RzIterator
* Refactor rz_core_analysis_op_bytes with RzIterator
* Refactor rz_core_analysis_bytes with RzIterator
* Add test_analysis_il
* Fix AnalysisBytesContext_next
* Fix heap-buffer-overflow and UBSan
* Fix use-after-free
2024-02-16 21:10:44 +08:00
Rot127
18a4d71492 Add rz_regex_get_group_idx_by_name() 2024-02-16 16:57:31 +08:00
Rot127
22827fd7ee Add rz_regex_find(). 2024-02-16 16:57:31 +08:00
Rot127
7ab605a142
Add (i)CFG node type annotations + bug fix (#4221)
* Read bytes at curr_op->fail/jump into buffer before decoding them.
* Add meta information of iCFG and CFG nodes to dot graph labels.
* Add subtype annotations to CFG and iCFG nodes.
* Test reading of buffer before node to RzAnalysisOp.jump/fail is added.
* Fix CFG tests by adding node type annotations.
* Add iCFG graph with 'alloc' annotations.
* Wrap ascii annotation symbols in brackets.
* Add doxygen to rz_str_append(f)
2024-02-14 23:40:00 +08:00
Rot127
9b4a93512d
Fix some token patterns for hexagon mnemonics. (#4220) 2024-02-13 17:56:33 +08:00
Anton Kochkov
25fd417a28
Add user pointer to RzListComparator (#4204) 2024-02-11 13:28:33 +08:00
Rot127
fcf4f7182f
Add different types of RzGraphNodeInfos. (#4189)
* Add different types of GraphNodeInfos.

This adds support for multiple graph node infos.
It removes the assumption that information of
a graph node must be some strings and an offset.

* Increase buffer for printing graph node body

* Don't hardcode maximum label size

* Add graph node info for icfg

* Add node type info to CFG.

* Access address members properly for iCFG and CFG nodes

* Update test. Function names are no longer saved.

* Fix reachable double free of label

* Split graph node type from its sub-type to make it less confusing.

* Add integration tests for iCFG nodes.

* Fix, add mising buffer read

* Recognize more calls

* Add test for iCFG generation and its node details.
2024-02-09 22:23:36 +08:00
Huzaifa
e82033d92c
Convert from rz_str_new to rz_str_dup (#4178) 2024-02-07 00:07:53 +08:00
Rot127
5afc51f0e2
Replace current regex engine with PCRE2 (#4185)
* Replace OpenBSD regex library with PCRE2.

PCRE2 has way better performance than the OpenBSD
library (something around 20 times faster).

The following flags are enabled for every pattern:

- PCRE2_UTF
- PCRE2_MATCH_INVALID_UTF
- PCRE2_NO_UTF_CHECK

All the others are optional.

Changes made:

- Adds PCRE2 as subproject.
- Changes the API away from POSIX to PCRE2.
- Edits many regex patterns because:
 - ' ' is skipped in patterns, if the EXTENDED flag is set for matching. '\s' must be set now.
 - '.' doesn't match newlines by default.
- Changes the API so matches and their groups are bundled into PVectors.
- Moves the regex component to rz_util.

* Fix cross build - add copy of PCRE2 dependecy

Meson currently doesn't support subprojects to be native and non-native at the same time.
See: https://github.com/mesonbuild/meson/issues/10947
Unfortunately, sdb depends on rz_util which in turn depends on PCRE2.
Excluding PCRE2 from the native build makes linking of rz_util not possible anymore.
Adding it, will make Meson complain that the dependencies cannot be mixed.

Hence, we compile a copy of PCRE2 for the native build if required.
2024-02-05 12:51:16 +08:00
Khairul Azhar Kasmiran
df6b6a9f17
In group help, indicate detailed help is provided (#4184) 2024-02-03 22:55:24 +08:00
Peiwei Hu
3a2148e1cd
Refactor sections in RzBinPlugin from list to pvector (#4089) 2024-01-11 12:19:22 +08:00
Heersin
48007b4ae0
Adding missing operation in bitvector lib and core theory (#4078)
* Add extra bitvector operations defined in core theory basic extra part

* Add extra bitvector operations test

* Fix bv64 init const overflow in windows x64 test

* Add test case for bv_pred and bv_succ near 0
2024-01-08 23:10:14 +08:00
Anton Kochkov
1f4befd24e Remove global RzLine instance 2024-01-07 22:40:25 +08:00
Peiwei Hu
32491012ee
Refactor the maps in RzBinPlugin from list to pvector (#4081) 2024-01-07 12:42:54 +08:00
wargio
f7589feb05 introduce user pointer in comparator to remove globals in table.c 2024-01-06 23:30:07 +08:00
wargio
b98ba64908 Remove hidden static in rz_analysis_cc_max_arg 2024-01-06 23:30:07 +08:00
Dhruv Maroo
97d336738c
Add a new helper to convert a long double to an 80-bit RzIL float (#4062)
* Add a new helper to convert a `long double` to an 80-bit RzIL float

    * New function: `rz_il_op_new_float_from_f80`
    * New opbuilder: `F80`

* Add test for `rz_il_op_new_float_from_f80`

    * Also add a float format check in `rz_il_sort_pure_eq`
    * Add a few `includes` so that some types are visible
2024-01-03 18:52:58 +05:30