Commit graph

81 commits

Author SHA1 Message Date
Anton Kochkov
f1006f97c2
arm: use cortexm cpu instead of cortex (#3674) 2023-07-20 16:20:04 +08:00
Heersin
c0850845f1
RzIL: asm tests for ARM32 VFP and NEON (#3662) 2023-07-20 11:30:17 +08:00
billow
e456c60e20 Fix tests for capstone v3/v4/v5
Co-authored-by: wargio <wargio@libero.it>
2023-07-16 13:22:47 +08:00
Dhruv Maroo
5f14d0e0b5 Fix analysis tests 2023-06-14 11:04:34 +08:00
Dhruv Maroo
2f6f2cfdce Fix ROR and update instruction asm tests 2023-06-14 11:04:34 +08:00
Dhruv Maroo
aa7781b098 Remove unnecessary local variable in IL for test instruction 2023-06-14 11:04:34 +08:00
Dhruv Maroo
5211e1835b Fix integration tests for x86 IL 2023-06-14 11:04:34 +08:00
Florian Märkl
daffe8bbbb
Fix arm64 adrp assembler (#3519)
Fixed the calculation of the immediate value and more spaces, e.g.
"adrp     x0, 0x1234000" are allowed now.
2023-05-21 11:16:37 +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
billow
291d2a683c
Uplifting 8051 architecture to new IL (#2999) 2022-12-14 13:13:21 +01:00
Dhruv Maroo
ce80a13aed
x86 RzIL uplifting (#2747) 2022-11-28 09:33:19 +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
Giovanni
008363fcc4
Fix #2851 - wrong AVR analysis jump value for rjmp/rcall (#3012) 2022-09-07 23:00:23 +02: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
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
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
Dean
bf2871c7eb
Add dotnet PE support (#2528)
* Add CIL support

* refactor dotnet parsing to pe/dotnet.c
* parse PE CLR metatables (based on yara implementation)
* use CLR methoddefs to add binsymbols (including method namespace/class)
* parse CLR method headers
* CIL disassembler using .NET opcodes.def
* CIL analysis plugin
2022-06-21 09:20:47 +08:00
Florian Märkl
3cbde10260
Update Hexagon for compact struct conversion (#2548)
This is updating with rz-hexagon 1ca78d073861b6ce66b682d200c7a3fc2734a6a3
2022-04-22 17:50:39 +02:00
Rot127
10bedc2b00
Add Hexagon register profile (#2490)
Although the reg profile was not really used yet it will be relevant for the RZIL uplifting.
Introduces:
* Double/quadruple registers now properly overlap with their counterparts.
* Registers have correct types assigned (vec, ctr, sys etc. Before, all regs were of type gbr)
* Consistent register names (asm name style: c3:2, r31 etc, alias style: lc1:sa1, lr etc.)
* Adds _tmp registers in the profile. Later used by uplifted instructions (think of .new registers).
2022-04-03 18:26:17 +02:00
Rot127
628d04f713
Add RzConfig for asm plugins (#2488)
* Add function to add config node to config by `RzConfigNode*`
* Move `SET<NODE>` macros to `rz_config.h`
* Add un/set functions for plugin specific configs.
* Add RzConfig and node setter to hexagon plugin.
* Use plugins RzConfig to determine sdk syntax setting.
* Use plugins RzConfig to determine if numbers should be signed.
* Use plugins RzConfig to determine if immediate hash should be printed.
* Remove unused parameter `rz_asm`.
* Remove unused variable.
* Remove unused callback.
* Remove unused flags from `RzAsm`
* Fix asm tests: Add NULL check; Set correct sign in asm test.
2022-04-03 20:44:50 +08:00
Florian Märkl
8414d224ed
[RzIL] Add lifter for Armv8 AArch64 (#2354) 2022-03-27 10:29:51 +02:00
Florian Märkl
298ac10d6e
[RzIL] Fix sbc/sbci and leaks in AVR lifter (#2389)
Leaks detected by running rz-test with asan-built rz-asm. The sbc
instructions didn't do the carry subtraction right and threw away half
of the computation, which is why it was detected through leaks.
2022-03-07 15:50:11 +00:00
Giovanni
63622fa9e6
[RzIL] AVR lifter (#1890)
Added all the ops excluding des and spm due their complexity
Added tests to verify output of each execution cycle.
2022-02-22 18:54:55 +01:00
Florian Märkl
bfb98ed20c
[RzIL] Add lifter for 32-bit Arm, including thumb (#2241) 2022-02-22 12:23:28 +00:00
Rot127
3d71687d5e
Add Hexagon IDE conforming packet syntax (#2209)
* Add option to print instruction packets syntax in objdump style.
* Add the config `plugins.hexagon.sdk` to toggle syntax.
* Remove unused trimming.
* Trim only newlines from the assembly string.
* Add new trim functions to allow trimming of certain chars.
2022-02-14 02:27:55 +08:00
Florian Märkl
d533276df8 Fix cmn, teq and tst in arm32 assembler 2022-02-06 12:32:22 +08:00
Florian Märkl
6af80b33a7
[RzIL] Coalesce nested seq when printing (#2262)
Change printing of
    (seq (...) (seq (...) (...)))
to just
    (seq (...) (...) (...))
2022-01-28 16:58:51 +01:00
Florian Märkl
bbe3c0724d
Add sb (= r9) alias to arm assembler (#2260) 2022-01-28 16:58:35 +01:00
Florian Märkl
5a2d80c728 [RzIL] Fix sbc V and unused status bit
Detected with rz-tracetest
2022-01-22 20:04:24 +01:00
Florian Märkl
5c4a9aac68 [RzIL] Fix 6502 asl and sbc 2022-01-22 09:40:20 +08:00
Rot127
e9be7afc37
Fix CID 367529 (#2231)
* Remove duplicated branch to determine instruction type.
* Fix test by removing not utilized 0x0.
2022-01-21 14:06:14 +01:00
Florian Märkl
90e4e5cf16
[RzIL] Fix rti and stack behavior in 6502 IL
Detected with rz-tracetest
2022-01-21 09:22:34 +01:00
Florian Märkl
20777b6e0b
[RzIL] Make bf emulation stateless (#2214) 2022-01-16 14:33:05 +01:00
Florian Märkl
114667a34e [RzIL] Implement 6502 Lifting
This adds RzIL lifting for all legal 6502 ops, except the special bcd
modes of adc and sbc for now. The lifting of every one of these ops is
covered by an asm test, making sure all IL is valid. Some manual
execution tests are available too, including one that runs a simple
real-world xor-"decryption" loop.
The lifting has not been tested against traces yet, so minor mistakes in
the semantics are currently expected.
2022-01-16 03:21:49 +01:00
Rot127
f40b5ef545
Hexagon v69 update (#2180)
Also new in this commit:
- Uses system registers as defined in LLVM definitions.
- Several new Hexagon v69 (HVX) instructions.
- File header now has the LLVM commit and timestamps of the source file generation.
2022-01-14 16:46:38 +08:00
Florian Märkl
4f1e4ee6d5 Add asm tests for all legal 6502 ops
Ops with relative addressing now also only pad with 4 leading zeroes.
2022-01-14 00:47:33 +08:00
Florian Märkl
c8a6359d83
Change IL string syntax to s-expressions (#2193)
Before:
	store(key:var(v:ptr), value:add(x:load(key:var(v:ptr), mem:0),
	    y:int(value:1, length:8)), mem:0)
After:
	(store 0 (var ptr) (+ (load 0 (var ptr)) (bv 8 0x1)))

S-Expressions like this are more concise and will be trivial to parse,
in case we want a parser for this later. It is also very similar to what
BAP uses, so it will be easier to compare.
2022-01-11 10:08:41 +01:00
Florian Märkl
7e36f4bd38 Add IL lifting testing to rz-test 2022-01-10 19:27:09 +01:00
Anton Kochkov
715dd14811
Remove unused, unupdated and largely untested ARM WineDBG and GNU (Binutils) plugins (#2085)
* Remove WineDBG ARM RzAsm plugin
* Remove unused and untested ARM GNU target
2021-12-10 16:40:58 +01:00
Rot127
26103ee383
Update Hexagon asm and analysis plugins (#1614)
* Add support for: v5-v68+HVX, System instructions/register; Change plugin design to monolithic; Basic ELF-reloc patching.

- Update instruction set to v5-v67 + HVX.
- Introduce monolithic plugin architecture to reverse opcodes in the same functions.
  - Analysis and Asm functionality was previously seperated and let to inconsistensies and incorrectly reversed opcodes.
- Add missing system instructions and registers.
- Enable search for immediates.
- Mark packets of instructions.
- Set more analysis data in RzAnalysisOp.
- Add basic ELF-reloc patching.
- Fix several disassembly and analysis bugs.
  - Jumps were not aligned to packet begin.
  - Endloop packets were not marked as such.
  - Rs.New registers were incorrectly disassembled.
  - Calling convention was out of date.
- Add several formatting configs for the produced disassembly.
  - Dis/Enable UTF-8.
  - Print or omit # prefix of immediates.
  - Print signed immediates as signed or unsigned integers.
2021-11-28 01:40:04 +08:00
Florian Märkl
fd8d84b475
Remove rX_rY Hacks in AVR ESIL (#1988) 2021-11-16 23:07:05 +01:00
Florian Märkl
86e4df8655
Remove r1_r0 Hack from AVR (#1985) 2021-11-16 02:52:10 +01:00
Murphy
0c74a7ef5d Fix #18619 - Wrong assembly generated for: "add x0, x0, 1, lsl #12" (ARM64) ##asm
Signed-off-by: Riccardo Schirone <sirmy15@gmail.com>
2021-08-18 09:16:23 +02:00
Giovanni
b9dd6ae264
AVR LGPL Assembler and Disassembler + tests (#1028) 2021-04-16 10:01:39 +08:00
Heersin
3bbff71ee1
Lua 5.3 support RzAsm + RzAnalysis 2021-04-14 16:22:15 +08:00
Giovanni
34e8f7e768
Java assembler (#903) 2021-03-25 17:52:36 +08:00
Florian Märkl
bed31a6173 Remove Whitespace Asm+Analysis Plugins because the Results are wrong 2021-03-25 08:52:39 +08:00