Commit graph

1904 commits

Author SHA1 Message Date
Florian Märkl
c79d7d2611 Add support for DYLD_CHAINED_PTR_32
arm64_32 is AArch64, but using 32bit pointers, which is primarily used
on watchOS. Handling DYLD_CHAINED_PTR_32 fixups is necessary to
correctly load such binaries.
2023-03-21 19:33:49 +01:00
Heersin
3a7d511624
Add validation for rzil float theory (#3420) 2023-03-11 09:53:13 +01:00
Giovanni
c7dfbbcdcd
Fix ar naming and io read/write api (#3419) 2023-03-10 06:21:39 +00:00
Giovanni
125f0333aa
Set perm to 644 to multiple text files (#3418)
Co-authored-by: Giovanni Grazioli <giovanni.grazioli@ubisoft.com>
2023-03-10 13:42:42 +08:00
Giovanni
eb3f7f80c5
Fix archive file io plugin (#3417)
* Fix loading .lib/.a files
* Add windows lib test for ar:// uri
2023-03-10 08:13:26 +08:00
billow
a8a6f36354
8051 RzIL fixes (#3413)
* fix `ljmp`
* fix `mov`
* fix push stack
* rename register `a` -> `acc`
* fix `ret`
* fix `j*`
* `dptr` -> `dpl`+`dph`
* memory mapping registers
* replace flags with `psw`
* fix duplicate register reads
* fix relative addressing
* fix reg_profile
* fix `mul` and `pc`
2023-03-05 12:54:25 +08:00
Pavel I
121e28a742
x86 IL: fix infinite loop caused by x86_il_get_parity (#3402)
* x86 IL: fix infinite loop caused by x86_il_get_parity
* Update tests
2023-02-28 10:01:41 +08:00
Anton Kochkov
315ba643b0 Fix CI by making GAS test Linux x86-only 2023-02-22 17:42:39 +08:00
R4444
0e8828c54e
Add GAS/AT&T syntax support in asm.c assembler (#3384) 2023-02-22 13:11:13 +08:00
Heersin
2b748567fa
Add fbasic theory to rzil using rz_util/float (#3184)
* Fbasic dev build test

* Add fbasic structure and enums

* Add fbasic op new

* Add fbasic op dup

* Add fbasic op free

* Add partial theory of float

* Add fbasic handlers to pure table default

* Add fbasic stringfy

* Add temporary float functions

* Add rz-float value and evaluation

* Add float json dump functions, todo add mode info in il_opdmp_* functions and compelete il_resolve_pure

* Complete fbasic il in il_export

* Fix detected error in compilation

* Add doxygen for il/definition/float

* Pack float_round function

* Add new version of rounding

* Add cast and convert, todo add 'float_get_sign' and 'float_get_no_bias_exp'

* Add comments and fix new version rounding

* Add util float functions

* Implement theory fbasic : cast, convert and round

* Remove bv_one warning

* Move basic functions into rz_util from definition/float

* Add two basic test cmp and extra format test

* Add test to fsucc, fpred and fneg

* Add round significant test case 1 and fix bug to pass it

* Test round significant and bug fixes

* Add 6 types test cases to round_and_pack function

* Finish round significant and round_pack test with bug fixes and signature changes

* Leave fround as unimplement now

* Pass all test to cast and convert

* Add SPDX header

* Add SPDX header

* Add round to integral float with test and bug fixes

* Add more tests to cast_sint and bug fixes

* Fix mem leak in cast_sfloat

* Replace the deprecated rounding method, fix bugs and pass tests

* Resolve some reviewed issues

* Fix most memleak and bug found

* Remove deprecated round_bv

* Remove unused functions to eliminate warnings

* Fix typo in comments

* Uncommented implmented operations

* Add test cases and bug fixes for fbasic theory in rzil

* Fix ret type of new_bitv_from_* from Bool to BitVector

* Add new float op from f32 and f64
2023-02-15 18:18:40 +08:00
Riccardo Schirone
c9d6ad9ee6
io: return error when reading/writing to unmapped memory (#3323)
* core: 'wow' command was replaced with 'wb'

* io: on_map_skyline returns false when nothing was done

Before this patch on_map_skyline returned true even when the callback
was not called on any part of the skyline. In other words,
reading/writing to an unmapped memory returned true.

This commit changes the behaviour to return false in those cases.

* analysis/esil: mem_read/mem_write were alway returning true

* use o malloc instead of oC

* librz: deal with seek errors
2023-02-11 11:36:27 +01:00
Riccardo Schirone
505bc3da7e tests/db: fix wrong tests using nonexisting eval/cmd 2023-02-09 08:44:53 +08:00
Florian Märkl
2221ab27af
Fix filling RzAnalysisDisasmText.arrow when asm.lines=false (#3361)
The arrow info is needed to print custom reflines, for example in
Cutter. In such a case, asm.lines will generally be false to not have
the lines also printed inside the text.
2023-02-09 08:00:52 +08:00
Anton Kochkov
5d7335c8b6
Add some missing Windows types (#3347) 2023-02-05 14:27:43 +08:00
Anton Kochkov
fd64b7ee25 Convert pr commands to the rzshell 2023-02-02 08:21:09 +08:00
Anton Kochkov
5082c1f0e8 Convert p= commands to rzshell 2023-01-31 08:27:30 +08:00
Giovanni
c3f9d4c1d3
Fix #2859 - Use minstring in all bin plugins (#3328)
* Do not hardcode min string size for bins using `rz_bin_file_strings()`
* Fix rz-bin to set properly `bin.[min|max]str`
* Add and fix tests
2023-01-30 18:38:08 +08:00
Giovanni
21333133d9
Fix bx after add lr, pc, 0 in arm32 (#3326)
Co-authored-by: pancake <pancake@nopcode.org>
2023-01-28 15:10:14 +08:00
Florian Märkl
62c0a6b880 Raise timeout for 6502 rzil test
On some platforms, the rizin startup itself takes multiple seconds,
which can make these tests timeout even if they would otherwise work.
2023-01-26 20:39:24 +01:00
Riccardo Schirone
d6c586bc3b
core: replace 'it' with 'iT' (#3320)
`it` is the table mode of the `i` command, thus leave it available and
use `iT` instead.
2023-01-26 16:01:06 +08:00
Florian Märkl
77a334a2af
Refactor srec reading to not use sscanf (#3321)
Parsing with sscanf turned out to cause an extreme slowdown. As only hex
values are being read, this can be done with RzUtil-provided
functionality. Relevant test cases exist in test/db/io/srec.
2023-01-25 16:42:46 +01:00
Anton Kochkov
38a909738c
Convert pC commands to rzshell (#3213) 2023-01-23 17:54:52 +08:00
Anton Kochkov
a3885e8f99
Remove legacy unit tests (#3088) 2023-01-23 17:46:21 +08:00
Rizan
bbc5457b7a
Use compiler intrinsics for rz_swap_* functions (#3300)
* Using `__builtin_swap*()` whenever available instead of `rz_swap*()`
* Moved `test_endian()` from test_utils.c to test_endian.h
* Added test cases
2023-01-22 21:30:21 +08:00
Florian Märkl
3f4570cd7a
Fix string flag sizes after aar (Fix #3305) (#3307)
Regression from 7af1353166, but most
likely already broken before and only made visible by it: String flags
set from bin had their size set to how many bytes the string takes, but
were overwritten to a size of 1 after running aar.
2023-01-21 15:28:05 +01:00
Giovanni
7af1353166
Use proper methods to detect strings in analysis loop. (#3284) 2023-01-20 12:02:10 +08:00
Riccardo Schirone
c4767cf1ac
Fix plugin removal and clean code (#3277)
* cmd: Fix summary of few "L" sub-commands
* util: start decluttering plugins handling

- Add Doxygen docs
- Remove unused API functions and make others internal only
- Use RzLibType enum for plugin type instead of int

* util: move dlopen/dlsym/dlclose to rz_sys
* util: make rz_lib_open/close return bool
* util: simplify rz_lib_add_handler and rz_lib_open*
* libs: implement rz_*_plugin_del to remove a plugin
* core: remove commands from RzCmd when removing plugins
* librz: call plugins 'fini' method when removing a plugin
* core/cmd: do not fail if the hashmap removal fails

When removing a group command, the inner command might have the same
name, thus it would result in trying to remove the same name twice.
Ignore it, as it is fine.

* librz: make RzCrypto plugins handling like the others
* librz/crypto: add rz_crypto_reset and use it
* librz: allocate the plugin structures before adding them
2023-01-16 13:32:46 +01:00
Florian Märkl
7c6579a614 Fix asm.bits-dependent open tests
Passing arch and bits as args instead of commands ensures they take
effect earlier. This fixes these tests on platforms where the default
asm.bits is 32.
2023-01-15 19:01:18 +01:00
Florian Märkl
953a81afc0
Make afs respect the cc (Fix #3291) (#3292)
Applying a function signature with afs to a function was using a
combination of the existing args and wrong stack addresses to apply the
args to function variables. This generally resulted in incorrect
locations. Instead, we now use the info from the cc.
2023-01-15 13:40:14 +01:00
Peter B
ca3c77e981
Set refptr for Xtensa l32r opcode for better disassembly output (#3289) 2023-01-15 09:32:37 +08:00
Giovanni
4a9740d11d
Fix pxj output (#3290) 2023-01-14 14:14:34 +08:00
Giovanni
3edb12c2d2
Temporary fix for the meta strings (#3283)
* Temporary fix for the meta strings
* Fix unit test
* Added test for Csl with raw binary
2023-01-11 12:31:49 +08:00
Florian Märkl
70c1a3e109
Fix some tests for platforms without native debugger (#3278) 2023-01-09 17:57:39 +01:00
Florian Märkl
01a82490d7 Raise timeout for some aez tests
On some platforms, the rizin startup itself takes multiple seconds,
which can make these tests timeout even if they would otherwise work.
2023-01-09 10:26:30 +08:00
Florian Märkl
1b4385e224
Make xnu reg profile depend on cpu type instead of RzDebug.bits (#3270)
RzDebug.bits often has nonsensical contents set from all kinds of
places. Specifically, when debugging fat binaries on arm64, it had a
value not matching the debuggee when the reg profile was loaded,
resulting in the arm32 profile being used.
The right way to determine the profile is to do it after attach, when
the cpu type of the debuggee is known.
2023-01-07 17:43:41 +01:00
Florian Märkl
de5aa96af9 Patch Mach-O chained ptrs into sparse overlay RzBuffer
Patching the chained ptrs on the fly during every read as before turned
out to be a major bottleneck on larger binaries. So now we patch
everything once into a sparse overlay buffer, like it is already done in
ELF and classic Mach-O relocs.
2023-01-07 11:04:22 +08:00
Florian Märkl
29adadc2b8 Speed up ppc64 IL tests by not loading hashes 2023-01-07 10:18:57 +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
fa15d2fbab Fix type bitsizes for struct/union member loops
Even if the case is nonsensical in practice, we can't rule out the
possibility that a struct or union may contain itself as a member
(optionally through multiple recursion steps). This must be caught when
calculating the size of the type in order to not recurse infinitely.
Structs containing pointers to itself are not meant by this, as that is
perfectly valid and the size is determined without recursion.
However typedefs and arrays must be taken into account.
2023-01-04 09:39:10 +08:00
Florian Märkl
5a229ca6a7 Fix rz_type_db_get_bitsize() without specifier and add tests 2023-01-04 09:39:10 +08:00
Giovanni
2c91585125
Fix wrong subvar in json (#3263) 2023-01-03 16:53:03 +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
Dhruv Maroo
d20f68d7ab
Add *pty API (#3221)
* Initial function signatur and struct for `RzPty` API

* Change type annotation to borrow

* Implement `rz_subprocess_login_tty`

* Add fork mode enum and move pty struct; restructure ifdef guards

* Add rough implementation of forkpty

  * Add `rz_sys` versions for `forkpty` family of functions

* Add forkpty code; Make changes according to review

* Implement forkpty properly and add unit test

  * Add `test_interactive_pty`

* Add documentation

* Remove const in function argument

  * Apparently, MacOS as non-const arguments for `openpty` and `forkpty`

* Add more tests for subprocess forkin using forkpty

  * `test_interactive_pipe_pty`: Create pipes between the slave's PTY
    and master and use them
  * `test_interactive_custom_pty`: Use a custom PTY for the slave

* Add PTY functions exist checks for unit tests

* Move terminal param code inside the forkpty branch

* Add comment about why we need to check `n_bytes = 0` in `subprocess_wait`

* Remove forkpty with a specified `RzPTY`

  * Also, no piping done in forkpty

* Add checks to disallow using `forkpty` with piping

* Make changes according to review

  * No need to check proc file descriptors for -1 in `forkpty` mode, since
    they *will* be -1
  * No need to check `n_bytes == 0` in for `std{out,err}_pty`

* Extract pipe initialization code in `init_pipes` function

* Allow using custom PTY for `rz_subprocess_forkpty`

* Remove const qualifiers for termios and winsize arguments

  * This makes the build pass on MacOS, which does accepts non-const
    arguments

* Change `pid_t` to int so that it compiles on Windows

* Add empty implementation for PTY API for Windows

  * Update function signature for `rz_subprocess_start_opt` for Windows
  * Re-add `#define` for `pid_t` in `librz/socket/run.c`

* Move functions to remove duplicate definitions

* Allow specifying piping options even in `forkpty` mode

    * Only expose the master fd for the streams which have pipe create
      as their piping option

* Add comment about not using `master_fd` directly

* Fix types in definition for Windows

* Free the allocated `RzPTY` object

* Add const qualifiers for `RzPTY` argument

* Assign `fork_mode` and `pty` in all instances of subprocess opt start

    * for good measure

* Compare master fd with -1, not 0

* Remove stray file

* Add second comment about the terminal attribute

* Overhaul the whole PTY implementation

    * Now the caller can either use a pipe or PTY to send and receive
      data from any of the streams
    * Extra option `make_raw` to use the slave PTY in raw mode
    * Add documentation for all the new functions

* Fix UAF bug

* Add error handling for `tcgetattr`

* Move the term param setting code

* Add documentation for the subprocess API and sys API

* Format according to clang-format
2022-12-29 20:38:39 +08:00
Peiwei Hu
276306b587
Add search.case_sensitive for grep case-sensitive/insensitive (#3241) 2022-12-28 09:38:32 +08:00
Peiwei Hu
1938890035
Fix: grep(~) will change the original result when ignores case (#3259) 2022-12-25 08:01:06 +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
Dhruv Maroo
a3ebd3fa99
Dalvik disassembly should not throw error for single opcode (#3255) 2022-12-20 22:36:56 +05:30
Riccardo Schirone
f64ef48277 test: fix 'core: ' message in help log error 2022-12-19 11:46:18 +01:00
Riccardo Schirone
efa5598e5e test/unit: Add small unit test for rz_log 2022-12-19 11:46:18 +01:00
Anton Kochkov
1d3fbac74a
Add Nord color theme (#3250) 2022-12-18 11:48:15 +08:00
Anton Kochkov
dcaf3ecd69
Add Mars color theme (#3252) 2022-12-17 20:25:41 +08:00
Dhruv Maroo
f8f042f818
Fix searching for strings in rz-bin when the file format is invalid (#3245)
* Fix searching for strings in `rz-bin` when the file format is invalid

  * Always try with "any" bin plugin before giving up searching a file
  * Add a test in `db/tools/rz_bin` for this

* Remove `EXPECT_ERR` from `rz-bin broken MZ` test
2022-12-15 23:08:48 +08:00
Riccardo Schirone
adf8b0717e
bin/formats/elf: consider stripped bins without sections (#3248)
Backport radare2 commit https://github.com/radareorg/radare2/pull/20864
2022-12-15 20:29:19 +08:00
billow
291d2a683c
Uplifting 8051 architecture to new IL (#2999) 2022-12-14 13:13:21 +01:00
Florian Märkl
3e75e1f6c7 Rewrite and extend type paths from offset
Tests and extends deriving paths into types at a given offset in the
following ways:
- Parameter for limiting the depth of the path
- Array support, e.g. `.member[5].anothermember`
- Typedef support
- Paths can be taken from arbitrary RzTypes, not only RzBaseType
- Removed the typename in the beginning of paths, which can be added by
  the caller if needed
2022-12-10 11:15:37 +01:00
Florian Märkl
ff778e7507 Unify and fix typedef loop handling
Even if the case is nonsensical in practice, we can't rule out the
possibility that the reference chain induced by a typedef may not
contain a loop, which could lead to infinite recursion when trying to
infer the actual underlying type.
Previously only the case where a typedef points to itself directly was
handled, but loops in multiple steps are possible too. So we introduce
rz_type_db_base_type_unwrap_typedef(), which handles the full
(multi-step) loop-aware unwrapping in one place and use it wherever
needed.
2022-12-10 11:15:37 +01:00
Giovanni
4f19d80aee
Fix #3191 - Esil wrong order in X86_INS_POP (#3236) 2022-12-09 20:18:03 +01:00
Giovanni
55e690990b
Fix endianness for win pagedump and winkd (#3204) 2022-12-09 11:41:28 +01:00
wargio
d7f793bb6f Fix endianness in analysis mips.gnu plugin 2022-12-06 07:51:33 +08:00
Giovanni
89717b141c
Fix wB test due broken pv1 (#3225) 2022-12-06 06:50:19 +08:00
Giovanni
e7e2156eed
Do not load sigdb from system and home when running rz-test (#3222) 2022-12-05 02:51:36 +01:00
Florian Märkl
86269942d0
Fix leaks in rz_type and tests (#3223)
All leaks detected by running valgrind on test/unit/test_type.
2022-12-04 20:42:46 +01:00
wargio
a3b8ed48b7 Remove esil debugger since it is a big todo 2022-12-04 16:53:58 +01:00
Dhruv Maroo
ce80a13aed
x86 RzIL uplifting (#2747) 2022-11-28 09:33:19 +08: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
Florian Märkl
0a3e96a6f0
Make color promt test not load user settings (#3202)
When a color theme is set in rizinrc, this test would fail.
2022-11-25 10:22:51 +01:00
Khairul Azhar Kasmiran
3ddbda0a9a
rz_heap_glibc.h: Add have_fastchunks member to RzHeap_MallocState_ structs (#3200)
* Add `have_fastchunks` member to `RzHeap_MallocState_` structs

* Show only last few lines of `dmh` output in "dmh allocated" test
2022-11-24 09:42:07 +08:00
Khairul Azhar Kasmiran
ea07efdfb8
Improve "dmh allocated" test (#3199) 2022-11-22 18:29:38 +01:00
Anton Kochkov
70a7016d97
Convert p- commands to rzshell (#3198) 2022-11-22 23:46:40 +08:00
Khairul Azhar Kasmiran
1b57ec3c2e
Make "dmi ld" test more robust to different ld (#3190) 2022-11-17 22:13:51 +08:00
Anton Kochkov
f2ca09fe24
Extract histograms and bars into RzCons (#3189) 2022-11-17 14:41:50 +01:00
Khairul Azhar Kasmiran
83eea37c4e
Make first dbg_dmh test invariant to r13 (#3188) 2022-11-16 21:36:13 +08:00
Khairul Azhar Kasmiran
935361e31b
Mask out ebx too in "Conditional dr/ar" test (#3183) 2022-11-13 14:51:33 +08:00
Khairul Azhar Kasmiran
315433d286
Make "dbg.px0" test invariant to ld (#3181) 2022-11-12 21:05:31 +08:00
Khairul Azhar Kasmiran
13a5aebea3
Make "debug stepback from callee" test invariant to env (#3179) 2022-11-12 00:28:07 +08:00
Khairul Azhar Kasmiran
5611bc3c79
Make dbg.stepback test invariant to env (#3176) 2022-11-10 19:32:08 +08:00
Anton Kochkov
2ed75e8364
Backport rz-ax conversion fixes (#3166)
* rz-ax: fix base64 null byte decoding bug
* rz-ax: fix broken tests for long number conversion
* rz-ax: add tests for 64-bit binary numbers

Co-authored-by: Sylvain Pelissier <sylvain.pelissier@gmail.com>
2022-11-07 00:27:17 +08:00
Florian Märkl
2a02548ec2 Fix some db/formats/mach0 tests on hosts with asm.bits=32
Fatmacho loading selects the file based on both arch and bits, so if the
preselected asm.bits was not 64 (which is the case on OpenBSD/sparc64
for some reason), these tests would fail.
2022-11-06 23:58:01 +08:00
Florian Märkl
b3c498dee0 Fix endian in macho reloc parsing 2022-11-06 23:58:01 +08:00
Khairul Azhar Kasmiran
2314f18063
Nop out calls_x64's printf call in some dbg_step and dbg_step_back tests (#3159) 2022-11-05 22:42:47 +08:00
Florian Märkl
3f077bce4a Remove deprecated rz_analysis_var_all_list()
This function only did a needlessly inefficient clone of
RzAnalysisFunction.vars, which can also be iterated directly.
Test differences are from different ordering of variables iterated, but
both are fine as there was no deliberate order before either.
2022-11-04 16:24:50 +01:00
Florian Märkl
47c63c59a9 Add rz_pvector_clone() and clone without free function
A clone function that also copies the free function is very prone for
misuse and resulting double-free/uaf. Current cases were only fine
because they either did not have a free function or pathced it to NULL
on the result manually, meaning they do not need this behavior anyway.
2022-11-04 16:24:50 +01:00
wargio
b59d9a03b2 Fix test 2022-11-02 00:53:54 +01:00
wargio
2b3c6b5102 Updated all tests 2022-11-01 10:58:16 +08:00
wargio
fe00dcdf68 Rewrite RzReg to use RzBitVector 2022-11-01 10:58:16 +08:00
wargio
bf6d162909 Implement float80 and RzFloat to decimal string 2022-11-01 10:58:16 +08:00
OGRE
3f6a8d54ba
Replace " with ' in ag* dot command (#3133) 2022-10-28 08:34:30 +08:00
wargio
da68d2507a Fix tests 2022-10-26 21:46:22 +02:00
Giovanni
3e5217456d
Fix mdmp endianness (#3126)
* MiniDmpHeader & MiniDmpLocDescr32/64 & MiniDmpMemDescr32/64

* MiniDmpException & MiniDmpExcStream

* MiniDmpModule

* MiniDmpThread & MiniDmpThreadList

* MiniDmpThreadEx & MiniDmpThreadExList

* Removed struct minidump_string

* MiniDmpDir

* MiniDmpExcPointers & MiniDmpExcInfo & MiniDmpFuncTableDescr

* MiniDmpFuncTableStream & MiniDmpHandleDataStream

* MiniDmpExcRecord & MiniDmpHandleDescr/2

* MiniDmpHandleObjInfo

* MiniDmpMemList64 & MiniDmpMemDescr64 (init)

* MiniDmpMemInfo & MiniDmpMemInfoList

* MiniDmpMiscInfo

* MiniDmpMiscInfo2

* MiniDmpSysInfo

* MiniDmpThreadInfoList & MiniDmpThreadInfo

* MiniDmpTokenInfo & MiniDmpTokenInfoList

* MiniDmpUnloadedModule & MiniDmpUnloadedModuleList

* MiniDmpUserStream & MiniDmpUserStreamInfo

* MiniDmpIncludeThreadCallback

* MiniDmpModuleCallback

* MiniDmpIncludeModuleCallback

* MiniDmpIOCallback

* MiniDmpReadMemoryFailureCallback

* MiniDmpCallbackOutput

* AVRFBacktraceInfo & AVRFHandleOp & MiniDmpHandleOpList

* MiniDmpObj
2022-10-25 09:37:05 +08:00
Giovanni
5789f6557e
Threaded analysis matching (#3090) 2022-10-24 00:40:42 +02:00
Giovanni
64a9459ea4
Fix flirt detection when function size is less than 32 bytes (#3118) 2022-10-23 16:34:43 +02:00
wargio
3b19487f87 Cleanup plugin names. 2022-10-23 11:36:17 +02:00
wargio
174d02b4a7 Fix ninds plugin endianness and improved it 2022-10-23 11:36:17 +02:00
Florian Märkl
9a379f345d
Make dyld_chained_ptr_* parsing endian-independent (#3113)
Fixes test/db/cmd/cmd_tc and test/db/formats/mach0/arm64e on big endian
2022-10-22 01:03:24 +02:00
wargio
ab5c0cb869 Fix endianness in px command 2022-10-20 23:12:58 +02:00
Giovanni
e2ee0c3fd6
Rewritten bin_nin3ds.c and add test (#3110) 2022-10-20 19:56:17 +02:00
Florian Märkl
68a06e69d2
Rewrite reading in io_mach (#3101)
The previous reading code was slow (performed too many
vm_region_recurse_64 calls) and broken, for example at boundaries of
memory maps. Details can be found in the code comments.
2022-10-17 09:15:59 +08: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
Florian Märkl
2237870395
Mach-O: Add support for DYLD_CHAINED_PTR_64 (#3094)
The added test case was checked against execution on real iOS.
2022-10-14 19:59:29 +02:00
Anton Kochkov
9f6e13f364
Remove rz-agent (#3087) 2022-10-12 10:34:46 +02:00
Anton Kochkov
4a037c2f2a
Convert dk commands to the rzshell (#3078) 2022-10-11 18:02:52 +08:00
Giovanni
171612c5e1
Add ssdeep hash (#3084) 2022-10-10 17:03:26 +02:00
Anton Kochkov
24503df48b
Convert pF commands to the rzshell (#3071)
* Convert `pF` commands to the rzshell
* Add json output for PKCS7 and x509 and rename test due FS issues

Co-authored-by: wargio <wargio@libero.it>
2022-10-09 19:18:05 +02:00
wargio
5ecc9b8a36 Added pF tests 2022-10-09 08:09:00 +08:00
Khairul Azhar Kasmiran
4cdad14ccd
Remove dk 9 from debug tests (#3070)
* Add `dk 9` test
2022-10-08 16:44:22 +08:00
Khairul Azhar Kasmiran
137d376f54
Kill debugged process on exit if non-interactive and dbg.exitkills is true (#3068) 2022-10-07 22:46:36 +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
Florian Märkl
2e8ec8ac75
Always detach when quitting from -q or -Q (#3058)
Previously, on macOS we were detaching properly when the user quit rizin
after an interactive `rz -d <file>` session, but not on
`rz -d -Qc <cmd> <file>`, which would leave behind a zombie process.
Now, the process is detached and keeps running, which also matches the
behavior on Linux. Hence the `dk 9` additions in the tests, to not
spoil the output with whatever the processes print.
2022-10-01 17:38:01 +02:00
Anton Kochkov
4bf6b67212
Convert dd commands to rzshell (#3049)
* Convert `dd` command to rzshell
* Remove unimplemented `dH` command
* Remove `ddt` command
* Move `date` command to the "shell" category
2022-09-29 08:24:50 +08:00
Giovanni
5b1e5e6762
Support blake3 hash algo (#3030) 2022-09-17 18:38:21 +02:00
wargio
8f40517990 Refactor rz_float_new_from_utXX_as_fXX 2022-09-16 21:55:58 +08:00
Anton Kochkov
52260857b5
Convert some of the a commands to the rzshell (#3025)
* Remove `ap` command
* Convert `ad` commands to rzshell
* Convert `aF` command to the rzshell
2022-09-15 21:09:15 +02:00
Heersin
b13202b934
RzUtil: softfloat support based on bitvector (#2784) 2022-09-14 14:38:22 +02:00
Giovanni
e3f72d8e72
Add nim lang support (#3015) 2022-09-10 18:20:05 +02:00
Giovanni
008363fcc4
Fix #2851 - wrong AVR analysis jump value for rjmp/rcall (#3012) 2022-09-07 23:00:23 +02:00
Giovanni
ade374378e
Add free-pascal demangling support (#3011)
* Add free-pascal demangling support
* Fixed tests
2022-09-06 10:39:58 +08:00
Dhruv Maroo
dee7baca00
Use correct enum for MOD and SMOD (#2988)
* Use correct rnum for `MOD` and `SMOD`

* Update `db/asm/ppc_64` to use `mod` instead of `smod`
2022-08-30 19:30:46 +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
Giovanni
c89b12a046
Removed plenty of eprintfs in rz_core (#2950) 2022-08-29 00:32:17 +08:00
Giovanni
3752e24b98
Update rz-libdemangle (#2984) 2022-08-27 02:35:07 +02:00
Riccardo Schirone
9ba89d8116 core/cmd: rewrite rz_cmd_macro API 2022-08-26 07:53:43 +08:00
Riccardo Schirone
02a0b7a1ad core/cmd: just store RzCore reference instead of void *data 2022-08-26 07:53:43 +08:00
wargio
0eef58115b Rewritten (partially) rz_run_parseline 2022-08-22 13:50:39 +02: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
c542bfcb4a Make cb use cfg.bigendian instead of host one
Fixes the remaining test in test/db/cmd/cmd_c on big endian hosts,
tested on OpenBSD/sparc64.
The mask calculation was removed because it was unnecessary (only
comparing selected bytes anyway) and wrong by a factor of 8 (bits vs.
bytes confusion).
2022-08-19 16:10:54 +02:00
Florian Märkl
e4182a6123 Make cu[1248] use cfg.bigendian instead of host one
Fixes the respective test in test/db/cmd/cmd_c on big endian hosts,
tested on OpenBSD/sparc64.
2022-08-19 16:10:54 +02:00
Riccardo Schirone
ac1b0e4d94
core/cmd: fix CHOICES argument selection between choices_cb/choices (#2932) 2022-08-18 20:10:13 +08:00
GustavoLCR
d25dff702a
Fix pg with fewer than 5 arguments (#2921) 2022-08-15 11:23:37 +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
a73e8ecd4d Add references and flags to constant pointers to data maps 2022-08-13 22:52:24 +02:00
karliss
32ef171354
Fix reset followed by color change in rz_cons_html_filter (#2912) 2022-08-13 09:43:18 +02:00
Giovanni
5655350535
Resolve golang string structures in data section (#2878) 2022-08-11 18:00:38 +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
Heersin
a9c59ce1dd
Add rz_bv_range_set and rz_bv_is_all_one to bitvector lib (#2891) 2022-08-10 08:20:16 +08:00
Rot127
9f64b41766
Disassemble invalid duplex instructions to invalid ; invalid. (#2889) 2022-08-08 21:05:50 +08:00
Rot127
720598f1f0
[Hexagon] Resolve duplex instructions dynamically (#2882)
* Chane HexInsn -> HexInsnContainer in asm plugin.

* Make HexInsn -> HexInsnContainer in hexagon_disas.c

* Add function to set concatinate textual disassembly parts.

* Switch expressions, fix segfault.

* Print number of unhandle ops, if they can not be added to RzAnalysisOp.

* Add lookup function to determine sub-instructions for duplex iclass.

* Fix asm tests.

* Add memcpy for instruction containers

* Fix off by one.

* Fix segfault if the packet held only the instruction which is currently resolved. `hic->bin.insn` would be NULL in this case.

* Remove duplicate index name.

* Set instruction address.

* Clean up hic->parse_bits use

* Fix: .new registers were not resolved dur to too early return.

* Fix rebase mistakes.
* Add missing code

* Fix build error: Use sizeof(`text_infix`) since it is way smaller than `text`

* Initialize `HexInsn` inside `setup_new_hic`. Fixes NULL access.

* Mark RzAsm/RzAnalysis members as deprecated and fix typo.
2022-08-08 08:12:53 +08:00
Anton Kochkov
f8def2f0f5
Remove reduntant license entries and READMEs (#2875)
* Remove reduntant license entries and READMEs
* Do not use `make`
2022-08-08 08:04:26 +08:00
Florian Märkl
e893d2fb66 Fix arm64 register access in xnu debugger
ARM_THREAD_STATE64 fetches arm_thread_state64_t but our struct was
arm_unified_thread_state_t, which adds a header. The pc in the register
profile was hacked to account for the shift, but all the x-regs were
not, so x7 had the value of x8 for example. Now we just use the specific
state for 32 or 64.
2022-08-07 19:22:40 +02:00
Florian Märkl
8681cdc43b Use cpu_type_t for checking xnu debuggee's arch
This fixes basic single-stepping on macOS/arm64.
dbg->bits is affected by all kinds of things going on in rizin, in
particular it currently randomly switches to 16 when calling pd during
an arm64 debug session, causing the stepping code to break.
We now fetch the cpu type of the process once during attach, similar to
how lldb does it. They also use 0 for the "invalid" value, so we do that
as well.
2022-08-07 19:22:40 +02:00
Florian Märkl
2525507152 Add tests for stepping and breakpoints on macOS/x86_64 2022-08-07 19:22:40 +02:00
billow
1054e6295f
Export pcA as rz_core_print_bytes_with_inst (#2880)
* export `rz_core_print_bytes_with_inst`
* move `pcA` to rzshell
2022-08-07 00:28:01 +08:00
Florian Märkl
5f97d93327 Rewrite and fix non-libuv tcp server (Rt command)
The non-libuv tcp server implementation had several issues:
* Relied on EINTR or self-connect through global vars for breaking,
  which did not work during recv() for example.
* Never retried on EINTR
* Called recv() only once, thus subject to fragmentation issues

To support breaking otherwise blocking socket calls, RzStopPipe has been
imported from chiaki (I am the sole author so I can relicense).

rz_socket_block_time() was also detected to be doing the exact opposite
than it should on Windows through the tests, and fixed.
2022-08-06 13:20:52 +02:00
billow
0908b65bc3
Convert px[ dDhHwWqQol] to rzshell
* `pxd` -> `pxd 4`
* `pxd<N> [len]` -> `pxd <N> [len]`
* expose APIs:
- `rz_core_print_cmp`
- `rz_core_print_dump`
- `rz_core_print_hexdump_`
- `rz_core_print_hexdump_byline`
* test for `pxW` `pxH`
* move `void rz_print_section` -> `const char *rz_print_section`
* `pxd` -> `pxd[ hwq]`
* `pxc`
* `pxAv` -> `pxAl`
* `pxt.` -> removed ?
* `px/` -> keep
* `pxf` -> TODO: not found old code ?
2022-08-04 09:11:22 +08: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
Rot127
b9fa2be193
Asm tokens fixes (#2855)
* Replace on s390x failing tms320 c55x test with c55x+ test.

* Fix resource leaks of parse paramters.

* Revive unreachable code.

* Raplace test with one which has not a different asm string in Capstone v3.

* Rename `new` to `newt` since `new` is a keyword and should not be used as var name.
2022-07-30 21:24:49 +08:00
Peiwei Hu
7f02a45dc3
Port command pb/B to new shell (#2828) 2022-07-29 00:20:10 +08:00
Florian Märkl
05a01569ac
Move warning from rz_reg_type_by_name to profile parsing (#2850)
The warning about non-existent register types is useful for register
profile parsing errors, but this function is also used by e.g.
`ar`/`dr`, so the overloaded `ar` would print a warning when given a
specific register name for example.
2022-07-28 15:22:04 +02:00
Florian Märkl
1d88af3c56
Refactor and replace .dm* calls with pure C (#2847)
This fixes the following minor issues:
* Errors like "Cannot create flag (...) because there is already (...)
  flag" during debug startup
* Unnecessary seeks during .dm* causing io reads and e.g. delays of up
  to 5s on x86 macOS during debug startup
* Flags are now created in the "maps" flagspace, rather than globally,
  making them easier to clean up later
* Flags now have the same size as the maps and not +1
2022-07-28 13:40:44 +02:00
Rot127
c009f8d7a3
Tokenize and colorize asm strings (#2417)
This introduces the ability to split asm strings into tokens and assign a type to them.

This means:
* Each asm strings is assigned a list of tokens. Each token points to a sub-string.
* A token has a type attached which describes it (e.g. register token, operator token, mnemonic token etc.)
* A generic parsing method is introduced which splits an asm string into tokens. The pattern it parses is `<mnem> <op> <op> ...`.
* Instead of the generic method, plugins can create the token strings on their own.
* An API method was introduced to help plugins implement their own parsing methods via regex patterns.
* Custom token strings are stored in `RzAsmOp.asm_toks`

Additionally the coloring of asm strings is now exclusively done via the token strings.
* For this a function was added to colorize tokenized asm strings according to their token types.
2022-07-27 08:52:01 -04:00