Update read/written registers for x86 string instructions (#2790)

* stosb/w/d/q

stosq only reads/writes rcx when there is a rep prefix.

With regard to reading 'es' in 64-bit mode, the SDM says for stosd

  For legacy mode, store EAX at address ES:(E)DI; For 64-bit mode store
  EAX at address RDI or EDI.

* lodsb/w/d/q

With regard to reading 'ds' in 64-bit mode, the SDM says for lodsd

  For legacy mode, Load dword at address DS:(E)SI into EAX. For 64-bit
  mode load dword at address (R)SI into EAX.

* scasb/w/d/q

X86_REG_ES was removed from the explicit set of read registers because
it was causing duplicate entries in 'detail->regs_read'.

With regard to reading 'es' in 64-bit mode, the SDM says for scasd

  Compare EAX with doubleword at ES:(E)DI or RDI then set status flags.

* cmpsb/w/d/q

The 'es' register is implicitly handled correctly. The 'ds' register
should only be read from in 16- and 32-bit mode. From the SDM for cmpsd:

  For legacy mode, compare dword at address DS:(E)SI with dword at
  address ES:(E)DI; For 64-bit mode compare dword at address (R|E)SI
  with dword at address (R|E)DI. The status flags are set accordingly.

* movsb/w/d/q

The 'es' register is implicitly handled correctly. The 'ds' register
should only be read from in 16- and 32-bit mode. From the SDM for movsd:

  For legacy mode, move dword from address DS:(E)SI to ES:(E)DI. For
  64-bit mode move dword from address (R|E)SI to (R|E)DI.

* insb/w/d/q

X86_REG_EDI was removed from the explicit set of read registers because
it was causing duplicate entries in 'detail->regs_read'.

The 'ds' register should only be read from in 16- and 32-bit mode. From
the SDM for insd:

  Input doubleword from I/O port specified in DX into memory location
  specified in ES:(E)DI or RDI.

* outsb/w/d/q

The 'ds' register should only be read from in 16- and 32-bit mode. From
the SDM for outsd:

  Output word from memory location specified in DS:(E)SI or RSI to I/O
  port specified in DX.
6 files changed
tree: 282e75ee7f10d402d6e041cde4b8e86ccabc25c3
  1. .github/
  2. .reuse/
  3. arch/
  4. bindings/
  5. contrib/
  6. cstool/
  7. docs/
  8. include/
  9. LICENSES/
  10. packages/
  11. suite/
  12. tests/
  13. windows/
  14. windowsce/
  15. xcode/
  16. .appveyor.yml
  17. .clang-format
  18. .dockerignore
  19. .editorconfig
  20. .gitattributes
  21. .gitignore
  22. .gitmodules
  23. BUILDING.md
  24. capstone-config.cmake.in
  25. capstone.pc.in
  26. ChangeLog
  27. cmake.sh
  28. cmake_uninstall.cmake.in
  29. CMakeLists.txt
  30. CMakePresets.json
  31. COMPILE_MAKE.TXT
  32. config.mk
  33. CONTRIBUTING.md
  34. CPackConfig.cmake
  35. CPackConfig.txt
  36. CREDITS.TXT
  37. cs.c
  38. cs_priv.h
  39. cs_simple_types.h
  40. functions.mk
  41. LEB128.h
  42. make.sh
  43. Makefile
  44. Mapping.c
  45. Mapping.h
  46. MathExtras.h
  47. MCAsmInfo.h
  48. MCDisassembler.h
  49. MCFixedLenDisassembler.h
  50. MCInst.c
  51. MCInst.h
  52. MCInstPrinter.c
  53. MCInstPrinter.h
  54. MCInstrDesc.c
  55. MCInstrDesc.h
  56. MCRegisterInfo.c
  57. MCRegisterInfo.h
  58. pkgconfig.mk
  59. README.md
  60. SPONSORS.TXT
  61. SStream.c
  62. SStream.h
  63. utils.c
  64. utils.h
README.md

Capstone Engine

Build status pypi package pypi downloads oss-fuzz Status

[!TIP] Welcome to join our community group!  

Capstone is a disassembly framework with the target of becoming the ultimate disasm engine for binary analysis and reversing in the security community.

Created by Nguyen Anh Quynh, then developed and maintained by a small community, Capstone offers some unparalleled features:

  • Support multiple hardware architectures: ARM, AArch64, Alpha, ARC, BPF, Ethereum VM, LoongArch, HP PA-RISC (HPPA), M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86 (16, 32, 64), Xtensa.

  • Having clean/simple/lightweight/intuitive architecture-neutral API.

  • Provide details on disassembled instruction (called “decomposer” by others).

  • Provide semantics of the disassembled instruction, such as list of implicit registers read & written.

  • Implemented in pure C language, with lightweight bindings for Swift, D, Clojure, F#, Common Lisp, Visual Basic, PHP, PowerShell, Emacs, Haskell, Perl, Python, Ruby, C#, NodeJS, Java, GO, C++, OCaml, Lua, Rust, Delphi, Free Pascal & Vala ready either in main code, or provided externally by the community).

  • Native support for all popular platforms: Windows, Mac OSX, iOS, Android, Linux, *BSD, Solaris, etc.

  • Thread-safe by design.

  • Special support for embedding into firmware or OS kernel.

  • High performance & suitable for malware analysis (capable of handling various X86 malware tricks).

  • Distributed under the open source BSD license.

Further information is available at https://www.capstone-engine.org

Compile

See BUILDING.md file for how to compile and install Capstone.

Documentation

Contributing

See CONTRIBUTING.md for an intro.

Fuzz

See suite/fuzz/README.md for more information.

License

This project is released under the BSD license. If you redistribute the binary or source code of Capstone, please attach file LICENSE.TXT with your products.