Commit Graph

57 Commits

Author SHA1 Message Date
Rot127 0c90fe13f5
Replace `assert` with `CS_ASSERT` in modules (#2478)
* Replace asserts with macros for AArch64, Alpha, LoongArch, Mips, SystemZ inc files.

* Add missing clearing of MCInst

* Ensure correct dir name is used.

* Replace asserts in inc files for PPC, ARM, TriCore

* Replace all asserts in modules with CS_ASSERT.

Also enable the CS_ASSERTs if CMAKE_BUILD_TYPE=Debug

* Formatting
2024-09-25 14:58:06 +08:00
Rot127 3a2cd3c331
Coverity defects (#2469)
* Fix CID 508418 - Uninitialized struct

* Fix CID 509089 - Fix OOB read and write

* Fix CID 509088 - OOB.

Also adds tests and to ensure no OOB access.

* Fix CID 509085 - Resource leak.

* Fix CID 508414 and companions - Using undefined values.

* Fix CID 508405 - Use of uninitialized value

* Remove unnecessary and badly implemented dev fuzz code.

* Fix CID 508396 - Uninitialzied variable.

* Fix CID 508393, 508365 -- OOB read.

* Fix CID 432207 - OVerlapping memory access.

* Remove unused functions

* Fix CID 432170 - Overlapping memory access.

* Fix CID 166022 - Check for negative index

* Let strncat not depend n src operand.

* Fix 509083 and 509084 - NULL dereference

* Remove duplicated code.

* Initialize sysop

* Fix resource leak

* Remove unreachable code.

* Remove duplicate code.

* Add assert to check return value of cmoack

* Fixed: d should be a signed value, since it is checked against < 0

* Add missing break.

* Add NULL check

* Fix signs of binary search comparisons.

* Add explicit cast of or result

* Fix correct scope of case.

* Handle invalid integer type.

* Return UINT_MAX instead of implicitly casted -1

* Remove dead code

* Fix type of im

* Fix type of d

* Remove duplicated code.

* Add returns after CS_ASSERTS

* Check for len == 0 case.

* Ensure shift operates on uint64

* Replace strcpy with strncpy.

* Handle edge cases for 32bit rotate

* Fix some out of enum warnings

* Replace a strcpy with strncpy.

* Fix increment of address

* Skip some linting

* Fix: set instruction id

* Remove unused enum

* Replace the last usages of strcpy with SStream functions.

* Increase number of allowed AArch64 operands.

* Check safety of incrementing t the next operand.

* Fix naming of operand

* Update python constants

* Fix option setup of CS_OPT_DETAIL_REAL

* Document DETAIL_REAL has to be used with CS_OPT_ON.

* Run Coverity scan every Monday.

* Remove dead code

* Fix OOB read

* Rename macro to reflect it is only used with sstreams

* Fix rebase issues
2024-09-18 21:19:42 +08:00
Sahil Siddiq 4f964a264e
Fix incorrect operand in disassembled instruction (#2401) (#2403)
Disassembling the "slwi", "srwi" and "rldicr" PowerPC instructions
with the "-d" option displays the wrong operands in the detailed
view. This is due to an incorrect break condition in the
"PPC_insert_detail_op_imm_at" function.

This patch fixes #2401.
2024-07-24 14:19:39 +08:00
Rot127 0a67596f70
Add test with ASAN enabled. (#2313)
* Add test with ASAN enabled.

* Fix leaks in cstool and cs.c

* Add work around so ASAN binaries don't DEADSIGNAL due to too many randomized address bits.

* Add ASAN build arguments to cstest

* Fix leaks in cstest

* Use cstest binary build by the main build.

* Add clonging step for cmocka when cstest is build

* Skip Python tests for ASAN

* Remove make build from CI

* Fix leaks in cstest.

- Rewrite split to remove leaks and improve runtime by 6%
- Add free()

* Fix cmocka external project to stable branch.

* Revert "Fix leaks in cstest."

This reverts commit bf8ee125b0c58f9c794eb081a69c80f8a71825cd.

* Fix memleaks in cstest

* Document adding of ASAN job to release guide

* Add CAPSTONE_BUILD_CSTEST to build docs

* Fix double free

* Add more detail tests to CI and fix them

* Initialize variables

* Fix typo

* Update cstest build docs

* Revert "Remove make build from CI"

This reverts commit 84f7360c6da6183cd41bec0fef3e1d0a2ee49ddf.

* Make cstest only run for cmake builds.

* Add cstest job for make build.

* Add CAPSTONE_DIET build test.

* Compile the compatibility header test with ASAN if enabled.

* Fix DIET build by excluding not used code.

* Missing "

* Build static library with ASAN and DIET if enabled.

* Revert "Add CAPSTONE_DIET build test."

This reverts commit 71e1469dee53bfdb6b275dd1be19f6eb21a0c023.
2024-06-10 10:01:00 +08:00
Florian Märkl 2ef45f2a73
Replace non-standard 0b(...) literals (#2314)
Despite being widely implemented and part of C++, the 0b prefix is not
part of any C standard and will be rejected by some compilers such as
Apple GCC 4.0.1 (5493).
2024-05-12 21:19:11 +08:00
RainRat b91c727481
fix typos (#2344) 2024-04-30 10:37:53 +08:00
Rot127 b4fde983de
[PPC] Expose instruction formats (#2276)
* Expose PPC formats in PPC details

* Add PPC format note in v6 release guide.

* Update python bindings
2024-02-23 13:20:46 +08:00
Rot127 123beeee4a Handle reserved values of the 'at' bits of BO fields. (#2168) 2023-09-22 12:55:18 +08:00
Rot127 3868266461 Add memory properties to iPTR operands. (#2165)
This has several consequences:

- Branch immediates are memory operands from now. Hence they are added manually as immediate.
- Some operands, handled over printOprerand(), are added to a mem operand, but the mem operand
  is never closed. There is simply no indication when a memory operand ends.
  So we close the mem operand now always, after an offset or disp awas added and the base exists.
2023-09-17 12:41:33 +08:00
Wu ChenXu 4d76f87640 [Fix] no return value error in Apple Silicon (#2160)
* Disable swift binding const generate

* Fix no return value error in Apple Silicon
2023-09-11 22:15:49 +08:00
Rot127 91fab10532 Run clang-format on PPC (#2157) 2023-09-09 21:09:13 +08:00
Rot127 926cfebd6b Architecture updater (auto-sync) - Updating PPC (#2013) 2023-09-05 12:24:59 +08:00
Rot127 104f693c11 Architecture updater (auto-sync) - Updating ARM (#1949)
* Add auto-sync updater.

* Update Capstone core with auto-sync changes.

* Update ARM via auto-sync.

* Make changes to arch modules which are introduced by auto-sync.

* Update tests for ARM.

* Fix build warnings for make

* Remove meson.build

* Print shift amount in decimal

* Patch non LLVM register alias.

* Change type of immediate operand to unsiged (due to: #771)

* Replace all occurances of a register with its alias.

* Fix printing of signed imms

* Print rotate amount in decimal

* CHange imm type to int64_t to match LLVM imm type.

* Fix search for register names, by completing string first.

* Print ModImm operands always in decimal

* Use number format of previous capstone version.

* Correct implicit writes and update_flags according to SBit.

* Add missing test for RegImmShift

* Reverse incorrect comparision.

* Set shift information for move instructions.

* Set mem access for all memory operands

* Set subtracted flag if offset is negative.

* Add flag for post-index memory operands.

* Add detail op for BX_RET and MOVPCLR

* Use instruction post_index operand.

* Add VPOP and VPUSH as unique CS IDs.

* Add shifting info for MOVsr.

* Add TODOs.

* Add in LLVM hardcoded operands to detail.

* Move detail editing from InstPrinter to Mapping

* Formatting

* Add removed check.

* Add writeback register and constraints to RFEI instructions.

* Translate shift immediate

* Print negative immediates

* Remove duplicate invalid entry

* Add CS groups to instructions

* Fix write attriutes of stores.

* Add missing names of added instructions

* Fix LLVM bug

* Add more post_index flags

* http -> https

* Make generated functions static

* Remove tab prefix for alias instructions.

* Set ValidateMCOperand to NULL.

* Fix AddrMode3Operand operands

* Allow getting system and banked register name via API

* Add writeback to STC/LDC instructions.

* Fix (hopefully) last case where disp is negative and subtracted = true

* Remove accidentially introduced regressions
2023-07-19 17:56:27 +08:00
Richard Patel 6a13a78d21 Run synctools (PPC PS support) 2022-07-23 08:50:47 +02:00
Richard Henderson 936dca0e2d Constify backends (#1549)
* Constify registerinfo.py output

Remove two conditionals separating identical bits of code.
Add "const" markup to MCRegisterDesc and MCRegisterClass.

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify instrinfo-arch.py output

In this case, do not actively strip const.

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the AArch64 backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the EVM backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify M680X backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify M68K backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the Mips backend

The Mips backend has not been regenerated from LLVM recently,
and there are more fixups required than I'd like.  Just apply
the fixes to the tables by hand for now.

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the Sparc backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the TMS320C64x backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the X86 backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the XCore backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify systemregister.py output

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the ARM backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the PowerPC backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the MOS65XX backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the SystemZ backend

The mapping of system register to indexes is easy to
generate read-only.  Since we know the indexes are
between 0 and 31, use uint8_t instead of unsigned.

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the WASM backend

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify cs.c

Signed-off-by: Richard Henderson <rth@twiddle.net>

* Constify the BPF backend

Signed-off-by: Richard Henderson <rth@twiddle.net>
2019-12-23 20:30:57 +08:00
Nguyen Anh Quynh baf70c9755 ppc: BDZLA is absolute branch. fix issue #968 2019-05-16 11:06:24 +08:00
Nguyen Anh Quynh ea538571e9 ppc: alias for Bcc instructions. issue #1468 2019-05-10 00:57:03 +08:00
Nguyen Anh Quynh 37dda9d4b7 ppc: proper map internal register ID to public register ID 2019-05-09 18:26:45 +08:00
Nguyen Anh Quynh 2a9e171e3c ppc: print condition register bits. issue #1469 2019-05-08 13:56:40 +08:00
Nguyen Anh Quynh 0ebcc815cf ppc: fix target address of B. issue #1468 2019-05-07 16:08:45 +08:00
Nguyen Anh Quynh b543c345ca ppc: sync with llvm 7.0.1 2019-04-30 13:50:42 +08:00
Riccardo Schirone c316ef189d arch/M68k: do not return reg_name if beyond limits (#1219)
* arch/M68k: do not return reg_name if beyond limits

(patch coming from radare2)

* arch: checks index when returning reg names
2018-07-24 16:25:47 +08:00
Nguyen Anh Quynh 76c1c3c4e9 merge next to master 2018-07-20 12:36:50 +08:00
Richard Henderson 5423b215bf Constify backend data (#1040)
* Constify string literals

Use -Wwrite-strings to force string literals to be of
type "const char[]", then fix up all warning fallout.

* Constify common infrastructure

Step one in allowing backend data to be readonly.
Minimal changes to backends for now; just set all pointers
in common structs that aren't modified to const.

* Constify AArch64 backend

Section size changes within libcapstone.so are

-.rodata               602587
-.data.rel.ro          228416
-.data                1003746
+.rodata               769051
+.data.rel.ro          241120
+.data                 824578

* Constify ARM backend

Section size changes within libcapstone.so are

-.rodata               769051
-.data.rel.ro          241120
-.data                 824578
+.rodata               959835
+.data.rel.ro          245120
+.data                 629506

* Constify Mips backend

Section size changes within libcapstone.so are

-.rodata               959835
-.data.rel.ro          245120
-.data                 629506
+.rodata              1069851
+.data.rel.ro          256416
+.data                 508194

* Constify PowerPC backend

Section size changes within libcapstone.so are

-.rodata              1069851
-.data.rel.ro          256416
-.data                 508194
+.rodata              1142715
+.data.rel.ro          272224
+.data                 419490

* Constify Sparc backend

Section size changes within libcapstone.so are

-.rodata              1142715
-.data.rel.ro          272224
-.data                 419490
+.rodata              1175227
+.data.rel.ro          277536
+.data                 381666

* Constify SystemZ backend

Section size changes within libcapstone.so are

-.rodata              1175227
-.data.rel.ro          277536
-.data                 381666
+.rodata              1221883
+.data.rel.ro          278016
+.data                 334498

* Constify X86 backend

Section size changes within libcapstone.so are

-.rodata              1221883
-.data.rel.ro          278016
-.data                 334498
+.rodata              1533531
+.data.rel.ro          281184
+.data                  19714

* Constify XCore backend

Section size changes within libcapstone.so are

-.rodata              1533531
-.data.rel.ro          281184
-.data                  19714
+.rodata              1553026
+.data.rel.ro          281280
+.data                     40
2017-10-22 08:45:40 +08:00
Nguyen Anh Quynh 1182d25759 simplify ARCH_group_name() by using lookup table as suggested by @learn_more. also added the missing group name for GRP_PRIVILEGE 2015-04-27 12:13:34 +08:00
Nguyen Anh Quynh efffe787d1 Add new API and start to provide access information for instruction operands
- New API cs_regs_access() that provide registers being read & modified by instruction

- New field cs_x86_op.access provides access info (READ, WRITE) for each operand

- New field cs_x86.eflags provides EFLAGS affected by instruction

- Extend cs_detail.{regs_read, regs_write} from uint8_t to uint16_t type
2015-03-25 15:02:13 +08:00
Nguyen Anh Quynh b8ffb86b02 ppc: fix a bug in QPX mode & add some QPX alias instructions. 2015-03-12 16:52:31 +08:00
Nguyen Anh Quynh 0cc0543486 ppc: add missing groups to group_name_maps[]. bug reported by Coverity 2015-03-12 00:30:44 +08:00
Nguyen Anh Quynh 8c212fd25e ppc: add the missing Q0 register to reg_name_maps[]. bug reported by Coverity 2015-03-11 10:29:08 +08:00
Nguyen Anh Quynh bb5dccedfa core: put insns[] into separate .inc files to make it easier to manage 2015-03-08 10:54:32 +08:00
Nguyen Anh Quynh bfcaba5851 2015 2015-03-04 17:45:23 +08:00
Nguyen Anh Quynh 0be9eab6ba ppc: update core 2015-03-04 17:06:48 +08:00
Nguyen Anh Quynh 674db4c96f ppc: fix some compilation bugs when DIET mode is enable 2014-12-16 22:12:23 +08:00
Nguyen Anh Quynh c00bc2efb6 fix the left-over C89 issues introduced by Pedro 2014-11-21 19:29:47 +08:00
reverser 68197d9a5e Make it C89 compatible. 2014-11-20 13:45:43 +00:00
reverser 202da41980 Fix compiler warnings about different sizes and sign. 2014-11-20 12:13:19 +00:00
Nguyen Anh Quynh c2ea812ea7 fix cs_group_name() after the change on generic group ids 2014-10-31 15:36:19 +08:00
kratolp 73835104a4 Merge branch 'next' of https://github.com/aquynh/capstone into next
Conflicts:
	arch/PowerPC/PPCInstPrinter.c
2014-10-01 11:54:14 +02:00
kratolp a3f0aef79a PPC: Fix absolute/relative offset for branch instruction
PPC: Fix non handling of bc instruction that uses the CTR
2014-10-01 11:39:15 +02:00
Nguyen Anh Quynh e135056f17 fix a negative array index read in PPC_alias_insn(). issue reported by Coverity 2014-10-01 14:23:35 +08:00
Nguyen Anh Quynh d7e42b7d36 rename all the constants marking ending from _MAX to _ENDING. this also updates Java/Python/Ocaml bindings accordingly 2014-09-29 17:15:25 +08:00
Nguyen Anh Quynh 7e57e79800 ppc: handle branch condition for alias instructions. this also updates Python & Java bindings 2014-09-21 13:04:50 +08:00
Nguyen Anh Quynh eaecfa4925 ppc: add PPC_INS_BNE for alias instruction BNE 2014-09-16 23:13:14 +08:00
Nguyen Anh Quynh 721d07f6b2 ppc: support alias instructions. update Python & Java bindings accordingly 2014-09-04 12:03:31 +08:00
Nguyen Anh Quynh 159ddbd99f ppc: add new groups to group_name_maps[] 2014-08-15 16:35:12 +08:00
Nguyen Anh Quynh 91a64776a8 ppc: fix a mistake on interpreting CR registers by deleting CR8 -> CR31 2014-08-15 13:48:11 +08:00
Nguyen Anh Quynh dd3deec1e9 ppc: update core. this added new instructions, groups & registers. updated Python & Java bindings accordingly 2014-08-15 13:26:12 +08:00
Nguyen Anh Quynh 650f96ce43 add new API cs_group_name() to return group name in string, given the group id 2014-07-08 08:59:27 +08:00
Nguyen Anh Quynh 04f2ec6d0f cleanup redundant headers included 2014-05-27 10:39:04 +08:00
Nguyen Anh Quynh 8598a219f3 enable arch code from source with CAPSTONE_HAS_* for MSVC to pick up 2014-05-14 11:26:41 +08:00