├── .gitattributes ├── .gitignore ├── 00doc.go ├── LICENSE ├── README.md ├── addresswidth.go ├── callbackmap.go ├── cmd └── demo.go ├── cpuflagaction.go ├── decoder.go ├── element.go ├── exceptionclass_string.go ├── features.go ├── formatter+callbacks.go ├── formatter.go ├── go.mod ├── instruction.go ├── instructioncategory_string.go ├── isaext.go ├── isaext_string.go ├── isaset.go ├── isaset_string.go ├── lib ├── Makefile └── include │ ├── Zycore │ ├── API │ │ ├── Memory.h │ │ ├── Synchronization.h │ │ ├── Terminal.h │ │ └── Thread.h │ ├── Allocator.h │ ├── ArgParse.h │ ├── Bitset.h │ ├── Comparison.h │ ├── Defines.h │ ├── Format.h │ ├── LibC.h │ ├── List.h │ ├── Object.h │ ├── Status.h │ ├── String.h │ ├── Types.h │ ├── Vector.h │ └── Zycore.h │ ├── ZycoreExportConfig.h │ ├── Zydis │ ├── Decoder.h │ ├── DecoderTypes.h │ ├── Formatter.h │ ├── FormatterBuffer.h │ ├── Generated │ │ ├── EnumISAExt.h │ │ ├── EnumISASet.h │ │ ├── EnumInstructionCategory.h │ │ ├── EnumMnemonic.h │ │ └── EnumRegister.h │ ├── Internal │ │ ├── DecoderData.h │ │ ├── FormatterATT.h │ │ ├── FormatterBase.h │ │ ├── FormatterIntel.h │ │ ├── SharedData.h │ │ └── String.h │ ├── MetaInfo.h │ ├── Mnemonic.h │ ├── Register.h │ ├── SharedTypes.h │ ├── ShortString.h │ ├── Status.h │ ├── Utils.h │ └── Zydis.h │ └── ZydisExportConfig.h ├── libzydis_darwin_amd64.syso ├── libzydis_darwin_arm64.syso ├── libzydis_linux_amd64.syso ├── libzydis_linux_arm64.syso ├── libzydis_windows_386.syso ├── libzydis_windows_amd64.syso ├── machinemode.go ├── mnemonic.go ├── mnemonic_string.go ├── opcodemap.go ├── operand.go ├── register.go └── register_string.go /.gitattributes: -------------------------------------------------------------------------------- 1 | *.syso filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib/zydis 2 | lib/out 3 | .vscode 4 | -------------------------------------------------------------------------------- /00doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Zydis is a Go wrapper for the fast and lightweight Zydis x86/x86-64 6 | // disassembler library, found at http://zydis.re/. This package provides 7 | // bindings via cgo and is considered a "complete" wrapper of the Zydis API, 8 | // ready for production use. 9 | // 10 | // It was created because the pure-Go disassembler, found at 11 | // https://godoc.org/golang.org/x/arch/x86/x86asm, is significantly lacking in 12 | // x86-64 support. Decoding x86* is complex business, and it was more 13 | // straightforward to write these bindings instead of digging deep into the 14 | // pure-Go package. 15 | // 16 | // Requires Git-LFS 17 | // 18 | // **This package uses Git LFS found to store a precompiled version of the Zydis 19 | // library (see below), so please make sure you have it installed before 20 | // getting this package.** Learn about Git LFS at https://git-lfs.github.com/. 21 | // 22 | // Sample Code 23 | // 24 | // See the file `cmd/demo.go`. 25 | // 26 | // Upgrading the Zydis Library 27 | // 28 | // The Zydis library is packaged as a static syso object file so that this 29 | // package is go gettable. Precompiled macOS (amd64, arm64), Linux (amd64, 30 | // arm64), and Windows (amd64, 386) binaries are provided. 31 | // 32 | // Use the Makefile in the `lib/` folder to upgrade to a newer version, 33 | // rebuild, or add support for another platform. The default Makefile target 34 | // clones the Zydis repo and its submodule, performs the build, and creates the 35 | // syso files for Go linkage under macOS with suitable cross-compilers 36 | // installed. 37 | // 38 | package zydis // import "go.jpap.org/zydis" 39 | 40 | // To install: `go install go.jpap.org/godoc-readme-gen` 41 | // 42 | //go:generate godoc-readme-gen -f -title "Zydis Bindings for Go" 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2019 John Papandriopoulos. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Zydis Bindings for Go [![GoDoc](https://pkg.go.dev/badge/go.jpap.org/zydis.svg)](https://pkg.go.dev/go.jpap.org/zydis) 3 | 4 | # Import 5 | 6 | ```go 7 | import "go.jpap.org/zydis" 8 | ``` 9 | # Overview 10 | 11 | Zydis is a Go wrapper for the fast and lightweight Zydis x86/x86-64 12 | disassembler library, found at http://zydis.re/. This package provides 13 | bindings via cgo and is considered a "complete" wrapper of the Zydis API, 14 | ready for production use. 15 | 16 | It was created because the pure-Go disassembler, found at 17 | https://godoc.org/golang.org/x/arch/x86/x86asm, is significantly lacking in 18 | x86-64 support. Decoding x86* is complex business, and it was more 19 | straightforward to write these bindings instead of digging deep into the 20 | pure-Go package. 21 | 22 | ## Requires Git-LFS 23 | **This package uses Git LFS found to store a precompiled version of the Zydis 24 | library (see below), so please make sure you have it installed before 25 | getting this package.** Learn about Git LFS at https://git-lfs.github.com/. 26 | 27 | ## Sample Code 28 | See the file `cmd/demo.go`. 29 | 30 | ## Upgrading the Zydis Library 31 | The Zydis library is packaged as a static syso object file so that this 32 | package is go gettable. Precompiled macOS (amd64, arm64), Linux (amd64, 33 | arm64), and Windows (amd64, 386) binaries are provided. 34 | 35 | Use the Makefile in the `lib/` folder to upgrade to a newer version, 36 | rebuild, or add support for another platform. The default Makefile target 37 | clones the Zydis repo and its submodule, performs the build, and creates the 38 | syso files for Go linkage under macOS with suitable cross-compilers 39 | installed. 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /addresswidth.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // AddressWidth is an enum of processor address widths. 8 | type AddressWidth int 9 | 10 | // AddressWidth enum values. 11 | const ( 12 | AddressWidth16 AddressWidth = iota 13 | AddressWidth32 14 | AddressWidth64 15 | ) 16 | -------------------------------------------------------------------------------- /callbackmap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | import ( 8 | "sync" 9 | "sync/atomic" 10 | "unsafe" 11 | ) 12 | 13 | // CallbackMap manages callback tokens in a threadsafe way. 14 | type CallbackMap struct { 15 | m sync.Map // token uintptr -> value interface{} 16 | k uintptr 17 | } 18 | 19 | // NewToken issues a new token that can be used for a callback. 20 | func (cm *CallbackMap) NewToken(value interface{}) (token unsafe.Pointer) { 21 | token = unsafe.Pointer(atomic.AddUintptr(&cm.k, 1)) 22 | cm.m.Store(token, value) 23 | return 24 | } 25 | 26 | // GetToken retrieves the value associated with a given token, removes it 27 | // from the map, and returns it. Panics on an unknown token. 28 | func (cm *CallbackMap) GetToken(token unsafe.Pointer) (value interface{}) { 29 | value, ok := cm.m.Load(token) 30 | if !ok { 31 | panic("CallbackMap: invalid token") 32 | } 33 | cm.m.Delete(token) 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /cmd/demo.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "encoding/hex" 9 | "fmt" 10 | 11 | "go.jpap.org/zydis" 12 | ) 13 | 14 | func main() { 15 | // Show Zydis library version. 16 | major, minor, patch, build := zydis.Version() 17 | fmt.Printf("Version: %d.%d.%d.%d\n", major, minor, patch, build) 18 | 19 | // Instruction stream to decode. 20 | data := []byte{ 21 | 0x55, // pushq %rbp 22 | 0x48, 0x89, 0xe5, // movq %rsp, %rbp 23 | 0x48, 0x83, 0xe4, 0xe0, // andq $-32, %rsp 24 | 0x48, 0x81, 0xec, 0xa0, 0x00, 0x00, 0x00, // subq $160, %rsp 25 | 0xc5, 0xf9, 0xef, 0xc0, // vpxor %xmm0, %xmm0, %xmm0 26 | 0xc5, 0xfd, 0x7f, 0x44, 0x24, 0x60, // vmovdqa %ymm0, 96(%rsp) 27 | 0xc5, 0xfd, 0x7f, 0x44, 0x24, 0x40, // vmovdqa %ymm0, 64(%rsp) 28 | 0xc5, 0xfd, 0x7f, 0x44, 0x24, 0x20, // vmovdqa %ymm0, 32(%rsp) 29 | 0xc5, 0xfd, 0x7f, 0x04, 0x24, // vmovdqa %ymm0, (%rsp) 30 | 0x4c, 0x8d, 0x05, 0x00, 0x00, 0x00, 0x00, // leaq (%rip), %r8 31 | } 32 | 33 | // Initialize decoder context. 34 | decoder := zydis.NewDecoder(zydis.MachineMode64, zydis.AddressWidth64) 35 | 36 | // Initialize formatter. 37 | // Only required when instruction formatting ("disassembling"), like below. 38 | formatter, err := zydis.NewFormatter(zydis.FormatterStyleIntel) 39 | if err != nil { 40 | panic(err) 41 | } 42 | 43 | // Loop over the instructions in our buffer. 44 | // The runtime-address (instruction pointer) is chosen arbitrary here in 45 | // order to better visualize relative addressing. 46 | runtimeAddress := uint64(0x007FFFFFFF400000) 47 | 48 | for len(data) > 0 { 49 | instr, err := decoder.Decode(data) 50 | if err != nil { 51 | break 52 | } 53 | 54 | // Format and print the binary instruction structure. 55 | str, err := formatter.FormatInstruction(instr, runtimeAddress) 56 | if err != nil { 57 | panic(err) 58 | } 59 | fmt.Printf( 60 | "%016x %s %s\n", 61 | runtimeAddress, 62 | hex.EncodeToString(data[:instr.Length]), 63 | str, 64 | ) 65 | 66 | // Advance instruction pointer. 67 | runtimeAddress += uint64(instr.Length) 68 | 69 | // Drop decoded instructions from the stream. 70 | data = data[instr.Length:] 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /cpuflagaction.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // CPUFlagAction is an enum of CPU action flags. 8 | type CPUFlagAction int 9 | 10 | // CPUFlagAction enum values. 11 | const ( 12 | // The CPU flag is not touched by the instruction. 13 | CPUFlagActionNone CPUFlagAction = iota 14 | // The CPU flag is tested (read). 15 | CPUFlagActionTested 16 | // The CPU flag is tested and modified aferwards (read-write). 17 | CPUFlagActionTestedModified 18 | // The CPU flag is modified (write). 19 | CPUFlagActionModified 20 | // The CPU flag is set to 0 (write). 21 | CPUFlagActionSet0 22 | // The CPU flag is set to 1 (write). 23 | CPUFlagActionSet1 24 | // The CPU flag is undefined (write). 25 | CPUFlagActionUndefined 26 | ) 27 | -------------------------------------------------------------------------------- /decoder.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | /* 8 | #cgo CFLAGS: -I./lib/include 9 | #include 10 | 11 | const ZyanStatus statusSuccess = ZYAN_STATUS_SUCCESS; 12 | */ 13 | import "C" 14 | import ( 15 | "fmt" 16 | "unsafe" 17 | ) 18 | 19 | // Decoder performs decoding of instruction bytes to a machine interpretable 20 | // struct. 21 | type Decoder struct { 22 | zdecoder C.ZydisDecoder 23 | } 24 | 25 | // NewDecoder returns a new instruction decoder. 26 | func NewDecoder(mm MachineMode, aw AddressWidth) *Decoder { 27 | d := &Decoder{} 28 | C.ZydisDecoderInit(&d.zdecoder, C.ZydisMachineMode(mm), C.ZydisAddressWidth(aw)) 29 | return d 30 | } 31 | 32 | // EnableMode enables/disables the given decoder mode. 33 | func (d *Decoder) EnableMode(m DecoderMode, en bool) error { 34 | enValue := 0 35 | if en { 36 | enValue = 1 37 | } 38 | ret := C.ZydisDecoderEnableMode(&d.zdecoder, C.ZydisDecoderMode(m), C.ZyanBool(enValue)) 39 | if zyanFailure(ret) { 40 | return fmt.Errorf("zydis: error enabling mode: 0x%x", ret) 41 | } 42 | return nil 43 | } 44 | 45 | // Decode decodes the instruction in the given input buffer. 46 | func (d *Decoder) Decode(buffer []byte) (*DecodedInstruction, error) { 47 | var zinst C.ZydisDecodedInstruction 48 | ret := C.ZydisDecoderDecodeBuffer( 49 | &d.zdecoder, 50 | unsafe.Pointer(&buffer[0]), 51 | C.ZyanUSize(len(buffer)), 52 | &zinst, 53 | ) 54 | if zyanFailure(ret) { 55 | return nil, fmt.Errorf("zydis: error decoding buffer: 0x%x", ret) 56 | } 57 | // Convert ZydisDecodedInstruction to a DecodedInstruction 58 | return newInstructionFromZydis(&zinst), nil 59 | } 60 | 61 | func zyanFailure(zs C.ZyanStatus) bool { 62 | return zs != C.statusSuccess 63 | } 64 | 65 | // DecoderMode is an enum of decoder modes. 66 | type DecoderMode int 67 | 68 | // DecoderMode enum values. 69 | const ( 70 | // Enables minimal instruction decoding without semantic analysis. 71 | // 72 | // This mode provides access to the mnemonic, the instruction-length, the 73 | // effective operand-size, the effective address-width, some attributes 74 | // (e.g. `ZYDIS_ATTRIB_IS_RELATIVE`) and all of the information in the 75 | // `raw` field of the `ZydisDecodedInstruction` struct. 76 | // 77 | // Operands, most attributes and other specific information (like `AVX` 78 | // info) are not accessible in this mode. 79 | // 80 | // This mode is NOT enabled by default. 81 | DecoderModeMinimal DecoderMode = iota 82 | 83 | // Enables the `AMD`-branch mode. 84 | // 85 | // Intel ignores the operand-size override-prefix (`0x66`) for all branches with 32-bit 86 | // immediates and forces the operand-size of the instruction to 64-bit in 64-bit mode. 87 | // In `AMD`-branch mode `0x66` is not ignored and changes the operand-size and the size of the 88 | // immediate to 16-bit. 89 | // 90 | // This mode is NOT enabled by default. 91 | DecoderModeAMDBranches 92 | 93 | // Enables `KNC` compatibility-mode. 94 | // 95 | // `KNC` and `KNL+` chips are sharing opcodes and encodings for some mask-related instructions. 96 | // Enable this mode to use the old `KNC` specifications (different mnemonics, operands, ..). 97 | // 98 | // This mode is NOT enabled by default. 99 | DecoderModeKNC 100 | 101 | // Enables the `MPX` mode. 102 | // 103 | // The `MPX` isa-extension reuses (overrides) some of the widenop instruction opcodes. 104 | // 105 | // This mode is enabled by default. 106 | DecoderModeMPX 107 | 108 | // Enables the `CET` mode. 109 | // 110 | // The `CET` isa-extension reuses (overrides) some of the widenop instruction opcodes. 111 | // 112 | // This mode is enabled by default. 113 | DecoderModeCET 114 | 115 | // Enables the `LZCNT` mode. 116 | // 117 | // The `LZCNT` isa-extension reuses (overrides) some of the widenop instruction opcodes. 118 | // 119 | // This mode is enabled by default. 120 | DecoderModeLZCNT 121 | 122 | // Enables the `TZCNT` mode. 123 | // 124 | // The `TZCNT` isa-extension reuses (overrides) some of the widenop instruction opcodes. 125 | // 126 | // This mode is enabled by default. 127 | DecoderModeTZCNT 128 | 129 | // Enables the `WBNOINVD` mode. 130 | // 131 | // The `WBINVD` instruction is interpreted as `WBNOINVD` on ICL chips, if a `F3` prefix is 132 | // used. 133 | // 134 | // This mode is disabled by default. 135 | DecoderModeWBNOINVD 136 | 137 | // Enables the `CLDEMOTE` mode. 138 | // 139 | // The `CLDEMOTE` isa-extension reuses (overrides) some of the widenop instruction opcodes. 140 | // 141 | // This mode is enabled by default. 142 | DecoderModeCLDEMOTE 143 | ) 144 | -------------------------------------------------------------------------------- /element.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // ElementType is an enum of processor element types. 8 | type ElementType int 9 | 10 | // ElementType enum values 11 | const ( 12 | ElementTypeInvalid ElementType = iota 13 | ElementTypeStruct // Struct 14 | ElementTypeUInt // Unsigned integer 15 | ElementTypeInt // Signed integer 16 | ElementTypeFloat16 // 16-bit floating point (`half`) 17 | ElementTypeFloat32 // 32-bit floating point (`single`) 18 | ElementTypeFloat64 // 64-bit floating point (`double`) 19 | ElementTypeFloat80 // 80-bit floating point (`extended`) 20 | ElementTypeLongBCD // Binary coded decimal 21 | ElementTypeCC // A condition code 22 | ) 23 | 24 | // ElementSize is the sizde of an element. 25 | type ElementSize uint16 26 | -------------------------------------------------------------------------------- /exceptionclass_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ExceptionClass -linecomment"; DO NOT EDIT. 2 | 3 | package zydis 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ExceptionClassNone-0] 12 | _ = x[ExceptionClassSSE1-1] 13 | _ = x[ExceptionClassSSE2-2] 14 | _ = x[ExceptionClassSSE3-3] 15 | _ = x[ExceptionClassSSE4-4] 16 | _ = x[ExceptionClassSSE5-5] 17 | _ = x[ExceptionClassSSE7-6] 18 | _ = x[ExceptionClassAVX1-7] 19 | _ = x[ExceptionClassAVX2-8] 20 | _ = x[ExceptionClassAVX3-9] 21 | _ = x[ExceptionClassAVX4-10] 22 | _ = x[ExceptionClassAVX5-11] 23 | _ = x[ExceptionClassAVX6-12] 24 | _ = x[ExceptionClassAVX7-13] 25 | _ = x[ExceptionClassAVX8-14] 26 | _ = x[ExceptionClassAVX11-15] 27 | _ = x[ExceptionClassAVX12-16] 28 | _ = x[ExceptionClassE1-17] 29 | _ = x[ExceptionClassE1NF-18] 30 | _ = x[ExceptionClassE2-19] 31 | _ = x[ExceptionClassE2NF-20] 32 | _ = x[ExceptionClassE3-21] 33 | _ = x[ExceptionClassE3NF-22] 34 | _ = x[ExceptionClassE4-23] 35 | _ = x[ExceptionClassE4NF-24] 36 | _ = x[ExceptionClassE5-25] 37 | _ = x[ExceptionClassE5NF-26] 38 | _ = x[ExceptionClassE6-27] 39 | _ = x[ExceptionClassE6NF-28] 40 | _ = x[ExceptionClassE7NM-29] 41 | _ = x[ExceptionClassE7NM128-30] 42 | _ = x[ExceptionClassE9NF-31] 43 | _ = x[ExceptionClassE10-32] 44 | _ = x[ExceptionClassE10NF-33] 45 | _ = x[ExceptionClassE11-34] 46 | _ = x[ExceptionClassE11NF-35] 47 | _ = x[ExceptionClassE12-36] 48 | _ = x[ExceptionClassE12NP-37] 49 | _ = x[ExceptionClassK20-38] 50 | _ = x[ExceptionClassK21-39] 51 | _ = x[ExceptionClassAMXE1-40] 52 | _ = x[ExceptionClassAMXE2-41] 53 | _ = x[ExceptionClassAMXE3-42] 54 | _ = x[ExceptionClassAMXE4-43] 55 | _ = x[ExceptionClassAMXE5-44] 56 | _ = x[ExceptionClassAMXE6-45] 57 | } 58 | 59 | const _ExceptionClass_name = "ExceptionClassNoneSSE1SSE2SSE3SSE4SSE5SSE7AVX1AVX2AVX3AVX4AVX5AVX6AVX7AVX8AVX11AVX12E1E1NFE2E2NFE3E3NFE4E4NFE5E5NFE6E6NFE7NME7NM128E9NFE10E10NFE11E11NFE12E12NPK20K21AMXE1AMXE2AMXE3AMXE4AMXE5AMXE6" 60 | 61 | var _ExceptionClass_index = [...]uint8{0, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58, 62, 66, 70, 74, 79, 84, 86, 90, 92, 96, 98, 102, 104, 108, 110, 114, 116, 120, 124, 131, 135, 138, 143, 146, 151, 154, 159, 162, 165, 170, 175, 180, 185, 190, 195} 62 | 63 | func (i ExceptionClass) String() string { 64 | if i < 0 || i >= ExceptionClass(len(_ExceptionClass_index)-1) { 65 | return "ExceptionClass(" + strconv.FormatInt(int64(i), 10) + ")" 66 | } 67 | return _ExceptionClass_name[_ExceptionClass_index[i]:_ExceptionClass_index[i+1]] 68 | } 69 | -------------------------------------------------------------------------------- /features.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | /* 8 | #cgo CFLAGS: -I./lib/include 9 | #include 10 | 11 | int zVerMajor(ZyanU64 v) { return ZYDIS_VERSION_MAJOR(v); } 12 | int zVerMinor(ZyanU64 v) { return ZYDIS_VERSION_MINOR(v); } 13 | int zVerBuild(ZyanU64 v) { return ZYDIS_VERSION_PATCH(v); } 14 | int zVerPatch(ZyanU64 v) { return ZYDIS_VERSION_BUILD(v); } 15 | */ 16 | import "C" 17 | import ( 18 | "fmt" 19 | ) 20 | 21 | // Version returns the zydis library version number. 22 | func Version() (major, minor, patch, build int) { 23 | v := C.ZydisGetVersion() 24 | return int(C.zVerMajor(v)), 25 | int(C.zVerMinor(v)), 26 | int(C.zVerBuild(v)), 27 | int(C.zVerPatch(v)) 28 | } 29 | 30 | // Feature is an enum of zydis library features. 31 | type Feature int 32 | 33 | // Feature enum values. 34 | const ( 35 | FeatureDecoder Feature = iota 36 | FeatureFormatter 37 | FeatureAVX512 38 | FeatureKNC 39 | ) 40 | 41 | // IsFeatureEnabled returns true when the given feature is included in 42 | // the zydis library. 43 | func IsFeatureEnabled(f Feature) (bool, error) { 44 | ret := C.ZydisIsFeatureEnabled(C.ZydisFeature(f)) 45 | if zyanFailure(ret) { 46 | return false, fmt.Errorf("zydis: error checking for feature: 0x%x", ret) 47 | } 48 | return ret == C.ZYAN_STATUS_TRUE, nil 49 | } 50 | -------------------------------------------------------------------------------- /formatter+callbacks.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | /* 8 | #cgo CFLAGS: -I./lib/include 9 | 10 | #include 11 | 12 | extern const ZyanStatus statusOK; 13 | extern const ZyanStatus statusSkipToken; 14 | extern const ZyanStatus statusCallbackFailure; 15 | */ 16 | import "C" 17 | import ( 18 | "reflect" 19 | "unsafe" 20 | ) 21 | 22 | // We use a separate file here because of: 23 | // https://golang.org/cmd/cgo/#hdr-C_references_to_Go 24 | // 25 | // Using //export in a file places a restriction on the preamble: since it 26 | // is copied into two different C output files, it must not contain any 27 | // definitions, only declarations. If a file contains both definitions and 28 | // declarations, then the two output files will produce duplicate symbols 29 | // and the linker will fail. To avoid this, definitions must be placed in 30 | // preambles in other files, or in C source files. 31 | 32 | // formatterCallbackMap is used to map callbacks to/from cgo. 33 | var formatterCallbackMap CallbackMap 34 | 35 | // writeZydisFormatterBufferString copies the provided string into the 36 | // ZydisFormatterBuffer, adhering to its capcity limit. 37 | func writeZydisFormatterBufferString(zbuf *C.ZydisFormatterBuffer, str string) { 38 | sh := reflect.SliceHeader{ 39 | Data: uintptr(zbuf.string.vector.data), 40 | Len: int(zbuf.string.vector.capacity - 1), 41 | Cap: int(zbuf.string.vector.capacity - 1), 42 | } 43 | zstr := *(*[]byte)(unsafe.Pointer(&sh)) 44 | copy(zstr, ([]byte)(str+"\000")) 45 | zbuf.string.vector.size = C.ZyanUSize(len(str)) 46 | } 47 | 48 | //export formatterXCallback 49 | func formatterXCallback( 50 | _type C.ZydisFormatterFunction, 51 | zbuffer *C.ZydisFormatterBuffer, 52 | zcontext *C.ZydisFormatterContext, 53 | ) C.ZyanStatus { 54 | // Extract user pointer to bootstrap Go callback. 55 | fcc := formatterCallbackMap.GetToken(unsafe.Pointer(zcontext.user_data)).(*formatterCallbackContext) 56 | // Extract hook 57 | hook := fcc.fmtr.hookForType[FormatterFunction(_type)] 58 | // Wrap format buffer 59 | buffer := &FormatterBuffer{ 60 | IsTokenList: zbuffer.is_token_list != 0, 61 | Value: C.GoString((*C.char)(zbuffer.string.vector.data)), 62 | } 63 | // Wrap format context 64 | context := FormatterContext{ 65 | Instruction: fcc.instr, 66 | RuntimeAddress: uint64(zcontext.runtime_address), 67 | } 68 | if zcontext.operand != nil { 69 | for i := 0; i < len(fcc.instr.Operands); i++ { 70 | op := &fcc.instr.Operands[i] 71 | if op.zdo == zcontext.operand { 72 | context.Operand = op 73 | break 74 | } 75 | } 76 | if context.Operand == nil { 77 | panic("zydis: unable to map callback operand to Go equivalent") 78 | } 79 | } 80 | // Execute hook 81 | skip, err := hook.(FormatterXFunc)(fcc.fmtr, buffer, context) 82 | if err != nil { 83 | return C.statusCallbackFailure 84 | } 85 | if skip { 86 | return C.statusSkipToken 87 | } 88 | writeZydisFormatterBufferString(zbuffer, buffer.Value) 89 | return C.statusOK 90 | } 91 | 92 | //export formatterRegisterCallback 93 | func formatterRegisterCallback( 94 | _type C.ZydisFormatterFunction, 95 | zbuffer *C.ZydisFormatterBuffer, 96 | zcontext *C.ZydisFormatterContext, 97 | zreg C.ZydisRegister, 98 | ) C.ZyanStatus { 99 | // Extract user pointer to bootstrap Go callback. 100 | fcc := formatterCallbackMap.GetToken(unsafe.Pointer(zcontext.user_data)).(*formatterCallbackContext) 101 | // Extract hook 102 | hook := fcc.fmtr.hookForType[FormatterFunction(_type)] 103 | // Wrap format buffer 104 | buffer := &FormatterBuffer{ 105 | IsTokenList: zbuffer.is_token_list != 0, 106 | Value: C.GoString((*C.char)(zbuffer.string.vector.data)), 107 | } 108 | // Wrap format context 109 | context := FormatterContext{ 110 | Instruction: fcc.instr, 111 | RuntimeAddress: uint64(zcontext.runtime_address), 112 | } 113 | for i := 0; i < len(fcc.instr.Operands); i++ { 114 | op := &fcc.instr.Operands[i] 115 | if op.zdo == zcontext.operand { 116 | context.Operand = op 117 | break 118 | } 119 | } 120 | if context.Operand == nil { 121 | panic("zydis: unable to map callback operand to Go equivalent") 122 | } 123 | // Wrap register 124 | reg := Register(zreg) 125 | // Execute hook 126 | err := hook.(FormatterRegisterFunc)(fcc.fmtr, buffer, context, reg) 127 | if err != nil { 128 | return C.statusCallbackFailure 129 | } 130 | writeZydisFormatterBufferString(zbuffer, buffer.Value) 131 | return C.statusOK 132 | } 133 | 134 | //export formatterDecoratorCallback 135 | func formatterDecoratorCallback( 136 | _type C.ZydisFormatterFunction, 137 | zbuffer *C.ZydisFormatterBuffer, 138 | zcontext *C.ZydisFormatterContext, 139 | zdecorator C.ZydisDecorator, 140 | ) C.ZyanStatus { 141 | // Extract user pointer to bootstrap Go callback. 142 | fcc := formatterCallbackMap.GetToken(unsafe.Pointer(zcontext.user_data)).(*formatterCallbackContext) 143 | // Extract hook 144 | hook := fcc.fmtr.hookForType[FormatterFunction(_type)] 145 | // Wrap format buffer 146 | buffer := &FormatterBuffer{ 147 | IsTokenList: zbuffer.is_token_list != 0, 148 | Value: C.GoString((*C.char)(zbuffer.string.vector.data)), 149 | } 150 | // Wrap format context 151 | context := FormatterContext{ 152 | Instruction: fcc.instr, 153 | RuntimeAddress: uint64(zcontext.runtime_address), 154 | } 155 | for i := 0; i < len(fcc.instr.Operands); i++ { 156 | op := &fcc.instr.Operands[i] 157 | if op.zdo == zcontext.operand { 158 | context.Operand = op 159 | break 160 | } 161 | } 162 | if context.Operand == nil { 163 | panic("zydis: unable to map callback operand to Go equivalent") 164 | } 165 | // Wrap decorator 166 | decorator := Decorator(zdecorator) 167 | // Execute hook 168 | err := hook.(FormatterDecoratorFunc)(fcc.fmtr, buffer, context, decorator) 169 | if err != nil { 170 | return C.statusCallbackFailure 171 | } 172 | writeZydisFormatterBufferString(zbuffer, buffer.Value) 173 | return C.statusOK 174 | } 175 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module go.jpap.org/zydis 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /instructioncategory_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=InstructionCategory -linecomment"; DO NOT EDIT. 2 | 3 | package zydis 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[InstructionCategoryInvalid-0] 12 | _ = x[InstructionCategoryADOX_ADCX-1] 13 | _ = x[InstructionCategoryAES-2] 14 | _ = x[InstructionCategoryAMD3DNOW-3] 15 | _ = x[InstructionCategoryAMX_TILE-4] 16 | _ = x[InstructionCategoryAVX-5] 17 | _ = x[InstructionCategoryAVX2-6] 18 | _ = x[InstructionCategoryAVX2GATHER-7] 19 | _ = x[InstructionCategoryAVX512-8] 20 | _ = x[InstructionCategoryAVX512_4FMAPS-9] 21 | _ = x[InstructionCategoryAVX512_4VNNIW-10] 22 | _ = x[InstructionCategoryAVX512_BITALG-11] 23 | _ = x[InstructionCategoryAVX512_VBMI-12] 24 | _ = x[InstructionCategoryAVX512_VP2INTERSECT-13] 25 | _ = x[InstructionCategoryBINARY-14] 26 | _ = x[InstructionCategoryBITBYTE-15] 27 | _ = x[InstructionCategoryBLEND-16] 28 | _ = x[InstructionCategoryBMI1-17] 29 | _ = x[InstructionCategoryBMI2-18] 30 | _ = x[InstructionCategoryBROADCAST-19] 31 | _ = x[InstructionCategoryCALL-20] 32 | _ = x[InstructionCategoryCET-21] 33 | _ = x[InstructionCategoryCLDEMOTE-22] 34 | _ = x[InstructionCategoryCLFLUSHOPT-23] 35 | _ = x[InstructionCategoryCLWB-24] 36 | _ = x[InstructionCategoryCLZERO-25] 37 | _ = x[InstructionCategoryCMOV-26] 38 | _ = x[InstructionCategoryCOMPRESS-27] 39 | _ = x[InstructionCategoryCOND_BR-28] 40 | _ = x[InstructionCategoryCONFLICT-29] 41 | _ = x[InstructionCategoryCONVERT-30] 42 | _ = x[InstructionCategoryDATAXFER-31] 43 | _ = x[InstructionCategoryDECIMAL-32] 44 | _ = x[InstructionCategoryENQCMD-33] 45 | _ = x[InstructionCategoryEXPAND-34] 46 | _ = x[InstructionCategoryFCMOV-35] 47 | _ = x[InstructionCategoryFLAGOP-36] 48 | _ = x[InstructionCategoryFMA4-37] 49 | _ = x[InstructionCategoryGATHER-38] 50 | _ = x[InstructionCategoryGFNI-39] 51 | _ = x[InstructionCategoryIFMA-40] 52 | _ = x[InstructionCategoryINTERRUPT-41] 53 | _ = x[InstructionCategoryIO-42] 54 | _ = x[InstructionCategoryIOSTRINGOP-43] 55 | _ = x[InstructionCategoryKMASK-44] 56 | _ = x[InstructionCategoryKNC-45] 57 | _ = x[InstructionCategoryKNCMASK-46] 58 | _ = x[InstructionCategoryKNCSCALAR-47] 59 | _ = x[InstructionCategoryLOGICAL-48] 60 | _ = x[InstructionCategoryLOGICAL_FP-49] 61 | _ = x[InstructionCategoryLZCNT-50] 62 | _ = x[InstructionCategoryMISC-51] 63 | _ = x[InstructionCategoryMMX-52] 64 | _ = x[InstructionCategoryMOVDIR-53] 65 | _ = x[InstructionCategoryMPX-54] 66 | _ = x[InstructionCategoryNOP-55] 67 | _ = x[InstructionCategoryPADLOCK-56] 68 | _ = x[InstructionCategoryPCLMULQDQ-57] 69 | _ = x[InstructionCategoryPCONFIG-58] 70 | _ = x[InstructionCategoryPKU-59] 71 | _ = x[InstructionCategoryPOP-60] 72 | _ = x[InstructionCategoryPREFETCH-61] 73 | _ = x[InstructionCategoryPREFETCHWT1-62] 74 | _ = x[InstructionCategoryPT-63] 75 | _ = x[InstructionCategoryPUSH-64] 76 | _ = x[InstructionCategoryRDPID-65] 77 | _ = x[InstructionCategoryRDPRU-66] 78 | _ = x[InstructionCategoryRDRAND-67] 79 | _ = x[InstructionCategoryRDSEED-68] 80 | _ = x[InstructionCategoryRDWRFSGS-69] 81 | _ = x[InstructionCategoryRET-70] 82 | _ = x[InstructionCategoryROTATE-71] 83 | _ = x[InstructionCategorySCATTER-72] 84 | _ = x[InstructionCategorySEGOP-73] 85 | _ = x[InstructionCategorySEMAPHORE-74] 86 | _ = x[InstructionCategorySERIALIZE-75] 87 | _ = x[InstructionCategorySETCC-76] 88 | _ = x[InstructionCategorySGX-77] 89 | _ = x[InstructionCategorySHA-78] 90 | _ = x[InstructionCategorySHIFT-79] 91 | _ = x[InstructionCategorySMAP-80] 92 | _ = x[InstructionCategorySSE-81] 93 | _ = x[InstructionCategorySTRINGOP-82] 94 | _ = x[InstructionCategorySTTNI-83] 95 | _ = x[InstructionCategorySYSCALL-84] 96 | _ = x[InstructionCategorySYSRET-85] 97 | _ = x[InstructionCategorySYSTEM-86] 98 | _ = x[InstructionCategoryTBM-87] 99 | _ = x[InstructionCategoryTSX_LDTRK-88] 100 | _ = x[InstructionCategoryUFMA-89] 101 | _ = x[InstructionCategoryUNCOND_BR-90] 102 | _ = x[InstructionCategoryVAES-91] 103 | _ = x[InstructionCategoryVBMI2-92] 104 | _ = x[InstructionCategoryVFMA-93] 105 | _ = x[InstructionCategoryVPCLMULQDQ-94] 106 | _ = x[InstructionCategoryVTX-95] 107 | _ = x[InstructionCategoryWAITPKG-96] 108 | _ = x[InstructionCategoryWIDENOP-97] 109 | _ = x[InstructionCategoryX87_ALU-98] 110 | _ = x[InstructionCategoryXOP-99] 111 | _ = x[InstructionCategoryXSAVE-100] 112 | _ = x[InstructionCategoryXSAVEOPT-101] 113 | } 114 | 115 | const _InstructionCategory_name = "INVALIDADOX_ADCXAESAMD3DNOWAMX_TILEAVXAVX2AVX2GATHERAVX512AVX512_4FMAPSAVX512_4VNNIWAVX512_BITALGAVX512_VBMIAVX512_VP2INTERSECTBINARYBITBYTEBLENDBMI1BMI2BROADCASTCALLCETCLDEMOTECLFLUSHOPTCLWBCLZEROCMOVCOMPRESSCOND_BRCONFLICTCONVERTDATAXFERDECIMALENQCMDEXPANDFCMOVFLAGOPFMA4GATHERGFNIIFMAINTERRUPTIOIOSTRINGOPKMASKKNCKNCMASKKNCSCALARLOGICALLOGICAL_FPLZCNTMISCMMXMOVDIRMPXNOPPADLOCKPCLMULQDQPCONFIGPKUPOPPREFETCHPREFETCHWT1PTPUSHRDPIDRDPRURDRANDRDSEEDRDWRFSGSRETROTATESCATTERSEGOPSEMAPHORESERIALIZESETCCSGXSHASHIFTSMAPSSESTRINGOPSTTNISYSCALLSYSRETSYSTEMTBMTSX_LDTRKUFMAUNCOND_BRVAESVBMI2VFMAVPCLMULQDQVTXWAITPKGWIDENOPX87_ALUXOPXSAVEXSAVEOPT" 116 | 117 | var _InstructionCategory_index = [...]uint16{0, 7, 16, 19, 27, 35, 38, 42, 52, 58, 71, 84, 97, 108, 127, 133, 140, 145, 149, 153, 162, 166, 169, 177, 187, 191, 197, 201, 209, 216, 224, 231, 239, 246, 252, 258, 263, 269, 273, 279, 283, 287, 296, 298, 308, 313, 316, 323, 332, 339, 349, 354, 358, 361, 367, 370, 373, 380, 389, 396, 399, 402, 410, 421, 423, 427, 432, 437, 443, 449, 457, 460, 466, 473, 478, 487, 496, 501, 504, 507, 512, 516, 519, 527, 532, 539, 545, 551, 554, 563, 567, 576, 580, 585, 589, 599, 602, 609, 616, 623, 626, 631, 639} 118 | 119 | func (i InstructionCategory) String() string { 120 | if i < 0 || i >= InstructionCategory(len(_InstructionCategory_index)-1) { 121 | return "InstructionCategory(" + strconv.FormatInt(int64(i), 10) + ")" 122 | } 123 | return _InstructionCategory_name[_InstructionCategory_index[i]:_InstructionCategory_index[i+1]] 124 | } 125 | -------------------------------------------------------------------------------- /isaext.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // ISAExt is an enum of Instruction Set Architecture Extensions. 8 | type ISAExt int 9 | 10 | //go:generate stringer -type=ISAExt -linecomment 11 | 12 | // IsaExt enum values. 13 | const ( 14 | ISAExtInvalid ISAExt = iota // INVALID 15 | IsaExtADOX_ADCX // ADOX_ADCX 16 | IsaExtAES // AES 17 | IsaExtAMD3DNOW // AMD3DNOW 18 | IsaExtAMD3DNOW_PREFETCH // AMD3DNOW_PREFETCH 19 | IsaExtAMD_INVLPGB // AMD_INVLPGB 20 | IsaExtAMX_BF16 // AMX_BF16 21 | IsaExtAMX_INT8 // AMX_INT8 22 | IsaExtAMX_TILE // AMX_TILE 23 | IsaExtAVX // AVX 24 | IsaExtAVX2 // AVX2 25 | IsaExtAVX2GATHER // AVX2GATHER 26 | IsaExtAVX512EVEX // AVX512EVEX 27 | IsaExtAVX512VEX // AVX512VEX 28 | IsaExtAVXAES // AVXAES 29 | IsaExtBASE // BASE 30 | IsaExtBMI1 // BMI1 31 | IsaExtBMI2 // BMI2 32 | IsaExtCET // CET 33 | IsaExtCLDEMOTE // CLDEMOTE 34 | IsaExtCLFLUSHOPT // CLFLUSHOPT 35 | IsaExtCLFSH // CLFSH 36 | IsaExtCLWB // CLWB 37 | IsaExtCLZERO // CLZERO 38 | IsaExtENQCMD // ENQCMD 39 | IsaExtF16C // F16C 40 | IsaExtFMA // FMA 41 | IsaExtFMA4 // FMA4 42 | IsaExtGFNI // GFNI 43 | IsaExtINVPCID // INVPCID 44 | IsaExtKNC // KNC 45 | IsaExtKNCE // KNCE 46 | IsaExtKNCV // KNCV 47 | IsaExtLONGMODE // LONGMODE 48 | IsaExtLZCNT // LZCNT 49 | IsaExtMCOMMIT // MCOMMIT 50 | IsaExtMMX // MMX 51 | IsaExtMONITOR // MONITOR 52 | IsaExtMONITORX // MONITORX 53 | IsaExtMOVBE // MOVBE 54 | IsaExtMOVDIR // MOVDIR 55 | IsaExtMPX // MPX 56 | IsaExtPADLOCK // PADLOCK 57 | IsaExtPAUSE // PAUSE 58 | IsaExtPCLMULQDQ // PCLMULQDQ 59 | IsaExtPCONFIG // PCONFIG 60 | IsaExtPKU // PKU 61 | IsaExtPREFETCHWT1 // PREFETCHWT1 62 | IsaExtPT // PT 63 | IsaExtRDPID // RDPID 64 | IsaExtRDPRU // RDPRU 65 | IsaExtRDRAND // RDRAND 66 | IsaExtRDSEED // RDSEED 67 | IsaExtRDTSCP // RDTSCP 68 | IsaExtRDWRFSGS // RDWRFSGS 69 | IsaExtRTM // RTM 70 | IsaExtSERIALIZE // SERIALIZE 71 | IsaExtSGX // SGX 72 | IsaExtSGX_ENCLV // SGX_ENCLV 73 | IsaExtSHA // SHA 74 | IsaExtSMAP // SMAP 75 | IsaExtSMX // SMX 76 | IsaExtSNP // SNP 77 | IsaExtSSE // SSE 78 | IsaExtSSE2 // SSE2 79 | IsaExtSSE3 // SSE3 80 | IsaExtSSE4 // SSE4 81 | IsaExtSSE4A // SSE4A 82 | IsaExtSSSE3 // SSSE3 83 | IsaExtSVM // SVM 84 | IsaExtTBM // TBM 85 | IsaExtTSX_LDTRK // TSX_LDTRK 86 | IsaExtVAES // VAES 87 | IsaExtVMFUNC // VMFUNC 88 | IsaExtVPCLMULQDQ // VPCLMULQDQ 89 | IsaExtVTX // VTX 90 | IsaExtWAITPKG // WAITPKG 91 | IsaExtX87 // X87 92 | IsaExtXOP // XOP 93 | IsaExtXSAVE // XSAVE 94 | IsaExtXSAVEC // XSAVEC 95 | IsaExtXSAVEOPT // XSAVEOPT 96 | IsaExtXSAVES // XSAVES 97 | ) 98 | -------------------------------------------------------------------------------- /isaext_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ISAExt -linecomment"; DO NOT EDIT. 2 | 3 | package zydis 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ISAExtInvalid-0] 12 | _ = x[IsaExtADOX_ADCX-1] 13 | _ = x[IsaExtAES-2] 14 | _ = x[IsaExtAMD3DNOW-3] 15 | _ = x[IsaExtAMD3DNOW_PREFETCH-4] 16 | _ = x[IsaExtAMD_INVLPGB-5] 17 | _ = x[IsaExtAMX_BF16-6] 18 | _ = x[IsaExtAMX_INT8-7] 19 | _ = x[IsaExtAMX_TILE-8] 20 | _ = x[IsaExtAVX-9] 21 | _ = x[IsaExtAVX2-10] 22 | _ = x[IsaExtAVX2GATHER-11] 23 | _ = x[IsaExtAVX512EVEX-12] 24 | _ = x[IsaExtAVX512VEX-13] 25 | _ = x[IsaExtAVXAES-14] 26 | _ = x[IsaExtBASE-15] 27 | _ = x[IsaExtBMI1-16] 28 | _ = x[IsaExtBMI2-17] 29 | _ = x[IsaExtCET-18] 30 | _ = x[IsaExtCLDEMOTE-19] 31 | _ = x[IsaExtCLFLUSHOPT-20] 32 | _ = x[IsaExtCLFSH-21] 33 | _ = x[IsaExtCLWB-22] 34 | _ = x[IsaExtCLZERO-23] 35 | _ = x[IsaExtENQCMD-24] 36 | _ = x[IsaExtF16C-25] 37 | _ = x[IsaExtFMA-26] 38 | _ = x[IsaExtFMA4-27] 39 | _ = x[IsaExtGFNI-28] 40 | _ = x[IsaExtINVPCID-29] 41 | _ = x[IsaExtKNC-30] 42 | _ = x[IsaExtKNCE-31] 43 | _ = x[IsaExtKNCV-32] 44 | _ = x[IsaExtLONGMODE-33] 45 | _ = x[IsaExtLZCNT-34] 46 | _ = x[IsaExtMCOMMIT-35] 47 | _ = x[IsaExtMMX-36] 48 | _ = x[IsaExtMONITOR-37] 49 | _ = x[IsaExtMONITORX-38] 50 | _ = x[IsaExtMOVBE-39] 51 | _ = x[IsaExtMOVDIR-40] 52 | _ = x[IsaExtMPX-41] 53 | _ = x[IsaExtPADLOCK-42] 54 | _ = x[IsaExtPAUSE-43] 55 | _ = x[IsaExtPCLMULQDQ-44] 56 | _ = x[IsaExtPCONFIG-45] 57 | _ = x[IsaExtPKU-46] 58 | _ = x[IsaExtPREFETCHWT1-47] 59 | _ = x[IsaExtPT-48] 60 | _ = x[IsaExtRDPID-49] 61 | _ = x[IsaExtRDPRU-50] 62 | _ = x[IsaExtRDRAND-51] 63 | _ = x[IsaExtRDSEED-52] 64 | _ = x[IsaExtRDTSCP-53] 65 | _ = x[IsaExtRDWRFSGS-54] 66 | _ = x[IsaExtRTM-55] 67 | _ = x[IsaExtSERIALIZE-56] 68 | _ = x[IsaExtSGX-57] 69 | _ = x[IsaExtSGX_ENCLV-58] 70 | _ = x[IsaExtSHA-59] 71 | _ = x[IsaExtSMAP-60] 72 | _ = x[IsaExtSMX-61] 73 | _ = x[IsaExtSNP-62] 74 | _ = x[IsaExtSSE-63] 75 | _ = x[IsaExtSSE2-64] 76 | _ = x[IsaExtSSE3-65] 77 | _ = x[IsaExtSSE4-66] 78 | _ = x[IsaExtSSE4A-67] 79 | _ = x[IsaExtSSSE3-68] 80 | _ = x[IsaExtSVM-69] 81 | _ = x[IsaExtTBM-70] 82 | _ = x[IsaExtTSX_LDTRK-71] 83 | _ = x[IsaExtVAES-72] 84 | _ = x[IsaExtVMFUNC-73] 85 | _ = x[IsaExtVPCLMULQDQ-74] 86 | _ = x[IsaExtVTX-75] 87 | _ = x[IsaExtWAITPKG-76] 88 | _ = x[IsaExtX87-77] 89 | _ = x[IsaExtXOP-78] 90 | _ = x[IsaExtXSAVE-79] 91 | _ = x[IsaExtXSAVEC-80] 92 | _ = x[IsaExtXSAVEOPT-81] 93 | _ = x[IsaExtXSAVES-82] 94 | } 95 | 96 | const _ISAExt_name = "INVALIDADOX_ADCXAESAMD3DNOWAMD3DNOW_PREFETCHAMD_INVLPGBAMX_BF16AMX_INT8AMX_TILEAVXAVX2AVX2GATHERAVX512EVEXAVX512VEXAVXAESBASEBMI1BMI2CETCLDEMOTECLFLUSHOPTCLFSHCLWBCLZEROENQCMDF16CFMAFMA4GFNIINVPCIDKNCKNCEKNCVLONGMODELZCNTMCOMMITMMXMONITORMONITORXMOVBEMOVDIRMPXPADLOCKPAUSEPCLMULQDQPCONFIGPKUPREFETCHWT1PTRDPIDRDPRURDRANDRDSEEDRDTSCPRDWRFSGSRTMSERIALIZESGXSGX_ENCLVSHASMAPSMXSNPSSESSE2SSE3SSE4SSE4ASSSE3SVMTBMTSX_LDTRKVAESVMFUNCVPCLMULQDQVTXWAITPKGX87XOPXSAVEXSAVECXSAVEOPTXSAVES" 97 | 98 | var _ISAExt_index = [...]uint16{0, 7, 16, 19, 27, 44, 55, 63, 71, 79, 82, 86, 96, 106, 115, 121, 125, 129, 133, 136, 144, 154, 159, 163, 169, 175, 179, 182, 186, 190, 197, 200, 204, 208, 216, 221, 228, 231, 238, 246, 251, 257, 260, 267, 272, 281, 288, 291, 302, 304, 309, 314, 320, 326, 332, 340, 343, 352, 355, 364, 367, 371, 374, 377, 380, 384, 388, 392, 397, 402, 405, 408, 417, 421, 427, 437, 440, 447, 450, 453, 458, 464, 472, 478} 99 | 100 | func (i ISAExt) String() string { 101 | if i < 0 || i >= ISAExt(len(_ISAExt_index)-1) { 102 | return "ISAExt(" + strconv.FormatInt(int64(i), 10) + ")" 103 | } 104 | return _ISAExt_name[_ISAExt_index[i]:_ISAExt_index[i+1]] 105 | } 106 | -------------------------------------------------------------------------------- /isaset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // ISASet is an enum of Instruction Set Architectures. 8 | type ISASet int 9 | 10 | //go:generate stringer -type=ISASet -linecomment 11 | 12 | // ISASet enum values. 13 | const ( 14 | ISASetInvalid ISASet = iota // INVALID 15 | ISASetADOX_ADCX // ADOX_ADCX 16 | ISASetAES // AES 17 | ISASetAMD // AMD 18 | ISASetAMD3DNOW // AMD3DNOW 19 | ISASetAMX_BF16 // AMX_BF16 20 | ISASetAMX_INT8 // AMX_INT8 21 | ISASetAMX_TILE // AMX_TILE 22 | ISASetAVX // AVX 23 | ISASetAVX2 // AVX2 24 | ISASetAVX2GATHER // AVX2GATHER 25 | ISASetAVX512BW_128 // AVX512BW_128 26 | ISASetAVX512BW_128N // AVX512BW_128N 27 | ISASetAVX512BW_256 // AVX512BW_256 28 | ISASetAVX512BW_512 // AVX512BW_512 29 | ISASetAVX512BW_KOP // AVX512BW_KOP 30 | ISASetAVX512CD_128 // AVX512CD_128 31 | ISASetAVX512CD_256 // AVX512CD_256 32 | ISASetAVX512CD_512 // AVX512CD_512 33 | ISASetAVX512DQ_128 // AVX512DQ_128 34 | ISASetAVX512DQ_128N // AVX512DQ_128N 35 | ISASetAVX512DQ_256 // AVX512DQ_256 36 | ISASetAVX512DQ_512 // AVX512DQ_512 37 | ISASetAVX512DQ_KOP // AVX512DQ_KOP 38 | ISASetAVX512DQ_SCALAR // AVX512DQ_SCALAR 39 | ISASetAVX512ER_512 // AVX512ER_512 40 | ISASetAVX512ER_SCALAR // AVX512ER_SCALAR 41 | ISASetAVX512F_128 // AVX512F_128 42 | ISASetAVX512F_128N // AVX512F_128N 43 | ISASetAVX512F_256 // AVX512F_256 44 | ISASetAVX512F_512 // AVX512F_512 45 | ISASetAVX512F_KOP // AVX512F_KOP 46 | ISASetAVX512F_SCALAR // AVX512F_SCALAR 47 | ISASetAVX512PF_512 // AVX512PF_512 48 | ISASetAVX512_4FMAPS_512 // AVX512_4FMAPS_512 49 | ISASetAVX512_4FMAPS_SCALAR // AVX512_4FMAPS_SCALAR 50 | ISASetAVX512_4VNNIW_512 // AVX512_4VNNIW_512 51 | ISASetAVX512_BF16_128 // AVX512_BF16_128 52 | ISASetAVX512_BF16_256 // AVX512_BF16_256 53 | ISASetAVX512_BF16_512 // AVX512_BF16_512 54 | ISASetAVX512_BITALG_128 // AVX512_BITALG_128 55 | ISASetAVX512_BITALG_256 // AVX512_BITALG_256 56 | ISASetAVX512_BITALG_512 // AVX512_BITALG_512 57 | ISASetAVX512_GFNI_128 // AVX512_GFNI_128 58 | ISASetAVX512_GFNI_256 // AVX512_GFNI_256 59 | ISASetAVX512_GFNI_512 // AVX512_GFNI_512 60 | ISASetAVX512_IFMA_128 // AVX512_IFMA_128 61 | ISASetAVX512_IFMA_256 // AVX512_IFMA_256 62 | ISASetAVX512_IFMA_512 // AVX512_IFMA_512 63 | ISASetAVX512_VAES_128 // AVX512_VAES_128 64 | ISASetAVX512_VAES_256 // AVX512_VAES_256 65 | ISASetAVX512_VAES_512 // AVX512_VAES_512 66 | ISASetAVX512_VBMI2_128 // AVX512_VBMI2_128 67 | ISASetAVX512_VBMI2_256 // AVX512_VBMI2_256 68 | ISASetAVX512_VBMI2_512 // AVX512_VBMI2_512 69 | ISASetAVX512_VBMI_128 // AVX512_VBMI_128 70 | ISASetAVX512_VBMI_256 // AVX512_VBMI_256 71 | ISASetAVX512_VBMI_512 // AVX512_VBMI_512 72 | ISASetAVX512_VNNI_128 // AVX512_VNNI_128 73 | ISASetAVX512_VNNI_256 // AVX512_VNNI_256 74 | ISASetAVX512_VNNI_512 // AVX512_VNNI_512 75 | ISASetAVX512_VP2INTERSECT_128 // AVX512_VP2INTERSECT_128 76 | ISASetAVX512_VP2INTERSECT_256 // AVX512_VP2INTERSECT_256 77 | ISASetAVX512_VP2INTERSECT_512 // AVX512_VP2INTERSECT_512 78 | ISASetAVX512_VPCLMULQDQ_128 // AVX512_VPCLMULQDQ_128 79 | ISASetAVX512_VPCLMULQDQ_256 // AVX512_VPCLMULQDQ_256 80 | ISASetAVX512_VPCLMULQDQ_512 // AVX512_VPCLMULQDQ_512 81 | ISASetAVX512_VPOPCNTDQ_128 // AVX512_VPOPCNTDQ_128 82 | ISASetAVX512_VPOPCNTDQ_256 // AVX512_VPOPCNTDQ_256 83 | ISASetAVX512_VPOPCNTDQ_512 // AVX512_VPOPCNTDQ_512 84 | ISASetAVXAES // AVXAES 85 | ISASetAVX_GFNI // AVX_GFNI 86 | ISASetBMI1 // BMI1 87 | ISASetBMI2 // BMI2 88 | ISASetCET // CET 89 | ISASetCLDEMOTE // CLDEMOTE 90 | ISASetCLFLUSHOPT // CLFLUSHOPT 91 | ISASetCLFSH // CLFSH 92 | ISASetCLWB // CLWB 93 | ISASetCLZERO // CLZERO 94 | ISASetCMOV // CMOV 95 | ISASetCMPXCHG16B // CMPXCHG16B 96 | ISASetENQCMD // ENQCMD 97 | ISASetF16C // F16C 98 | ISASetFAT_NOP // FAT_NOP 99 | ISASetFCMOV // FCMOV 100 | ISASetFMA // FMA 101 | ISASetFMA4 // FMA4 102 | ISASetFXSAVE // FXSAVE 103 | ISASetFXSAVE64 // FXSAVE64 104 | ISASetGFNI // GFNI 105 | ISASetI186 // I186 106 | ISASetI286PROTECTED // I286PROTECTED 107 | ISASetI286REAL // I286REAL 108 | ISASetI386 // I386 109 | ISASetI486 // I486 110 | ISASetI486REAL // I486REAL 111 | ISASetI86 // I86 112 | ISASetINVPCID // INVPCID 113 | ISASetKNCE // KNCE 114 | ISASetKNCJKBR // KNCJKBR 115 | ISASetKNCSTREAM // KNCSTREAM 116 | ISASetKNCV // KNCV 117 | ISASetKNC_MISC // KNC_MISC 118 | ISASetKNC_PF_HINT // KNC_PF_HINT 119 | ISASetLAHF // LAHF 120 | ISASetLONGMODE // LONGMODE 121 | ISASetLZCNT // LZCNT 122 | ISASetMCOMMIT // MCOMMIT 123 | ISASetMONITOR // MONITOR 124 | ISASetMONITORX // MONITORX 125 | ISASetMOVBE // MOVBE 126 | ISASetMOVDIR // MOVDIR 127 | ISASetMPX // MPX 128 | ISASetPADLOCK_ACE // PADLOCK_ACE 129 | ISASetPADLOCK_PHE // PADLOCK_PHE 130 | ISASetPADLOCK_PMM // PADLOCK_PMM 131 | ISASetPADLOCK_RNG // PADLOCK_RNG 132 | ISASetPAUSE // PAUSE 133 | ISASetPCLMULQDQ // PCLMULQDQ 134 | ISASetPCONFIG // PCONFIG 135 | ISASetPENTIUMMMX // PENTIUMMMX 136 | ISASetPENTIUMREAL // PENTIUMREAL 137 | ISASetPKU // PKU 138 | ISASetPOPCNT // POPCNT 139 | ISASetPPRO // PPRO 140 | ISASetPREFETCHWT1 // PREFETCHWT1 141 | ISASetPREFETCH_NOP // PREFETCH_NOP 142 | ISASetPT // PT 143 | ISASetRDPID // RDPID 144 | ISASetRDPMC // RDPMC 145 | ISASetRDPRU // RDPRU 146 | ISASetRDRAND // RDRAND 147 | ISASetRDSEED // RDSEED 148 | ISASetRDTSCP // RDTSCP 149 | ISASetRDWRFSGS // RDWRFSGS 150 | ISASetRTM // RTM 151 | ISASetSERIALIZE // SERIALIZE 152 | ISASetSGX // SGX 153 | ISASetSGX_ENCLV // SGX_ENCLV 154 | ISASetSHA // SHA 155 | ISASetSMAP // SMAP 156 | ISASetSMX // SMX 157 | ISASetSSE // SSE 158 | ISASetSSE2 // SSE2 159 | ISASetSSE2MMX // SSE2MMX 160 | ISASetSSE3 // SSE3 161 | ISASetSSE3X87 // SSE3X87 162 | ISASetSSE4 // SSE4 163 | ISASetSSE42 // SSE42 164 | ISASetSSE4A // SSE4A 165 | ISASetSSEMXCSR // SSEMXCSR 166 | ISASetSSE_PREFETCH // SSE_PREFETCH 167 | ISASetSSSE3 // SSSE3 168 | ISASetSSSE3MMX // SSSE3MMX 169 | ISASetSVM // SVM 170 | ISASetTBM // TBM 171 | ISASetTSX_LDTRK // TSX_LDTRK 172 | ISASetVAES // VAES 173 | ISASetVMFUNC // VMFUNC 174 | ISASetVPCLMULQDQ // VPCLMULQDQ 175 | ISASetVTX // VTX 176 | ISASetWAITPKG // WAITPKG 177 | ISASetX87 // X87 178 | ISASetXOP // XOP 179 | ISASetXSAVE // XSAVE 180 | ISASetXSAVEC // XSAVEC 181 | ISASetXSAVEOPT // XSAVEOPT 182 | ISASetXSAVES // XSAVES 183 | ) 184 | -------------------------------------------------------------------------------- /isaset_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=ISASet -linecomment"; DO NOT EDIT. 2 | 3 | package zydis 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[ISASetInvalid-0] 12 | _ = x[ISASetADOX_ADCX-1] 13 | _ = x[ISASetAES-2] 14 | _ = x[ISASetAMD-3] 15 | _ = x[ISASetAMD3DNOW-4] 16 | _ = x[ISASetAMX_BF16-5] 17 | _ = x[ISASetAMX_INT8-6] 18 | _ = x[ISASetAMX_TILE-7] 19 | _ = x[ISASetAVX-8] 20 | _ = x[ISASetAVX2-9] 21 | _ = x[ISASetAVX2GATHER-10] 22 | _ = x[ISASetAVX512BW_128-11] 23 | _ = x[ISASetAVX512BW_128N-12] 24 | _ = x[ISASetAVX512BW_256-13] 25 | _ = x[ISASetAVX512BW_512-14] 26 | _ = x[ISASetAVX512BW_KOP-15] 27 | _ = x[ISASetAVX512CD_128-16] 28 | _ = x[ISASetAVX512CD_256-17] 29 | _ = x[ISASetAVX512CD_512-18] 30 | _ = x[ISASetAVX512DQ_128-19] 31 | _ = x[ISASetAVX512DQ_128N-20] 32 | _ = x[ISASetAVX512DQ_256-21] 33 | _ = x[ISASetAVX512DQ_512-22] 34 | _ = x[ISASetAVX512DQ_KOP-23] 35 | _ = x[ISASetAVX512DQ_SCALAR-24] 36 | _ = x[ISASetAVX512ER_512-25] 37 | _ = x[ISASetAVX512ER_SCALAR-26] 38 | _ = x[ISASetAVX512F_128-27] 39 | _ = x[ISASetAVX512F_128N-28] 40 | _ = x[ISASetAVX512F_256-29] 41 | _ = x[ISASetAVX512F_512-30] 42 | _ = x[ISASetAVX512F_KOP-31] 43 | _ = x[ISASetAVX512F_SCALAR-32] 44 | _ = x[ISASetAVX512PF_512-33] 45 | _ = x[ISASetAVX512_4FMAPS_512-34] 46 | _ = x[ISASetAVX512_4FMAPS_SCALAR-35] 47 | _ = x[ISASetAVX512_4VNNIW_512-36] 48 | _ = x[ISASetAVX512_BF16_128-37] 49 | _ = x[ISASetAVX512_BF16_256-38] 50 | _ = x[ISASetAVX512_BF16_512-39] 51 | _ = x[ISASetAVX512_BITALG_128-40] 52 | _ = x[ISASetAVX512_BITALG_256-41] 53 | _ = x[ISASetAVX512_BITALG_512-42] 54 | _ = x[ISASetAVX512_GFNI_128-43] 55 | _ = x[ISASetAVX512_GFNI_256-44] 56 | _ = x[ISASetAVX512_GFNI_512-45] 57 | _ = x[ISASetAVX512_IFMA_128-46] 58 | _ = x[ISASetAVX512_IFMA_256-47] 59 | _ = x[ISASetAVX512_IFMA_512-48] 60 | _ = x[ISASetAVX512_VAES_128-49] 61 | _ = x[ISASetAVX512_VAES_256-50] 62 | _ = x[ISASetAVX512_VAES_512-51] 63 | _ = x[ISASetAVX512_VBMI2_128-52] 64 | _ = x[ISASetAVX512_VBMI2_256-53] 65 | _ = x[ISASetAVX512_VBMI2_512-54] 66 | _ = x[ISASetAVX512_VBMI_128-55] 67 | _ = x[ISASetAVX512_VBMI_256-56] 68 | _ = x[ISASetAVX512_VBMI_512-57] 69 | _ = x[ISASetAVX512_VNNI_128-58] 70 | _ = x[ISASetAVX512_VNNI_256-59] 71 | _ = x[ISASetAVX512_VNNI_512-60] 72 | _ = x[ISASetAVX512_VP2INTERSECT_128-61] 73 | _ = x[ISASetAVX512_VP2INTERSECT_256-62] 74 | _ = x[ISASetAVX512_VP2INTERSECT_512-63] 75 | _ = x[ISASetAVX512_VPCLMULQDQ_128-64] 76 | _ = x[ISASetAVX512_VPCLMULQDQ_256-65] 77 | _ = x[ISASetAVX512_VPCLMULQDQ_512-66] 78 | _ = x[ISASetAVX512_VPOPCNTDQ_128-67] 79 | _ = x[ISASetAVX512_VPOPCNTDQ_256-68] 80 | _ = x[ISASetAVX512_VPOPCNTDQ_512-69] 81 | _ = x[ISASetAVXAES-70] 82 | _ = x[ISASetAVX_GFNI-71] 83 | _ = x[ISASetBMI1-72] 84 | _ = x[ISASetBMI2-73] 85 | _ = x[ISASetCET-74] 86 | _ = x[ISASetCLDEMOTE-75] 87 | _ = x[ISASetCLFLUSHOPT-76] 88 | _ = x[ISASetCLFSH-77] 89 | _ = x[ISASetCLWB-78] 90 | _ = x[ISASetCLZERO-79] 91 | _ = x[ISASetCMOV-80] 92 | _ = x[ISASetCMPXCHG16B-81] 93 | _ = x[ISASetENQCMD-82] 94 | _ = x[ISASetF16C-83] 95 | _ = x[ISASetFAT_NOP-84] 96 | _ = x[ISASetFCMOV-85] 97 | _ = x[ISASetFMA-86] 98 | _ = x[ISASetFMA4-87] 99 | _ = x[ISASetFXSAVE-88] 100 | _ = x[ISASetFXSAVE64-89] 101 | _ = x[ISASetGFNI-90] 102 | _ = x[ISASetI186-91] 103 | _ = x[ISASetI286PROTECTED-92] 104 | _ = x[ISASetI286REAL-93] 105 | _ = x[ISASetI386-94] 106 | _ = x[ISASetI486-95] 107 | _ = x[ISASetI486REAL-96] 108 | _ = x[ISASetI86-97] 109 | _ = x[ISASetINVPCID-98] 110 | _ = x[ISASetKNCE-99] 111 | _ = x[ISASetKNCJKBR-100] 112 | _ = x[ISASetKNCSTREAM-101] 113 | _ = x[ISASetKNCV-102] 114 | _ = x[ISASetKNC_MISC-103] 115 | _ = x[ISASetKNC_PF_HINT-104] 116 | _ = x[ISASetLAHF-105] 117 | _ = x[ISASetLONGMODE-106] 118 | _ = x[ISASetLZCNT-107] 119 | _ = x[ISASetMCOMMIT-108] 120 | _ = x[ISASetMONITOR-109] 121 | _ = x[ISASetMONITORX-110] 122 | _ = x[ISASetMOVBE-111] 123 | _ = x[ISASetMOVDIR-112] 124 | _ = x[ISASetMPX-113] 125 | _ = x[ISASetPADLOCK_ACE-114] 126 | _ = x[ISASetPADLOCK_PHE-115] 127 | _ = x[ISASetPADLOCK_PMM-116] 128 | _ = x[ISASetPADLOCK_RNG-117] 129 | _ = x[ISASetPAUSE-118] 130 | _ = x[ISASetPCLMULQDQ-119] 131 | _ = x[ISASetPCONFIG-120] 132 | _ = x[ISASetPENTIUMMMX-121] 133 | _ = x[ISASetPENTIUMREAL-122] 134 | _ = x[ISASetPKU-123] 135 | _ = x[ISASetPOPCNT-124] 136 | _ = x[ISASetPPRO-125] 137 | _ = x[ISASetPREFETCHWT1-126] 138 | _ = x[ISASetPREFETCH_NOP-127] 139 | _ = x[ISASetPT-128] 140 | _ = x[ISASetRDPID-129] 141 | _ = x[ISASetRDPMC-130] 142 | _ = x[ISASetRDPRU-131] 143 | _ = x[ISASetRDRAND-132] 144 | _ = x[ISASetRDSEED-133] 145 | _ = x[ISASetRDTSCP-134] 146 | _ = x[ISASetRDWRFSGS-135] 147 | _ = x[ISASetRTM-136] 148 | _ = x[ISASetSERIALIZE-137] 149 | _ = x[ISASetSGX-138] 150 | _ = x[ISASetSGX_ENCLV-139] 151 | _ = x[ISASetSHA-140] 152 | _ = x[ISASetSMAP-141] 153 | _ = x[ISASetSMX-142] 154 | _ = x[ISASetSSE-143] 155 | _ = x[ISASetSSE2-144] 156 | _ = x[ISASetSSE2MMX-145] 157 | _ = x[ISASetSSE3-146] 158 | _ = x[ISASetSSE3X87-147] 159 | _ = x[ISASetSSE4-148] 160 | _ = x[ISASetSSE42-149] 161 | _ = x[ISASetSSE4A-150] 162 | _ = x[ISASetSSEMXCSR-151] 163 | _ = x[ISASetSSE_PREFETCH-152] 164 | _ = x[ISASetSSSE3-153] 165 | _ = x[ISASetSSSE3MMX-154] 166 | _ = x[ISASetSVM-155] 167 | _ = x[ISASetTBM-156] 168 | _ = x[ISASetTSX_LDTRK-157] 169 | _ = x[ISASetVAES-158] 170 | _ = x[ISASetVMFUNC-159] 171 | _ = x[ISASetVPCLMULQDQ-160] 172 | _ = x[ISASetVTX-161] 173 | _ = x[ISASetWAITPKG-162] 174 | _ = x[ISASetX87-163] 175 | _ = x[ISASetXOP-164] 176 | _ = x[ISASetXSAVE-165] 177 | _ = x[ISASetXSAVEC-166] 178 | _ = x[ISASetXSAVEOPT-167] 179 | _ = x[ISASetXSAVES-168] 180 | } 181 | 182 | const _ISASet_name = "INVALIDADOX_ADCXAESAMDAMD3DNOWAMX_BF16AMX_INT8AMX_TILEAVXAVX2AVX2GATHERAVX512BW_128AVX512BW_128NAVX512BW_256AVX512BW_512AVX512BW_KOPAVX512CD_128AVX512CD_256AVX512CD_512AVX512DQ_128AVX512DQ_128NAVX512DQ_256AVX512DQ_512AVX512DQ_KOPAVX512DQ_SCALARAVX512ER_512AVX512ER_SCALARAVX512F_128AVX512F_128NAVX512F_256AVX512F_512AVX512F_KOPAVX512F_SCALARAVX512PF_512AVX512_4FMAPS_512AVX512_4FMAPS_SCALARAVX512_4VNNIW_512AVX512_BF16_128AVX512_BF16_256AVX512_BF16_512AVX512_BITALG_128AVX512_BITALG_256AVX512_BITALG_512AVX512_GFNI_128AVX512_GFNI_256AVX512_GFNI_512AVX512_IFMA_128AVX512_IFMA_256AVX512_IFMA_512AVX512_VAES_128AVX512_VAES_256AVX512_VAES_512AVX512_VBMI2_128AVX512_VBMI2_256AVX512_VBMI2_512AVX512_VBMI_128AVX512_VBMI_256AVX512_VBMI_512AVX512_VNNI_128AVX512_VNNI_256AVX512_VNNI_512AVX512_VP2INTERSECT_128AVX512_VP2INTERSECT_256AVX512_VP2INTERSECT_512AVX512_VPCLMULQDQ_128AVX512_VPCLMULQDQ_256AVX512_VPCLMULQDQ_512AVX512_VPOPCNTDQ_128AVX512_VPOPCNTDQ_256AVX512_VPOPCNTDQ_512AVXAESAVX_GFNIBMI1BMI2CETCLDEMOTECLFLUSHOPTCLFSHCLWBCLZEROCMOVCMPXCHG16BENQCMDF16CFAT_NOPFCMOVFMAFMA4FXSAVEFXSAVE64GFNII186I286PROTECTEDI286REALI386I486I486REALI86INVPCIDKNCEKNCJKBRKNCSTREAMKNCVKNC_MISCKNC_PF_HINTLAHFLONGMODELZCNTMCOMMITMONITORMONITORXMOVBEMOVDIRMPXPADLOCK_ACEPADLOCK_PHEPADLOCK_PMMPADLOCK_RNGPAUSEPCLMULQDQPCONFIGPENTIUMMMXPENTIUMREALPKUPOPCNTPPROPREFETCHWT1PREFETCH_NOPPTRDPIDRDPMCRDPRURDRANDRDSEEDRDTSCPRDWRFSGSRTMSERIALIZESGXSGX_ENCLVSHASMAPSMXSSESSE2SSE2MMXSSE3SSE3X87SSE4SSE42SSE4ASSEMXCSRSSE_PREFETCHSSSE3SSSE3MMXSVMTBMTSX_LDTRKVAESVMFUNCVPCLMULQDQVTXWAITPKGX87XOPXSAVEXSAVECXSAVEOPTXSAVES" 183 | 184 | var _ISASet_index = [...]uint16{0, 7, 16, 19, 22, 30, 38, 46, 54, 57, 61, 71, 83, 96, 108, 120, 132, 144, 156, 168, 180, 193, 205, 217, 229, 244, 256, 271, 282, 294, 305, 316, 327, 341, 353, 370, 390, 407, 422, 437, 452, 469, 486, 503, 518, 533, 548, 563, 578, 593, 608, 623, 638, 654, 670, 686, 701, 716, 731, 746, 761, 776, 799, 822, 845, 866, 887, 908, 928, 948, 968, 974, 982, 986, 990, 993, 1001, 1011, 1016, 1020, 1026, 1030, 1040, 1046, 1050, 1057, 1062, 1065, 1069, 1075, 1083, 1087, 1091, 1104, 1112, 1116, 1120, 1128, 1131, 1138, 1142, 1149, 1158, 1162, 1170, 1181, 1185, 1193, 1198, 1205, 1212, 1220, 1225, 1231, 1234, 1245, 1256, 1267, 1278, 1283, 1292, 1299, 1309, 1320, 1323, 1329, 1333, 1344, 1356, 1358, 1363, 1368, 1373, 1379, 1385, 1391, 1399, 1402, 1411, 1414, 1423, 1426, 1430, 1433, 1436, 1440, 1447, 1451, 1458, 1462, 1467, 1472, 1480, 1492, 1497, 1505, 1508, 1511, 1520, 1524, 1530, 1540, 1543, 1550, 1553, 1556, 1561, 1567, 1575, 1581} 185 | 186 | func (i ISASet) String() string { 187 | if i < 0 || i >= ISASet(len(_ISASet_index)-1) { 188 | return "ISASet(" + strconv.FormatInt(int64(i), 10) + ")" 189 | } 190 | return _ISASet_name[_ISASet_index[i]:_ISASet_index[i+1]] 191 | } 192 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2019 John Papandriopoulos. All rights reserved. 2 | # Use of this source code is governed by a MIT-style 3 | # license that can be found in the LICENSE file. 4 | 5 | # This Makefile was designed to run on macOS, using a cross-compiler to 6 | # build the Linux and Windows versions of the zydis library. 7 | # 1. Xcode 8 | # 2. brew install mingw-w64 9 | # 3. brew install musl-cross --with-aarch64 10 | 11 | CC_DARWIN_AMD64=clang -arch x86_64 12 | CC_DARWIN_ARM64=clang -arch arm64 13 | CC_LINUX_AMD64=x86_64-linux-musl-gcc 14 | CC_LINUX_ARM64=aarch64-linux-musl-gcc 15 | CC_WINDOWS_386=i686-w64-mingw32-gcc 16 | CC_WINDOWS_AMD64=x86_64-w64-mingw32-gcc 17 | 18 | CXX_DARWIN_AMD64=clang++ -arch x86_64 19 | CXX_DARWIN_ARM64=clang++ -arch arm64 20 | CXX_LINUX_AMD64=x86_64-linux-musl-g++ 21 | CXX_LINUX_ARM64=aarch64-linux-musl-g++ 22 | CXX_WINDOWS_386=i686-w64-mingw32-g++ 23 | CXX_WINDOWS_AMD64=x86_64-w64-mingw32-g++ 24 | 25 | LD_DARWIN_AMD64=ld -arch x86_64 26 | LD_DARWIN_ARM64=ld -arch arm64 27 | LD_LINUX_AMD64=x86_64-linux-musl-ld 28 | LD_LINUX_ARM64=aarch64-linux-musl-ld 29 | LD_WINDOWS_386=i686-w64-mingw32-ld 30 | LD_WINDOWS_AMD64=x86_64-w64-mingw32-ld 31 | 32 | .PHONY: all prepare clean install_headers darwin_amd64 darwin_arm64 linux_amd64 linux_arm64 windows_386 windows_amd64 33 | 34 | all: darwin_amd64 darwin_arm64 linux_amd64 linux_arm64 windows_386 windows_amd64 install_headers 35 | 36 | # Prepare the build 37 | prepare: clean 38 | git clone https://github.com/zyantific/zydis.git zydis 39 | cd zydis && \ 40 | git submodule update --init 41 | 42 | darwin_amd64: prepare 43 | mkdir -p out/darwin_amd64 44 | env \ 45 | CC="$(CC_DARWIN_AMD64)" \ 46 | CXX="$(CXX_DARWIN_AMD64)" \ 47 | cmake \ 48 | -DCMAKE_INSTALL_PREFIX=./out/install \ 49 | -S zydis -B out/darwin_amd64 && \ 50 | cmake --build out/darwin_amd64 51 | $(LD_DARWIN_AMD64) -r -o ../libzydis_darwin_amd64.syso -force_load out/darwin_amd64/libZydis.a 52 | 53 | darwin_arm64: prepare 54 | mkdir -p out/darwin_arm64 55 | env \ 56 | CC="$(CC_DARWIN_RM64)" \ 57 | CXX="$(CXX_DARWIN_RM64)" \ 58 | cmake -S zydis -B out/darwin_arm64 && \ 59 | cmake --build out/darwin_arm64 60 | $(LD_DARWIN_ARM64) -r -o ../libzydis_darwin_arm64.syso -force_load out/darwin_arm64/libZydis.a 61 | 62 | linux_amd64: prepare 63 | mkdir -p out/linux_amd64 64 | env \ 65 | CC=$(CC_LINUX_AMD64) \ 66 | CXX=$(CXX_LINUX_AMD64) \ 67 | cmake \ 68 | -DCMAKE_SYSTEM_NAME=linux \ 69 | -DZYDIS_BUILD_EXAMPLES=OFF \ 70 | -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ 71 | -S zydis -B out/linux_amd64 && \ 72 | cmake --build out/linux_amd64 73 | $(LD_LINUX_AMD64) -r -o ../libzydis_linux_amd64.syso --whole-archive out/linux_amd64/libZydis.a 74 | 75 | linux_arm64: prepare 76 | mkdir -p out/linux_arm64 77 | env \ 78 | CC=$(CC_LINUX_ARM64) \ 79 | CXX=$(CXX_LINUX_ARM64) \ 80 | cmake \ 81 | -DCMAKE_SYSTEM_NAME=linux \ 82 | -DZYDIS_BUILD_EXAMPLES=OFF \ 83 | -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ 84 | -S zydis -B out/linux_arm64 && \ 85 | cmake --build out/linux_arm64 86 | $(LD_LINUX_ARM64) -r -o ../libzydis_linux_arm64.syso --whole-archive out/linux_arm64/libZydis.a 87 | 88 | windows_amd64: prepare 89 | mkdir -p out/windows_amd64 90 | env \ 91 | CC=$(CC_WINDOWS_AMD64) \ 92 | CXX=$(CXX_WINDOWS_AMD64) \ 93 | cmake \ 94 | -DCMAKE_SYSTEM_NAME=windows \ 95 | -DZYDIS_BUILD_EXAMPLES=OFF \ 96 | -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ 97 | -S zydis -B out/windows_amd64 && \ 98 | cmake --build out/windows_amd64 99 | $(LD_WINDOWS_AMD64) -r -o ../libzydis_windows_amd64.syso --whole-archive out/windows_amd64/libZydis.a 100 | 101 | windows_386: prepare 102 | mkdir -p out/windows_386 103 | env \ 104 | CC=$(CC_WINDOWS_386) \ 105 | CXX=$(CXX_WINDOWS_386) \ 106 | cmake \ 107 | -DCMAKE_SYSTEM_NAME=windows \ 108 | -DZYDIS_BUILD_EXAMPLES=OFF \ 109 | -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ 110 | -S zydis -B out/windows_386 && \ 111 | cmake --build out/windows_386 112 | $(LD_WINDOWS_386) -r -o ../libzydis_windows_386.syso --whole-archive out/windows_386/libZydis.a 113 | 114 | # Clean the build 115 | clean: 116 | rm -rf zydis out 117 | 118 | install_headers: darwin_amd64 119 | # Copy include folder 120 | mkdir -p include 121 | mkdir -p out/install 122 | cmake --install out/darwin_amd64 123 | cmake --install out/darwin_amd64/zycore 124 | cp -Rvp out/install/include/* include/ 125 | -------------------------------------------------------------------------------- /lib/include/Zycore/API/Memory.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYCORE_MEMORY_H 33 | #define ZYCORE_MEMORY_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #if defined(ZYAN_WINDOWS) 41 | # include 42 | #elif defined(ZYAN_POSIX) 43 | # include 44 | #else 45 | # error "Unsupported platform detected" 46 | #endif 47 | 48 | /* ============================================================================================== */ 49 | /* Enums and types */ 50 | /* ============================================================================================== */ 51 | 52 | /** 53 | * Defines the `ZyanMemoryPageProtection` enum. 54 | */ 55 | typedef enum ZyanMemoryPageProtection_ 56 | { 57 | #if defined(ZYAN_WINDOWS) 58 | 59 | ZYAN_PAGE_READONLY = PAGE_READONLY, 60 | ZYAN_PAGE_READWRITE = PAGE_READWRITE, 61 | ZYAN_PAGE_EXECUTE = PAGE_EXECUTE, 62 | ZYAN_PAGE_EXECUTE_READ = PAGE_EXECUTE_READ, 63 | ZYAN_PAGE_EXECUTE_READWRITE = PAGE_EXECUTE_READWRITE 64 | 65 | #elif defined(ZYAN_POSIX) 66 | 67 | ZYAN_PAGE_READONLY = PROT_READ, 68 | ZYAN_PAGE_READWRITE = PROT_READ | PROT_WRITE, 69 | ZYAN_PAGE_EXECUTE = PROT_EXEC, 70 | ZYAN_PAGE_EXECUTE_READ = PROT_EXEC | PROT_READ, 71 | ZYAN_PAGE_EXECUTE_READWRITE = PROT_EXEC | PROT_READ | PROT_WRITE 72 | 73 | #endif 74 | } ZyanMemoryPageProtection; 75 | 76 | /* ============================================================================================== */ 77 | /* Exported functions */ 78 | /* ============================================================================================== */ 79 | 80 | /* ---------------------------------------------------------------------------------------------- */ 81 | /* General */ 82 | /* ---------------------------------------------------------------------------------------------- */ 83 | 84 | /** 85 | * Returns the system page size. 86 | * 87 | * @return The system page size. 88 | */ 89 | ZyanU32 ZyanMemoryGetSystemPageSize(); 90 | 91 | /** 92 | * Returns the system allocation granularity. 93 | * 94 | * The system allocation granularity specifies the minimum amount of bytes which can be allocated 95 | * at a specific address by a single call of `ZyanMemoryVirtualAlloc`. 96 | * 97 | * This value is typically 64KiB on Windows systems and equal to the page size on most POSIX 98 | * platforms. 99 | * 100 | * @return The system allocation granularity. 101 | */ 102 | ZyanU32 ZyanMemoryGetSystemAllocationGranularity(); 103 | 104 | /* ---------------------------------------------------------------------------------------------- */ 105 | /* Memory management */ 106 | /* ---------------------------------------------------------------------------------------------- */ 107 | 108 | /** 109 | * Changes the memory protection value of one or more pages. 110 | * 111 | * @param address The start address aligned to a page boundary. 112 | * @param size The size. 113 | * @param protection The new page protection value. 114 | * 115 | * @return A zyan status code. 116 | */ 117 | ZyanStatus ZyanMemoryVirtualProtect(void* address, ZyanUSize size, 118 | ZyanMemoryPageProtection protection); 119 | 120 | /** 121 | * Releases one or more memory pages starting at the given address. 122 | * 123 | * @param address The start address aligned to a page boundary. 124 | * @param size The size. 125 | * 126 | * @return A zyan status code. 127 | */ 128 | ZyanStatus ZyanMemoryVirtualFree(void* address, ZyanUSize size); 129 | 130 | /* ---------------------------------------------------------------------------------------------- */ 131 | 132 | /* ============================================================================================== */ 133 | 134 | #endif /* ZYCORE_MEMORY_H */ 135 | -------------------------------------------------------------------------------- /lib/include/Zycore/API/Synchronization.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYCORE_SYNCHRONIZATION_H 33 | #define ZYCORE_SYNCHRONIZATION_H 34 | 35 | #ifndef ZYAN_NO_LIBC 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* ============================================================================================== */ 46 | /* Enums and types */ 47 | /* ============================================================================================== */ 48 | 49 | #if defined(ZYAN_POSIX) 50 | 51 | #include 52 | 53 | /* ---------------------------------------------------------------------------------------------- */ 54 | /* Critical Section */ 55 | /* ---------------------------------------------------------------------------------------------- */ 56 | 57 | typedef pthread_mutex_t ZyanCriticalSection; 58 | 59 | /* ---------------------------------------------------------------------------------------------- */ 60 | 61 | #elif defined(ZYAN_WINDOWS) 62 | 63 | #include 64 | 65 | /* ---------------------------------------------------------------------------------------------- */ 66 | /* Critical Section */ 67 | /* ---------------------------------------------------------------------------------------------- */ 68 | 69 | typedef CRITICAL_SECTION ZyanCriticalSection; 70 | 71 | /* ---------------------------------------------------------------------------------------------- */ 72 | 73 | #else 74 | # error "Unsupported platform detected" 75 | #endif 76 | 77 | /* ============================================================================================== */ 78 | /* Exported functions */ 79 | /* ============================================================================================== */ 80 | 81 | /* ---------------------------------------------------------------------------------------------- */ 82 | /* Critical Section */ 83 | /* ---------------------------------------------------------------------------------------------- */ 84 | 85 | /** 86 | * Initializes a critical section. 87 | * 88 | * @param critical_section A pointer to the `ZyanCriticalSection` struct. 89 | */ 90 | ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionInitialize(ZyanCriticalSection* critical_section); 91 | 92 | /** 93 | * Enters a critical section. 94 | * 95 | * @param critical_section A pointer to the `ZyanCriticalSection` struct. 96 | */ 97 | ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionEnter(ZyanCriticalSection* critical_section); 98 | 99 | /** 100 | * Tries to enter a critical section. 101 | * 102 | * @param critical_section A pointer to the `ZyanCriticalSection` struct. 103 | * 104 | * @return Returns `ZYAN_TRUE` if the critical section was successfully entered or `ZYAN_FALSE`, 105 | * if not. 106 | */ 107 | ZYCORE_EXPORT ZyanBool ZyanCriticalSectionTryEnter(ZyanCriticalSection* critical_section); 108 | 109 | /** 110 | * Leaves a critical section. 111 | * 112 | * @param critical_section A pointer to the `ZyanCriticalSection` struct. 113 | */ 114 | ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionLeave(ZyanCriticalSection* critical_section); 115 | 116 | /** 117 | * Deletes a critical section. 118 | * 119 | * @param critical_section A pointer to the `ZyanCriticalSection` struct. 120 | */ 121 | ZYCORE_EXPORT ZyanStatus ZyanCriticalSectionDelete(ZyanCriticalSection* critical_section); 122 | 123 | /* ---------------------------------------------------------------------------------------------- */ 124 | 125 | /* ============================================================================================== */ 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | 131 | #endif /* ZYAN_NO_LIBC */ 132 | 133 | #endif /* ZYCORE_SYNCHRONIZATION_H */ 134 | -------------------------------------------------------------------------------- /lib/include/Zycore/API/Terminal.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file Provides cross-platform terminal helper functions. 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYCORE_TERMINAL_H 33 | #define ZYCORE_TERMINAL_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #ifndef ZYAN_NO_LIBC 44 | 45 | /* ============================================================================================== */ 46 | /* VT100 CSI SGR sequences */ 47 | /* ============================================================================================== */ 48 | 49 | /* ---------------------------------------------------------------------------------------------- */ 50 | /* General */ 51 | /* ---------------------------------------------------------------------------------------------- */ 52 | 53 | #define ZYAN_VT100SGR_RESET "\033[0m" 54 | 55 | /* ---------------------------------------------------------------------------------------------- */ 56 | /* Foreground colors */ 57 | /* ---------------------------------------------------------------------------------------------- */ 58 | 59 | #define ZYAN_VT100SGR_FG_DEFAULT "\033[39m" 60 | 61 | #define ZYAN_VT100SGR_FG_BLACK "\033[30m" 62 | #define ZYAN_VT100SGR_FG_RED "\033[31m" 63 | #define ZYAN_VT100SGR_FG_GREEN "\033[32m" 64 | #define ZYAN_VT100SGR_FG_YELLOW "\033[33m" 65 | #define ZYAN_VT100SGR_FG_BLUE "\033[34m" 66 | #define ZYAN_VT100SGR_FG_MAGENTA "\033[35m" 67 | #define ZYAN_VT100SGR_FG_CYAN "\033[36m" 68 | #define ZYAN_VT100SGR_FG_WHITE "\033[37m" 69 | #define ZYAN_VT100SGR_FG_BRIGHT_BLACK "\033[90m" 70 | #define ZYAN_VT100SGR_FG_BRIGHT_RED "\033[91m" 71 | #define ZYAN_VT100SGR_FG_BRIGHT_GREEN "\033[92m" 72 | #define ZYAN_VT100SGR_FG_BRIGHT_YELLOW "\033[93m" 73 | #define ZYAN_VT100SGR_FG_BRIGHT_BLUE "\033[94m" 74 | #define ZYAN_VT100SGR_FG_BRIGHT_MAGENTA "\033[95m" 75 | #define ZYAN_VT100SGR_FG_BRIGHT_CYAN "\033[96m" 76 | #define ZYAN_VT100SGR_FG_BRIGHT_WHITE "\033[97m" 77 | 78 | /* ---------------------------------------------------------------------------------------------- */ 79 | /* Background color */ 80 | /* ---------------------------------------------------------------------------------------------- */ 81 | 82 | #define ZYAN_VT100SGR_BG_DEFAULT "\033[49m" 83 | 84 | #define ZYAN_VT100SGR_BG_BLACK "\033[40m" 85 | #define ZYAN_VT100SGR_BG_RED "\033[41m" 86 | #define ZYAN_VT100SGR_BG_GREEN "\033[42m" 87 | #define ZYAN_VT100SGR_BG_YELLOW "\033[43m" 88 | #define ZYAN_VT100SGR_BG_BLUE "\033[44m" 89 | #define ZYAN_VT100SGR_BG_MAGENTA "\033[45m" 90 | #define ZYAN_VT100SGR_BG_CYAN "\033[46m" 91 | #define ZYAN_VT100SGR_BG_WHITE "\033[47m" 92 | #define ZYAN_VT100SGR_BG_BRIGHT_BLACK "\033[100m" 93 | #define ZYAN_VT100SGR_BG_BRIGHT_RED "\033[101m" 94 | #define ZYAN_VT100SGR_BG_BRIGHT_GREEN "\033[102m" 95 | #define ZYAN_VT100SGR_BG_BRIGHT_YELLOW "\033[103m" 96 | #define ZYAN_VT100SGR_BG_BRIGHT_BLUE "\033[104m" 97 | #define ZYAN_VT100SGR_BG_BRIGHT_MAGENTA "\033[105m" 98 | #define ZYAN_VT100SGR_BG_BRIGHT_CYAN "\033[106m" 99 | #define ZYAN_VT100SGR_BG_BRIGHT_WHITE "\033[107m" 100 | 101 | /* ---------------------------------------------------------------------------------------------- */ 102 | 103 | /* ============================================================================================== */ 104 | /* Enums and types */ 105 | /* ============================================================================================== */ 106 | 107 | /** 108 | * Declares the `ZyanStandardStream` enum. 109 | */ 110 | typedef enum ZyanStandardStream_ 111 | { 112 | /** 113 | * The default input stream. 114 | */ 115 | ZYAN_STDSTREAM_IN, 116 | /** 117 | * The default output stream. 118 | */ 119 | ZYAN_STDSTREAM_OUT, 120 | /** 121 | * The default error stream. 122 | */ 123 | ZYAN_STDSTREAM_ERR 124 | } ZyanStandardStream; 125 | 126 | /* ============================================================================================== */ 127 | /* Exported functions */ 128 | /* ============================================================================================== */ 129 | 130 | /** 131 | * Enables VT100 ansi escape codes for the given stream. 132 | * 133 | * @param stream Either `ZYAN_STDSTREAM_OUT` or `ZYAN_STDSTREAM_ERR`. 134 | * 135 | * @return A zyan status code. 136 | * 137 | * This functions returns `ZYAN_STATUS_SUCCESS` on all non-Windows systems without performing any 138 | * operations, assuming that VT100 is supported by default. 139 | * 140 | * On Windows systems, VT100 functionality is only supported on Windows 10 build 1607 (anniversary 141 | * update) and later. 142 | */ 143 | ZYCORE_EXPORT ZyanStatus ZyanTerminalEnableVT100(ZyanStandardStream stream); 144 | 145 | /** 146 | * Checks, if the given standard stream reads from or writes to a terminal. 147 | * 148 | * @param stream The standard stream to check. 149 | * 150 | * @return `ZYAN_STATUS_TRUE`, if the stream is bound to a terminal, `ZYAN_STATUS_FALSE` if not, 151 | * or another zyan status code if an error occured. 152 | */ 153 | ZYCORE_EXPORT ZyanStatus ZyanTerminalIsTTY(ZyanStandardStream stream); 154 | 155 | /* ============================================================================================== */ 156 | 157 | #endif // ZYAN_NO_LIBC 158 | 159 | #ifdef __cplusplus 160 | } 161 | #endif 162 | 163 | #endif /* ZYCORE_TERMINAL_H */ 164 | -------------------------------------------------------------------------------- /lib/include/Zycore/API/Thread.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYCORE_THREAD_H 33 | #define ZYCORE_THREAD_H 34 | 35 | #ifndef ZYAN_NO_LIBC 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | /* ============================================================================================== */ 46 | /* Enums and types */ 47 | /* ============================================================================================== */ 48 | 49 | #if defined(ZYAN_POSIX) 50 | 51 | #include 52 | 53 | /* ---------------------------------------------------------------------------------------------- */ 54 | /* General */ 55 | /* ---------------------------------------------------------------------------------------------- */ 56 | 57 | /** 58 | * Defines the `ZyanThread` data-type. 59 | */ 60 | typedef pthread_t ZyanThread; 61 | 62 | /** 63 | * Defines the `ZyanThreadId` data-type. 64 | */ 65 | typedef ZyanU64 ZyanThreadId; 66 | 67 | /* ---------------------------------------------------------------------------------------------- */ 68 | /* Thread Local Storage (TLS) */ 69 | /* ---------------------------------------------------------------------------------------------- */ 70 | 71 | /** 72 | * Defines the `ZyanThreadTlsIndex` data-type. 73 | */ 74 | typedef pthread_key_t ZyanThreadTlsIndex; 75 | 76 | /** 77 | * Defines the `ZyanThreadTlsCallback` function prototype. 78 | */ 79 | typedef void(*ZyanThreadTlsCallback)(void* data); 80 | 81 | /** 82 | * Declares a Thread Local Storage (TLS) callback function. 83 | * 84 | * @param name The callback function name. 85 | * @param param_type The callback data parameter type. 86 | * @param param_name The callback data parameter name. 87 | */ 88 | #define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \ 89 | void name(param_type* param_name) 90 | 91 | /* ---------------------------------------------------------------------------------------------- */ 92 | 93 | #elif defined(ZYAN_WINDOWS) 94 | 95 | #include 96 | 97 | /* ---------------------------------------------------------------------------------------------- */ 98 | /* General */ 99 | /* ---------------------------------------------------------------------------------------------- */ 100 | 101 | /** 102 | * Defines the `ZyanThread` data-type. 103 | */ 104 | typedef HANDLE ZyanThread; 105 | 106 | /** 107 | * Defines the `ZyanThreadId` data-type. 108 | */ 109 | typedef DWORD ZyanThreadId; 110 | 111 | /* ---------------------------------------------------------------------------------------------- */ 112 | /* Thread Local Storage (TLS) */ 113 | /* ---------------------------------------------------------------------------------------------- */ 114 | 115 | /** 116 | * Defines the `ZyanThreadTlsIndex` data-type. 117 | */ 118 | typedef DWORD ZyanThreadTlsIndex; 119 | 120 | /** 121 | * Defines the `ZyanThreadTlsCallback` function prototype. 122 | */ 123 | typedef PFLS_CALLBACK_FUNCTION ZyanThreadTlsCallback; 124 | 125 | /** 126 | * Declares a Thread Local Storage (TLS) callback function. 127 | * 128 | * @param name The callback function name. 129 | * @param param_type The callback data parameter type. 130 | * @param param_name The callback data parameter name. 131 | */ 132 | #define ZYAN_THREAD_DECLARE_TLS_CALLBACK(name, param_type, param_name) \ 133 | VOID NTAPI name(param_type* param_name) 134 | 135 | /* ---------------------------------------------------------------------------------------------- */ 136 | 137 | #else 138 | # error "Unsupported platform detected" 139 | #endif 140 | 141 | /* ============================================================================================== */ 142 | /* Exported functions */ 143 | /* ============================================================================================== */ 144 | 145 | /* ---------------------------------------------------------------------------------------------- */ 146 | /* General */ 147 | /* ---------------------------------------------------------------------------------------------- */ 148 | 149 | /** 150 | * Returns the handle of the current thread. 151 | * 152 | * @param thread Receives the handle of the current thread. 153 | * 154 | * @return A zyan status code. 155 | */ 156 | ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThread(ZyanThread* thread); 157 | 158 | /** 159 | * Returns the unique id of the current thread. 160 | * 161 | * @param thread_id Receives the unique id of the current thread. 162 | * 163 | * @return A zyan status code. 164 | */ 165 | ZYCORE_EXPORT ZyanStatus ZyanThreadGetCurrentThreadId(ZyanThreadId* thread_id); 166 | 167 | /* ---------------------------------------------------------------------------------------------- */ 168 | /* Thread Local Storage (TLS) */ 169 | /* ---------------------------------------------------------------------------------------------- */ 170 | 171 | /** 172 | * Allocates a new Thread Local Storage (TLS) slot. 173 | * 174 | * @param index Receives the TLS slot index. 175 | * @param destructor A pointer to a destructor callback which is invoked to finalize the data 176 | * in the TLS slot or `ZYAN_NULL`, if not needed. 177 | * 178 | * The maximum available number of TLS slots is implementation specific and different on each 179 | * platform: 180 | * - Windows 181 | * - A total amount of 128 slots per process are guaranteed 182 | * - POSIX 183 | * - A total amount of 128 slots per process are guaranteed 184 | * - Some systems guarantee larger amounts like e.g. 1024 slots per process 185 | * 186 | * Note that the invocation rules for the destructor callback are implementation specific and 187 | * different on each platform: 188 | * - Windows 189 | * - The callback is invoked when a thread exits 190 | * - The callback is invoked when the process exits 191 | * - The callback is invoked when the TLS slot is released 192 | * - POSIX 193 | * - The callback is invoked when a thread exits and the stored value is not null 194 | * - The callback is NOT invoked when the process exits 195 | * - The callback is NOT invoked when the TLS slot is released 196 | * 197 | * @return A zyan status code. 198 | */ 199 | ZYCORE_EXPORT ZyanStatus ZyanThreadTlsAlloc(ZyanThreadTlsIndex* index, 200 | ZyanThreadTlsCallback destructor); 201 | 202 | /** 203 | * Releases a Thread Local Storage (TLS) slot. 204 | * 205 | * @param index The TLS slot index. 206 | * 207 | * @return A zyan status code. 208 | */ 209 | ZYCORE_EXPORT ZyanStatus ZyanThreadTlsFree(ZyanThreadTlsIndex index); 210 | 211 | /** 212 | * Returns the value inside the given Thread Local Storage (TLS) slot for the 213 | * calling thread. 214 | * 215 | * @param index The TLS slot index. 216 | * @param data Receives the value inside the given Thread Local Storage 217 | * (TLS) slot for the calling thread. 218 | * 219 | * @return A zyan status code. 220 | */ 221 | ZYCORE_EXPORT ZyanStatus ZyanThreadTlsGetValue(ZyanThreadTlsIndex index, void** data); 222 | 223 | /** 224 | * Set the value of the given Thread Local Storage (TLS) slot for the calling thread. 225 | * 226 | * @param index The TLS slot index. 227 | * @param data The value to store inside the given Thread Local Storage (TLS) slot for the 228 | * calling thread 229 | * 230 | * @return A zyan status code. 231 | */ 232 | ZYCORE_EXPORT ZyanStatus ZyanThreadTlsSetValue(ZyanThreadTlsIndex index, void* data); 233 | 234 | /* ---------------------------------------------------------------------------------------------- */ 235 | 236 | /* ============================================================================================== */ 237 | 238 | #ifdef __cplusplus 239 | } 240 | #endif 241 | 242 | #endif /* ZYAN_NO_LIBC */ 243 | 244 | #endif /* ZYCORE_THREAD_H */ 245 | -------------------------------------------------------------------------------- /lib/include/Zycore/Allocator.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYCORE_ALLOCATOR_H 33 | #define ZYCORE_ALLOCATOR_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* ============================================================================================== */ 44 | /* Enums and types */ 45 | /* ============================================================================================== */ 46 | 47 | struct ZyanAllocator_; 48 | 49 | /** 50 | * Defines the `ZyanAllocatorAllocate` function prototype. 51 | * 52 | * @param allocator A pointer to the `ZyanAllocator` instance. 53 | * @param p Receives a pointer to the first memory block sufficient to hold an 54 | * array of `n` elements with a size of `element_size`. 55 | * @param element_size The size of a single element. 56 | * @param n The number of elements to allocate storage for. 57 | * 58 | * @return A zyan status code. 59 | * 60 | * This prototype is used for the `allocate()` and `reallocate()` functions. 61 | * 62 | * The result of the `reallocate()` function is undefined, if `p` does not point to a memory block 63 | * previously obtained by `(re-)allocate()`. 64 | */ 65 | typedef ZyanStatus (*ZyanAllocatorAllocate)(struct ZyanAllocator_* allocator, void** p, 66 | ZyanUSize element_size, ZyanUSize n); 67 | 68 | /** 69 | * Defines the `ZyanAllocatorDeallocate` function prototype. 70 | * 71 | * @param allocator A pointer to the `ZyanAllocator` instance. 72 | * @param p The pointer obtained from `(re-)allocate()`. 73 | * @param element_size The size of a single element. 74 | * @param n The number of elements earlier passed to `(re-)allocate()`. 75 | * 76 | * @return A zyan status code. 77 | */ 78 | typedef ZyanStatus (*ZyanAllocatorDeallocate)(struct ZyanAllocator_* allocator, void* p, 79 | ZyanUSize element_size, ZyanUSize n); 80 | 81 | /** 82 | * Defines the `ZyanAllocator` struct. 83 | * 84 | * This is the base class for all custom allocator implementations. 85 | * 86 | * All fields in this struct should be considered as "private". Any changes may lead to unexpected 87 | * behavior. 88 | */ 89 | typedef struct ZyanAllocator_ 90 | { 91 | /** 92 | * The allocate function. 93 | */ 94 | ZyanAllocatorAllocate allocate; 95 | /** 96 | * The reallocate function. 97 | */ 98 | ZyanAllocatorAllocate reallocate; 99 | /** 100 | * The deallocate function. 101 | */ 102 | ZyanAllocatorDeallocate deallocate; 103 | } ZyanAllocator; 104 | 105 | /* ============================================================================================== */ 106 | /* Exported functions */ 107 | /* ============================================================================================== */ 108 | 109 | /** 110 | * Initializes the given `ZyanAllocator` instance. 111 | * 112 | * @param allocator A pointer to the `ZyanAllocator` instance. 113 | * @param allocate The allocate function. 114 | * @param reallocate The reallocate function. 115 | * @param deallocate The deallocate function. 116 | * 117 | * @return A zyan status code. 118 | */ 119 | ZYCORE_EXPORT ZyanStatus ZyanAllocatorInit(ZyanAllocator* allocator, ZyanAllocatorAllocate allocate, 120 | ZyanAllocatorAllocate reallocate, ZyanAllocatorDeallocate deallocate); 121 | 122 | #ifndef ZYAN_NO_LIBC 123 | 124 | /** 125 | * Returns the default `ZyanAllocator` instance. 126 | * 127 | * @return A pointer to the default `ZyanAllocator` instance. 128 | * 129 | * The default allocator uses the default memory manager to allocate memory on the heap. 130 | * 131 | * You should in no case modify the returned allocator instance to avoid unexpected behavior. 132 | */ 133 | ZYCORE_EXPORT ZYAN_REQUIRES_LIBC ZyanAllocator* ZyanAllocatorDefault(void); 134 | 135 | #endif // ZYAN_NO_LIBC 136 | 137 | /* ============================================================================================== */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* ZYCORE_ALLOCATOR_H */ 144 | -------------------------------------------------------------------------------- /lib/include/Zycore/ArgParse.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Joel Hoener 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Implements command-line argument parsing. 30 | */ 31 | 32 | #ifndef ZYCORE_ARGPARSE_H 33 | #define ZYCORE_ARGPARSE_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* ============================================================================================== */ 45 | /* Structs and other types */ 46 | /* ============================================================================================== */ 47 | 48 | /** 49 | * Definition of a single argument. 50 | */ 51 | typedef struct ZyanArgParseDefinition_ 52 | { 53 | /** 54 | * The argument name, e.g. `--help`. 55 | * 56 | * Must start with either one or two dashes. Single dash arguments must consist of a single 57 | * character, (e.g. `-n`), double-dash arguments can be of arbitrary length. 58 | */ 59 | const char* name; 60 | /** 61 | * Whether the argument is boolean or expects a value. 62 | */ 63 | ZyanBool boolean; 64 | /** 65 | * Whether this argument is required (error if missing). 66 | */ 67 | ZyanBool required; 68 | } ZyanArgParseDefinition; 69 | 70 | /** 71 | * Configuration for argument parsing. 72 | */ 73 | typedef struct ZyanArgParseConfig_ 74 | { 75 | /** 76 | * `argv` argument passed to `main` by LibC. 77 | */ 78 | const char** argv; 79 | /** 80 | * `argc` argument passed to `main` by LibC. 81 | */ 82 | ZyanUSize argc; 83 | /** 84 | * Minimum # of accepted unnamed / anonymous arguments. 85 | */ 86 | ZyanUSize min_unnamed_args; 87 | /** 88 | * Maximum # of accepted unnamed / anonymous arguments. 89 | */ 90 | ZyanUSize max_unnamed_args; 91 | /** 92 | * Argument definition array, or `ZYAN_NULL`. 93 | * 94 | * Expects a pointer to an array of `ZyanArgParseDefinition` instances. The array is 95 | * terminated by setting the `.name` field of the last element to `ZYAN_NULL`. If no named 96 | * arguments should be parsed, you can also set this to `ZYAN_NULL`. 97 | */ 98 | ZyanArgParseDefinition* args; 99 | } ZyanArgParseConfig; 100 | 101 | /** 102 | * Information about a parsed argument. 103 | */ 104 | typedef struct ZyanArgParseArg_ 105 | { 106 | /** 107 | * Corresponding argument definition, or `ZYAN_NULL` for unnamed args. 108 | * 109 | * This pointer is borrowed from the `cfg` pointer passed to `ZyanArgParse`. 110 | */ 111 | const ZyanArgParseDefinition* def; 112 | /** 113 | * Whether the argument has a value (is non-boolean). 114 | */ 115 | ZyanBool has_value; 116 | /** 117 | * If `has_value == true`, then the argument value. 118 | * 119 | * This is a view into the `argv` string array passed to `ZyanArgParse` via the `cfg` argument. 120 | */ 121 | ZyanStringView value; 122 | } ZyanArgParseArg; 123 | 124 | /* ============================================================================================== */ 125 | /* Exported functions */ 126 | /* ============================================================================================== */ 127 | 128 | #ifndef ZYAN_NO_LIBC 129 | 130 | /** 131 | * Parse arguments according to a `ZyanArgParseConfig` definition. 132 | * 133 | * @param cfg Argument parser config to use. 134 | * @param parsed Receives the parsed output. Vector of `ZyanArgParseArg`. Ownership is 135 | * transferred to the user. Input is expected to be uninitialized. On error, 136 | * the vector remains uninitialized. 137 | * @param error_token On error, if it makes sense, receives the argument fragment causing the 138 | * error. Optional, may be `ZYAN_NULL`. The pointer borrows into the `cfg` 139 | * struct and doesn't have to be freed by the user. 140 | * 141 | * @return A `ZyanStatus` status determining whether the parsing succeeded. 142 | */ 143 | ZYCORE_EXPORT ZyanStatus ZyanArgParse(const ZyanArgParseConfig *cfg, ZyanVector* parsed, 144 | const char** error_token); 145 | 146 | #endif 147 | 148 | /** 149 | * Parse arguments according to a `ZyanArgParseConfig` definition. 150 | * 151 | * This version allows specification of a custom memory allocator and thus supports no-libc. 152 | * 153 | * @param cfg Argument parser config to use. 154 | * @param parsed Receives the parsed output. Vector of `ZyanArgParseArg`. Ownership is 155 | * transferred to the user. Input is expected to be uninitialized. On error, 156 | * the vector remains uninitialized. 157 | * @param error_token On error, if it makes sense, receives the argument fragment causing the 158 | * error. Optional, may be `ZYAN_NULL`. The pointer borrows into the `cfg` 159 | * struct and doesn't have to be freed by the user. 160 | * @param allocator The `ZyanAllocator` to be used for allocating the output vector's data. 161 | * 162 | * @return A `ZyanStatus` status determining whether the parsing succeeded. 163 | */ 164 | ZYCORE_EXPORT ZyanStatus ZyanArgParseEx(const ZyanArgParseConfig *cfg, ZyanVector* parsed, 165 | const char** error_token, ZyanAllocator* allocator); 166 | 167 | /* ============================================================================================== */ 168 | 169 | #ifdef __cplusplus 170 | } 171 | #endif 172 | 173 | #endif /* ZYCORE_ARGPARSE_H */ 174 | -------------------------------------------------------------------------------- /lib/include/Zycore/Object.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Defines some generic object-related datatypes. 30 | */ 31 | 32 | #ifndef ZYCORE_OBJECT_H 33 | #define ZYCORE_OBJECT_H 34 | 35 | #include 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* ============================================================================================== */ 43 | /* Enums and types */ 44 | /* ============================================================================================== */ 45 | 46 | /** 47 | * Defines the `ZyanMemberProcedure` function prototype. 48 | * 49 | * @param object A pointer to the object. 50 | */ 51 | typedef void (*ZyanMemberProcedure)(void* object); 52 | 53 | /** 54 | * Defines the `ZyanConstMemberProcedure` function prototype. 55 | * 56 | * @param object A pointer to the object. 57 | */ 58 | typedef void (*ZyanConstMemberProcedure)(const void* object); 59 | 60 | /** 61 | * Defines the `ZyanMemberFunction` function prototype. 62 | * 63 | * @param object A pointer to the object. 64 | * 65 | * @return A zyan status code. 66 | */ 67 | typedef ZyanStatus (*ZyanMemberFunction)(void* object); 68 | 69 | /** 70 | * Defines the `ZyanConstMemberFunction` function prototype. 71 | * 72 | * @param object A pointer to the object. 73 | * 74 | * @return A zyan status code. 75 | */ 76 | typedef ZyanStatus (*ZyanConstMemberFunction)(const void* object); 77 | 78 | /* ============================================================================================== */ 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* ZYCORE_OBJECT_H */ 85 | -------------------------------------------------------------------------------- /lib/include/Zycore/Status.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zyan-C) 4 | 5 | Original Author : Florian Bernd, Joel Hoener 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Status code definitions and check macros. 30 | */ 31 | 32 | #ifndef ZYCORE_STATUS_H 33 | #define ZYCORE_STATUS_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include 40 | 41 | /* ============================================================================================== */ 42 | /* Enums and types */ 43 | /* ============================================================================================== */ 44 | 45 | /** 46 | * Defines the `ZyanStatus` data type. 47 | */ 48 | typedef ZyanU32 ZyanStatus; 49 | 50 | /* ============================================================================================== */ 51 | /* Macros */ 52 | /* ============================================================================================== */ 53 | 54 | /* ---------------------------------------------------------------------------------------------- */ 55 | /* Definition */ 56 | /* ---------------------------------------------------------------------------------------------- */ 57 | 58 | /** 59 | * Defines a zyan status code. 60 | * 61 | * @param error `1`, if the status code signals an error or `0`, if not. 62 | * @param module The module id. 63 | * @param code The actual code. 64 | * 65 | * @return The zyan status code. 66 | */ 67 | #define ZYAN_MAKE_STATUS(error, module, code) \ 68 | (ZyanStatus)((((error) & 0x01u) << 31u) | (((module) & 0x7FFu) << 20u) | ((code) & 0xFFFFFu)) 69 | 70 | /* ---------------------------------------------------------------------------------------------- */ 71 | /* Checks */ 72 | /* ---------------------------------------------------------------------------------------------- */ 73 | 74 | /** 75 | * Checks if a zyan operation was successful. 76 | * 77 | * @param status The zyan status-code to check. 78 | * 79 | * @return `ZYAN_TRUE`, if the operation succeeded or `ZYAN_FALSE`, if not. 80 | */ 81 | #define ZYAN_SUCCESS(status) \ 82 | (!((status) & 0x80000000u)) 83 | 84 | /** 85 | * Checks if a zyan operation failed. 86 | * 87 | * @param status The zyan status-code to check. 88 | * 89 | * @return `ZYAN_TRUE`, if the operation failed or `ZYAN_FALSE`, if not. 90 | */ 91 | #define ZYAN_FAILED(status) \ 92 | ((status) & 0x80000000u) 93 | 94 | /** 95 | * Checks if a zyan operation was successful and returns with the status-code, if not. 96 | * 97 | * @param status The zyan status-code to check. 98 | */ 99 | #define ZYAN_CHECK(status) \ 100 | do \ 101 | { \ 102 | const ZyanStatus status_047620348 = (status); \ 103 | if (!ZYAN_SUCCESS(status_047620348)) \ 104 | { \ 105 | return status_047620348; \ 106 | } \ 107 | } while (0) 108 | 109 | /* ---------------------------------------------------------------------------------------------- */ 110 | /* Information */ 111 | /* ---------------------------------------------------------------------------------------------- */ 112 | 113 | /** 114 | * Returns the module id of a zyan status-code. 115 | * 116 | * @param status The zyan status-code. 117 | * 118 | * @return The module id of the zyan status-code. 119 | */ 120 | #define ZYAN_STATUS_MODULE(status) \ 121 | (((status) >> 20) & 0x7FFu) 122 | 123 | /** 124 | * Returns the code of a zyan status-code. 125 | * 126 | * @param status The zyan status-code. 127 | * 128 | * @return The code of the zyan status-code. 129 | */ 130 | #define ZYAN_STATUS_CODE(status) \ 131 | ((status) & 0xFFFFFu) 132 | 133 | /* ============================================================================================== */ 134 | /* Status codes */ 135 | /* ============================================================================================== */ 136 | 137 | /* ---------------------------------------------------------------------------------------------- */ 138 | /* Module IDs */ 139 | /* ---------------------------------------------------------------------------------------------- */ 140 | 141 | /** 142 | * The zycore generic module id. 143 | */ 144 | #define ZYAN_MODULE_ZYCORE 0x001u 145 | 146 | /** 147 | * The zycore arg-parse submodule id. 148 | */ 149 | #define ZYAN_MODULE_ARGPARSE 0x003u 150 | 151 | /** 152 | * The base module id for user-defined status codes. 153 | */ 154 | #define ZYAN_MODULE_USER 0x3FFu 155 | 156 | /* ---------------------------------------------------------------------------------------------- */ 157 | /* Status codes (general purpose) */ 158 | /* ---------------------------------------------------------------------------------------------- */ 159 | 160 | /** 161 | * The operation completed successfully. 162 | */ 163 | #define ZYAN_STATUS_SUCCESS \ 164 | ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x00u) 165 | 166 | /** 167 | * The operation failed with an generic error. 168 | */ 169 | #define ZYAN_STATUS_FAILED \ 170 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x01u) 171 | 172 | /** 173 | * The operation completed successfully and returned `ZYAN_TRUE`. 174 | */ 175 | #define ZYAN_STATUS_TRUE \ 176 | ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x02u) 177 | 178 | /** 179 | * The operation completed successfully and returned `ZYAN_FALSE`. 180 | */ 181 | #define ZYAN_STATUS_FALSE \ 182 | ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYCORE, 0x03u) 183 | 184 | /** 185 | * An invalid argument was passed to a function. 186 | */ 187 | #define ZYAN_STATUS_INVALID_ARGUMENT \ 188 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x04u) 189 | 190 | /** 191 | * An attempt was made to perform an invalid operation. 192 | */ 193 | #define ZYAN_STATUS_INVALID_OPERATION \ 194 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x05u) 195 | 196 | /** 197 | * Insufficient privileges to perform the requested operation. 198 | */ 199 | #define ZYAN_STATUS_ACCESS_DENIED \ 200 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x06u) 201 | 202 | /** 203 | * The requested entity was not found. 204 | */ 205 | #define ZYAN_STATUS_NOT_FOUND \ 206 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x07u) 207 | 208 | /** 209 | * An index passed to a function was out of bounds. 210 | */ 211 | #define ZYAN_STATUS_OUT_OF_RANGE \ 212 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x08u) 213 | 214 | /** 215 | * A buffer passed to a function was too small to complete the requested operation. 216 | */ 217 | #define ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE \ 218 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x09u) 219 | 220 | /** 221 | * Insufficient memory to perform the operation. 222 | */ 223 | #define ZYAN_STATUS_NOT_ENOUGH_MEMORY \ 224 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Au) 225 | 226 | /** 227 | * An unknown error occurred during a system function call. 228 | */ 229 | #define ZYAN_STATUS_BAD_SYSTEMCALL \ 230 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Bu) 231 | 232 | /** 233 | * The process ran out of resources while performing an operation. 234 | */ 235 | #define ZYAN_STATUS_OUT_OF_RESOURCES \ 236 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Cu) 237 | 238 | /** 239 | * A dependency library was not found or does have an unexpected version number or 240 | * feature-set. 241 | */ 242 | #define ZYAN_STATUS_MISSING_DEPENDENCY \ 243 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYCORE, 0x0Du) 244 | 245 | /* ---------------------------------------------------------------------------------------------- */ 246 | /* Status codes (arg parse) */ 247 | /* ---------------------------------------------------------------------------------------------- */ 248 | 249 | /** 250 | * Argument was not expected. 251 | */ 252 | #define ZYAN_STATUS_ARG_NOT_UNDERSTOOD \ 253 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x00u) 254 | 255 | /** 256 | * Too few arguments were provided. 257 | */ 258 | #define ZYAN_STATUS_TOO_FEW_ARGS \ 259 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x01u) 260 | 261 | /** 262 | * Too many arguments were provided. 263 | */ 264 | #define ZYAN_STATUS_TOO_MANY_ARGS \ 265 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x02u) 266 | 267 | /** 268 | * An argument that expected a value misses its value. 269 | */ 270 | #define ZYAN_STATUS_ARG_MISSES_VALUE \ 271 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x03u) 272 | 273 | /** 274 | * A required argument is missing. 275 | */ 276 | #define ZYAN_STATUS_REQUIRED_ARG_MISSING \ 277 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ARGPARSE, 0x04u) 278 | 279 | /* ---------------------------------------------------------------------------------------------- */ 280 | 281 | /* ============================================================================================== */ 282 | 283 | #ifdef __cplusplus 284 | } 285 | #endif 286 | 287 | #endif /* ZYCORE_STATUS_H */ 288 | -------------------------------------------------------------------------------- /lib/include/Zycore/Types.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zyan-C) 4 | 5 | Original Author : Florian Bernd, Joel Hoener 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Includes and defines some default data types. 30 | */ 31 | 32 | #ifndef ZYCORE_TYPES_H 33 | #define ZYCORE_TYPES_H 34 | 35 | #include 36 | 37 | /* ============================================================================================== */ 38 | /* Integer types */ 39 | /* ============================================================================================== */ 40 | 41 | #if defined(ZYAN_NO_LIBC) || \ 42 | (defined(ZYAN_MSVC) && defined(ZYAN_KERNEL)) // The WDK LibC lacks stdint.h. 43 | // No LibC mode, use compiler built-in types / macros. 44 | # if defined(ZYAN_MSVC) || defined(ZYAN_ICC) 45 | typedef unsigned __int8 ZyanU8; 46 | typedef unsigned __int16 ZyanU16; 47 | typedef unsigned __int32 ZyanU32; 48 | typedef unsigned __int64 ZyanU64; 49 | typedef signed __int8 ZyanI8; 50 | typedef signed __int16 ZyanI16; 51 | typedef signed __int32 ZyanI32; 52 | typedef signed __int64 ZyanI64; 53 | # if _WIN64 54 | typedef ZyanU64 ZyanUSize; 55 | typedef ZyanI64 ZyanISize; 56 | typedef ZyanU64 ZyanUPointer; 57 | typedef ZyanI64 ZyanIPointer; 58 | # else 59 | typedef ZyanU32 ZyanUSize; 60 | typedef ZyanI32 ZyanISize; 61 | typedef ZyanU32 ZyanUPointer; 62 | typedef ZyanI32 ZyanIPointer; 63 | # endif 64 | # elif defined(ZYAN_GNUC) 65 | typedef __UINT8_TYPE__ ZyanU8; 66 | typedef __UINT16_TYPE__ ZyanU16; 67 | typedef __UINT32_TYPE__ ZyanU32; 68 | typedef __UINT64_TYPE__ ZyanU64; 69 | typedef __INT8_TYPE__ ZyanI8; 70 | typedef __INT16_TYPE__ ZyanI16; 71 | typedef __INT32_TYPE__ ZyanI32; 72 | typedef __INT64_TYPE__ ZyanI64; 73 | typedef __SIZE_TYPE__ ZyanUSize; 74 | typedef __PTRDIFF_TYPE__ ZyanISize; 75 | typedef __UINTPTR_TYPE__ ZyanUPointer; 76 | typedef __INTPTR_TYPE__ ZyanIPointer; 77 | # else 78 | # error "Unsupported compiler for no-libc mode." 79 | # endif 80 | #else 81 | // If is LibC present, we use stdint types. 82 | # include 83 | # include 84 | typedef uint8_t ZyanU8; 85 | typedef uint16_t ZyanU16; 86 | typedef uint32_t ZyanU32; 87 | typedef uint64_t ZyanU64; 88 | typedef int8_t ZyanI8; 89 | typedef int16_t ZyanI16; 90 | typedef int32_t ZyanI32; 91 | typedef int64_t ZyanI64; 92 | typedef size_t ZyanUSize; 93 | typedef ptrdiff_t ZyanISize; 94 | typedef uintptr_t ZyanUPointer; 95 | typedef intptr_t ZyanIPointer; 96 | #endif 97 | 98 | // Verify size assumptions. 99 | ZYAN_STATIC_ASSERT(sizeof(ZyanU8 ) == 1 ); 100 | ZYAN_STATIC_ASSERT(sizeof(ZyanU16 ) == 2 ); 101 | ZYAN_STATIC_ASSERT(sizeof(ZyanU32 ) == 4 ); 102 | ZYAN_STATIC_ASSERT(sizeof(ZyanU64 ) == 8 ); 103 | ZYAN_STATIC_ASSERT(sizeof(ZyanI8 ) == 1 ); 104 | ZYAN_STATIC_ASSERT(sizeof(ZyanI16 ) == 2 ); 105 | ZYAN_STATIC_ASSERT(sizeof(ZyanI32 ) == 4 ); 106 | ZYAN_STATIC_ASSERT(sizeof(ZyanI64 ) == 8 ); 107 | ZYAN_STATIC_ASSERT(sizeof(ZyanUSize ) == sizeof(void*)); // TODO: This one is incorrect! 108 | ZYAN_STATIC_ASSERT(sizeof(ZyanISize ) == sizeof(void*)); // TODO: This one is incorrect! 109 | ZYAN_STATIC_ASSERT(sizeof(ZyanUPointer) == sizeof(void*)); 110 | ZYAN_STATIC_ASSERT(sizeof(ZyanIPointer) == sizeof(void*)); 111 | 112 | // Verify signedness assumptions (relies on size checks above). 113 | ZYAN_STATIC_ASSERT((ZyanI8 )-1 >> 1 < (ZyanI8 )((ZyanU8 )-1 >> 1)); 114 | ZYAN_STATIC_ASSERT((ZyanI16)-1 >> 1 < (ZyanI16)((ZyanU16)-1 >> 1)); 115 | ZYAN_STATIC_ASSERT((ZyanI32)-1 >> 1 < (ZyanI32)((ZyanU32)-1 >> 1)); 116 | ZYAN_STATIC_ASSERT((ZyanI64)-1 >> 1 < (ZyanI64)((ZyanU64)-1 >> 1)); 117 | 118 | /* ============================================================================================== */ 119 | /* Pointer */ 120 | /* ============================================================================================== */ 121 | 122 | /** 123 | * Defines the `ZyanVoidPointer` data-type. 124 | */ 125 | typedef char* ZyanVoidPointer; 126 | 127 | /** 128 | * Defines the `ZyanConstVoidPointer` data-type. 129 | */ 130 | typedef const void* ZyanConstVoidPointer; 131 | 132 | #define ZYAN_NULL ((void*)0) 133 | 134 | /* ============================================================================================== */ 135 | /* Logic types */ 136 | /* ============================================================================================== */ 137 | 138 | /* ---------------------------------------------------------------------------------------------- */ 139 | /* Boolean */ 140 | /* ---------------------------------------------------------------------------------------------- */ 141 | 142 | #define ZYAN_FALSE 0 143 | #define ZYAN_TRUE 1 144 | 145 | /** 146 | * Defines the `ZyanBool` data-type. 147 | * 148 | * Represents a default boolean data-type where `0` is interpreted as `false` and all other values 149 | * as `true`. 150 | */ 151 | typedef ZyanU8 ZyanBool; 152 | 153 | /* ---------------------------------------------------------------------------------------------- */ 154 | /* Ternary */ 155 | /* ---------------------------------------------------------------------------------------------- */ 156 | 157 | /** 158 | * Defines the `ZyanTernary` data-type. 159 | * 160 | * The `ZyanTernary` is a balanced ternary type that uses three truth values indicating `true`, 161 | * `false` and an indeterminate third value. 162 | */ 163 | typedef ZyanI8 ZyanTernary; 164 | 165 | #define ZYAN_TERNARY_FALSE (-1) 166 | #define ZYAN_TERNARY_UNKNOWN 0x00 167 | #define ZYAN_TERNARY_TRUE 0x01 168 | 169 | /* ============================================================================================== */ 170 | /* String types */ 171 | /* ============================================================================================== */ 172 | 173 | /* ---------------------------------------------------------------------------------------------- */ 174 | /* C-style strings */ 175 | /* ---------------------------------------------------------------------------------------------- */ 176 | 177 | /** 178 | * Defines the `ZyanCharPointer` data-type. 179 | * 180 | * This type is most often used to represent null-terminated strings aka. C-style strings. 181 | */ 182 | typedef char* ZyanCharPointer; 183 | 184 | /** 185 | * Defines the `ZyanConstCharPointer` data-type. 186 | * 187 | * This type is most often used to represent null-terminated strings aka. C-style strings. 188 | */ 189 | typedef const char* ZyanConstCharPointer; 190 | 191 | /* ---------------------------------------------------------------------------------------------- */ 192 | 193 | /* ============================================================================================== */ 194 | 195 | #endif /* ZYCORE_TYPES_H */ 196 | -------------------------------------------------------------------------------- /lib/include/Zycore/Zycore.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Core Library (Zycore-C) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Master include file, including everything else. 30 | */ 31 | 32 | #ifndef ZYCORE_H 33 | #define ZYCORE_H 34 | 35 | #include 36 | #include 37 | 38 | // TODO: 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* ============================================================================================== */ 45 | /* Macros */ 46 | /* ============================================================================================== */ 47 | 48 | /* ---------------------------------------------------------------------------------------------- */ 49 | /* Constants */ 50 | /* ---------------------------------------------------------------------------------------------- */ 51 | 52 | /** 53 | * A macro that defines the zycore version. 54 | */ 55 | #define ZYCORE_VERSION (ZyanU64)0x0001000000000000 56 | 57 | /* ---------------------------------------------------------------------------------------------- */ 58 | /* Helper macros */ 59 | /* ---------------------------------------------------------------------------------------------- */ 60 | 61 | /** 62 | * Extracts the major-part of the zycore version. 63 | * 64 | * @param version The zycore version value 65 | */ 66 | #define ZYCORE_VERSION_MAJOR(version) (ZyanU16)((version & 0xFFFF000000000000) >> 48) 67 | 68 | /** 69 | * Extracts the minor-part of the zycore version. 70 | * 71 | * @param version The zycore version value 72 | */ 73 | #define ZYCORE_VERSION_MINOR(version) (ZyanU16)((version & 0x0000FFFF00000000) >> 32) 74 | 75 | /** 76 | * Extracts the patch-part of the zycore version. 77 | * 78 | * @param version The zycore version value 79 | */ 80 | #define ZYCORE_VERSION_PATCH(version) (ZyanU16)((version & 0x00000000FFFF0000) >> 16) 81 | 82 | /** 83 | * Extracts the build-part of the zycore version. 84 | * 85 | * @param version The zycore version value 86 | */ 87 | #define ZYCORE_VERSION_BUILD(version) (ZyanU16)(version & 0x000000000000FFFF) 88 | 89 | /* ---------------------------------------------------------------------------------------------- */ 90 | 91 | /* ============================================================================================== */ 92 | /* Exported functions */ 93 | /* ============================================================================================== */ 94 | 95 | /** 96 | * Returns the zycore version. 97 | * 98 | * @return The zycore version. 99 | * 100 | * Use the macros provided in this file to extract the major, minor, patch and build part from the 101 | * returned version value. 102 | */ 103 | ZYCORE_EXPORT ZyanU64 ZycoreGetVersion(void); 104 | 105 | /* ============================================================================================== */ 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* ZYCORE_H */ 112 | -------------------------------------------------------------------------------- /lib/include/ZycoreExportConfig.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ZYCORE_EXPORT_H 3 | #define ZYCORE_EXPORT_H 4 | 5 | #ifdef ZYCORE_STATIC_DEFINE 6 | # define ZYCORE_EXPORT 7 | # define ZYCORE_NO_EXPORT 8 | #else 9 | # ifndef ZYCORE_EXPORT 10 | # ifdef Zycore_EXPORTS 11 | /* We are building this library */ 12 | # define ZYCORE_EXPORT 13 | # else 14 | /* We are using this library */ 15 | # define ZYCORE_EXPORT 16 | # endif 17 | # endif 18 | 19 | # ifndef ZYCORE_NO_EXPORT 20 | # define ZYCORE_NO_EXPORT 21 | # endif 22 | #endif 23 | 24 | #ifndef ZYCORE_DEPRECATED 25 | # define ZYCORE_DEPRECATED __attribute__ ((__deprecated__)) 26 | #endif 27 | 28 | #ifndef ZYCORE_DEPRECATED_EXPORT 29 | # define ZYCORE_DEPRECATED_EXPORT ZYCORE_EXPORT ZYCORE_DEPRECATED 30 | #endif 31 | 32 | #ifndef ZYCORE_DEPRECATED_NO_EXPORT 33 | # define ZYCORE_DEPRECATED_NO_EXPORT ZYCORE_NO_EXPORT ZYCORE_DEPRECATED 34 | #endif 35 | 36 | #if 0 /* DEFINE_NO_DEPRECATED */ 37 | # ifndef ZYCORE_NO_DEPRECATED 38 | # define ZYCORE_NO_DEPRECATED 39 | # endif 40 | #endif 41 | 42 | #endif /* ZYCORE_EXPORT_H */ 43 | -------------------------------------------------------------------------------- /lib/include/Zydis/Decoder.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Functions for decoding instructions. 30 | */ 31 | 32 | #ifndef ZYDIS_DECODER_H 33 | #define ZYDIS_DECODER_H 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* ============================================================================================== */ 45 | /* Enums and types */ 46 | /* ============================================================================================== */ 47 | 48 | /* ---------------------------------------------------------------------------------------------- */ 49 | /* Decoder mode */ 50 | /* ---------------------------------------------------------------------------------------------- */ 51 | 52 | /** 53 | * Defines the `ZydisDecoderMode` enum. 54 | */ 55 | typedef enum ZydisDecoderMode_ 56 | { 57 | /** 58 | * Enables minimal instruction decoding without semantic analysis. 59 | * 60 | * This mode provides access to the mnemonic, the instruction-length, the effective 61 | * operand-size, the effective address-width, some attributes (e.g. `ZYDIS_ATTRIB_IS_RELATIVE`) 62 | * and all of the information in the `raw` field of the `ZydisDecodedInstruction` struct. 63 | * 64 | * Operands, most attributes and other specific information (like `AVX` info) are not 65 | * accessible in this mode. 66 | * 67 | * This mode is NOT enabled by default. 68 | */ 69 | ZYDIS_DECODER_MODE_MINIMAL, 70 | /** 71 | * Enables the `AMD`-branch mode. 72 | * 73 | * Intel ignores the operand-size override-prefix (`0x66`) for all branches with 32-bit 74 | * immediates and forces the operand-size of the instruction to 64-bit in 64-bit mode. 75 | * In `AMD`-branch mode `0x66` is not ignored and changes the operand-size and the size of the 76 | * immediate to 16-bit. 77 | * 78 | * This mode is NOT enabled by default. 79 | */ 80 | ZYDIS_DECODER_MODE_AMD_BRANCHES, 81 | /** 82 | * Enables `KNC` compatibility-mode. 83 | * 84 | * `KNC` and `KNL+` chips are sharing opcodes and encodings for some mask-related instructions. 85 | * Enable this mode to use the old `KNC` specifications (different mnemonics, operands, ..). 86 | * 87 | * This mode is NOT enabled by default. 88 | */ 89 | ZYDIS_DECODER_MODE_KNC, 90 | /** 91 | * Enables the `MPX` mode. 92 | * 93 | * The `MPX` isa-extension reuses (overrides) some of the widenop instruction opcodes. 94 | * 95 | * This mode is enabled by default. 96 | */ 97 | ZYDIS_DECODER_MODE_MPX, 98 | /** 99 | * Enables the `CET` mode. 100 | * 101 | * The `CET` isa-extension reuses (overrides) some of the widenop instruction opcodes. 102 | * 103 | * This mode is enabled by default. 104 | */ 105 | ZYDIS_DECODER_MODE_CET, 106 | /** 107 | * Enables the `LZCNT` mode. 108 | * 109 | * The `LZCNT` isa-extension reuses (overrides) some of the widenop instruction opcodes. 110 | * 111 | * This mode is enabled by default. 112 | */ 113 | ZYDIS_DECODER_MODE_LZCNT, 114 | /** 115 | * Enables the `TZCNT` mode. 116 | * 117 | * The `TZCNT` isa-extension reuses (overrides) some of the widenop instruction opcodes. 118 | * 119 | * This mode is enabled by default. 120 | */ 121 | ZYDIS_DECODER_MODE_TZCNT, 122 | /** 123 | * Enables the `WBNOINVD` mode. 124 | * 125 | * The `WBINVD` instruction is interpreted as `WBNOINVD` on ICL chips, if a `F3` prefix is 126 | * used. 127 | * 128 | * This mode is disabled by default. 129 | */ 130 | ZYDIS_DECODER_MODE_WBNOINVD, 131 | /** 132 | * Enables the `CLDEMOTE` mode. 133 | * 134 | * The `CLDEMOTE` isa-extension reuses (overrides) some of the widenop instruction opcodes. 135 | * 136 | * This mode is enabled by default. 137 | */ 138 | ZYDIS_DECODER_MODE_CLDEMOTE, 139 | 140 | /** 141 | * Maximum value of this enum. 142 | */ 143 | ZYDIS_DECODER_MODE_MAX_VALUE = ZYDIS_DECODER_MODE_CLDEMOTE, 144 | /** 145 | * The minimum number of bits required to represent all values of this enum. 146 | */ 147 | ZYDIS_DECODER_MODE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_DECODER_MODE_MAX_VALUE) 148 | } ZydisDecoderMode; 149 | 150 | /* ---------------------------------------------------------------------------------------------- */ 151 | /* Decoder struct */ 152 | /* ---------------------------------------------------------------------------------------------- */ 153 | 154 | /** 155 | * Defines the `ZydisDecoder` struct. 156 | * 157 | * All fields in this struct should be considered as "private". Any changes may lead to unexpected 158 | * behavior. 159 | */ 160 | typedef struct ZydisDecoder_ 161 | { 162 | /** 163 | * The machine mode. 164 | */ 165 | ZydisMachineMode machine_mode; 166 | /** 167 | * The address width. 168 | */ 169 | ZydisAddressWidth address_width; 170 | /** 171 | * The decoder mode array. 172 | */ 173 | ZyanBool decoder_mode[ZYDIS_DECODER_MODE_MAX_VALUE + 1]; 174 | } ZydisDecoder; 175 | 176 | /* ---------------------------------------------------------------------------------------------- */ 177 | 178 | /* ============================================================================================== */ 179 | /* Exported functions */ 180 | /* ============================================================================================== */ 181 | 182 | /** 183 | * @addtogroup decoder Decoder 184 | * Functions allowing decoding of instruction bytes to a machine interpretable struct. 185 | * @{ 186 | */ 187 | 188 | /** 189 | * Initializes the given `ZydisDecoder` instance. 190 | * 191 | * @param decoder A pointer to the `ZydisDecoder` instance. 192 | * @param machine_mode The machine mode. 193 | * @param address_width The address width. 194 | * 195 | * @return A zyan status code. 196 | */ 197 | ZYDIS_EXPORT ZyanStatus ZydisDecoderInit(ZydisDecoder* decoder, ZydisMachineMode machine_mode, 198 | ZydisAddressWidth address_width); 199 | 200 | /** 201 | * Enables or disables the specified decoder-mode. 202 | * 203 | * @param decoder A pointer to the `ZydisDecoder` instance. 204 | * @param mode The decoder mode. 205 | * @param enabled `ZYAN_TRUE` to enable, or `ZYAN_FALSE` to disable the specified decoder-mode. 206 | * 207 | * @return A zyan status code. 208 | */ 209 | ZYDIS_EXPORT ZyanStatus ZydisDecoderEnableMode(ZydisDecoder* decoder, ZydisDecoderMode mode, 210 | ZyanBool enabled); 211 | 212 | /** 213 | * Decodes the instruction in the given input `buffer`. 214 | * 215 | * @param decoder A pointer to the `ZydisDecoder` instance. 216 | * @param buffer A pointer to the input buffer. 217 | * @param length The length of the input buffer. Note that this can be bigger than the 218 | * actual size of the instruction -- you don't have to know the size up 219 | * front. This length is merely used to prevent Zydis from doing 220 | * out-of-bounds reads on your buffer. 221 | * @param instruction A pointer to the `ZydisDecodedInstruction` struct, that receives the 222 | * details about the decoded instruction. 223 | * 224 | * @return A zyan status code. 225 | */ 226 | ZYDIS_EXPORT ZyanStatus ZydisDecoderDecodeBuffer(const ZydisDecoder* decoder, 227 | const void* buffer, ZyanUSize length, ZydisDecodedInstruction* instruction); 228 | 229 | /** @} */ 230 | 231 | /* ============================================================================================== */ 232 | 233 | #ifdef __cplusplus 234 | } 235 | #endif 236 | 237 | #endif /* ZYDIS_DECODER_H */ 238 | -------------------------------------------------------------------------------- /lib/include/Zydis/Generated/EnumISAExt.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Defines the `ZydisISAExt` enum. 3 | */ 4 | typedef enum ZydisISAExt_ 5 | { 6 | ZYDIS_ISA_EXT_INVALID, 7 | ZYDIS_ISA_EXT_ADOX_ADCX, 8 | ZYDIS_ISA_EXT_AES, 9 | ZYDIS_ISA_EXT_AMD3DNOW, 10 | ZYDIS_ISA_EXT_AMD3DNOW_PREFETCH, 11 | ZYDIS_ISA_EXT_AMD_INVLPGB, 12 | ZYDIS_ISA_EXT_AMX_BF16, 13 | ZYDIS_ISA_EXT_AMX_INT8, 14 | ZYDIS_ISA_EXT_AMX_TILE, 15 | ZYDIS_ISA_EXT_AVX, 16 | ZYDIS_ISA_EXT_AVX2, 17 | ZYDIS_ISA_EXT_AVX2GATHER, 18 | ZYDIS_ISA_EXT_AVX512EVEX, 19 | ZYDIS_ISA_EXT_AVX512VEX, 20 | ZYDIS_ISA_EXT_AVXAES, 21 | ZYDIS_ISA_EXT_BASE, 22 | ZYDIS_ISA_EXT_BMI1, 23 | ZYDIS_ISA_EXT_BMI2, 24 | ZYDIS_ISA_EXT_CET, 25 | ZYDIS_ISA_EXT_CLDEMOTE, 26 | ZYDIS_ISA_EXT_CLFLUSHOPT, 27 | ZYDIS_ISA_EXT_CLFSH, 28 | ZYDIS_ISA_EXT_CLWB, 29 | ZYDIS_ISA_EXT_CLZERO, 30 | ZYDIS_ISA_EXT_ENQCMD, 31 | ZYDIS_ISA_EXT_F16C, 32 | ZYDIS_ISA_EXT_FMA, 33 | ZYDIS_ISA_EXT_FMA4, 34 | ZYDIS_ISA_EXT_GFNI, 35 | ZYDIS_ISA_EXT_INVPCID, 36 | ZYDIS_ISA_EXT_KNC, 37 | ZYDIS_ISA_EXT_KNCE, 38 | ZYDIS_ISA_EXT_KNCV, 39 | ZYDIS_ISA_EXT_LONGMODE, 40 | ZYDIS_ISA_EXT_LZCNT, 41 | ZYDIS_ISA_EXT_MCOMMIT, 42 | ZYDIS_ISA_EXT_MMX, 43 | ZYDIS_ISA_EXT_MONITOR, 44 | ZYDIS_ISA_EXT_MONITORX, 45 | ZYDIS_ISA_EXT_MOVBE, 46 | ZYDIS_ISA_EXT_MOVDIR, 47 | ZYDIS_ISA_EXT_MPX, 48 | ZYDIS_ISA_EXT_PADLOCK, 49 | ZYDIS_ISA_EXT_PAUSE, 50 | ZYDIS_ISA_EXT_PCLMULQDQ, 51 | ZYDIS_ISA_EXT_PCONFIG, 52 | ZYDIS_ISA_EXT_PKU, 53 | ZYDIS_ISA_EXT_PREFETCHWT1, 54 | ZYDIS_ISA_EXT_PT, 55 | ZYDIS_ISA_EXT_RDPID, 56 | ZYDIS_ISA_EXT_RDPRU, 57 | ZYDIS_ISA_EXT_RDRAND, 58 | ZYDIS_ISA_EXT_RDSEED, 59 | ZYDIS_ISA_EXT_RDTSCP, 60 | ZYDIS_ISA_EXT_RDWRFSGS, 61 | ZYDIS_ISA_EXT_RTM, 62 | ZYDIS_ISA_EXT_SERIALIZE, 63 | ZYDIS_ISA_EXT_SGX, 64 | ZYDIS_ISA_EXT_SGX_ENCLV, 65 | ZYDIS_ISA_EXT_SHA, 66 | ZYDIS_ISA_EXT_SMAP, 67 | ZYDIS_ISA_EXT_SMX, 68 | ZYDIS_ISA_EXT_SNP, 69 | ZYDIS_ISA_EXT_SSE, 70 | ZYDIS_ISA_EXT_SSE2, 71 | ZYDIS_ISA_EXT_SSE3, 72 | ZYDIS_ISA_EXT_SSE4, 73 | ZYDIS_ISA_EXT_SSE4A, 74 | ZYDIS_ISA_EXT_SSSE3, 75 | ZYDIS_ISA_EXT_SVM, 76 | ZYDIS_ISA_EXT_TBM, 77 | ZYDIS_ISA_EXT_TSX_LDTRK, 78 | ZYDIS_ISA_EXT_VAES, 79 | ZYDIS_ISA_EXT_VMFUNC, 80 | ZYDIS_ISA_EXT_VPCLMULQDQ, 81 | ZYDIS_ISA_EXT_VTX, 82 | ZYDIS_ISA_EXT_WAITPKG, 83 | ZYDIS_ISA_EXT_X87, 84 | ZYDIS_ISA_EXT_XOP, 85 | ZYDIS_ISA_EXT_XSAVE, 86 | ZYDIS_ISA_EXT_XSAVEC, 87 | ZYDIS_ISA_EXT_XSAVEOPT, 88 | ZYDIS_ISA_EXT_XSAVES, 89 | 90 | /** 91 | * Maximum value of this enum. 92 | */ 93 | ZYDIS_ISA_EXT_MAX_VALUE = ZYDIS_ISA_EXT_XSAVES, 94 | /** 95 | * The minimum number of bits required to represent all values of this enum. 96 | */ 97 | ZYDIS_ISA_EXT_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ISA_EXT_MAX_VALUE) 98 | } ZydisISAExt; 99 | -------------------------------------------------------------------------------- /lib/include/Zydis/Generated/EnumISASet.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Defines the `ZydisISASet` enum. 3 | */ 4 | typedef enum ZydisISASet_ 5 | { 6 | ZYDIS_ISA_SET_INVALID, 7 | ZYDIS_ISA_SET_ADOX_ADCX, 8 | ZYDIS_ISA_SET_AES, 9 | ZYDIS_ISA_SET_AMD, 10 | ZYDIS_ISA_SET_AMD3DNOW, 11 | ZYDIS_ISA_SET_AMX_BF16, 12 | ZYDIS_ISA_SET_AMX_INT8, 13 | ZYDIS_ISA_SET_AMX_TILE, 14 | ZYDIS_ISA_SET_AVX, 15 | ZYDIS_ISA_SET_AVX2, 16 | ZYDIS_ISA_SET_AVX2GATHER, 17 | ZYDIS_ISA_SET_AVX512BW_128, 18 | ZYDIS_ISA_SET_AVX512BW_128N, 19 | ZYDIS_ISA_SET_AVX512BW_256, 20 | ZYDIS_ISA_SET_AVX512BW_512, 21 | ZYDIS_ISA_SET_AVX512BW_KOP, 22 | ZYDIS_ISA_SET_AVX512CD_128, 23 | ZYDIS_ISA_SET_AVX512CD_256, 24 | ZYDIS_ISA_SET_AVX512CD_512, 25 | ZYDIS_ISA_SET_AVX512DQ_128, 26 | ZYDIS_ISA_SET_AVX512DQ_128N, 27 | ZYDIS_ISA_SET_AVX512DQ_256, 28 | ZYDIS_ISA_SET_AVX512DQ_512, 29 | ZYDIS_ISA_SET_AVX512DQ_KOP, 30 | ZYDIS_ISA_SET_AVX512DQ_SCALAR, 31 | ZYDIS_ISA_SET_AVX512ER_512, 32 | ZYDIS_ISA_SET_AVX512ER_SCALAR, 33 | ZYDIS_ISA_SET_AVX512F_128, 34 | ZYDIS_ISA_SET_AVX512F_128N, 35 | ZYDIS_ISA_SET_AVX512F_256, 36 | ZYDIS_ISA_SET_AVX512F_512, 37 | ZYDIS_ISA_SET_AVX512F_KOP, 38 | ZYDIS_ISA_SET_AVX512F_SCALAR, 39 | ZYDIS_ISA_SET_AVX512PF_512, 40 | ZYDIS_ISA_SET_AVX512_4FMAPS_512, 41 | ZYDIS_ISA_SET_AVX512_4FMAPS_SCALAR, 42 | ZYDIS_ISA_SET_AVX512_4VNNIW_512, 43 | ZYDIS_ISA_SET_AVX512_BF16_128, 44 | ZYDIS_ISA_SET_AVX512_BF16_256, 45 | ZYDIS_ISA_SET_AVX512_BF16_512, 46 | ZYDIS_ISA_SET_AVX512_BITALG_128, 47 | ZYDIS_ISA_SET_AVX512_BITALG_256, 48 | ZYDIS_ISA_SET_AVX512_BITALG_512, 49 | ZYDIS_ISA_SET_AVX512_GFNI_128, 50 | ZYDIS_ISA_SET_AVX512_GFNI_256, 51 | ZYDIS_ISA_SET_AVX512_GFNI_512, 52 | ZYDIS_ISA_SET_AVX512_IFMA_128, 53 | ZYDIS_ISA_SET_AVX512_IFMA_256, 54 | ZYDIS_ISA_SET_AVX512_IFMA_512, 55 | ZYDIS_ISA_SET_AVX512_VAES_128, 56 | ZYDIS_ISA_SET_AVX512_VAES_256, 57 | ZYDIS_ISA_SET_AVX512_VAES_512, 58 | ZYDIS_ISA_SET_AVX512_VBMI2_128, 59 | ZYDIS_ISA_SET_AVX512_VBMI2_256, 60 | ZYDIS_ISA_SET_AVX512_VBMI2_512, 61 | ZYDIS_ISA_SET_AVX512_VBMI_128, 62 | ZYDIS_ISA_SET_AVX512_VBMI_256, 63 | ZYDIS_ISA_SET_AVX512_VBMI_512, 64 | ZYDIS_ISA_SET_AVX512_VNNI_128, 65 | ZYDIS_ISA_SET_AVX512_VNNI_256, 66 | ZYDIS_ISA_SET_AVX512_VNNI_512, 67 | ZYDIS_ISA_SET_AVX512_VP2INTERSECT_128, 68 | ZYDIS_ISA_SET_AVX512_VP2INTERSECT_256, 69 | ZYDIS_ISA_SET_AVX512_VP2INTERSECT_512, 70 | ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_128, 71 | ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_256, 72 | ZYDIS_ISA_SET_AVX512_VPCLMULQDQ_512, 73 | ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_128, 74 | ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_256, 75 | ZYDIS_ISA_SET_AVX512_VPOPCNTDQ_512, 76 | ZYDIS_ISA_SET_AVXAES, 77 | ZYDIS_ISA_SET_AVX_GFNI, 78 | ZYDIS_ISA_SET_BMI1, 79 | ZYDIS_ISA_SET_BMI2, 80 | ZYDIS_ISA_SET_CET, 81 | ZYDIS_ISA_SET_CLDEMOTE, 82 | ZYDIS_ISA_SET_CLFLUSHOPT, 83 | ZYDIS_ISA_SET_CLFSH, 84 | ZYDIS_ISA_SET_CLWB, 85 | ZYDIS_ISA_SET_CLZERO, 86 | ZYDIS_ISA_SET_CMOV, 87 | ZYDIS_ISA_SET_CMPXCHG16B, 88 | ZYDIS_ISA_SET_ENQCMD, 89 | ZYDIS_ISA_SET_F16C, 90 | ZYDIS_ISA_SET_FAT_NOP, 91 | ZYDIS_ISA_SET_FCMOV, 92 | ZYDIS_ISA_SET_FMA, 93 | ZYDIS_ISA_SET_FMA4, 94 | ZYDIS_ISA_SET_FXSAVE, 95 | ZYDIS_ISA_SET_FXSAVE64, 96 | ZYDIS_ISA_SET_GFNI, 97 | ZYDIS_ISA_SET_I186, 98 | ZYDIS_ISA_SET_I286PROTECTED, 99 | ZYDIS_ISA_SET_I286REAL, 100 | ZYDIS_ISA_SET_I386, 101 | ZYDIS_ISA_SET_I486, 102 | ZYDIS_ISA_SET_I486REAL, 103 | ZYDIS_ISA_SET_I86, 104 | ZYDIS_ISA_SET_INVPCID, 105 | ZYDIS_ISA_SET_KNCE, 106 | ZYDIS_ISA_SET_KNCJKBR, 107 | ZYDIS_ISA_SET_KNCSTREAM, 108 | ZYDIS_ISA_SET_KNCV, 109 | ZYDIS_ISA_SET_KNC_MISC, 110 | ZYDIS_ISA_SET_KNC_PF_HINT, 111 | ZYDIS_ISA_SET_LAHF, 112 | ZYDIS_ISA_SET_LONGMODE, 113 | ZYDIS_ISA_SET_LZCNT, 114 | ZYDIS_ISA_SET_MCOMMIT, 115 | ZYDIS_ISA_SET_MONITOR, 116 | ZYDIS_ISA_SET_MONITORX, 117 | ZYDIS_ISA_SET_MOVBE, 118 | ZYDIS_ISA_SET_MOVDIR, 119 | ZYDIS_ISA_SET_MPX, 120 | ZYDIS_ISA_SET_PADLOCK_ACE, 121 | ZYDIS_ISA_SET_PADLOCK_PHE, 122 | ZYDIS_ISA_SET_PADLOCK_PMM, 123 | ZYDIS_ISA_SET_PADLOCK_RNG, 124 | ZYDIS_ISA_SET_PAUSE, 125 | ZYDIS_ISA_SET_PCLMULQDQ, 126 | ZYDIS_ISA_SET_PCONFIG, 127 | ZYDIS_ISA_SET_PENTIUMMMX, 128 | ZYDIS_ISA_SET_PENTIUMREAL, 129 | ZYDIS_ISA_SET_PKU, 130 | ZYDIS_ISA_SET_POPCNT, 131 | ZYDIS_ISA_SET_PPRO, 132 | ZYDIS_ISA_SET_PREFETCHWT1, 133 | ZYDIS_ISA_SET_PREFETCH_NOP, 134 | ZYDIS_ISA_SET_PT, 135 | ZYDIS_ISA_SET_RDPID, 136 | ZYDIS_ISA_SET_RDPMC, 137 | ZYDIS_ISA_SET_RDPRU, 138 | ZYDIS_ISA_SET_RDRAND, 139 | ZYDIS_ISA_SET_RDSEED, 140 | ZYDIS_ISA_SET_RDTSCP, 141 | ZYDIS_ISA_SET_RDWRFSGS, 142 | ZYDIS_ISA_SET_RTM, 143 | ZYDIS_ISA_SET_SERIALIZE, 144 | ZYDIS_ISA_SET_SGX, 145 | ZYDIS_ISA_SET_SGX_ENCLV, 146 | ZYDIS_ISA_SET_SHA, 147 | ZYDIS_ISA_SET_SMAP, 148 | ZYDIS_ISA_SET_SMX, 149 | ZYDIS_ISA_SET_SSE, 150 | ZYDIS_ISA_SET_SSE2, 151 | ZYDIS_ISA_SET_SSE2MMX, 152 | ZYDIS_ISA_SET_SSE3, 153 | ZYDIS_ISA_SET_SSE3X87, 154 | ZYDIS_ISA_SET_SSE4, 155 | ZYDIS_ISA_SET_SSE42, 156 | ZYDIS_ISA_SET_SSE4A, 157 | ZYDIS_ISA_SET_SSEMXCSR, 158 | ZYDIS_ISA_SET_SSE_PREFETCH, 159 | ZYDIS_ISA_SET_SSSE3, 160 | ZYDIS_ISA_SET_SSSE3MMX, 161 | ZYDIS_ISA_SET_SVM, 162 | ZYDIS_ISA_SET_TBM, 163 | ZYDIS_ISA_SET_TSX_LDTRK, 164 | ZYDIS_ISA_SET_VAES, 165 | ZYDIS_ISA_SET_VMFUNC, 166 | ZYDIS_ISA_SET_VPCLMULQDQ, 167 | ZYDIS_ISA_SET_VTX, 168 | ZYDIS_ISA_SET_WAITPKG, 169 | ZYDIS_ISA_SET_X87, 170 | ZYDIS_ISA_SET_XOP, 171 | ZYDIS_ISA_SET_XSAVE, 172 | ZYDIS_ISA_SET_XSAVEC, 173 | ZYDIS_ISA_SET_XSAVEOPT, 174 | ZYDIS_ISA_SET_XSAVES, 175 | 176 | /** 177 | * Maximum value of this enum. 178 | */ 179 | ZYDIS_ISA_SET_MAX_VALUE = ZYDIS_ISA_SET_XSAVES, 180 | /** 181 | * The minimum number of bits required to represent all values of this enum. 182 | */ 183 | ZYDIS_ISA_SET_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_ISA_SET_MAX_VALUE) 184 | } ZydisISASet; 185 | -------------------------------------------------------------------------------- /lib/include/Zydis/Generated/EnumInstructionCategory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Defines the `ZydisInstructionCategory` enum. 3 | */ 4 | typedef enum ZydisInstructionCategory_ 5 | { 6 | ZYDIS_CATEGORY_INVALID, 7 | ZYDIS_CATEGORY_ADOX_ADCX, 8 | ZYDIS_CATEGORY_AES, 9 | ZYDIS_CATEGORY_AMD3DNOW, 10 | ZYDIS_CATEGORY_AMX_TILE, 11 | ZYDIS_CATEGORY_AVX, 12 | ZYDIS_CATEGORY_AVX2, 13 | ZYDIS_CATEGORY_AVX2GATHER, 14 | ZYDIS_CATEGORY_AVX512, 15 | ZYDIS_CATEGORY_AVX512_4FMAPS, 16 | ZYDIS_CATEGORY_AVX512_4VNNIW, 17 | ZYDIS_CATEGORY_AVX512_BITALG, 18 | ZYDIS_CATEGORY_AVX512_VBMI, 19 | ZYDIS_CATEGORY_AVX512_VP2INTERSECT, 20 | ZYDIS_CATEGORY_BINARY, 21 | ZYDIS_CATEGORY_BITBYTE, 22 | ZYDIS_CATEGORY_BLEND, 23 | ZYDIS_CATEGORY_BMI1, 24 | ZYDIS_CATEGORY_BMI2, 25 | ZYDIS_CATEGORY_BROADCAST, 26 | ZYDIS_CATEGORY_CALL, 27 | ZYDIS_CATEGORY_CET, 28 | ZYDIS_CATEGORY_CLDEMOTE, 29 | ZYDIS_CATEGORY_CLFLUSHOPT, 30 | ZYDIS_CATEGORY_CLWB, 31 | ZYDIS_CATEGORY_CLZERO, 32 | ZYDIS_CATEGORY_CMOV, 33 | ZYDIS_CATEGORY_COMPRESS, 34 | ZYDIS_CATEGORY_COND_BR, 35 | ZYDIS_CATEGORY_CONFLICT, 36 | ZYDIS_CATEGORY_CONVERT, 37 | ZYDIS_CATEGORY_DATAXFER, 38 | ZYDIS_CATEGORY_DECIMAL, 39 | ZYDIS_CATEGORY_ENQCMD, 40 | ZYDIS_CATEGORY_EXPAND, 41 | ZYDIS_CATEGORY_FCMOV, 42 | ZYDIS_CATEGORY_FLAGOP, 43 | ZYDIS_CATEGORY_FMA4, 44 | ZYDIS_CATEGORY_GATHER, 45 | ZYDIS_CATEGORY_GFNI, 46 | ZYDIS_CATEGORY_IFMA, 47 | ZYDIS_CATEGORY_INTERRUPT, 48 | ZYDIS_CATEGORY_IO, 49 | ZYDIS_CATEGORY_IOSTRINGOP, 50 | ZYDIS_CATEGORY_KMASK, 51 | ZYDIS_CATEGORY_KNC, 52 | ZYDIS_CATEGORY_KNCMASK, 53 | ZYDIS_CATEGORY_KNCSCALAR, 54 | ZYDIS_CATEGORY_LOGICAL, 55 | ZYDIS_CATEGORY_LOGICAL_FP, 56 | ZYDIS_CATEGORY_LZCNT, 57 | ZYDIS_CATEGORY_MISC, 58 | ZYDIS_CATEGORY_MMX, 59 | ZYDIS_CATEGORY_MOVDIR, 60 | ZYDIS_CATEGORY_MPX, 61 | ZYDIS_CATEGORY_NOP, 62 | ZYDIS_CATEGORY_PADLOCK, 63 | ZYDIS_CATEGORY_PCLMULQDQ, 64 | ZYDIS_CATEGORY_PCONFIG, 65 | ZYDIS_CATEGORY_PKU, 66 | ZYDIS_CATEGORY_POP, 67 | ZYDIS_CATEGORY_PREFETCH, 68 | ZYDIS_CATEGORY_PREFETCHWT1, 69 | ZYDIS_CATEGORY_PT, 70 | ZYDIS_CATEGORY_PUSH, 71 | ZYDIS_CATEGORY_RDPID, 72 | ZYDIS_CATEGORY_RDPRU, 73 | ZYDIS_CATEGORY_RDRAND, 74 | ZYDIS_CATEGORY_RDSEED, 75 | ZYDIS_CATEGORY_RDWRFSGS, 76 | ZYDIS_CATEGORY_RET, 77 | ZYDIS_CATEGORY_ROTATE, 78 | ZYDIS_CATEGORY_SCATTER, 79 | ZYDIS_CATEGORY_SEGOP, 80 | ZYDIS_CATEGORY_SEMAPHORE, 81 | ZYDIS_CATEGORY_SERIALIZE, 82 | ZYDIS_CATEGORY_SETCC, 83 | ZYDIS_CATEGORY_SGX, 84 | ZYDIS_CATEGORY_SHA, 85 | ZYDIS_CATEGORY_SHIFT, 86 | ZYDIS_CATEGORY_SMAP, 87 | ZYDIS_CATEGORY_SSE, 88 | ZYDIS_CATEGORY_STRINGOP, 89 | ZYDIS_CATEGORY_STTNI, 90 | ZYDIS_CATEGORY_SYSCALL, 91 | ZYDIS_CATEGORY_SYSRET, 92 | ZYDIS_CATEGORY_SYSTEM, 93 | ZYDIS_CATEGORY_TBM, 94 | ZYDIS_CATEGORY_TSX_LDTRK, 95 | ZYDIS_CATEGORY_UFMA, 96 | ZYDIS_CATEGORY_UNCOND_BR, 97 | ZYDIS_CATEGORY_VAES, 98 | ZYDIS_CATEGORY_VBMI2, 99 | ZYDIS_CATEGORY_VFMA, 100 | ZYDIS_CATEGORY_VPCLMULQDQ, 101 | ZYDIS_CATEGORY_VTX, 102 | ZYDIS_CATEGORY_WAITPKG, 103 | ZYDIS_CATEGORY_WIDENOP, 104 | ZYDIS_CATEGORY_X87_ALU, 105 | ZYDIS_CATEGORY_XOP, 106 | ZYDIS_CATEGORY_XSAVE, 107 | ZYDIS_CATEGORY_XSAVEOPT, 108 | 109 | /** 110 | * Maximum value of this enum. 111 | */ 112 | ZYDIS_CATEGORY_MAX_VALUE = ZYDIS_CATEGORY_XSAVEOPT, 113 | /** 114 | * The minimum number of bits required to represent all values of this enum. 115 | */ 116 | ZYDIS_CATEGORY_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_CATEGORY_MAX_VALUE) 117 | } ZydisInstructionCategory; 118 | -------------------------------------------------------------------------------- /lib/include/Zydis/Generated/EnumRegister.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Defines the `ZydisRegister` enum. 3 | */ 4 | typedef enum ZydisRegister_ 5 | { 6 | ZYDIS_REGISTER_NONE, 7 | 8 | // General purpose registers 8-bit 9 | ZYDIS_REGISTER_AL, 10 | ZYDIS_REGISTER_CL, 11 | ZYDIS_REGISTER_DL, 12 | ZYDIS_REGISTER_BL, 13 | ZYDIS_REGISTER_AH, 14 | ZYDIS_REGISTER_CH, 15 | ZYDIS_REGISTER_DH, 16 | ZYDIS_REGISTER_BH, 17 | ZYDIS_REGISTER_SPL, 18 | ZYDIS_REGISTER_BPL, 19 | ZYDIS_REGISTER_SIL, 20 | ZYDIS_REGISTER_DIL, 21 | ZYDIS_REGISTER_R8B, 22 | ZYDIS_REGISTER_R9B, 23 | ZYDIS_REGISTER_R10B, 24 | ZYDIS_REGISTER_R11B, 25 | ZYDIS_REGISTER_R12B, 26 | ZYDIS_REGISTER_R13B, 27 | ZYDIS_REGISTER_R14B, 28 | ZYDIS_REGISTER_R15B, 29 | // General purpose registers 16-bit 30 | ZYDIS_REGISTER_AX, 31 | ZYDIS_REGISTER_CX, 32 | ZYDIS_REGISTER_DX, 33 | ZYDIS_REGISTER_BX, 34 | ZYDIS_REGISTER_SP, 35 | ZYDIS_REGISTER_BP, 36 | ZYDIS_REGISTER_SI, 37 | ZYDIS_REGISTER_DI, 38 | ZYDIS_REGISTER_R8W, 39 | ZYDIS_REGISTER_R9W, 40 | ZYDIS_REGISTER_R10W, 41 | ZYDIS_REGISTER_R11W, 42 | ZYDIS_REGISTER_R12W, 43 | ZYDIS_REGISTER_R13W, 44 | ZYDIS_REGISTER_R14W, 45 | ZYDIS_REGISTER_R15W, 46 | // General purpose registers 32-bit 47 | ZYDIS_REGISTER_EAX, 48 | ZYDIS_REGISTER_ECX, 49 | ZYDIS_REGISTER_EDX, 50 | ZYDIS_REGISTER_EBX, 51 | ZYDIS_REGISTER_ESP, 52 | ZYDIS_REGISTER_EBP, 53 | ZYDIS_REGISTER_ESI, 54 | ZYDIS_REGISTER_EDI, 55 | ZYDIS_REGISTER_R8D, 56 | ZYDIS_REGISTER_R9D, 57 | ZYDIS_REGISTER_R10D, 58 | ZYDIS_REGISTER_R11D, 59 | ZYDIS_REGISTER_R12D, 60 | ZYDIS_REGISTER_R13D, 61 | ZYDIS_REGISTER_R14D, 62 | ZYDIS_REGISTER_R15D, 63 | // General purpose registers 64-bit 64 | ZYDIS_REGISTER_RAX, 65 | ZYDIS_REGISTER_RCX, 66 | ZYDIS_REGISTER_RDX, 67 | ZYDIS_REGISTER_RBX, 68 | ZYDIS_REGISTER_RSP, 69 | ZYDIS_REGISTER_RBP, 70 | ZYDIS_REGISTER_RSI, 71 | ZYDIS_REGISTER_RDI, 72 | ZYDIS_REGISTER_R8, 73 | ZYDIS_REGISTER_R9, 74 | ZYDIS_REGISTER_R10, 75 | ZYDIS_REGISTER_R11, 76 | ZYDIS_REGISTER_R12, 77 | ZYDIS_REGISTER_R13, 78 | ZYDIS_REGISTER_R14, 79 | ZYDIS_REGISTER_R15, 80 | // Floating point legacy registers 81 | ZYDIS_REGISTER_ST0, 82 | ZYDIS_REGISTER_ST1, 83 | ZYDIS_REGISTER_ST2, 84 | ZYDIS_REGISTER_ST3, 85 | ZYDIS_REGISTER_ST4, 86 | ZYDIS_REGISTER_ST5, 87 | ZYDIS_REGISTER_ST6, 88 | ZYDIS_REGISTER_ST7, 89 | ZYDIS_REGISTER_X87CONTROL, 90 | ZYDIS_REGISTER_X87STATUS, 91 | ZYDIS_REGISTER_X87TAG, 92 | // Floating point multimedia registers 93 | ZYDIS_REGISTER_MM0, 94 | ZYDIS_REGISTER_MM1, 95 | ZYDIS_REGISTER_MM2, 96 | ZYDIS_REGISTER_MM3, 97 | ZYDIS_REGISTER_MM4, 98 | ZYDIS_REGISTER_MM5, 99 | ZYDIS_REGISTER_MM6, 100 | ZYDIS_REGISTER_MM7, 101 | // Floating point vector registers 128-bit 102 | ZYDIS_REGISTER_XMM0, 103 | ZYDIS_REGISTER_XMM1, 104 | ZYDIS_REGISTER_XMM2, 105 | ZYDIS_REGISTER_XMM3, 106 | ZYDIS_REGISTER_XMM4, 107 | ZYDIS_REGISTER_XMM5, 108 | ZYDIS_REGISTER_XMM6, 109 | ZYDIS_REGISTER_XMM7, 110 | ZYDIS_REGISTER_XMM8, 111 | ZYDIS_REGISTER_XMM9, 112 | ZYDIS_REGISTER_XMM10, 113 | ZYDIS_REGISTER_XMM11, 114 | ZYDIS_REGISTER_XMM12, 115 | ZYDIS_REGISTER_XMM13, 116 | ZYDIS_REGISTER_XMM14, 117 | ZYDIS_REGISTER_XMM15, 118 | ZYDIS_REGISTER_XMM16, 119 | ZYDIS_REGISTER_XMM17, 120 | ZYDIS_REGISTER_XMM18, 121 | ZYDIS_REGISTER_XMM19, 122 | ZYDIS_REGISTER_XMM20, 123 | ZYDIS_REGISTER_XMM21, 124 | ZYDIS_REGISTER_XMM22, 125 | ZYDIS_REGISTER_XMM23, 126 | ZYDIS_REGISTER_XMM24, 127 | ZYDIS_REGISTER_XMM25, 128 | ZYDIS_REGISTER_XMM26, 129 | ZYDIS_REGISTER_XMM27, 130 | ZYDIS_REGISTER_XMM28, 131 | ZYDIS_REGISTER_XMM29, 132 | ZYDIS_REGISTER_XMM30, 133 | ZYDIS_REGISTER_XMM31, 134 | // Floating point vector registers 256-bit 135 | ZYDIS_REGISTER_YMM0, 136 | ZYDIS_REGISTER_YMM1, 137 | ZYDIS_REGISTER_YMM2, 138 | ZYDIS_REGISTER_YMM3, 139 | ZYDIS_REGISTER_YMM4, 140 | ZYDIS_REGISTER_YMM5, 141 | ZYDIS_REGISTER_YMM6, 142 | ZYDIS_REGISTER_YMM7, 143 | ZYDIS_REGISTER_YMM8, 144 | ZYDIS_REGISTER_YMM9, 145 | ZYDIS_REGISTER_YMM10, 146 | ZYDIS_REGISTER_YMM11, 147 | ZYDIS_REGISTER_YMM12, 148 | ZYDIS_REGISTER_YMM13, 149 | ZYDIS_REGISTER_YMM14, 150 | ZYDIS_REGISTER_YMM15, 151 | ZYDIS_REGISTER_YMM16, 152 | ZYDIS_REGISTER_YMM17, 153 | ZYDIS_REGISTER_YMM18, 154 | ZYDIS_REGISTER_YMM19, 155 | ZYDIS_REGISTER_YMM20, 156 | ZYDIS_REGISTER_YMM21, 157 | ZYDIS_REGISTER_YMM22, 158 | ZYDIS_REGISTER_YMM23, 159 | ZYDIS_REGISTER_YMM24, 160 | ZYDIS_REGISTER_YMM25, 161 | ZYDIS_REGISTER_YMM26, 162 | ZYDIS_REGISTER_YMM27, 163 | ZYDIS_REGISTER_YMM28, 164 | ZYDIS_REGISTER_YMM29, 165 | ZYDIS_REGISTER_YMM30, 166 | ZYDIS_REGISTER_YMM31, 167 | // Floating point vector registers 512-bit 168 | ZYDIS_REGISTER_ZMM0, 169 | ZYDIS_REGISTER_ZMM1, 170 | ZYDIS_REGISTER_ZMM2, 171 | ZYDIS_REGISTER_ZMM3, 172 | ZYDIS_REGISTER_ZMM4, 173 | ZYDIS_REGISTER_ZMM5, 174 | ZYDIS_REGISTER_ZMM6, 175 | ZYDIS_REGISTER_ZMM7, 176 | ZYDIS_REGISTER_ZMM8, 177 | ZYDIS_REGISTER_ZMM9, 178 | ZYDIS_REGISTER_ZMM10, 179 | ZYDIS_REGISTER_ZMM11, 180 | ZYDIS_REGISTER_ZMM12, 181 | ZYDIS_REGISTER_ZMM13, 182 | ZYDIS_REGISTER_ZMM14, 183 | ZYDIS_REGISTER_ZMM15, 184 | ZYDIS_REGISTER_ZMM16, 185 | ZYDIS_REGISTER_ZMM17, 186 | ZYDIS_REGISTER_ZMM18, 187 | ZYDIS_REGISTER_ZMM19, 188 | ZYDIS_REGISTER_ZMM20, 189 | ZYDIS_REGISTER_ZMM21, 190 | ZYDIS_REGISTER_ZMM22, 191 | ZYDIS_REGISTER_ZMM23, 192 | ZYDIS_REGISTER_ZMM24, 193 | ZYDIS_REGISTER_ZMM25, 194 | ZYDIS_REGISTER_ZMM26, 195 | ZYDIS_REGISTER_ZMM27, 196 | ZYDIS_REGISTER_ZMM28, 197 | ZYDIS_REGISTER_ZMM29, 198 | ZYDIS_REGISTER_ZMM30, 199 | ZYDIS_REGISTER_ZMM31, 200 | // Matrix registers 201 | ZYDIS_REGISTER_TMM0, 202 | ZYDIS_REGISTER_TMM1, 203 | ZYDIS_REGISTER_TMM2, 204 | ZYDIS_REGISTER_TMM3, 205 | ZYDIS_REGISTER_TMM4, 206 | ZYDIS_REGISTER_TMM5, 207 | ZYDIS_REGISTER_TMM6, 208 | ZYDIS_REGISTER_TMM7, 209 | // Flags registers 210 | ZYDIS_REGISTER_FLAGS, 211 | ZYDIS_REGISTER_EFLAGS, 212 | ZYDIS_REGISTER_RFLAGS, 213 | // Instruction-pointer registers 214 | ZYDIS_REGISTER_IP, 215 | ZYDIS_REGISTER_EIP, 216 | ZYDIS_REGISTER_RIP, 217 | // Segment registers 218 | ZYDIS_REGISTER_ES, 219 | ZYDIS_REGISTER_CS, 220 | ZYDIS_REGISTER_SS, 221 | ZYDIS_REGISTER_DS, 222 | ZYDIS_REGISTER_FS, 223 | ZYDIS_REGISTER_GS, 224 | // Table registers 225 | ZYDIS_REGISTER_GDTR, 226 | ZYDIS_REGISTER_LDTR, 227 | ZYDIS_REGISTER_IDTR, 228 | ZYDIS_REGISTER_TR, 229 | // Test registers 230 | ZYDIS_REGISTER_TR0, 231 | ZYDIS_REGISTER_TR1, 232 | ZYDIS_REGISTER_TR2, 233 | ZYDIS_REGISTER_TR3, 234 | ZYDIS_REGISTER_TR4, 235 | ZYDIS_REGISTER_TR5, 236 | ZYDIS_REGISTER_TR6, 237 | ZYDIS_REGISTER_TR7, 238 | // Control registers 239 | ZYDIS_REGISTER_CR0, 240 | ZYDIS_REGISTER_CR1, 241 | ZYDIS_REGISTER_CR2, 242 | ZYDIS_REGISTER_CR3, 243 | ZYDIS_REGISTER_CR4, 244 | ZYDIS_REGISTER_CR5, 245 | ZYDIS_REGISTER_CR6, 246 | ZYDIS_REGISTER_CR7, 247 | ZYDIS_REGISTER_CR8, 248 | ZYDIS_REGISTER_CR9, 249 | ZYDIS_REGISTER_CR10, 250 | ZYDIS_REGISTER_CR11, 251 | ZYDIS_REGISTER_CR12, 252 | ZYDIS_REGISTER_CR13, 253 | ZYDIS_REGISTER_CR14, 254 | ZYDIS_REGISTER_CR15, 255 | // Debug registers 256 | ZYDIS_REGISTER_DR0, 257 | ZYDIS_REGISTER_DR1, 258 | ZYDIS_REGISTER_DR2, 259 | ZYDIS_REGISTER_DR3, 260 | ZYDIS_REGISTER_DR4, 261 | ZYDIS_REGISTER_DR5, 262 | ZYDIS_REGISTER_DR6, 263 | ZYDIS_REGISTER_DR7, 264 | ZYDIS_REGISTER_DR8, 265 | ZYDIS_REGISTER_DR9, 266 | ZYDIS_REGISTER_DR10, 267 | ZYDIS_REGISTER_DR11, 268 | ZYDIS_REGISTER_DR12, 269 | ZYDIS_REGISTER_DR13, 270 | ZYDIS_REGISTER_DR14, 271 | ZYDIS_REGISTER_DR15, 272 | // Mask registers 273 | ZYDIS_REGISTER_K0, 274 | ZYDIS_REGISTER_K1, 275 | ZYDIS_REGISTER_K2, 276 | ZYDIS_REGISTER_K3, 277 | ZYDIS_REGISTER_K4, 278 | ZYDIS_REGISTER_K5, 279 | ZYDIS_REGISTER_K6, 280 | ZYDIS_REGISTER_K7, 281 | // Bound registers 282 | ZYDIS_REGISTER_BND0, 283 | ZYDIS_REGISTER_BND1, 284 | ZYDIS_REGISTER_BND2, 285 | ZYDIS_REGISTER_BND3, 286 | ZYDIS_REGISTER_BNDCFG, 287 | ZYDIS_REGISTER_BNDSTATUS, 288 | // Uncategorized 289 | ZYDIS_REGISTER_MXCSR, 290 | ZYDIS_REGISTER_PKRU, 291 | ZYDIS_REGISTER_XCR0, 292 | 293 | /** 294 | * Maximum value of this enum. 295 | */ 296 | ZYDIS_REGISTER_MAX_VALUE = ZYDIS_REGISTER_XCR0, 297 | /** 298 | * The minimum number of bits required to represent all values of this enum. 299 | */ 300 | ZYDIS_REGISTER_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_REGISTER_MAX_VALUE) 301 | } ZydisRegister; 302 | -------------------------------------------------------------------------------- /lib/include/Zydis/Internal/FormatterATT.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd, Joel Hoener 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Implements the `AT&T` style instruction-formatter. 30 | */ 31 | 32 | #ifndef ZYDIS_FORMATTER_ATT_H 33 | #define ZYDIS_FORMATTER_ATT_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* ============================================================================================== */ 44 | /* Formatter functions */ 45 | /* ============================================================================================== */ 46 | 47 | /* ---------------------------------------------------------------------------------------------- */ 48 | /* Instruction */ 49 | /* ---------------------------------------------------------------------------------------------- */ 50 | 51 | ZyanStatus ZydisFormatterATTFormatInstruction(const ZydisFormatter* formatter, 52 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 53 | 54 | /* ---------------------------------------------------------------------------------------------- */ 55 | /* Operands */ 56 | /* ---------------------------------------------------------------------------------------------- */ 57 | 58 | ZyanStatus ZydisFormatterATTFormatOperandMEM(const ZydisFormatter* formatter, 59 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 60 | 61 | /* ---------------------------------------------------------------------------------------------- */ 62 | /* Elemental tokens */ 63 | /* ---------------------------------------------------------------------------------------------- */ 64 | 65 | ZyanStatus ZydisFormatterATTPrintMnemonic(const ZydisFormatter* formatter, 66 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 67 | 68 | ZyanStatus ZydisFormatterATTPrintRegister(const ZydisFormatter* formatter, 69 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context, ZydisRegister reg); 70 | 71 | ZyanStatus ZydisFormatterATTPrintDISP(const ZydisFormatter* formatter, 72 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 73 | 74 | ZyanStatus ZydisFormatterATTPrintIMM(const ZydisFormatter* formatter, 75 | ZydisFormatterBuffer* buffer, ZydisFormatterContext* context); 76 | 77 | /* ---------------------------------------------------------------------------------------------- */ 78 | 79 | /* ============================================================================================== */ 80 | /* Fomatter presets */ 81 | /* ============================================================================================== */ 82 | 83 | /* ---------------------------------------------------------------------------------------------- */ 84 | /* AT&T */ 85 | /* ---------------------------------------------------------------------------------------------- */ 86 | 87 | /** 88 | * The default formatter configuration for `AT&T` style disassembly. 89 | */ 90 | static const ZydisFormatter FORMATTER_ATT = 91 | { 92 | /* style */ ZYDIS_FORMATTER_STYLE_ATT, 93 | /* force_memory_size */ ZYAN_FALSE, 94 | /* force_memory_seg */ ZYAN_FALSE, 95 | /* force_relative_branches */ ZYAN_FALSE, 96 | /* force_relative_riprel */ ZYAN_FALSE, 97 | /* print_branch_size */ ZYAN_FALSE, 98 | /* detailed_prefixes */ ZYAN_FALSE, 99 | /* addr_base */ ZYDIS_NUMERIC_BASE_HEX, 100 | /* addr_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 101 | /* addr_padding_absolute */ ZYDIS_PADDING_AUTO, 102 | /* addr_padding_relative */ 2, 103 | /* disp_base */ ZYDIS_NUMERIC_BASE_HEX, 104 | /* disp_signedness */ ZYDIS_SIGNEDNESS_SIGNED, 105 | /* disp_padding */ 2, 106 | /* imm_base */ ZYDIS_NUMERIC_BASE_HEX, 107 | /* imm_signedness */ ZYDIS_SIGNEDNESS_AUTO, 108 | /* imm_padding */ 2, 109 | /* case_prefixes */ ZYDIS_LETTER_CASE_DEFAULT, 110 | /* case_mnemonic */ ZYDIS_LETTER_CASE_DEFAULT, 111 | /* case_registers */ ZYDIS_LETTER_CASE_DEFAULT, 112 | /* case_typecasts */ ZYDIS_LETTER_CASE_DEFAULT, 113 | /* case_decorators */ ZYDIS_LETTER_CASE_DEFAULT, 114 | /* hex_uppercase */ ZYAN_TRUE, 115 | /* number_format */ 116 | { 117 | // ZYDIS_NUMERIC_BASE_DEC 118 | { 119 | // Prefix 120 | { 121 | /* string */ ZYAN_NULL, 122 | /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 123 | /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 124 | }, 125 | // Suffix 126 | { 127 | /* string */ ZYAN_NULL, 128 | /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 129 | /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 130 | } 131 | }, 132 | // ZYDIS_NUMERIC_BASE_HEX 133 | { 134 | // Prefix 135 | { 136 | /* string */ &FORMATTER_ATT.number_format[ 137 | ZYDIS_NUMERIC_BASE_HEX][0].string_data, 138 | /* string_data */ ZYAN_DEFINE_STRING_VIEW("0x"), 139 | /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 140 | }, 141 | // Suffix 142 | { 143 | /* string */ ZYAN_NULL, 144 | /* string_data */ ZYAN_DEFINE_STRING_VIEW(""), 145 | /* buffer */ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 146 | } 147 | } 148 | }, 149 | /* func_pre_instruction */ ZYAN_NULL, 150 | /* func_post_instruction */ ZYAN_NULL, 151 | /* func_format_instruction */ &ZydisFormatterATTFormatInstruction, 152 | /* func_pre_operand */ ZYAN_NULL, 153 | /* func_post_operand */ ZYAN_NULL, 154 | /* func_format_operand_reg */ &ZydisFormatterBaseFormatOperandREG, 155 | /* func_format_operand_mem */ &ZydisFormatterATTFormatOperandMEM, 156 | /* func_format_operand_ptr */ &ZydisFormatterBaseFormatOperandPTR, 157 | /* func_format_operand_imm */ &ZydisFormatterBaseFormatOperandIMM, 158 | /* func_print_mnemonic */ &ZydisFormatterATTPrintMnemonic, 159 | /* func_print_register */ &ZydisFormatterATTPrintRegister, 160 | /* func_print_address_abs */ &ZydisFormatterBasePrintAddressABS, 161 | /* func_print_address_rel */ &ZydisFormatterBasePrintAddressREL, 162 | /* func_print_disp */ &ZydisFormatterATTPrintDISP, 163 | /* func_print_imm */ &ZydisFormatterATTPrintIMM, 164 | /* func_print_typecast */ ZYAN_NULL, 165 | /* func_print_segment */ &ZydisFormatterBasePrintSegment, 166 | /* func_print_prefixes */ &ZydisFormatterBasePrintPrefixes, 167 | /* func_print_decorator */ &ZydisFormatterBasePrintDecorator 168 | }; 169 | 170 | /* ---------------------------------------------------------------------------------------------- */ 171 | 172 | /* ============================================================================================== */ 173 | 174 | #ifdef __cplusplus 175 | } 176 | #endif 177 | 178 | #endif // ZYDIS_FORMATTER_ATT_H 179 | -------------------------------------------------------------------------------- /lib/include/Zydis/MetaInfo.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * @brief 30 | */ 31 | 32 | #ifndef ZYDIS_METAINFO_H 33 | #define ZYDIS_METAINFO_H 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* ============================================================================================== */ 44 | /* Enums and types */ 45 | /* ============================================================================================== */ 46 | 47 | #include 48 | #include 49 | #include 50 | 51 | /* ============================================================================================== */ 52 | /* Exported functions */ 53 | /* ============================================================================================== */ 54 | 55 | /** 56 | * Returns the specified instruction category string. 57 | * 58 | * @param category The instruction category. 59 | * 60 | * @return The instruction category string or `ZYAN_NULL`, if an invalid category was passed. 61 | */ 62 | ZYDIS_EXPORT const char* ZydisCategoryGetString(ZydisInstructionCategory category); 63 | 64 | /** 65 | * Returns the specified isa-set string. 66 | * 67 | * @param isa_set The isa-set. 68 | * 69 | * @return The isa-set string or `ZYAN_NULL`, if an invalid isa-set was passed. 70 | */ 71 | ZYDIS_EXPORT const char* ZydisISASetGetString(ZydisISASet isa_set); 72 | 73 | /** 74 | * Returns the specified isa-extension string. 75 | * 76 | * @param isa_ext The isa-extension. 77 | * 78 | * @return The isa-extension string or `ZYAN_NULL`, if an invalid isa-extension was passed. 79 | */ 80 | ZYDIS_EXPORT const char* ZydisISAExtGetString(ZydisISAExt isa_ext); 81 | 82 | /* ============================================================================================== */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* ZYDIS_METAINFO_H */ 89 | -------------------------------------------------------------------------------- /lib/include/Zydis/Mnemonic.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Mnemonic constant definitions and helper functions. 30 | */ 31 | 32 | #ifndef ZYDIS_MNEMONIC_H 33 | #define ZYDIS_MNEMONIC_H 34 | 35 | #include 36 | #include 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* ============================================================================================== */ 43 | /* Enums and types */ 44 | /* ============================================================================================== */ 45 | 46 | #include 47 | 48 | /* ============================================================================================== */ 49 | /* Exported functions */ 50 | /* ============================================================================================== */ 51 | 52 | /** 53 | * @addtogroup mnemonic Mnemonic 54 | * Functions for retrieving mnemonic names. 55 | * @{ 56 | */ 57 | 58 | /** 59 | * Returns the specified instruction mnemonic string. 60 | * 61 | * @param mnemonic The mnemonic. 62 | * 63 | * @return The instruction mnemonic string or `ZYAN_NULL`, if an invalid mnemonic was passed. 64 | */ 65 | ZYDIS_EXPORT const char* ZydisMnemonicGetString(ZydisMnemonic mnemonic); 66 | 67 | /** 68 | * Returns the specified instruction mnemonic as `ZydisShortString`. 69 | * 70 | * @param mnemonic The mnemonic. 71 | * 72 | * @return The instruction mnemonic string or `ZYAN_NULL`, if an invalid mnemonic was passed. 73 | * 74 | * The `buffer` of the returned struct is guaranteed to be zero-terminated in this special case. 75 | */ 76 | ZYDIS_EXPORT const ZydisShortString* ZydisMnemonicGetStringWrapped(ZydisMnemonic mnemonic); 77 | 78 | /** 79 | * @} 80 | */ 81 | 82 | /* ============================================================================================== */ 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* ZYDIS_MNEMONIC_H */ 89 | -------------------------------------------------------------------------------- /lib/include/Zydis/ShortString.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Defines the immutable and storage-efficient `ZydisShortString` struct, which 30 | * is used to store strings in the generated tables. 31 | */ 32 | 33 | #ifndef ZYDIS_SHORTSTRING_H 34 | #define ZYDIS_SHORTSTRING_H 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | /* ============================================================================================== */ 45 | /* Enums and types */ 46 | /* ============================================================================================== */ 47 | 48 | #pragma pack(push, 1) 49 | 50 | /** 51 | * Defines the `ZydisShortString` struct. 52 | * 53 | * This compact struct is mainly used for internal string-tables to save up some bytes. 54 | * 55 | * All fields in this struct should be considered as "private". Any changes may lead to unexpected 56 | * behavior. 57 | */ 58 | typedef struct ZydisShortString_ 59 | { 60 | /** 61 | * The buffer that contains the actual (null-terminated) string. 62 | */ 63 | const char* data; 64 | /** 65 | * The length (number of characters) of the string (without 0-termination). 66 | */ 67 | ZyanU8 size; 68 | } ZydisShortString; 69 | 70 | #pragma pack(pop) 71 | 72 | /* ============================================================================================== */ 73 | /* Macros */ 74 | /* ============================================================================================== */ 75 | 76 | /** 77 | * Declares a `ZydisShortString` from a static C-style string. 78 | * 79 | * @param string The C-string constant. 80 | */ 81 | #define ZYDIS_MAKE_SHORTSTRING(string) \ 82 | { string, sizeof(string) - 1 } 83 | 84 | /* ============================================================================================== */ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* ZYDIS_SHORTSTRING_H */ 91 | -------------------------------------------------------------------------------- /lib/include/Zydis/Status.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Status code definitions and check macros. 30 | */ 31 | 32 | #ifndef ZYDIS_STATUS_H 33 | #define ZYDIS_STATUS_H 34 | 35 | #include 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* ============================================================================================== */ 42 | /* Status codes */ 43 | /* ============================================================================================== */ 44 | 45 | /* ---------------------------------------------------------------------------------------------- */ 46 | /* Module IDs */ 47 | /* ---------------------------------------------------------------------------------------------- */ 48 | 49 | /** 50 | * The zydis module id. 51 | */ 52 | #define ZYAN_MODULE_ZYDIS 0x002u 53 | 54 | /* ---------------------------------------------------------------------------------------------- */ 55 | /* Status codes */ 56 | /* ---------------------------------------------------------------------------------------------- */ 57 | 58 | /* ---------------------------------------------------------------------------------------------- */ 59 | /* Decoder */ 60 | /* ---------------------------------------------------------------------------------------------- */ 61 | 62 | /** 63 | * An attempt was made to read data from an input data-source that has no more 64 | * data available. 65 | */ 66 | #define ZYDIS_STATUS_NO_MORE_DATA \ 67 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x00u) 68 | 69 | /** 70 | * An general error occured while decoding the current instruction. The 71 | * instruction might be undefined. 72 | */ 73 | #define ZYDIS_STATUS_DECODING_ERROR \ 74 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x01u) 75 | 76 | /** 77 | * The instruction exceeded the maximum length of 15 bytes. 78 | */ 79 | #define ZYDIS_STATUS_INSTRUCTION_TOO_LONG \ 80 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x02u) 81 | 82 | /** 83 | * The instruction encoded an invalid register. 84 | */ 85 | #define ZYDIS_STATUS_BAD_REGISTER \ 86 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x03u) 87 | 88 | /** 89 | * A lock-prefix (F0) was found while decoding an instruction that does not 90 | * support locking. 91 | */ 92 | #define ZYDIS_STATUS_ILLEGAL_LOCK \ 93 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x04u) 94 | 95 | /** 96 | * A legacy-prefix (F2, F3, 66) was found while decoding a XOP/VEX/EVEX/MVEX 97 | * instruction. 98 | */ 99 | #define ZYDIS_STATUS_ILLEGAL_LEGACY_PFX \ 100 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x05u) 101 | 102 | /** 103 | * A rex-prefix was found while decoding a XOP/VEX/EVEX/MVEX instruction. 104 | */ 105 | #define ZYDIS_STATUS_ILLEGAL_REX \ 106 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x06u) 107 | 108 | /** 109 | * An invalid opcode-map value was found while decoding a XOP/VEX/EVEX/MVEX-prefix. 110 | */ 111 | #define ZYDIS_STATUS_INVALID_MAP \ 112 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x07u) 113 | 114 | /** 115 | * An error occured while decoding the EVEX-prefix. 116 | */ 117 | #define ZYDIS_STATUS_MALFORMED_EVEX \ 118 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x08u) 119 | 120 | /** 121 | * An error occured while decoding the MVEX-prefix. 122 | */ 123 | #define ZYDIS_STATUS_MALFORMED_MVEX \ 124 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x09u) 125 | 126 | /** 127 | * An invalid write-mask was specified for an EVEX/MVEX instruction. 128 | */ 129 | #define ZYDIS_STATUS_INVALID_MASK \ 130 | ZYAN_MAKE_STATUS(1u, ZYAN_MODULE_ZYDIS, 0x0Au) 131 | 132 | /* ---------------------------------------------------------------------------------------------- */ 133 | /* Formatter */ 134 | /* ---------------------------------------------------------------------------------------------- */ 135 | 136 | /** 137 | * Returning this status code in some specified formatter callbacks will cause 138 | * the formatter to omit the corresponding token. 139 | * 140 | * Valid callbacks: 141 | * - `ZYDIS_FORMATTER_FUNC_PRE_OPERAND` 142 | * - `ZYDIS_FORMATTER_FUNC_POST_OPERAND` 143 | * - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_REG` 144 | * - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_MEM` 145 | * - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_PTR` 146 | * - `ZYDIS_FORMATTER_FUNC_FORMAT_OPERAND_IMM` 147 | */ 148 | #define ZYDIS_STATUS_SKIP_TOKEN \ 149 | ZYAN_MAKE_STATUS(0u, ZYAN_MODULE_ZYDIS, 0x0Bu) 150 | 151 | /* ---------------------------------------------------------------------------------------------- */ 152 | 153 | /* ============================================================================================== */ 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #endif /* ZYDIS_STATUS_H */ 160 | -------------------------------------------------------------------------------- /lib/include/Zydis/Zydis.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************************************** 2 | 3 | Zyan Disassembler Library (Zydis) 4 | 5 | Original Author : Florian Bernd 6 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | 25 | ***************************************************************************************************/ 26 | 27 | /** 28 | * @file 29 | * Master include file, including everything else. 30 | */ 31 | 32 | #ifndef ZYDIS_H 33 | #define ZYDIS_H 34 | 35 | #include 36 | #include 37 | 38 | #ifndef ZYDIS_DISABLE_DECODER 39 | # include 40 | # include 41 | #endif 42 | 43 | #ifndef ZYDIS_DISABLE_FORMATTER 44 | # include 45 | #endif 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | 54 | #ifdef __cplusplus 55 | extern "C" { 56 | #endif 57 | 58 | /* ============================================================================================== */ 59 | /* Macros */ 60 | /* ============================================================================================== */ 61 | 62 | /* ---------------------------------------------------------------------------------------------- */ 63 | /* Constants */ 64 | /* ---------------------------------------------------------------------------------------------- */ 65 | 66 | /** 67 | * A macro that defines the zydis version. 68 | */ 69 | #define ZYDIS_VERSION (ZyanU64)0x0003000100000000 70 | 71 | /* ---------------------------------------------------------------------------------------------- */ 72 | /* Helper macros */ 73 | /* ---------------------------------------------------------------------------------------------- */ 74 | 75 | /** 76 | * Extracts the major-part of the zydis version. 77 | * 78 | * @param version The zydis version value 79 | */ 80 | #define ZYDIS_VERSION_MAJOR(version) (ZyanU16)(((version) & 0xFFFF000000000000) >> 48) 81 | 82 | /** 83 | * Extracts the minor-part of the zydis version. 84 | * 85 | * @param version The zydis version value 86 | */ 87 | #define ZYDIS_VERSION_MINOR(version) (ZyanU16)(((version) & 0x0000FFFF00000000) >> 32) 88 | 89 | /** 90 | * Extracts the patch-part of the zydis version. 91 | * 92 | * @param version The zydis version value 93 | */ 94 | #define ZYDIS_VERSION_PATCH(version) (ZyanU16)(((version) & 0x00000000FFFF0000) >> 16) 95 | 96 | /** 97 | * Extracts the build-part of the zydis version. 98 | * 99 | * @param version The zydis version value 100 | */ 101 | #define ZYDIS_VERSION_BUILD(version) (ZyanU16)((version) & 0x000000000000FFFF) 102 | 103 | /* ---------------------------------------------------------------------------------------------- */ 104 | 105 | /* ============================================================================================== */ 106 | /* Enums and types */ 107 | /* ============================================================================================== */ 108 | 109 | /** 110 | * Defines the `ZydisFeature` enum. 111 | */ 112 | typedef enum ZydisFeature_ 113 | { 114 | ZYDIS_FEATURE_DECODER, 115 | ZYDIS_FEATURE_FORMATTER, 116 | ZYDIS_FEATURE_AVX512, 117 | ZYDIS_FEATURE_KNC, 118 | 119 | /** 120 | * Maximum value of this enum. 121 | */ 122 | ZYDIS_FEATURE_MAX_VALUE = ZYDIS_FEATURE_KNC, 123 | /** 124 | * The minimum number of bits required to represent all values of this enum. 125 | */ 126 | ZYDIS_FEATURE_REQUIRED_BITS = ZYAN_BITS_TO_REPRESENT(ZYDIS_FEATURE_MAX_VALUE) 127 | } ZydisFeature; 128 | 129 | /* ============================================================================================== */ 130 | /* Exported functions */ 131 | /* ============================================================================================== */ 132 | 133 | /** 134 | * @addtogroup version Version 135 | * Functions for checking the library version and build options. 136 | * @{ 137 | */ 138 | 139 | /** 140 | * Returns the zydis version. 141 | * 142 | * @return The zydis version. 143 | * 144 | * Use the macros provided in this file to extract the major, minor, patch and build part from the 145 | * returned version value. 146 | */ 147 | ZYDIS_EXPORT ZyanU64 ZydisGetVersion(void); 148 | 149 | /** 150 | * Checks, if the specified feature is enabled in the current zydis library instance. 151 | * 152 | * @param feature The feature. 153 | * 154 | * @return `ZYAN_STATUS_TRUE` if the feature is enabled, `ZYAN_STATUS_FALSE` if not. Another 155 | * zyan status code, if an error occured. 156 | */ 157 | ZYDIS_EXPORT ZyanStatus ZydisIsFeatureEnabled(ZydisFeature feature); 158 | 159 | /** 160 | * @} 161 | */ 162 | 163 | /* ============================================================================================== */ 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* ZYDIS_H */ 170 | -------------------------------------------------------------------------------- /lib/include/ZydisExportConfig.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef ZYDIS_EXPORT_H 3 | #define ZYDIS_EXPORT_H 4 | 5 | #ifdef ZYDIS_STATIC_DEFINE 6 | # define ZYDIS_EXPORT 7 | # define ZYDIS_NO_EXPORT 8 | #else 9 | # ifndef ZYDIS_EXPORT 10 | # ifdef Zydis_EXPORTS 11 | /* We are building this library */ 12 | # define ZYDIS_EXPORT 13 | # else 14 | /* We are using this library */ 15 | # define ZYDIS_EXPORT 16 | # endif 17 | # endif 18 | 19 | # ifndef ZYDIS_NO_EXPORT 20 | # define ZYDIS_NO_EXPORT 21 | # endif 22 | #endif 23 | 24 | #ifndef ZYDIS_DEPRECATED 25 | # define ZYDIS_DEPRECATED __attribute__ ((__deprecated__)) 26 | #endif 27 | 28 | #ifndef ZYDIS_DEPRECATED_EXPORT 29 | # define ZYDIS_DEPRECATED_EXPORT ZYDIS_EXPORT ZYDIS_DEPRECATED 30 | #endif 31 | 32 | #ifndef ZYDIS_DEPRECATED_NO_EXPORT 33 | # define ZYDIS_DEPRECATED_NO_EXPORT ZYDIS_NO_EXPORT ZYDIS_DEPRECATED 34 | #endif 35 | 36 | #if 0 /* DEFINE_NO_DEPRECATED */ 37 | # ifndef ZYDIS_NO_DEPRECATED 38 | # define ZYDIS_NO_DEPRECATED 39 | # endif 40 | #endif 41 | 42 | #endif /* ZYDIS_EXPORT_H */ 43 | -------------------------------------------------------------------------------- /libzydis_darwin_amd64.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6ea0e3681eb997a3d82f6a4798d24879cd06e6ceaaf0117d40cae77a7f7bf5b2 3 | size 581952 4 | -------------------------------------------------------------------------------- /libzydis_darwin_arm64.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2e40df7ba72e76cb2e3707cb0506762f88e6e1be7ec5c56f12c389d311014465 3 | size 562312 4 | -------------------------------------------------------------------------------- /libzydis_linux_amd64.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:0202291bf5f52a4a3b61c265ad07b6aebd3142ec6a71b61c8e9cd4a146495643 3 | size 628488 4 | -------------------------------------------------------------------------------- /libzydis_linux_arm64.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:13e3e3373130f99b0e6f90533b033fedb43febf19e202011771ec6ab8fdbe28e 3 | size 680112 4 | -------------------------------------------------------------------------------- /libzydis_windows_386.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:fafaa6d203207be2095729ccac0b1f52f8e3ab00cf09e1370426908cdbaff6ed 3 | size 519205 4 | -------------------------------------------------------------------------------- /libzydis_windows_amd64.syso: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:923a94da7e51708cb7be0616adb9fa5e3d7a928c2fb2c3ef38207da5fcc33abb 3 | size 545082 4 | -------------------------------------------------------------------------------- /machinemode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // MachineMode is an enum of processor modes. 8 | type MachineMode int 9 | 10 | // MachineMode enum values. 11 | const ( 12 | MachineMode64 MachineMode = iota // 64 bit mode 13 | MachineModeCompat32 // 32 bit protected mode 14 | MachineModeCompat16 // 16 bit protected mode 15 | MachineModeLegacy32 // 32 bit protected mode 16 | MachineModeLegacy16 // 16 bit protected mode 17 | MachineModeReal16 // 16 bit real mode 18 | ) 19 | -------------------------------------------------------------------------------- /opcodemap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // OpcodeMap represents a processor's opcode map. 8 | type OpcodeMap int 9 | 10 | // OpcodeMap values 11 | const ( 12 | OpcodeMapDefault OpcodeMap = iota 13 | OpcodeMap0F 14 | OpcodeMap0F38 15 | OpcodeMap0F3A 16 | OpcodeMap0F0F 17 | OpcodeMapXOP8 18 | OpcodeMapXOP9 19 | OpcodeMapXOPA 20 | ) 21 | -------------------------------------------------------------------------------- /operand.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | /* 8 | #cgo CFLAGS: -I./lib/include 9 | #include 10 | */ 11 | import "C" 12 | 13 | import ( 14 | "fmt" 15 | ) 16 | 17 | // OperandType is an enum of operand types. 18 | type OperandType int 19 | 20 | // OperandType enum values. 21 | const ( 22 | // The operand is not used. 23 | OperandTypeInvalid OperandType = iota 24 | // The operand is a register operand. 25 | OperandTypeRegister 26 | // The operand is a memory operand. 27 | OperandTypeMemory 28 | // The operand is a pointer operand with a segment:offset lvalue. 29 | OperandTypePointer 30 | // The operand is an immediate operand. 31 | OperandTypeImmediate 32 | ) 33 | 34 | // OperandVisibility is an enum of operand visibility types. 35 | type OperandVisibility int 36 | 37 | // OperandVisibility enum values. 38 | const ( 39 | OperandVisibilityInvalid OperandVisibility = iota 40 | // The operand is explicitly encoded in the instruction. 41 | OperandVisibilityExplicit 42 | // The operand is part of the opcode, but listed as an operand. 43 | OperandVisibilityImplicit 44 | // The operand is part of the opcode, and not typically listed as an operand. 45 | OperandVisibilityHidden 46 | ) 47 | 48 | // OperandAction is a bitfield that represents an operand action. 49 | type OperandAction int 50 | 51 | // OperandAction bitfield values. 52 | const ( 53 | // The operand is read by the instruction. 54 | OperandActionRead OperandAction = 1 << iota 55 | // The operand is written by the instruction (must write). 56 | OperandActionWrite 57 | // The operand is conditionally read by the instruction. 58 | OperandActionCondRead 59 | // The operand is conditionally written by the instruction (may write). 60 | OperandActionCondWrite 61 | 62 | // The operand is read (must read) and written by the instruction (must 63 | // write). 64 | OperandActionReadWrite = OperandActionRead | OperandActionWrite 65 | // The operand is conditionally read (may read) and conditionally written 66 | // by the instruction (may write). 67 | OperandActionCondReadCondWrite = OperandActionCondRead | OperandActionCondWrite 68 | // The operand is read (must read) and conditionally written by the 69 | // instruction (may write). 70 | OperandActionReadCondWrite = OperandActionRead | OperandActionCondWrite 71 | // The operand is written (must write) and conditionally read by 72 | // the instruction (may read). 73 | OperandActionCondReadWrite = OperandActionCondRead | OperandActionWrite 74 | // Mask combining all reading access flags. 75 | OperandActionMaskRead = OperandActionRead | OperandActionCondRead 76 | // Mask combining all writing access flags. 77 | OperandActionMaskWrite = OperandActionWrite | OperandActionCondWrite 78 | ) 79 | 80 | // OperandActions is a...? 81 | type OperandActions uint8 82 | 83 | // MemoryOperandType is an enum of memory operand types. 84 | type MemoryOperandType int 85 | 86 | // MemoryOperandType enum values. 87 | const ( 88 | MemoryOperandTypeInvalid MemoryOperandType = iota 89 | // Normal memory operand 90 | MemoryOperandTypeMemory 91 | // The memory operand is only used for address-generation. 92 | // No real memory-access is caused. 93 | MemoryOperandTypeAddressGeneration 94 | // A memory operand using `SIB` addressing form, where the index register 95 | // is not used in address calculation and scale is ignored. 96 | // No real memory-access is caused. 97 | MemoryOperandTypeMIB 98 | ) 99 | 100 | // OperandEncoding is an enum of the operand encoding. 101 | type OperandEncoding int 102 | 103 | // OperandEncoding enum 104 | const ( 105 | OperandEncodingNone OperandEncoding = iota 106 | OperandEncodingModRmReg 107 | OperandEncodingModRmRm 108 | OperandEncodingOpcode 109 | OperandEncodingNDSNDD 110 | OperandEncodingIS4 111 | OperandEncodingMask 112 | OperandEncodingDisp8 113 | OperandEncodingDisp16 114 | OperandEncodingDisp32 115 | OperandEncodingDisp64 116 | OperandEncodingDisp16_32_64 117 | OperandEncodingDisp32_32_64 118 | OperandEncodingDisp16_32_32 119 | OperandEncodingUImm8 120 | OperandEncodingUImm16 121 | OperandEncodingUImm32 122 | OperandEncodingUImm64 123 | OperandEncodingUImm16_32_64 124 | OperandEncodingUImm32_32_64 125 | OperandEncodingUImm16_32_32 126 | OperandEncodingSImm8 127 | OperandEncodingSImm16 128 | OperandEncodingSImm32 129 | OperandEncodingSImm64 130 | OperandEncodingSImm16_32_64 131 | OperandEncodingSImm32_32_64 132 | OperandEncodingSImm16_32_32 133 | OperandEncodingJImm8 134 | OperandEncodingJImm16 135 | OperandEncodingJImm32 136 | OperandEncodingJImm64 137 | OperandEncodingJImm16_32_64 138 | OperandEncodingJImm32_32_64 139 | OperandEncodingJImm16_32_32 140 | ) 141 | 142 | // DecodedOperand is an operand in a DecodedInstruction. 143 | type DecodedOperand struct { 144 | instr *DecodedInstruction 145 | zdo *C.ZydisDecodedOperand 146 | 147 | // Operand-ID. 148 | ID uint8 149 | // Type of the operand. 150 | Type OperandType 151 | // Visibility of the operand. 152 | Visibility OperandVisibility 153 | // Operand actions. 154 | Actions OperandActions 155 | // Operand encoding. 156 | Encoding OperandEncoding 157 | // Logical size of the operand (in bits). 158 | Size uint16 159 | // Element type. 160 | ElementType 161 | // Element size. 162 | ElementSize 163 | // Number of elements. 164 | ElementCount uint16 165 | // Extended info for register operands. 166 | Reg struct { 167 | Value Register 168 | } 169 | // Extended info for memory operands. 170 | Mem struct { 171 | // Type of the memory operand. 172 | Type MemoryOperandType 173 | // Segment register. 174 | Segment Register 175 | // Base register. 176 | Base Register 177 | // Index register. 178 | Index Register 179 | // Scale factor. 180 | Scale uint8 181 | // Extended info for memory-operands with displacement. 182 | Disp struct { 183 | // Signals if the displacement value is used. 184 | HasDisplacement bool 185 | // The displacement value. 186 | Value int64 187 | } 188 | } 189 | // Extended info for pointer-operands. 190 | Ptr struct { 191 | Segment uint16 192 | Offset uint32 193 | } 194 | // Extended info for immediate-operands. 195 | Imm struct { 196 | // Signals if the immediate value is signed. 197 | IsSigned bool 198 | // Signals if the immediate value contains a relative offset. 199 | // You can use `ZydisCalcAbsoluteAddress` to determine the absolute 200 | // address value. 201 | IsRelative bool 202 | // The immediate value. 203 | Value struct { 204 | Unsigned uint64 205 | Signed int64 206 | } 207 | } 208 | } 209 | 210 | // AbsoluteAddress returns the absolute address value for the given instruction operand. 211 | // 212 | // You should use this function in the following cases: 213 | // - `IMM` operands with relative address (e.g. `JMP`, `CALL`, ...) 214 | // - `MEM` operands with `RIP`/`EIP`-relative address (e.g. `MOV RAX, [RIP+0x12345678]`) 215 | // - `MEM` operands with absolute address (e.g. `MOV RAX, [0x12345678]`) 216 | // - The displacement needs to get truncated and zero extended 217 | func (do *DecodedOperand) AbsoluteAddress(runtimeAddress uint64) (uint64, error) { 218 | var resultAddress C.ZyanU64 219 | ret := C.ZydisCalcAbsoluteAddress( 220 | do.instr.zdi, 221 | do.zdo, 222 | C.ZyanU64(runtimeAddress), 223 | &resultAddress, 224 | ) 225 | if zyanFailure(ret) { 226 | return 0, fmt.Errorf("zydis: failed to compute absolute address: 0x%x", ret) 227 | } 228 | return uint64(resultAddress), nil 229 | } 230 | 231 | // RegisterContext is a mapping from register to its value 232 | type RegisterContext map[Register]uint64 233 | 234 | // AbsoluteAddressWithContext is like AbsoluteAddress, but takes some register 235 | // context values, to allow calculation of addresses depending on runtime 236 | // register values. 237 | // 238 | // Note that `IP/EIP/RIP` from the register-context will be ignored in favor 239 | // of the passed runtime-address. 240 | func (do *DecodedOperand) AbsoluteAddressWithContext(runtimeAddress uint64, context RegisterContext) (uint64, error) { 241 | var rctx C.ZydisRegisterContext 242 | for reg, val := range context { 243 | rctx.values[reg] = C.ZyanU64(val) 244 | } 245 | var resultAddress C.ZyanU64 246 | ret := C.ZydisCalcAbsoluteAddressEx( 247 | do.instr.zdi, 248 | do.zdo, 249 | C.ZyanU64(runtimeAddress), 250 | &rctx, 251 | &resultAddress, 252 | ) 253 | if zyanFailure(ret) { 254 | return 0, fmt.Errorf("zydis: failed to compute absolute address: 0x%x", ret) 255 | } 256 | return uint64(resultAddress), nil 257 | } 258 | -------------------------------------------------------------------------------- /register.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 John Papandriopoulos. All rights reserved. 2 | // Use of this source code is governed by a MIT-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package zydis 6 | 7 | // Register is an enum of processor registers. 8 | type Register int 9 | 10 | //go:generate stringer -type=Register -linecomment 11 | 12 | // Register enum values. 13 | const ( 14 | RegisterNone Register = iota // None 15 | // General purpose registers 8-bit 16 | RegisterAL // AL 17 | RegisterCL // CL 18 | RegisterDL // DL 19 | RegisterBL // BL 20 | RegisterAH // AH 21 | RegisterCH // CH 22 | RegisterDH // DH 23 | RegisterBH // BH 24 | RegisterSPL // SPL 25 | RegisterBPL // BPL 26 | RegisterSIL // SIL 27 | RegisterDIL // DIL 28 | RegisterR8B // R8B 29 | RegisterR9B // R9B 30 | RegisterR10B // R10B 31 | RegisterR11B // R11B 32 | RegisterR12B // R12B 33 | RegisterR13B // R13B 34 | RegisterR14B // R14B 35 | RegisterR15B // R15B 36 | // General purpose registers 16-bit 37 | RegisterAX // AX 38 | RegisterCX // CX 39 | RegisterDX // DX 40 | RegisterBX // BX 41 | RegisterSP // SP 42 | RegisterBP // BP 43 | RegisterSI // SI 44 | RegisterDI // DI 45 | RegisterR8W // R8W 46 | RegisterR9W // R9W 47 | RegisterR10W // R10W 48 | RegisterR11W // R11W 49 | RegisterR12W // R12W 50 | RegisterR13W // R13W 51 | RegisterR14W // R14W 52 | RegisterR15W // R15W 53 | // General purpose registers 32-bit 54 | RegisterEAX // EAX 55 | RegisterECX // ECX 56 | RegisterEDX // EDX 57 | RegisterEBX // EBX 58 | RegisterESP // ESP 59 | RegisterEBP // EBP 60 | RegisterESI // ESI 61 | RegisterEDI // EDI 62 | RegisterR8D // R8D 63 | RegisterR9D // R9D 64 | RegisterR10D // R10D 65 | RegisterR11D // R11D 66 | RegisterR12D // R12D 67 | RegisterR13D // R13D 68 | RegisterR14D // R14D 69 | RegisterR15D // R15D 70 | // General purpose registers 64-bit 71 | RegisterRAX // RAX 72 | RegisterRCX // RCX 73 | RegisterRDX // RDX 74 | RegisterRBX // RBX 75 | RegisterRSP // RSP 76 | RegisterRBP // RBP 77 | RegisterRSI // RSI 78 | RegisterRDI // RDI 79 | RegisterR8 // R8 80 | RegisterR9 // R9 81 | RegisterR10 // R10 82 | RegisterR11 // R11 83 | RegisterR12 // R12 84 | RegisterR13 // R13 85 | RegisterR14 // R14 86 | RegisterR15 // R15 87 | // Floating point legacy registers 88 | RegisterST0 // ST0 89 | RegisterST1 // ST1 90 | RegisterST2 // ST2 91 | RegisterST3 // ST3 92 | RegisterST4 // ST4 93 | RegisterST5 // ST5 94 | RegisterST6 // ST6 95 | RegisterST7 // ST7 96 | RegisterX87Control // X87Control 97 | RegisterX87Status // X87Status 98 | RegisterX87Tag // X87Tag 99 | // Floating point multimedia registers 100 | RegisterMM0 // MM0 101 | RegisterMM1 // MM1 102 | RegisterMM2 // MM2 103 | RegisterMM3 // MM3 104 | RegisterMM4 // MM4 105 | RegisterMM5 // MM5 106 | RegisterMM6 // MM6 107 | RegisterMM7 // MM7 108 | // Floating point vector registers 128-bit 109 | RegisterXMM0 // XMM0 110 | RegisterXMM1 // XMM1 111 | RegisterXMM2 // XMM2 112 | RegisterXMM3 // XMM3 113 | RegisterXMM4 // XMM4 114 | RegisterXMM5 // XMM5 115 | RegisterXMM6 // XMM6 116 | RegisterXMM7 // XMM7 117 | RegisterXMM8 // XMM8 118 | RegisterXMM9 // XMM9 119 | RegisterXMM10 // XMM10 120 | RegisterXMM11 // XMM11 121 | RegisterXMM12 // XMM12 122 | RegisterXMM13 // XMM13 123 | RegisterXMM14 // XMM14 124 | RegisterXMM15 // XMM15 125 | RegisterXMM16 // XMM16 126 | RegisterXMM17 // XMM17 127 | RegisterXMM18 // XMM18 128 | RegisterXMM19 // XMM19 129 | RegisterXMM20 // XMM20 130 | RegisterXMM21 // XMM21 131 | RegisterXMM22 // XMM22 132 | RegisterXMM23 // XMM23 133 | RegisterXMM24 // XMM24 134 | RegisterXMM25 // XMM25 135 | RegisterXMM26 // XMM26 136 | RegisterXMM27 // XMM27 137 | RegisterXMM28 // XMM28 138 | RegisterXMM29 // XMM29 139 | RegisterXMM30 // XMM30 140 | RegisterXMM31 // XMM31 141 | // Floating point vector registers 256-bit 142 | RegisterYMM0 // YMM0 143 | RegisterYMM1 // YMM1 144 | RegisterYMM2 // YMM2 145 | RegisterYMM3 // YMM3 146 | RegisterYMM4 // YMM4 147 | RegisterYMM5 // YMM5 148 | RegisterYMM6 // YMM6 149 | RegisterYMM7 // YMM7 150 | RegisterYMM8 // YMM8 151 | RegisterYMM9 // YMM9 152 | RegisterYMM10 // YMM10 153 | RegisterYMM11 // YMM11 154 | RegisterYMM12 // YMM12 155 | RegisterYMM13 // YMM13 156 | RegisterYMM14 // YMM14 157 | RegisterYMM15 // YMM15 158 | RegisterYMM16 // YMM16 159 | RegisterYMM17 // YMM17 160 | RegisterYMM18 // YMM18 161 | RegisterYMM19 // YMM19 162 | RegisterYMM20 // YMM20 163 | RegisterYMM21 // YMM21 164 | RegisterYMM22 // YMM22 165 | RegisterYMM23 // YMM23 166 | RegisterYMM24 // YMM24 167 | RegisterYMM25 // YMM25 168 | RegisterYMM26 // YMM26 169 | RegisterYMM27 // YMM27 170 | RegisterYMM28 // YMM28 171 | RegisterYMM29 // YMM29 172 | RegisterYMM30 // YMM30 173 | RegisterYMM31 // YMM31 174 | // Floating point vector registers 512-bit 175 | RegisterZMM0 // ZMM0 176 | RegisterZMM1 // ZMM1 177 | RegisterZMM2 // ZMM2 178 | RegisterZMM3 // ZMM3 179 | RegisterZMM4 // ZMM4 180 | RegisterZMM5 // ZMM5 181 | RegisterZMM6 // ZMM6 182 | RegisterZMM7 // ZMM7 183 | RegisterZMM8 // ZMM8 184 | RegisterZMM9 // ZMM9 185 | RegisterZMM10 // ZMM10 186 | RegisterZMM11 // ZMM11 187 | RegisterZMM12 // ZMM12 188 | RegisterZMM13 // ZMM13 189 | RegisterZMM14 // ZMM14 190 | RegisterZMM15 // ZMM15 191 | RegisterZMM16 // ZMM16 192 | RegisterZMM17 // ZMM17 193 | RegisterZMM18 // ZMM18 194 | RegisterZMM19 // ZMM19 195 | RegisterZMM20 // ZMM20 196 | RegisterZMM21 // ZMM21 197 | RegisterZMM22 // ZMM22 198 | RegisterZMM23 // ZMM23 199 | RegisterZMM24 // ZMM24 200 | RegisterZMM25 // ZMM25 201 | RegisterZMM26 // ZMM26 202 | RegisterZMM27 // ZMM27 203 | RegisterZMM28 // ZMM28 204 | RegisterZMM29 // ZMM29 205 | RegisterZMM30 // ZMM30 206 | RegisterZMM31 // ZMM31 207 | // Matrix registers 208 | RegisterTMM0 // TMM0 209 | RegisterTMM1 // TMM1 210 | RegisterTMM2 // TMM2 211 | RegisterTMM3 // TMM3 212 | RegisterTMM4 // TMM4 213 | RegisterTMM5 // TMM5 214 | RegisterTMM6 // TMM6 215 | RegisterTMM7 // TMM7 216 | // Flags registers 217 | RegisterFlags // Flags 218 | RegisterEFlags // EFlags 219 | RegisterRFlags // RFlags 220 | // Instruction-pointer registers 221 | RegisterIP // IP 222 | RegisterEIP // EIP 223 | RegisterRIP // RIP 224 | // Segment registers 225 | RegisterES // ES 226 | RegisterCS // CS 227 | RegisterSS // SS 228 | RegisterDS // DS 229 | RegisterFS // FS 230 | RegisterGS // GS 231 | // Table registers 232 | RegisterGDTR // GDTR 233 | RegisterLDTR // LDTR 234 | RegisterIDTR // IDTR 235 | RegisterTR // TR 236 | // Test registers 237 | RegisterTR0 // TR0 238 | RegisterTR1 // TR1 239 | RegisterTR2 // TR2 240 | RegisterTR3 // TR3 241 | RegisterTR4 // TR4 242 | RegisterTR5 // TR5 243 | RegisterTR6 // TR6 244 | RegisterTR7 // TR7 245 | // Control registers 246 | RegisterCR0 // CR0 247 | RegisterCR1 // CR1 248 | RegisterCR2 // CR2 249 | RegisterCR3 // CR3 250 | RegisterCR4 // CR4 251 | RegisterCR5 // CR5 252 | RegisterCR6 // CR6 253 | RegisterCR7 // CR7 254 | RegisterCR8 // CR8 255 | RegisterCR9 // CR9 256 | RegisterCR10 // CR10 257 | RegisterCR11 // CR11 258 | RegisterCR12 // CR12 259 | RegisterCR13 // CR13 260 | RegisterCR14 // CR14 261 | RegisterCR15 // CR15 262 | // Debug registers 263 | RegisterDR0 // DR0 264 | RegisterDR1 // DR1 265 | RegisterDR2 // DR2 266 | RegisterDR3 // DR3 267 | RegisterDR4 // DR4 268 | RegisterDR5 // DR5 269 | RegisterDR6 // DR6 270 | RegisterDR7 // DR7 271 | RegisterDR8 // DR8 272 | RegisterDR9 // DR9 273 | RegisterDR10 // DR10 274 | RegisterDR11 // DR11 275 | RegisterDR12 // DR12 276 | RegisterDR13 // DR13 277 | RegisterDR14 // DR14 278 | RegisterDR15 // DR15 279 | // Mask registers 280 | RegisterK0 // K0 281 | RegisterK1 // K1 282 | RegisterK2 // K2 283 | RegisterK3 // K3 284 | RegisterK4 // K4 285 | RegisterK5 // K5 286 | RegisterK6 // K6 287 | RegisterK7 // K7 288 | // Bound registers 289 | RegisterBND0 // BND0 290 | RegisterBND1 // BND1 291 | RegisterBND2 // BND2 292 | RegisterBND3 // BND3 293 | RegisterBNDCfg // BNDCfg 294 | RegisterBNDStatus // BNDStatus 295 | // Uncategorized 296 | RegisterMXCSR // MXCSR 297 | RegisterPKRU // PKRU 298 | RegisterXCR0 // XCR0 299 | ) 300 | -------------------------------------------------------------------------------- /register_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Register -linecomment"; DO NOT EDIT. 2 | 3 | package zydis 4 | 5 | import "strconv" 6 | 7 | func _() { 8 | // An "invalid array index" compiler error signifies that the constant values have changed. 9 | // Re-run the stringer command to generate them again. 10 | var x [1]struct{} 11 | _ = x[RegisterNone-0] 12 | _ = x[RegisterAL-1] 13 | _ = x[RegisterCL-2] 14 | _ = x[RegisterDL-3] 15 | _ = x[RegisterBL-4] 16 | _ = x[RegisterAH-5] 17 | _ = x[RegisterCH-6] 18 | _ = x[RegisterDH-7] 19 | _ = x[RegisterBH-8] 20 | _ = x[RegisterSPL-9] 21 | _ = x[RegisterBPL-10] 22 | _ = x[RegisterSIL-11] 23 | _ = x[RegisterDIL-12] 24 | _ = x[RegisterR8B-13] 25 | _ = x[RegisterR9B-14] 26 | _ = x[RegisterR10B-15] 27 | _ = x[RegisterR11B-16] 28 | _ = x[RegisterR12B-17] 29 | _ = x[RegisterR13B-18] 30 | _ = x[RegisterR14B-19] 31 | _ = x[RegisterR15B-20] 32 | _ = x[RegisterAX-21] 33 | _ = x[RegisterCX-22] 34 | _ = x[RegisterDX-23] 35 | _ = x[RegisterBX-24] 36 | _ = x[RegisterSP-25] 37 | _ = x[RegisterBP-26] 38 | _ = x[RegisterSI-27] 39 | _ = x[RegisterDI-28] 40 | _ = x[RegisterR8W-29] 41 | _ = x[RegisterR9W-30] 42 | _ = x[RegisterR10W-31] 43 | _ = x[RegisterR11W-32] 44 | _ = x[RegisterR12W-33] 45 | _ = x[RegisterR13W-34] 46 | _ = x[RegisterR14W-35] 47 | _ = x[RegisterR15W-36] 48 | _ = x[RegisterEAX-37] 49 | _ = x[RegisterECX-38] 50 | _ = x[RegisterEDX-39] 51 | _ = x[RegisterEBX-40] 52 | _ = x[RegisterESP-41] 53 | _ = x[RegisterEBP-42] 54 | _ = x[RegisterESI-43] 55 | _ = x[RegisterEDI-44] 56 | _ = x[RegisterR8D-45] 57 | _ = x[RegisterR9D-46] 58 | _ = x[RegisterR10D-47] 59 | _ = x[RegisterR11D-48] 60 | _ = x[RegisterR12D-49] 61 | _ = x[RegisterR13D-50] 62 | _ = x[RegisterR14D-51] 63 | _ = x[RegisterR15D-52] 64 | _ = x[RegisterRAX-53] 65 | _ = x[RegisterRCX-54] 66 | _ = x[RegisterRDX-55] 67 | _ = x[RegisterRBX-56] 68 | _ = x[RegisterRSP-57] 69 | _ = x[RegisterRBP-58] 70 | _ = x[RegisterRSI-59] 71 | _ = x[RegisterRDI-60] 72 | _ = x[RegisterR8-61] 73 | _ = x[RegisterR9-62] 74 | _ = x[RegisterR10-63] 75 | _ = x[RegisterR11-64] 76 | _ = x[RegisterR12-65] 77 | _ = x[RegisterR13-66] 78 | _ = x[RegisterR14-67] 79 | _ = x[RegisterR15-68] 80 | _ = x[RegisterST0-69] 81 | _ = x[RegisterST1-70] 82 | _ = x[RegisterST2-71] 83 | _ = x[RegisterST3-72] 84 | _ = x[RegisterST4-73] 85 | _ = x[RegisterST5-74] 86 | _ = x[RegisterST6-75] 87 | _ = x[RegisterST7-76] 88 | _ = x[RegisterX87Control-77] 89 | _ = x[RegisterX87Status-78] 90 | _ = x[RegisterX87Tag-79] 91 | _ = x[RegisterMM0-80] 92 | _ = x[RegisterMM1-81] 93 | _ = x[RegisterMM2-82] 94 | _ = x[RegisterMM3-83] 95 | _ = x[RegisterMM4-84] 96 | _ = x[RegisterMM5-85] 97 | _ = x[RegisterMM6-86] 98 | _ = x[RegisterMM7-87] 99 | _ = x[RegisterXMM0-88] 100 | _ = x[RegisterXMM1-89] 101 | _ = x[RegisterXMM2-90] 102 | _ = x[RegisterXMM3-91] 103 | _ = x[RegisterXMM4-92] 104 | _ = x[RegisterXMM5-93] 105 | _ = x[RegisterXMM6-94] 106 | _ = x[RegisterXMM7-95] 107 | _ = x[RegisterXMM8-96] 108 | _ = x[RegisterXMM9-97] 109 | _ = x[RegisterXMM10-98] 110 | _ = x[RegisterXMM11-99] 111 | _ = x[RegisterXMM12-100] 112 | _ = x[RegisterXMM13-101] 113 | _ = x[RegisterXMM14-102] 114 | _ = x[RegisterXMM15-103] 115 | _ = x[RegisterXMM16-104] 116 | _ = x[RegisterXMM17-105] 117 | _ = x[RegisterXMM18-106] 118 | _ = x[RegisterXMM19-107] 119 | _ = x[RegisterXMM20-108] 120 | _ = x[RegisterXMM21-109] 121 | _ = x[RegisterXMM22-110] 122 | _ = x[RegisterXMM23-111] 123 | _ = x[RegisterXMM24-112] 124 | _ = x[RegisterXMM25-113] 125 | _ = x[RegisterXMM26-114] 126 | _ = x[RegisterXMM27-115] 127 | _ = x[RegisterXMM28-116] 128 | _ = x[RegisterXMM29-117] 129 | _ = x[RegisterXMM30-118] 130 | _ = x[RegisterXMM31-119] 131 | _ = x[RegisterYMM0-120] 132 | _ = x[RegisterYMM1-121] 133 | _ = x[RegisterYMM2-122] 134 | _ = x[RegisterYMM3-123] 135 | _ = x[RegisterYMM4-124] 136 | _ = x[RegisterYMM5-125] 137 | _ = x[RegisterYMM6-126] 138 | _ = x[RegisterYMM7-127] 139 | _ = x[RegisterYMM8-128] 140 | _ = x[RegisterYMM9-129] 141 | _ = x[RegisterYMM10-130] 142 | _ = x[RegisterYMM11-131] 143 | _ = x[RegisterYMM12-132] 144 | _ = x[RegisterYMM13-133] 145 | _ = x[RegisterYMM14-134] 146 | _ = x[RegisterYMM15-135] 147 | _ = x[RegisterYMM16-136] 148 | _ = x[RegisterYMM17-137] 149 | _ = x[RegisterYMM18-138] 150 | _ = x[RegisterYMM19-139] 151 | _ = x[RegisterYMM20-140] 152 | _ = x[RegisterYMM21-141] 153 | _ = x[RegisterYMM22-142] 154 | _ = x[RegisterYMM23-143] 155 | _ = x[RegisterYMM24-144] 156 | _ = x[RegisterYMM25-145] 157 | _ = x[RegisterYMM26-146] 158 | _ = x[RegisterYMM27-147] 159 | _ = x[RegisterYMM28-148] 160 | _ = x[RegisterYMM29-149] 161 | _ = x[RegisterYMM30-150] 162 | _ = x[RegisterYMM31-151] 163 | _ = x[RegisterZMM0-152] 164 | _ = x[RegisterZMM1-153] 165 | _ = x[RegisterZMM2-154] 166 | _ = x[RegisterZMM3-155] 167 | _ = x[RegisterZMM4-156] 168 | _ = x[RegisterZMM5-157] 169 | _ = x[RegisterZMM6-158] 170 | _ = x[RegisterZMM7-159] 171 | _ = x[RegisterZMM8-160] 172 | _ = x[RegisterZMM9-161] 173 | _ = x[RegisterZMM10-162] 174 | _ = x[RegisterZMM11-163] 175 | _ = x[RegisterZMM12-164] 176 | _ = x[RegisterZMM13-165] 177 | _ = x[RegisterZMM14-166] 178 | _ = x[RegisterZMM15-167] 179 | _ = x[RegisterZMM16-168] 180 | _ = x[RegisterZMM17-169] 181 | _ = x[RegisterZMM18-170] 182 | _ = x[RegisterZMM19-171] 183 | _ = x[RegisterZMM20-172] 184 | _ = x[RegisterZMM21-173] 185 | _ = x[RegisterZMM22-174] 186 | _ = x[RegisterZMM23-175] 187 | _ = x[RegisterZMM24-176] 188 | _ = x[RegisterZMM25-177] 189 | _ = x[RegisterZMM26-178] 190 | _ = x[RegisterZMM27-179] 191 | _ = x[RegisterZMM28-180] 192 | _ = x[RegisterZMM29-181] 193 | _ = x[RegisterZMM30-182] 194 | _ = x[RegisterZMM31-183] 195 | _ = x[RegisterTMM0-184] 196 | _ = x[RegisterTMM1-185] 197 | _ = x[RegisterTMM2-186] 198 | _ = x[RegisterTMM3-187] 199 | _ = x[RegisterTMM4-188] 200 | _ = x[RegisterTMM5-189] 201 | _ = x[RegisterTMM6-190] 202 | _ = x[RegisterTMM7-191] 203 | _ = x[RegisterFlags-192] 204 | _ = x[RegisterEFlags-193] 205 | _ = x[RegisterRFlags-194] 206 | _ = x[RegisterIP-195] 207 | _ = x[RegisterEIP-196] 208 | _ = x[RegisterRIP-197] 209 | _ = x[RegisterES-198] 210 | _ = x[RegisterCS-199] 211 | _ = x[RegisterSS-200] 212 | _ = x[RegisterDS-201] 213 | _ = x[RegisterFS-202] 214 | _ = x[RegisterGS-203] 215 | _ = x[RegisterGDTR-204] 216 | _ = x[RegisterLDTR-205] 217 | _ = x[RegisterIDTR-206] 218 | _ = x[RegisterTR-207] 219 | _ = x[RegisterTR0-208] 220 | _ = x[RegisterTR1-209] 221 | _ = x[RegisterTR2-210] 222 | _ = x[RegisterTR3-211] 223 | _ = x[RegisterTR4-212] 224 | _ = x[RegisterTR5-213] 225 | _ = x[RegisterTR6-214] 226 | _ = x[RegisterTR7-215] 227 | _ = x[RegisterCR0-216] 228 | _ = x[RegisterCR1-217] 229 | _ = x[RegisterCR2-218] 230 | _ = x[RegisterCR3-219] 231 | _ = x[RegisterCR4-220] 232 | _ = x[RegisterCR5-221] 233 | _ = x[RegisterCR6-222] 234 | _ = x[RegisterCR7-223] 235 | _ = x[RegisterCR8-224] 236 | _ = x[RegisterCR9-225] 237 | _ = x[RegisterCR10-226] 238 | _ = x[RegisterCR11-227] 239 | _ = x[RegisterCR12-228] 240 | _ = x[RegisterCR13-229] 241 | _ = x[RegisterCR14-230] 242 | _ = x[RegisterCR15-231] 243 | _ = x[RegisterDR0-232] 244 | _ = x[RegisterDR1-233] 245 | _ = x[RegisterDR2-234] 246 | _ = x[RegisterDR3-235] 247 | _ = x[RegisterDR4-236] 248 | _ = x[RegisterDR5-237] 249 | _ = x[RegisterDR6-238] 250 | _ = x[RegisterDR7-239] 251 | _ = x[RegisterDR8-240] 252 | _ = x[RegisterDR9-241] 253 | _ = x[RegisterDR10-242] 254 | _ = x[RegisterDR11-243] 255 | _ = x[RegisterDR12-244] 256 | _ = x[RegisterDR13-245] 257 | _ = x[RegisterDR14-246] 258 | _ = x[RegisterDR15-247] 259 | _ = x[RegisterK0-248] 260 | _ = x[RegisterK1-249] 261 | _ = x[RegisterK2-250] 262 | _ = x[RegisterK3-251] 263 | _ = x[RegisterK4-252] 264 | _ = x[RegisterK5-253] 265 | _ = x[RegisterK6-254] 266 | _ = x[RegisterK7-255] 267 | _ = x[RegisterBND0-256] 268 | _ = x[RegisterBND1-257] 269 | _ = x[RegisterBND2-258] 270 | _ = x[RegisterBND3-259] 271 | _ = x[RegisterBNDCfg-260] 272 | _ = x[RegisterBNDStatus-261] 273 | _ = x[RegisterMXCSR-262] 274 | _ = x[RegisterPKRU-263] 275 | _ = x[RegisterXCR0-264] 276 | } 277 | 278 | const _Register_name = "NoneALCLDLBLAHCHDHBHSPLBPLSILDILR8BR9BR10BR11BR12BR13BR14BR15BAXCXDXBXSPBPSIDIR8WR9WR10WR11WR12WR13WR14WR15WEAXECXEDXEBXESPEBPESIEDIR8DR9DR10DR11DR12DR13DR14DR15DRAXRCXRDXRBXRSPRBPRSIRDIR8R9R10R11R12R13R14R15ST0ST1ST2ST3ST4ST5ST6ST7X87ControlX87StatusX87TagMM0MM1MM2MM3MM4MM5MM6MM7XMM0XMM1XMM2XMM3XMM4XMM5XMM6XMM7XMM8XMM9XMM10XMM11XMM12XMM13XMM14XMM15XMM16XMM17XMM18XMM19XMM20XMM21XMM22XMM23XMM24XMM25XMM26XMM27XMM28XMM29XMM30XMM31YMM0YMM1YMM2YMM3YMM4YMM5YMM6YMM7YMM8YMM9YMM10YMM11YMM12YMM13YMM14YMM15YMM16YMM17YMM18YMM19YMM20YMM21YMM22YMM23YMM24YMM25YMM26YMM27YMM28YMM29YMM30YMM31ZMM0ZMM1ZMM2ZMM3ZMM4ZMM5ZMM6ZMM7ZMM8ZMM9ZMM10ZMM11ZMM12ZMM13ZMM14ZMM15ZMM16ZMM17ZMM18ZMM19ZMM20ZMM21ZMM22ZMM23ZMM24ZMM25ZMM26ZMM27ZMM28ZMM29ZMM30ZMM31TMM0TMM1TMM2TMM3TMM4TMM5TMM6TMM7FlagsEFlagsRFlagsIPEIPRIPESCSSSDSFSGSGDTRLDTRIDTRTRTR0TR1TR2TR3TR4TR5TR6TR7CR0CR1CR2CR3CR4CR5CR6CR7CR8CR9CR10CR11CR12CR13CR14CR15DR0DR1DR2DR3DR4DR5DR6DR7DR8DR9DR10DR11DR12DR13DR14DR15K0K1K2K3K4K5K6K7BND0BND1BND2BND3BNDCfgBNDStatusMXCSRPKRUXCR0" 279 | 280 | var _Register_index = [...]uint16{0, 4, 6, 8, 10, 12, 14, 16, 18, 20, 23, 26, 29, 32, 35, 38, 42, 46, 50, 54, 58, 62, 64, 66, 68, 70, 72, 74, 76, 78, 81, 84, 88, 92, 96, 100, 104, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 142, 146, 150, 154, 158, 162, 165, 168, 171, 174, 177, 180, 183, 186, 188, 190, 193, 196, 199, 202, 205, 208, 211, 214, 217, 220, 223, 226, 229, 232, 242, 251, 257, 260, 263, 266, 269, 272, 275, 278, 281, 285, 289, 293, 297, 301, 305, 309, 313, 317, 321, 326, 331, 336, 341, 346, 351, 356, 361, 366, 371, 376, 381, 386, 391, 396, 401, 406, 411, 416, 421, 426, 431, 435, 439, 443, 447, 451, 455, 459, 463, 467, 471, 476, 481, 486, 491, 496, 501, 506, 511, 516, 521, 526, 531, 536, 541, 546, 551, 556, 561, 566, 571, 576, 581, 585, 589, 593, 597, 601, 605, 609, 613, 617, 621, 626, 631, 636, 641, 646, 651, 656, 661, 666, 671, 676, 681, 686, 691, 696, 701, 706, 711, 716, 721, 726, 731, 735, 739, 743, 747, 751, 755, 759, 763, 768, 774, 780, 782, 785, 788, 790, 792, 794, 796, 798, 800, 804, 808, 812, 814, 817, 820, 823, 826, 829, 832, 835, 838, 841, 844, 847, 850, 853, 856, 859, 862, 865, 868, 872, 876, 880, 884, 888, 892, 895, 898, 901, 904, 907, 910, 913, 916, 919, 922, 926, 930, 934, 938, 942, 946, 948, 950, 952, 954, 956, 958, 960, 962, 966, 970, 974, 978, 984, 993, 998, 1002, 1006} 281 | 282 | func (i Register) String() string { 283 | if i < 0 || i >= Register(len(_Register_index)-1) { 284 | return "Register(" + strconv.FormatInt(int64(i), 10) + ")" 285 | } 286 | return _Register_name[_Register_index[i]:_Register_index[i+1]] 287 | } 288 | --------------------------------------------------------------------------------