Commit graph

1066 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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