Commit graph

585 commits

Author SHA1 Message Date
wargio
ec32a8fc75 Move librz/asm int librz/arch 2024-03-07 18:38:49 +08:00
billow
3b3d57c36c
project: fix global var loading (#4298) 2024-02-27 20:42:23 +08:00
Giovanni
78d4043afb
Fix arm64 analysis to fix regression on ARM64 switch tables. (#4284)
* Bump capstone next
* Fix arm64 analysis to fix regression on ARM64 switch tables.
* Fix tests
2024-02-24 00:00:12 +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
Anton Kochkov
9719961b82
analysis: fix capstone 4 and 5 builds (#4283) 2024-02-21 23:47:11 +08:00
Anton Kochkov
e690ea37de
analysis/dwarf: extract register profiles in headers (#4281) 2024-02-21 23:25:16 +08:00
Huzaifa
bde374dad6
Remove Static Variables from RzAnalysis Plugins (#4282) 2024-02-21 23:24:58 +08:00
Heersin
d37fc4c8f8
rx: add DWARF profile (register mapping) (#4277) 2024-02-21 00:09:10 +08:00
billow
3eb9527bcd
rl78: add DWARF register profile (#4276) 2024-02-20 22:34:40 +08:00
billow
f89e875d8f
v850: add local variables detection (#4271)
* v850: fix local variable detect
* v850: add local variable test
* v850: fix stack inc
2024-02-20 00:08:03 +08:00
wargio
a80622bcc1 Remove old options and replace with new global ones for string search.
Removed options:
- `bin.maxstr`

Renamed options:
- `bin.minstr` is now `str.search.min_length`
- `bin.maxstrbuf` is now `str.search.buffer_size`
- `bin.str.enc` is now `str.search.encoding`

New options:
- `str.search.reload`
- `str.search.max_threads`
- `str.search.max_uni_blocks`
- `str.search.max_region_size`
- `str.search.raw_alignment`
- `str.search.check_ascii_freq`
- `str.search.mode`
2024-02-19 19:39:00 +08:00
Rot127
4e6f21b07f Add include guards for post CS v4 instructions. 2024-02-18 21:29:03 +08:00
Rot127
0363f71654 Fix JUMP flag is overwitten with MOV flag.
Fix test for mov to pc
2024-02-18 21:29:03 +08:00
Dhruv Maroo
de4a1297a1
Add RzIL for floating-point x86 instructions (#3865)
* Create `il_fp_ops.inc`, for floating-point instructions' IL ops

* Add IL implementation for `FABS`

 * Also add `x86_il_{get,set}_st_reg` helper functions

* Add IL implementation for `FNINIT` and `FLDCW`

* Add IL implementations for `FNSTCW` and `FNSTSW`

* Add IL implementation for `FNCLEX`

* Add ST push and pop functions

* Fix clang formatting

* Add fucntions for updating FPSW TOP pointer

* Add `FLD` instruction lifitng, FPSW flag support, FP operand support

* Remove `x86_bool_to_bv` and use the standard `BOOL_TO_BV`

* Add implementation for `FST{P}`, and rounding mode support

* Add `FLD` variants for constants

* Fix formatting and build

* Add IL lifting for `FXCH`

* Add width checks to avoid redundant rounding

* Implement IL lifting for `FILD`, `FIST{P}`

    * Add helper functions to inter-convert floating point values and
      integers using the rounding mode in the control word

* FPU stack regs are 80-bit, not 64-bit

* Add RzIL lifting for `FBLD`

* Add RzIL implementation for `FBSTP`

    * An invalid-arithmetic-operand (#IA) exception may occurr if the
      value being converted to the BCD integer cannot fit in an 18-bit
      BCD integer. For the IL's purpose, we just jump to the "int" label
      (stands for interrupt) using `GOTO`.

* Remove all the `EMPTY()` ops after `GOTO()` ops

    * On second thought, using `EMPTY()` ops after `GOTO()` ops is not
      the best idea to indicate end of analysis. Maybe the hooks can
      signal that analysis needs to be restarted.
    * Also, clean up the comments of a bunch of unimplemented ops

* Moved some code around

* Rename "rmode" local variable to "_rmode"

* Add some TODOs for deffered work

* Fix failing asm tests

    * Caused due to the removal of the [empty] opcode

* Implement IL lifting for `FADD` (and some other minor refactoring)

    * Implement the IL lifting for `FADD`: This is not entirely correct
      as of now, because we don't handle setting C1 based on rounding
      up/down, but I think it should be fine for now. Need to tackle
      setting the control word bits later
    * Start using `RzFloatFormat` to describe the float's width instead
      of using an unsigned integer. Provide and expose conversion
      functions between the two

* Use a global to denote when RMode needs to be init, implement FIADD

    * Other minor refactor which fixes the CI (hopefully)

* Implement `FMUL` and `FIMUL`

    * Extract the common code into a C macro

* Implement RzIL for `FSUB` and `FISUB`

    * Also add `x86_il_fsub_with_rmode` helper

* Implement RzIL for `FSUBR` and `FISUBR`

    * Reuse the implementation of `x86_il_fsub_with_rmode` and just pass
      the arguments in the opposite order

* Add RzIL implementation for `FDIV`, `FIDIV`, `FDIVR`, `FIDIVR`

* Add pop versions of floating point arithmetic instuctions

    * Add a new macro `X86_ARITHMETIC_POP_IL` macro for the same
    * Fix a typo
    * Add a note for using `X86_INS_PFADD` for FADDP instruction on
      Capstone version newer than 4

* Add RzIL implementations for `FCOM`, `FCOMP` and `FCOMPP`

* Add RzIL lifting for `FUCOM` and `FCOMI` families of instructions

* Implement RzIL lifting for `FCHS` and `FTST`

* Add RzIL implementation for `FRNDINT` and `FSQRT`

* Add RzIL implementation for `FNOP` and `FISTTP`

* Remove global variable `use_rmode` and use pass around a context instead

    * Define a new `X86ILContext` struct to pass around information
      whether we need to intitialize the rouding mode or not
    * Remove the global variable which was previously responsible for
      doing so

* Add RzIL for `FICOM` and `FICOMP`, add register bindings and fix bugs

* Make `rz-test` more robust against IL outputs with newlines in them

* Add RzIL tests in db/asm for x86 FPU instructions

* Fix the bug when using `FADDP` with Capstone version > 4

* Fix remaining db tests

* Remove tests for `FSTSW` or `FSTCW` instructions

    * We already test `WAIT` (in `db/asm/x86_32`) and `FSTSW` (or
      `FSTCW`) (in `db/asm/x86_64`)
    * Remove the newline replacement code in `rz-test` as well, since we
      wouldn't need that functionality anymore

* Add asm tests for math constant push instructions

* Add `RZ_IPI` annotation for all the functions exposed through the header

* Add `RZ_OWN`, `RZ_BORROW` and `RZ_NONNULL` annotations

* Add Doxygen doc for `ctx` argument

* Add description for the `EXEC_WITH_RMODE` macro

* Move the non-null check for `ctx` inside the valid branch

    * When we pop the FPU stack we pass in a `NULL` context since no
      resizing would be needed, which causes a failure if the non-null
      check for the `ctx` is outside the branch
    * Fixes failing tests in `db/asm`

* Minor bug fixes + make the annotations less strict than they need to be

* Minor bug fixes

    * Incorrect implementation for `RET` and `CALL`
    * Swapped arguments for shift right

* Fix asm tests for `JMP` and `RET` instructions

* Fix indexing error for `FXCH`

* Review changes

    * Move all unimplemented instructions to the end
    * Remove support for Capstone version less than 4
2024-02-18 08:48:34 +08:00
Heersin
5c79c42a56
Disassembler arch for RX microcontroller (MCU) family (#4198)
* Basic framework of rx implemented
* Add match and parse flow
* Add part of description for RxV1 instruction set
* Add datasheet for rxv1
* Implement stringify op for rx
* Add missing TST instruction in datasheet
* Test to div instruction and fix bugs
* Test known rxv1 instruction set
* Fix bugs in rx disasm plugin and add SPDX
* Add rz_analysis for renesas rx
* Fix rz_analysis bug for renesas rx
* Add rz_asm test and fix bug in datasheet
* Add analysis test and fix bugs for renesas rx
2024-02-17 22:29:16 +08:00
Rot127
008f4edaf3 Add pacibsp as valid function prologue. 2024-02-17 15:04:47 +08:00
billow
cd92cce3cb rz_analysis_function_set_var: Fix incorrectly adding the same variable 2024-02-17 11:05:16 +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
Anton Kochkov
3b0f42acb9
analysis/types: add more WinAPI types (#4244) 2024-02-16 14:51:21 +08:00
wargio
50fedb2f77 CID 429545: Uninitialized pointer read 2024-02-15 19:41:12 +08:00
Anton Kochkov
0867fd9d3d
Remove assert() calls (#4230) 2024-02-15 15:34:29 +08:00
Giovanni
39e4e74c4e
Add ppc32, mips, sh, sparc, loongarch, s390, riscv DWARF register mapping. (#4232) 2024-02-15 15:33:56 +08:00
billow
5d434c47a4
Add V850 32bit register profile (#4229) 2024-02-15 01:46:28 +08:00
Anton Kochkov
13c7e1116c
Better error messages when creating new function (#4085) 2024-02-12 14:51:51 +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
billow
77d758da7d
v850: Add some undocumented instructions (#4187)
* v850: fix `decode_formatIX` and `lift_bit`
* v850: fix `ldbu` decode
* v850: fix JR JARL format V target
* v850: fix LDBU format VII target
* v850: add float instructions
* v850: fix `fmt_list` and add `v850_decode_formatUnk_float`
2024-02-08 23:10:31 +08:00
Huzaifa
e82033d92c
Convert from rz_str_new to rz_str_dup (#4178) 2024-02-07 00:07:53 +08:00
billow
6eeb9e4f83
V850: Improve RH850 support, add RzIL uplifting (#4103)
V850: Add RzIL support

V850: fix fallthrough

V850: Add docs

V850: fix v850 prelude

V850: add `loop`

V850: add docs to register profile

V850: add `syscall`

V850: add `sx[bh]` `zx[bh]`

V850: add `snooze` `sync?` `switch`

V850: add `sbf` `sch[01][lr]`

V850: fix `rotl`

V850: add `rie` `rotl`

V850: add `pushsp` `popsp`

V850: add `mac` `macu`

V850: add `ldl.w` `stc.w`

V850: add `hsh` `hsw`

V850: add `feret` `eiret`

V850: add `fetrap`

V850: add `cll` `ctret` `cmov`

V850: add caxi

V850: add callt

V850: add bsw

V850: add bsh

V850: fix bins

V850: add bins

V850: fix add and add adf

V850: format

V850: fix stack-buffer-overflow

V850: add emulateme test

V850: fix dispose and prepare

V850: fix all

V850: fix mulh and cmp satadd add shl shr sar

V850: mov

V850: fix sld.*

V850: fix runtime error left shift

V850: fix test

V850: fix jarl and refactor

V850: fix ld st

V850: fix inst.format

V850: fix rzil ld.*

V850: fix rzil dispose and prepare

V850: fix rzil and register profile

V850: fix disas memleak

V850: fix ld

V850: fix jump target
2024-02-03 06:28:12 +08:00
Anton Kochkov
d5bfd4534d
Disable analysis ARM hacks for Capstone 6 (#4180) 2024-02-02 23:22:22 +08:00
billow
809961fb59
TriCore: fix negative array index access (#4171) 2024-02-01 16:44:43 +08:00
Giovanni
1d98f08e1f
PowerPC DWARF Register Mapping (from PPC ELF ABI v1) (#4155) 2024-01-26 08:03:27 +08:00
billow
d29e7ef529
v850: Add RzAsm and RzAnalysis support for rh850 (#4151) 2024-01-25 21:53:07 +08:00
Giovanni
3b591e68c3
Remove static buffer from dwarf code. (#4117) 2024-01-18 08:55:52 +08:00
billow
df93e2c003
tricore fixes coverity (#4116) 2024-01-17 15:16:39 +08:00
billow
fc6e9019f2
Fix tricore RzIL ADDSC.A (#4112) 2024-01-16 07:07:39 +08:00
Rot127
09692c01d3
Fix #4110 (#4111) 2024-01-15 23:12:35 +08:00
Rot127
9ea0b64372
Enable CFG generation. (#4037)
* Add CFG generation function.
* Document rz_analysis_op()
* Set type annotation to NONNULL
* Add command to generate CFG.
* Add note about not following calls.
* Add tests and simplify check.
2024-01-15 07:51:35 +08:00
Rot127
9073cc2464 Add support for mtocrf and mfocrf if CS v6 is present. 2024-01-14 22:23:59 +08:00
billow
02634787e9
v810: RzIL support (#4096)
* RzIL v810 support
* Fix v810 asm tests
* Fix analysis/v810
* v810: move ESIL formation into a separate function
* bin/elf: autodetect v810 architecture
2024-01-14 10:45:48 +08:00
billow
524fe19222
Build tricore_il only when cs =next or >v4 (#4102) 2024-01-13 23:02:33 +08:00
billow
ce88bbed49
RzIL TriCore Support (#3478)
* RzIL TriCore Support
2024-01-13 13:59:55 +08:00
Peiwei Hu
3a2148e1cd
Refactor sections in RzBinPlugin from list to pvector (#4089) 2024-01-11 12:19:22 +08:00
billow
a592ea1e8c
Remove static and global variables in TriCore RzAsm and RzAnalysis plugin (#4092) 2024-01-10 23:44:12 +08:00
wargio
a9131cede7 Remove hidden static in rz_str_pad 2024-01-06 23:30:07 +08:00
wargio
aa7e6d80ad Remove hidden static in run_basic_block_analysis 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
wargio
036606c8b6 Remove hidden static in __stepOut 2024-01-06 23:30:07 +08:00
wargio
9597f1f9d3 Move cmpval into RzAnalysis 2024-01-06 23:30:07 +08:00
wargio
c93624712a Remove read ahead globals.
backport from radare2 dd01b31f71ce7698a416f41556df488da5676dfe
2024-01-06 23:30:07 +08:00