Commit graph

1360 commits

Author SHA1 Message Date
Giovanni
60657d7780
Fix NULL dereference due invalid command. (#4511) 2024-05-23 16:47:42 +08:00
timiv
c7464ab983
Support ARM ELF THM_PC22 / THM_JUMP24 relocs (#4503)
* Support ARM ELF THM_PC22 / THM_JUMP24 relocs

This revision adds proper support for the following ARM ELF relocations:

- RZ_ARM_THM_PC22
- RZ_ARM_THM_JUMP24

These require a rather special encoding as some bits of the relative
offset are encoded in a non-common fashion.
2024-05-21 07:12:32 +08:00
billow
14e97874a3
pic: add RzIL uplifting (#4322)
- Add uplifters
- Add memory maps for different devices in PIC16F family
- Fix pic18 register mapping
- Fix pic18 asm
- Detect pic arch
- Add pic_archinfo
- Extract ESIL uplifting to a separate file
- Support RZ_ANALYSIS_OP_MASK_DISASM
- Add pic18 emulateme test
- Add pic16 emulateme test

---------

Co-authored-by: brightprogrammer <bshock665@gmail.com>
2024-05-19 12:17:53 +08:00
Peiwei Hu
48c2c5f287 Add file percentage in visual mode (V/Vv) 2024-05-17 18:06:50 +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
Khairul Azhar Kasmiran
a6d4a6bd02
Fix dbg_dmh test based on libc6 2.35-0ubuntu3.7 (#4495) 2024-05-16 21:31:40 +08:00
pelijah
ca2bbc076c Refactor rz_bin_pe_get_libs() to use SetS and RzPVector 2024-05-11 08:09:59 +08:00
Khairul Azhar Kasmiran
e283bda5de
Fix debuginfod test timeout under -q (#4470) 2024-05-05 10:41:12 +08:00
Heersin
ba780a78dc
Relocation and analysis improvement for Renesas RX (#4461)
* Improve RX analysis of stack pointer
* Add Renesas RX ELF e_flag and reloc type macros
* Add Renesas RX relocation patch and elf_reloc to rz_reloc converter
* Update Renesas RX 'ir-info relocs' cmd test
* Add Renesas RX instruction description sdb
2024-05-01 09:34:52 +08:00
z3phyr
a7a29f110d
Revert memory leak fix for relocs (#4463) 2024-04-27 17:31:41 +08:00
Anton Kochkov
9526b6c0bc
Remove NIOS-II architecture (#4457) 2024-04-24 20:11:17 +08:00
Khairul Azhar Kasmiran
652591f826
..(: Declare macro args as raw (#4453) 2024-04-21 12:16:30 +08:00
z3phyr
0551f2545f
Fix memory leaks in linux heap parser (#4426)
* Fix memory leaks in debug path
* Fix memory leaks in mach and mdmp format
* Update the fix for mach
* Add support for aarch64 tcache parsing
* Test case fix
* Comment update

---------

Co-authored-by: Giridhar Prasath R <giridh1337@gmail.com>
2024-04-21 12:14:06 +08:00
Khairul Azhar Kasmiran
688c2bbe7c
.(: Don't unescape macro args (#4450) 2024-04-21 09:58:38 +08:00
Giovanni
3033f62865
Refactor logging. (#4446)
* Remove globals and refactor to complete implementation of logging.
* Renamed log.traplevel to log.abortlevel and hide it on release builds.
2024-04-19 13:02:58 +08:00
Khairul Azhar Kasmiran
36ce78bc38
.(: Don't unwrap quoted args (#4417) 2024-04-15 18:32:12 +08:00
Dhruv Maroo
c6537d917e
Fix EXEC_WITH_RMODE macro and make the IL generated more concise (#4413)
* Use local variables in methods using `EXEC_WITH_RMODE` instead of
      `DUP`ing the values. Do the same for ST register stack popping.
      This leads to lesser code in the IL since the same long expression
      does not get repeated in the IL everytime (since we don't `DUP`
      anymore).
2024-04-05 08:30:35 +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
Florian Märkl
f223247b46 Remove fb command
The fb command can modify the offset of a flag, but does not update the
skiplist they are stored in, leading to a corrupted flag database. This
can be seen for example when executing
f test @ 0x4; fb 0x10 test; fl; pd 0x8 @ 0
2024-04-04 13:22:57 +02:00
pelijah
3d93397dd8
RzIL: replace float comparison macros with functions (#4400)
* Replace float comparison macros with functions
* Move to float operations into il_routines.c
* Add RZ_OWN/RZ_BORROW tags
2024-04-02 09:18:21 +08:00
Giovanni
5cd4cff7eb
Update libdemangle to latest main and add LD command as alias of iDl (#4411) 2024-04-01 14:39:35 +08:00
billow
8f7f03cff6
TriCore IL: fix CSUB/CSUBN (#4409) 2024-04-01 07:45:33 +08:00
Khairul Azhar Kasmiran
754538fd8a
Fix unescaping of \\ esc seq (#4402) 2024-03-31 11:48:15 +08:00
Khairul Azhar Kasmiran
508bbae8a5
izj/izzj: Fix escaping of special chars (#4392) 2024-03-26 22:52:06 +08:00
Rot127
b4fe418375
Fix broken CI (#4376)
* Increase timeout for OpenBSD

* Reset all members of a packet.

* Replace calloc with Rizin macros

* Add returns after fatal logs

* Init time structs with 0.

* Use monotonic clock to set last access timestamps.

Because instruction packets get pushed out of the buffer based in their last access,
using the real-time clock leads to problems. On Windows the real time clock seems to
not always give ascending values with multiple calls
(real-time clock = best bet of machine of current day time, which can fluctuate).

Using the monotonic clock will always give strictly ascending timestamps.

Due to the use of the real-clock, the instruction packets got
sometimes pushed out of the buffer non-deterministically.
2024-03-25 19:15:56 +08:00
Khairul Azhar Kasmiran
c52750ccfe
$: Use rz_flag_get to check if flag exists (#4377) 2024-03-22 22:12:20 +08: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
Giovanni
94099b860e
Add RzIL info to rz-asm -L and La (#4369) 2024-03-18 21:16:13 +08:00
Khairul Azhar Kasmiran
547732cd58
$: Refactor out code for $* and $** (#4368) 2024-03-17 21:23:13 +08:00
billow
30eef53291 dwarf: refactor
- Remove dwarf's dependency on RzBuffer

- Delete `cdwarf.c` and move dwarfdump (`id`) related functions to their respective modules

- Improved output of dwarfdump (`id`)

- add more DW_AT*

- fix escape

- fix debuglink

- remove cache in RzBinDwarfStr

- replace `rz_bin_dwarf_rnglists_parse_at` with `rz_bin_dwarf_rnglists_get`

- remove rz_bin_dwarf_loclists_parse_at

- fix logging

- cache all escaped strings
2024-03-09 09:41:13 +08:00
billow
cae54ff8d9 uleb128: fix sign extend in read_i{32,64}_leb128 2024-03-09 09:41:13 +08:00
Huzaifa
2c85412a50
Rz-find -E "filename" to execute command on match (#4200) 2024-03-08 13:49:04 +08:00
wargio
5f3af7deee Fix build with capstone v4 and v5 and disable hacks for v6 2024-03-08 12:33:07 +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
Anton Kochkov
660146d520 type/format: fix union format generation 2024-03-03 20:42:21 +08:00
Peiwei Hu
33c8299eef
Refine the heuristic rule for encoding detection (#4319) 2024-03-03 08:10:49 +08:00
Khairul Azhar Kasmiran
299454138b
$: Add rzshell façade (#4314) 2024-03-02 17:11:02 +08:00
Peiwei Hu
0fff253fd9
Fold XREFs line more than 3 when in the graph mode (#4308) 2024-02-29 14:28:26 +08:00
Khairul Azhar Kasmiran
b61b951232
$: Fix $alias=$<backtick>cmd<backtick> (#4293) 2024-02-24 13:55:14 +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
Anton Kochkov
551cf21ac7
type/format: fix output in pf commands (#4272) 2024-02-20 21:37:14 +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
bc6946bc4d Add long string test 2024-02-19 19:39:00 +08:00
wargio
ef5d22e13d Fix string search related tests 2024-02-19 19:39:00 +08:00
Rot127
31f6c53d4c Attempt to fix test regex. 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
Anton Kochkov
f98ab29273
Convert p2 and p8 commands to rzshell (#4250) 2024-02-17 21:59:20 +08:00