Commit graph

44 commits

Author SHA1 Message Date
billow
8e29b959b8 DWARF improve DWARF5 support and refactor
- `RZ_PROJECT_VERSION` 14
- Add `RzCallable`.has_unspecified_parameters
- Add `RzAnalysis`.debug_info
- Add `RzAnalysisVarStorageType` composite and `eval` `pending`
- Support for parse DWARF section "debug_loclists", "debug_ranges", "debug_rnglists"
- Partial support for eval DWARF expr_loc
- Support for anonymous Type, function variable, struct member
- Cache all DWARF information in `RzAnalysisDebugInfo` and remove `SDB` based caching.
- Add arm32, arm64, TriCore DWARF register name
- Fix same name basetype
2023-08-25 23:32:05 +08:00
Peiwei Hu
a5780a3855
Refactor imports-related stuff from RzList to RzPVector (#3781)
+ Switch the member imports in RzBinPlugin from RzList to RzPVector
+ Also switch the member imports in RzBinObject from RzList to RzPVector to meet the refactor of RzBinPlugin
+ Modify the traverse and invocation related to the aforementioned changes
+ Remove the deprecated API rz_bin_get_imports
2023-08-24 16:14:32 +08:00
Gleb Popov
30ba928f54 test/unit/test_analysis_var: Use types DB from the build dir. 2023-08-03 15:35:25 +08:00
Anton Kochkov
8e41d975bf
Easier API for creating global variable (#3655) 2023-07-11 20:53:34 +08:00
Anton Kochkov
8c1ce710e1
Remove type links and use global vars (#3618) 2023-07-03 02:02:12 +08:00
billow
d0732c5c88 Update tests 2023-06-05 22:41:20 +08:00
billow
c0154a26a0
Fix function arguments augmentation with DWARF (#3530)
* Add `VariableKind` to Dwarf `Variable`
* Refactor `rz_analysis_dwarf_integrate_functions`
* Add `RzAnalysisVarKind` to `RzAnalysisVar`
* Add function parameters tests for x86, ARM, Tricore
2023-05-30 16:40:09 +08:00
billow
9497f711eb
Add project migrate v12 (#3515)
* Revert rzdb change in 59f32b6db8
* Add `rz_project_migrate_v11_v12` and integration test
* Add v12 rzdb
2023-05-17 06:28:39 +08:00
Anton Kochkov
309398b1ca
Add RzBin symbols API test (#3458) 2023-04-13 19:35:41 +08:00
brightprogrammer
16e722cffc
Replace rz_core_cmd0 calls in tui/panels.c and port cmd_help commands to RzShell as cmd_math (#3421) 2023-03-30 18:36:48 +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
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
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
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
Florian Märkl
6479bd53ab
Add missing project migrations tests up to v9 and fix leaks (#3205)
Even though many of the migrations were trivial, for all previous
versions X it is important to have both tests for X->X+1 migrations
and loading X in current rizin.
See leading comment in test_project_migrate.c for details.
Leaks detected by these tests were also fixed.
2022-11-27 09:39:10 +08:00
wargio
fbad0b4859 Remove agd and add rz_analysis_similarity/match + refactoring
- Introduce the following new methods:
  * `rz_analysis_similarity_basic_block()`
  * `rz_analysis_similarity_function()`
  * `rz_analysis_similarity_basic_block_2()`
  * `rz_analysis_similarity_function_2()`
  * `rz_analysis_match_basic_blocks()`
  * `rz_analysis_match_functions()`
  * `rz_analysis_match_basic_blocks_2()`
  * `rz_analysis_match_functions_2()`
- Remove `RzAnalysisDiff` and its usages
- Remove `librz/analysis/diff.c` entirely to and adds `librz/analysis/similarity.c`
- Remove a lot of unused structures and simplified the code by a lot
- Fix typo in levenshtein
- Remove `librz/core/gdiff.c` and `gdiff` functions since they were unused or only used in rz-diff
- Remove `difftype` (or "color") from `RzANode` which lead to dead code
- Decrease serialized data in projects.
- Add `RzAnalysisVarKind` and `RzAnalysisVarType` and replaces all the hardcoded values
- Remove command `agd`
- Remove all `rz_core_gdiff` usages from `rz_core.h`
- Refactor `rz_analysis_var_list` and `rz_analysis_var_count` due unused argument (`RzAnalysis` was not used)
- Add new method `rz_analysis_var_count_total` to simplify some usages
- Remove `rz_core_graph_diff`
- Add `typedef RzAnalysisFcnType` on `enum``used for function types
- Remove unused `RZ_ANALYSIS_FCN_VARKIND_LOCAL`
- Remove from `RzAnalysisFunction` the following variables:
  * `fingerprint`
  * `fingerprint_size`
  * `diff`
  * `diff_ops`
  * `diff_thbb`
  * `diff_thfcn`
- Remove from `RzAnalysisBlock` the following variables:
  * `fingerprint`
  * `diff`
- Remove `RZ_ANALYSIS_THRESHOLDBB` and `RZ_ANALYSIS_THRESHOLDFCN`
- Remove the following callbacks from `RzAnalysisPlugin`
  * `RzAnalysisDiffBBCallback`
  * `RzAnalysisDiffFcnCallback`
  * `RzAnalysisDiffEvalCallback`
- Fix fancy table columns/rows when a color string is in a cell
- Bumped project version to 9
2022-10-04 20:02:35 +02:00
billow
46a1929397
Refactor rz_core_analysis_graph*() functions (#2949)
- fix `ags` and `agl` commands
- add more tests for the `ag` commands
- move graph related code to cgraph.c
- remove APIs `rz_core_print_bb_custom` `rz_core_print_bb_gml`
- exports
    - `rz_graph_drawable_to_json_str`
    - `rz_graph_drawable_to_cmd`
    - `rz_graph_drawable_to_gml`
    - `rz_core_graph`
    - `rz_core_graph_diff`
    - `rz_core_graph_format_from_string`
    - `rz_core_graph_type_from_string`
    - `rz_core_graph_write`
    - `create_agraph_from_graph_at`
- add unit/integration tests for the graph API
2022-08-29 22:48:23 +08:00
Riccardo Schirone
02a0b7a1ad core/cmd: just store RzCore reference instead of void *data 2022-08-26 07:53:43 +08:00
Riccardo Schirone
ac1b0e4d94
core/cmd: fix CHOICES argument selection between choices_cb/choices (#2932) 2022-08-18 20:10:13 +08: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
Riccardo Schirone
1331474286 test: Use rz_file_tmpdir to have temporary dir 2022-07-17 12:11:13 +02:00
Giovanni
2e0d490d2f
Add RzBaseFindOpt for custom thread status callback (#2768) 2022-07-06 11:34:00 +02:00
Giovanni
f355dcf557
Add RzBinStrDb and api to interact with it via rz_bin_object_string_* (#2754)
* Add RzBinStrDb and api to interact with it via rz_bin_object_string_*
* use update instead of insert
* check for null deref in rz_analysis_set_stringrefs
* Never delete strings just add them and fixed comments
2022-07-01 06:34:41 +08:00
Giovanni
ea02b0d25f
Remove zignatures and move aaF[l] -> F[al] , zf[sdc] -> F[sdc] (#2682) 2022-06-29 07:49:43 +08:00
Giovanni
6f6ae6e019
Rename rz_arch to rz_platform (#2708) 2022-06-22 17:22:13 +02:00
Riccardo Schirone
6f8a59072c test: allow to run unit tests without installation 2022-05-10 16:57:44 +02:00
Riccardo Schirone
27e0d7ae82
RzBin: improve handling of addresses in ELF (#2591)
* RzBin/ELF: avoid the creation of useless flags at 0

Use UT64_MAX as an error value for addresses like symbols, imports,
sections, etc., and do not create flags for those because they are not
meaningful. This is useful for imports that do not have an address in
the virtual/file space and for non-alloc sections (e.g. .comment).
2022-05-10 10:17:35 +08:00
Riccardo Schirone
474effacc6 RzBin: add APIs to convert paddr/vaddr addresses based on binary info 2022-05-06 18:09:17 +02:00
Giovanni
f87025d1e8
Remove cb_printf() from RzBin (#2446)
* Remove `cb_printf()` from RzBin
* Removed `bin.rawstr` from `rz-bin`
* Dropping `izzz` since does the same as `izz`
* Fix PE one section executables
* Fix behaviour of BFLT, LE, and SMD bin plugins
2022-03-26 20:30:55 +08:00
Riccardo Schirone
7f19c8f867 Split unit and integration tests 2022-03-23 10:34:53 +01:00
Florian Märkl
f9e01ba07d [RzIL] Rewrite RzAnalysisRzil as RzAnalysisILVM with config
RzAnalysisILVM wraps around the low-level RzILVM and enables emulation
of real code from disassembly, rather than raw IL.
Analysis plugins now don't actively initialize the vm anymore, but
return a fully declarative description RzAnalysisILConfig of how to set
up the vm and optionally its initial state.
This also enables multiple IL vms to exist at the same time as plugins
can not mess with the global vm anymore. See the added integration test
for an example.
2022-01-17 16:50:40 +01:00
Khairul Azhar Kasmiran
906ece4211
Add asan build for clang (#1910) 2021-11-17 21:02:02 +08:00
Riccardo Schirone
9c3e6c15b4 Add few unit tests for @ autocompletion 2021-10-27 09:31:50 +02:00
Giovanni
215113b49e
Fixed build warning (#1832) 2021-10-13 17:38:08 +02:00
Dhruv Maroo
a25ef4e9c6
Add rz_deflate* functions and save projects in compressed format (#1446) 2021-08-30 16:54:09 +08: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
Alexis Ehret
1c7daaf12e
Modification of rz_buf_read* API (#1440)
* Small cleanup RzBuffer constructors
* Small cleanup RzBuffer methods
* Refactor rz_buf_read* for a better error handling
* Add documentation for RzBuffer API ##doc
2021-08-16 18:23:46 +08:00
Aswin C
93defcfb4b
Fix the broken integration test for CPU profiles (#1307)
* Use resource packing and fix the broken integration test for CPU profiles
* Use `sizeof` to calculate size and run `clang-format`
* Use `rz_file_temp` to create a temporary SDB file rather than manually naming it
2021-07-15 10:13:57 +02:00
Aswin C
dafa52b48b
RzArch: Fix clang-ci and Coverity warnings (#1302) 2021-07-13 10:15:11 +02:00
Aswin C
a07663a212
Add integration test for CPU and Platform profiles. (#1271)
* Add integration test and a fix Coverity scan issue

* Return `NULL` if `target->platforms` is `NULL` in
`rz_arch_platform_target_new`

* Move the call of the API which adds the flags/comments for both
CPU and platform profiles inside `rz_core_analysis_all()`.

* Use `rz_file_is_directory` instead of `rz_file_exists` for the
integration tests

* Use `RZ_SYS_DIR` on the path while checking for `.tmp` folder

* Add a comma at the end of the list on \`meson.build\`
2021-07-07 15:16:51 +08:00
Riccardo Schirone
28faeff9ef
Use rz_file_is_directory to check if the directory .tmp already exists (#1273)
* Use rz_file_is_directory to check if the directory .tmp already exists
* Update test/integration/test_open_analyse_save_load_project.c

Co-authored-by: Giovanni <561184+wargio@users.noreply.github.com>
2021-07-06 22:04:20 +08:00
Florian Märkl
d0c66d2724
Add Integration Test for RzBinVirtualFiles without RzCore (#1186) 2021-06-03 12:06:34 +08:00
Florian Märkl
b212b462d6 Clean up RzCoreFile 2021-05-01 20:41:29 +02:00
Anton Kochkov
80b41ed827 First integration test 2021-04-12 20:13:05 +08:00