capstone-engine / capstone

Capstone disassembly/disassembler framework for ARM, ARM64 (ARMv8), Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
http://www.capstone-engine.org
7.51k stars 1.54k forks source link

Auto-Sync Mips #2410

Closed wargio closed 3 weeks ago

wargio commented 2 months ago

Your checklist for this pull request

Detailed description Adds options for:

Adds support for:

cstool has been refactored for better UX: now by adding +<feature> you can directly modify the output of capstone using all options.

Arch specific options:
        +att             ATT syntax (only: x86)
        +intel           Intel syntax (only: x86)
        +masm            Intel MASM syntax (only: x86)
        +noregname       Number only registers (only: Arm64, ARM, LoongArch, Mips, PowerPC)
        +moto            Use $ as hex prefix (only: MOS65XX)
        +regalias        Use register aliases, like r9 > sb (only: ARM, Arm64)
        +percentage      Adds % in front of the registers (only: PowerPC)
        +nodollar        Removes $ in front of the registers (only: Mips)
        +nofloat         Disables floating point support (only: Mips)
        +ptr64           Enables 64-bit pointers support (only: Mips)

For example:

$ ./build/cstool -s mipsel64+nofloat "32 C0 38 46 32 02 20 46 32 03 20 "
 0  32 c0 38 46  .byte  0x32, 0xc0, 0x38, 0x46
 4  32 02 20 46  .byte  0x32, 0x02, 0x20, 0x46
$ ./build/cstool -s mipsel64 "32 C0 38 46 32 02 20 46 32 03 20 "
 0  32 c0 38 46  c.eq.d $f24, $f24
 4  32 02 20 46  c.eq.d $fcc2, $f0, $f0

Also fixes the following issues:

$ ./build/cstool mips3 0120102d0080e82d40ab500000a0402d0080502d01a0702d40ac1000
 0  01 20 10 2d  move   $v0, $t1
 4  00 80 e8 2d  move   $sp, $a0
 8  40 ab 50 00  dmtc0  $t3, $10, 0
 c  00 a0 40 2d  move   $t0, $a1
10  00 80 50 2d  move   $t2, $a0
14  01 a0 70 2d  move   $t6, $t5
18  40 ac 10 00  dmtc0  $t4, $2, 0
Rot127 commented 1 month ago

The auto-sync test is fixed in the modern_testing PR.

Rot127 commented 4 weeks ago
diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py
index 67f7faae..58092ea0 100644
--- a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py
+++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py
@@ -41,9 +41,9 @@ class FieldFromInstr(Patch):

         # Determine width of instruction by the variable name.
         if ffi_first_arg_text[-2:] == "32":
-            inst_width = 4
+            inst_width = b"4"
         elif ffi_first_arg_text[-2:] == "16":
-            inst_width = 2
+            inst_width = b"2"
         else:
             # Get the Val/Inst parameter.
             # Its type determines the instruction width.
diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml
index 9d26470d..d1428d06 100644
--- a/.github/workflows/auto-sync.yml
+++ b/.github/workflows/auto-sync.yml
@@ -101,4 +101,3 @@ jobs:
           ./src/autosync/cpptranslator/Differ.py -a ARM --check_saved
           ./src/autosync/cpptranslator/Differ.py -a PPC --check_saved
           ./src/autosync/cpptranslator/Differ.py -a LoongArch --check_saved
-          ./src/autosync/cpptranslator/Differ.py -a Mips --check_saved
wargio commented 4 weeks ago

@Rot127 fixed

wargio commented 3 weeks ago

@kabeor

XVilka commented 3 weeks ago

Would be nice to get it merged, so Coverity would check this code too, also we could update it in Rizin @kabeor