Commit graph

392 commits

Author SHA1 Message Date
Giovanni
5789f6557e
Threaded analysis matching (#3090) 2022-10-24 00:40:42 +02:00
wargio
50063714f6 Resolve some BE issues on various files 2022-10-20 23:12:58 +02:00
Rot127
36d6c07b75
Fix PPC RZIL endianness issue on SystemZ (#3096)
* Fix endianness issue by passing `cs_ppc_op.reg` instead of `.imm` to cs_reg_name.

The issue with using the `.imm` union member is that it is a `st64` while `.reg` is an enum (on SystemZ 32bit wide).
On little endian systems `.reg == .imm`. Not so on big endian systems. In which
case it is `.reg == .imm >> 32`.

* Set correct test for broken instruction `bne cr5, <target>`.

See issue: https://github.com/capstone-engine/capstone/issues/1914
2022-10-15 20:39:37 +08:00
Giovanni
171612c5e1
Add ssdeep hash (#3084) 2022-10-10 17:03:26 +02:00
Giovanni
16230bfc57
Fix doxygen typo (#3065) 2022-10-05 11:58:18 +02: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
Giovanni
4d510733ba
Remove unused fingerprint callbacks (#3037)
* Remove unused fingerprint_fcn callback
* Remove unused fingerprint_bb callback
2022-09-19 11:04:32 +08:00
wargio
b35d3ea195 Fix #3032 - Fix oob read in dwarf_process.c 2022-09-17 18:37:54 +02:00
Giovanni
c5ce00e5bb
Remove sdb_fmt from analysis (#3029)
* Remove sdb_fmt from analysis/analysis.c
* Remove sdb_fmt from analysis/fcn.c
* Remove sdb_fmt from analysis/var.c
* Remove sdb_fmt from analysis/cc.c and replace RzStrBuf with rz_str_newf
2022-09-17 15:42:58 +02: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
Giovanni
008363fcc4
Fix #2851 - wrong AVR analysis jump value for rjmp/rcall (#3012) 2022-09-07 23:00:23 +02:00
wargio
f674aecd20 fix #2971 - null deref dwarf_process.c 2022-08-24 08:26:37 +08:00
billow
4b385978a1
Convert ag to rzshell (#2916)
* `BROKEN=1` for `ag[df]`

Co-authored-by: Anton Kochkov <anton.kochkov@gmail.com>
2022-08-22 08:16:14 +08: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
Florian Märkl
7cc70d80b0
Fix oob read and endian dependency in asm_ebc (#2929)
Fixes all tests in test/db/asm/ebc on big endian. Tested on
OpenBSD/sparc64.
Also fixes oob reads in cases like `rz-asm -a ebc -d cc`.
2022-08-17 21:58:06 +08:00
Giovanni
eedfde9e97
Ensure RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE always return at least 1 (#2917) 2022-08-15 01:15:31 +08:00
wargio
25ff470ecd Removing dead code in esil.
Before this fix, rz_analysis_archinfo(RZ_ANALYSIS_ARCHINFO_DATA_ALIGN) always returned -1
because the RZ_ANALYSIS_ARCHINFO_DATA_ALIGN value was not set in the switch;
when the code was refactored, this broke esil because several checks that were always set
as true, now were actually correctly executed.
To resolve this the dead code has been removed.
2022-08-13 22:52:24 +02:00
wargio
a2925b7df5 Fixed OOB read in 6502 analysis plugin. 2022-08-13 22:52:24 +02:00
wargio
a73e8ecd4d Add references and flags to constant pointers to data maps 2022-08-13 22:52:24 +02:00
Rot127
bd30920c60
Add forgotten cases from #2908 (#2911) 2022-08-13 10:26:39 +08:00
Rot127
07b2358120
Fix #2904 (#2908)
* Remove Capstone v3/v5 unsupported instructions.

They are remove because non of them were implemented.

* Add include guard for instructions not present in Capstone v3.
2022-08-12 02:18:50 +08:00
Rot127
b46e7bd4f2
PPC uplifting to RzIL (#2823)
* Print a warning if config for VM was NULL.
* Add warning if register is not added to VM due to overlap.
* Update PPC register profile.
* Add vector and float registers. As well as some control and system registers.
* Enable to write values 4bit registers.
* PPC: Uplift most common instructions.
* Print warning if reserved SPR instruction is encountered.
* Update PC/LR addresses and add ca32 writes.
* Write cache needs to get flushed so load and store tests don't share the same memory.
* Add missing T/F branch mnemonics.
* Add Move to/from CR/CR0-7
* Fix TA address calculation for branch instructions.
* Add branch tests for branch mnemonics.
* Add XNOP
* NOP cache touch instructions.
* Add undocumented ATTN instruction to the not_implemented group.
* Add isel instruction.
* Implement CRCLR, CRSET, CROR.
* Add CNTLZ instructions.
* Add mcrf instructions.
* Add inacive test for cmpb.
* Add Load bytes reverse instructions.
* Add test and add address alignment to dcbz.
* Add eqv test
* Correct DIV and MUL operations
* Add div tests.
* Add tests and correct MT/MFXER
* Remove register ca32, ov32
* Remove explici setting of cr register because QEMU does not do it. Otherwise we get a mismatch in the trace
* Simplify carry set for add and sub. Sub instructions are exclusivly defined with addition. Hence no sub case needed.
* Unify BD and fix branch instructions. Fix: Check the single bit not the cr reg
* Document Conditional branches and replace NOPs with EMPTY
* Add mulli instruction to double word instructions.
* Fix ca set for shift instructions:
* ca value had to be determined before the shift happened. The wrong ca value was calculated if the src and target reg were the same.
* Replace NOP wit EMPTY.
* Use MSB isntead of SLT.
* Brought fixup of ADD and SUB instructions: The add and sub instructions had several issues which let to incorrect execution.
* The carry was incorrectly if three add operations happened (only the last add were checked, not both).
* The carry was incorrectly set if the src and target register matched.
* Same applies for the CR bit.
* It was too complex. Several local variables were introduced for this.
* Set result in local var, since it would change if src and target reg are the same.
* Remove MTMSR and MFMSR since it is too complex and untestable currently.
* Use unsigned int for shift. Otherwise the 0x1c shift produces a runtime error since 0xf is int as default.
* Fix mtxer: Only write flag bits.
* Let NOT_IMPLEMENTED macro return NULL.
* Mark st[wd]cx and l[wd]cx as not implemented.
* Increase dcache_line_size to 128 bytes.
* Fix cntlz for ppc32. m was set incorrectly, since it is 0 not 32 for 32bit cpus.
* Fix isel: Use op.crx reg instead of imm.
* Unify helper function names: Prependnig `ppc_` mark as IPI
* Add more "Move to SPR" cases.
* MULLI opeartes only on double word on 64bit CPUs.
* Most registers are now assigned the control register type and no longer show up in the ar command.
* Fix xor if dest and src registers match by saving result in local var.
* Fix BE/LE issue for Load BRX instructions.
* Fix shifts: Use only lower 6bits of n.
* User Pure local variables for ROT macros.
* Fix rldimi instructions.
* n was not inverted.
* more than 6 bits of n could be used
* Add 32bit emulateme tests.
* Add 64bit emulateme tests.
* Determine lg(v) in inline function.
* Calculate CR bit in C not in the VM.
* Check if `~mask = 0` and skip mask calculation if yes.
* Check for `sh == 0` and skip rotations where possible.
* Remove `la` instruction. `la` is a mnemonic for `addi`.
* Remove SPR instructions which are not supported by QEMU or not traced yet. For most set/read SPR instructions QEMU segfaults.


In case of SPR 1 (xer), 8 (lr) and 9 (ctr) the assembler resolves them to their mnemonics (mtxer, mtlr etc.). This means the code here is never reached.
To test the get_xer code MFXER was added again. The rz-tracetests will fail for this instructions (due to missing ca32, ov32). But this case is covert in an issue.
2022-08-11 08:41:15 +08:00
wingdeans
a6a7a5f530 Fix annotation inconsistencies 2022-08-03 00:29:56 -04:00
Dhruv Maroo
d44b5748eb
[RzIL] IL lifting of SuperH ISA (#2518)
* Add an assembler for the SuperH ISA
	* Rewrite GPL GNU disassembler code
2022-08-02 02:37:03 +05:30
pluswave
68f6f71fd2
ARM esil32: ldr reg, [pc, reg] correct (#2826)
* ARM esil32: ldr reg, [pc, reg] correct
* Fix test for db/esil/apple
2022-07-22 09:23:40 +08:00
Dean
6b7ea38969
Prepare headers for rz-bindgen (#2786)
* add some missing /*<types>*/ to rz_core, bin, analysis, cons
* add annotation attributes for rz-bindgen
* fix extern "C" in some headers
* rename RzBuffer functions from length to len
* fix rz_core_analysis_name naming conflict
2022-07-22 01:09:19 +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
GustavoLCR
51cb80569a Remove globals from 8051 code 2022-07-20 00:09:05 +08:00
GustavoLCR
57831ae5ae Remove globals from pyc code 2022-07-20 00:09:05 +08:00
Rot127
2e48303443
TMS320 and TMS320c64x register profile (#2805) 2022-07-19 18:08:43 +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
6c665c6098 Use Rizin specific macros instead of the ones from SDB 2022-07-17 12:11:13 +02:00
Mario Haustein
2b8104bc5e Fix capstone include directory 2022-07-07 21:12:27 +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
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
Giovanni
6f6ae6e019
Rename rz_arch to rz_platform (#2708) 2022-06-22 17:22:13 +02:00
Dean
bf2871c7eb
Add dotnet PE support (#2528)
* Add CIL support

* refactor dotnet parsing to pe/dotnet.c
* parse PE CLR metatables (based on yara implementation)
* use CLR methoddefs to add binsymbols (including method namespace/class)
* parse CLR method headers
* CIL disassembler using .NET opcodes.def
* CIL analysis plugin
2022-06-21 09:20:47 +08:00
GustavoLCR
d8dd2c5097 Add analysis.jmp.tblmaxoffset configuration option
Allows the user to configure the maximum offset from the jump table jump instruction to consider it valid
2022-06-19 18:41:08 +08:00
GustavoLCR
2eba4e190d Analysis: Avoid reloading analysis plugin 2022-06-19 17:29:42 +08:00
GustavoLCR
399a9f83ba ArchPlatform: Save plat target path to avoid reloading 2022-06-19 17:29:42 +08:00
GustavoLCR
7d06f5cbb8 ArchProfile: Save current arch/cpu pair to avoid reloading 2022-06-19 17:29:42 +08:00
Dhruv Maroo
b2d84a9796
Replace IL opbuilder macro NOP with NOP() to make it more intuitive (#2705)
* Also, undef `EMPTY` in `rz_il_opbuilder_end.h`
2022-06-19 10:12:26 +08:00
GustavoLCR
fc99ec8484 Debug: Fix x86-32 EIP tracing 2022-06-03 19:50:52 +02:00
Florian Märkl
bc595b6c72
Change arm64 REGBITS assert to regular check (#2631)
Many instructions like str coming from capstone can also have for
example d-registers in them, which we do not implement yet. But we
should not fail an assertion in these cases.
2022-05-24 08:57:41 +02:00
wargio
31d2976731 Fixed analysis for ppc and riscv 2022-05-18 19:24:53 +02:00
Riccardo Schirone
e36d66abe7 Remove analysis.endsize config
Commit taken from radare2 project:
03afa631ff37ecb7585d3d4bb052f7208e68c25dA ("Kill anal.endsize ##anal")
2022-05-18 10:25:01 +02:00
Anton Kochkov
2188b4564d
Various Coverity fixes (#2615)
* Fix CID 392733 - memory leak

* Fix CID 392732 - memory leak

* Fix CID 392730 - memory leak

* Fix CID 392729 - memory leak

* Fix `rz_analysis_diff_free()` API function

* Fix CID 392685 - memory leak

* Fix CID 392012 - use after free

* Fix CID 391968 - uninitialized pointer read

* Fix CID 391966 - memory leak

* Fix CID 391964 - uninitialized pointer read

* Fix CID 390013 - memory leak

* Fix CID 389939 - memory leak

* Fix CID 379249 - memory leak

* Fix CID 378881 - uninitialized scalar variable

* Fix CID 378973 - uninitialized scalar variable

* Fix CID 378850 - uninitialized scalar variable

* Fix CID 371079 - memory leak

* Fix CID 367478 - memory leak

* Fix CID 366821 - memory leak

* Fix CID 366736 - memory leak

* Fix CID 361684 - uninitialized scalar value

* Fix CID 352581 - memory leak

* Fix CID 352557 - memory leak

* Fix CID 348937 - memory leak

* Fix CID 322229 - memory leak

* Fix CID 320122 - memory leak

* Fix CID 317611 - memory leak
2022-05-15 23:15:28 +08:00
Giovanni
423617930c
[dalvik] handle move-exception after gotos/returns and mid op jumps (#2603)
* Fix dalvik analysis by looking for move-exception after gotos/returns
* Fixed Dalvik analysis due compiler optimizations
2022-05-12 13:16:54 +02:00
Paul I
9db3ed0670 Rename RzAnalysisXRefType enum members 2022-05-12 09:24:12 +02:00