hexcore-capstone 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,74 @@
1
+ Capstone Engine
2
+ ===============
3
+
4
+ [![Build status](https://ci.appveyor.com/api/projects/status/a4wvbn89wu3pinas/branch/next?svg=true)](https://ci.appveyor.com/project/aquynh/capstone/branch/next)
5
+ [![pypi package](https://badge.fury.io/py/capstone.svg)](https://pypi.python.org/pypi/capstone)
6
+ [![pypi downloads](https://pepy.tech/badge/capstone)](https://pepy.tech/project/capstone)
7
+ [![oss-fuzz Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/capstone.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:capstone)
8
+
9
+ Capstone is a disassembly framework with the target of becoming the ultimate
10
+ disasm engine for binary analysis and reversing in the security community.
11
+
12
+ Created by Nguyen Anh Quynh, then developed and maintained by a small community,
13
+ Capstone offers some unparalleled features:
14
+
15
+ - Support multiple hardware architectures: ARM, ARM64 (ARMv8), BPF, Ethereum VM,
16
+ M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G), SH, Sparc, SystemZ,
17
+ TMS320C64X, TriCore, Webassembly, XCore and X86 (16, 32, 64).
18
+
19
+ - Having clean/simple/lightweight/intuitive architecture-neutral API.
20
+
21
+ - Provide details on disassembled instruction (called “decomposer” by others).
22
+
23
+ - Provide semantics of the disassembled instruction, such as list of implicit
24
+ registers read & written.
25
+
26
+ - Implemented in pure C language, with lightweight bindings for Swift, D, Clojure, F#,
27
+ Common Lisp, Visual Basic, PHP, PowerShell, Emacs, Haskell, Perl, Python,
28
+ Ruby, C#, NodeJS, Java, GO, C++, OCaml, Lua, Rust, Delphi, Free Pascal & Vala
29
+ ready either in main code, or provided externally by the community).
30
+
31
+ - Native support for all popular platforms: Windows, Mac OSX, iOS, Android,
32
+ Linux, \*BSD, Solaris, etc.
33
+
34
+ - Thread-safe by design.
35
+
36
+ - Special support for embedding into firmware or OS kernel.
37
+
38
+ - High performance & suitable for malware analysis (capable of handling various
39
+ X86 malware tricks).
40
+
41
+ - Distributed under the open source BSD license.
42
+
43
+ Further information is available at https://www.capstone-engine.org
44
+
45
+
46
+ Compile
47
+ -------
48
+
49
+ See COMPILE.TXT file for how to compile and install Capstone.
50
+
51
+
52
+ Documentation
53
+ -------------
54
+
55
+ See docs/README for how to customize & program your own tools with Capstone.
56
+
57
+
58
+ Hack
59
+ ----
60
+
61
+ See HACK.TXT file for the structure of the source code.
62
+
63
+
64
+ Fuzz
65
+ ----
66
+
67
+ See suite/fuzz/README.md for more information.
68
+
69
+
70
+ License
71
+ -------
72
+
73
+ This project is released under the BSD license. If you redistribute the binary
74
+ or source code of Capstone, please attach file LICENSE.TXT with your products.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexcore-capstone",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Modern Node.js bindings for Capstone disassembler engine using N-API",
5
5
  "main": "./index.js",
6
6
  "module": "./index.mjs",
@@ -72,7 +72,7 @@
72
72
  "binding.gyp",
73
73
  "index.js",
74
74
  "index.mjs",
75
- "index.d.ts"
75
+ "README.md"
76
76
  ],
77
77
  "binary": {
78
78
  "napi_versions": [
package/index.d.ts DELETED
@@ -1,448 +0,0 @@
1
- /**
2
- * HexCore Capstone - TypeScript Definitions
3
- * Modern N-API bindings for Capstone disassembler engine
4
- *
5
- * Copyright (c) HikariSystem. All rights reserved.
6
- * Licensed under MIT License.
7
- */
8
-
9
- /// <reference types="node" />
10
-
11
- /**
12
- * Architecture constants
13
- */
14
- export const ARCH: {
15
- readonly ARM: number;
16
- readonly ARM64: number;
17
- readonly MIPS: number;
18
- readonly X86: number;
19
- readonly PPC: number;
20
- readonly SPARC: number;
21
- readonly SYSZ: number;
22
- readonly XCORE: number;
23
- readonly M68K: number;
24
- readonly TMS320C64X: number;
25
- readonly M680X: number;
26
- readonly EVM: number;
27
- readonly WASM?: number;
28
- readonly BPF?: number;
29
- readonly RISCV?: number;
30
- };
31
-
32
- /**
33
- * Mode constants
34
- */
35
- export const MODE: {
36
- readonly LITTLE_ENDIAN: number;
37
- readonly BIG_ENDIAN: number;
38
- readonly ARM: number;
39
- readonly THUMB: number;
40
- readonly MCLASS: number;
41
- readonly V8: number;
42
- readonly MODE_16: number;
43
- readonly MODE_32: number;
44
- readonly MODE_64: number;
45
- readonly MICRO: number;
46
- readonly MIPS3: number;
47
- readonly MIPS32R6: number;
48
- readonly MIPS2: number;
49
- readonly V9: number;
50
- readonly QPX: number;
51
- readonly M68K_000: number;
52
- readonly M68K_010: number;
53
- readonly M68K_020: number;
54
- readonly M68K_030: number;
55
- readonly M68K_040: number;
56
- readonly M68K_060: number;
57
- readonly RISCV32?: number;
58
- readonly RISCV64?: number;
59
- readonly RISCVC?: number;
60
- };
61
-
62
- /**
63
- * Option type constants
64
- */
65
- export const OPT: {
66
- readonly SYNTAX: number;
67
- readonly DETAIL: number;
68
- readonly MODE: number;
69
- readonly MEM: number;
70
- readonly SKIPDATA: number;
71
- readonly SKIPDATA_SETUP: number;
72
- readonly MNEMONIC: number;
73
- readonly UNSIGNED: number;
74
- };
75
-
76
- /**
77
- * Option value constants
78
- */
79
- export const OPT_VALUE: {
80
- readonly OFF: number;
81
- readonly ON: number;
82
- readonly SYNTAX_DEFAULT: number;
83
- readonly SYNTAX_INTEL: number;
84
- readonly SYNTAX_ATT: number;
85
- readonly SYNTAX_NOREGNAME: number;
86
- readonly SYNTAX_MASM: number;
87
- };
88
-
89
- /**
90
- * Error code constants
91
- */
92
- export const ERR: {
93
- readonly OK: number;
94
- readonly MEM: number;
95
- readonly ARCH: number;
96
- readonly HANDLE: number;
97
- readonly CSH: number;
98
- readonly MODE: number;
99
- readonly OPTION: number;
100
- readonly DETAIL: number;
101
- readonly MEMSETUP: number;
102
- readonly VERSION: number;
103
- readonly DIET: number;
104
- readonly SKIPDATA: number;
105
- readonly X86_ATT: number;
106
- readonly X86_INTEL: number;
107
- readonly X86_MASM: number;
108
- };
109
-
110
- /**
111
- * Memory operand structure
112
- */
113
- export interface MemoryOperand {
114
- segment?: number;
115
- base: number;
116
- index?: number;
117
- scale?: number;
118
- disp: number;
119
- }
120
-
121
- /**
122
- * x86 operand structure
123
- */
124
- export interface X86Operand {
125
- type: number;
126
- size: number;
127
- access: number;
128
- avxBcast: number;
129
- avxZeroOpmask: boolean;
130
- reg?: number;
131
- imm?: number;
132
- mem?: MemoryOperand;
133
- }
134
-
135
- /**
136
- * x86 instruction detail
137
- */
138
- export interface X86Detail {
139
- prefix: number[];
140
- opcode: number[];
141
- rexPrefix: number;
142
- addrSize: number;
143
- modRM: number;
144
- sib: number;
145
- disp: number;
146
- sibIndex: number;
147
- sibScale: number;
148
- sibBase: number;
149
- xopCC: number;
150
- sseCC: number;
151
- avxCC: number;
152
- avxSAE: boolean;
153
- avxRM: number;
154
- eflags: number;
155
- operands: X86Operand[];
156
- }
157
-
158
- /**
159
- * ARM operand structure
160
- */
161
- export interface ArmOperand {
162
- type: number;
163
- access: number;
164
- reg?: number;
165
- imm?: number;
166
- fp?: number;
167
- }
168
-
169
- /**
170
- * ARM instruction detail
171
- */
172
- export interface ArmDetail {
173
- usermode: boolean;
174
- vectorSize: number;
175
- vectorData: number;
176
- cpsMode: number;
177
- cpsFlag: number;
178
- cc: number;
179
- updateFlags: boolean;
180
- writeback: boolean;
181
- memBarrier: number;
182
- operands: ArmOperand[];
183
- }
184
-
185
- /**
186
- * ARM64 operand structure
187
- */
188
- export interface Arm64Operand {
189
- type: number;
190
- access: number;
191
- reg?: number;
192
- imm?: number;
193
- fp?: number;
194
- }
195
-
196
- /**
197
- * ARM64 instruction detail
198
- */
199
- export interface Arm64Detail {
200
- cc: number;
201
- updateFlags: boolean;
202
- writeback: boolean;
203
- operands: Arm64Operand[];
204
- }
205
-
206
- /**
207
- * MIPS operand structure
208
- */
209
- export interface MipsOperand {
210
- type: number;
211
- reg?: number;
212
- imm?: number;
213
- mem?: {
214
- base: number;
215
- disp: number;
216
- };
217
- }
218
-
219
- /**
220
- * MIPS instruction detail
221
- */
222
- export interface MipsDetail {
223
- operands: MipsOperand[];
224
- }
225
-
226
- /**
227
- * Instruction detail (when detail mode is enabled)
228
- */
229
- export interface InstructionDetail {
230
- regsRead: number[];
231
- regsWrite: number[];
232
- groups: number[];
233
- x86?: X86Detail;
234
- arm?: ArmDetail;
235
- arm64?: Arm64Detail;
236
- mips?: MipsDetail;
237
- }
238
-
239
- /**
240
- * Disassembled instruction
241
- */
242
- export interface Instruction {
243
- /** Instruction ID */
244
- id: number;
245
- /** Address of this instruction */
246
- address: number;
247
- /** Size of this instruction in bytes */
248
- size: number;
249
- /** Raw bytes of this instruction */
250
- bytes: Buffer;
251
- /** Mnemonic (e.g., "mov", "push") */
252
- mnemonic: string;
253
- /** Operand string (e.g., "rax, rbx") */
254
- opStr: string;
255
- /** Detailed info (only when detail mode is enabled) */
256
- detail?: InstructionDetail;
257
- }
258
-
259
- /**
260
- * Version information
261
- */
262
- export interface Version {
263
- major: number;
264
- minor: number;
265
- string: string;
266
- }
267
-
268
- /**
269
- * Capstone disassembler class
270
- *
271
- * @example
272
- * ```typescript
273
- * import { Capstone, ARCH, MODE, OPT, OPT_VALUE } from 'hexcore-capstone';
274
- *
275
- * // Create disassembler for x86-64
276
- * const cs = new Capstone(ARCH.X86, MODE.MODE_64);
277
- *
278
- * // Enable detail mode for operand info
279
- * cs.setOption(OPT.DETAIL, OPT_VALUE.ON);
280
- *
281
- * // Disassemble code
282
- * const code = Buffer.from([0x55, 0x48, 0x89, 0xe5]);
283
- * const instructions = cs.disasm(code, 0x1000);
284
- *
285
- * for (const insn of instructions) {
286
- * console.log(`${insn.address.toString(16)}: ${insn.mnemonic} ${insn.opStr}`);
287
- * }
288
- *
289
- * // Clean up
290
- * cs.close();
291
- * ```
292
- */
293
- export class Capstone {
294
- /**
295
- * Create a new Capstone disassembler instance
296
- *
297
- * @param arch - Architecture constant (use ARCH.X86, ARCH.ARM, etc.)
298
- * @param mode - Mode flags (use MODE.MODE_64, MODE.LITTLE_ENDIAN, etc.)
299
- * @throws Error if architecture or mode is invalid
300
- *
301
- * @example
302
- * ```typescript
303
- * // x86-64 disassembler
304
- * const cs64 = new Capstone(ARCH.X86, MODE.MODE_64);
305
- *
306
- * // ARM Thumb mode
307
- * const csArm = new Capstone(ARCH.ARM, MODE.THUMB);
308
- *
309
- * // MIPS big-endian 32-bit
310
- * const csMips = new Capstone(ARCH.MIPS, MODE.MODE_32 | MODE.BIG_ENDIAN);
311
- * ```
312
- */
313
- constructor(arch: number, mode: number);
314
-
315
- /**
316
- * Disassemble code buffer (synchronous)
317
- *
318
- * **Note:** For large buffers (>1MB), use `disasmAsync()` to avoid blocking.
319
- *
320
- * @param code - Buffer containing machine code to disassemble
321
- * @param address - Base address of the code (for correct jump targets)
322
- * @param count - Maximum number of instructions to disassemble (0 = all)
323
- * @returns Array of disassembled instructions
324
- *
325
- * @example
326
- * ```typescript
327
- * const code = Buffer.from([0x55, 0x48, 0x89, 0xe5, 0xc3]);
328
- * const insns = cs.disasm(code, 0x401000);
329
- * // Returns: push rbp, mov rbp,rsp, ret
330
- * ```
331
- */
332
- disasm(code: Buffer | Uint8Array, address: number, count?: number): Instruction[];
333
-
334
- /**
335
- * Disassemble code buffer (asynchronous, non-blocking)
336
- *
337
- * Use this method for large buffers to avoid blocking the event loop.
338
- * The disassembly runs in a background thread and returns a Promise.
339
- *
340
- * @param code - Buffer containing machine code to disassemble
341
- * @param address - Base address of the code (for correct jump targets)
342
- * @param count - Maximum number of instructions to disassemble (0 = all)
343
- * @returns Promise resolving to array of disassembled instructions
344
- *
345
- * @example
346
- * ```typescript
347
- * // Large file async disassembly
348
- * const largeCode = fs.readFileSync('large_binary.bin');
349
- * const insns = await cs.disasmAsync(largeCode, 0x401000);
350
- * console.log(`Disassembled ${insns.length} instructions`);
351
- * ```
352
- */
353
- disasmAsync(code: Buffer | Uint8Array, address: number, count?: number): Promise<Instruction[]>;
354
-
355
- /**
356
- * Set a disassembler option
357
- *
358
- * @param type - Option type (OPT.DETAIL, OPT.SYNTAX, etc.)
359
- * @param value - Option value (OPT_VALUE.ON, OPT_VALUE.SYNTAX_INTEL, etc.)
360
- * @returns true on success, throws on failure
361
- *
362
- * @example
363
- * ```typescript
364
- * // Enable detailed instruction info
365
- * cs.setOption(OPT.DETAIL, OPT_VALUE.ON);
366
- *
367
- * // Use Intel syntax (default)
368
- * cs.setOption(OPT.SYNTAX, OPT_VALUE.SYNTAX_INTEL);
369
- *
370
- * // Use AT&T syntax
371
- * cs.setOption(OPT.SYNTAX, OPT_VALUE.SYNTAX_ATT);
372
- * ```
373
- */
374
- setOption(type: number, value: number): boolean;
375
-
376
- /**
377
- * Close the disassembler and free resources
378
- *
379
- * Always call this when done to prevent memory leaks.
380
- */
381
- close(): void;
382
-
383
- /**
384
- * Get register name by ID
385
- *
386
- * @param regId - Register ID from instruction details
387
- * @returns Register name (e.g., "rax", "eip") or null if not found
388
- *
389
- * @example
390
- * ```typescript
391
- * const insn = cs.disasm(code, 0x1000)[0];
392
- * if (insn.detail?.x86?.operands[0]?.reg) {
393
- * console.log(cs.regName(insn.detail.x86.operands[0].reg)); // "rbp"
394
- * }
395
- * ```
396
- */
397
- regName(regId: number): string | null;
398
-
399
- /**
400
- * Get instruction name by ID
401
- *
402
- * @param insnId - Instruction ID from disassembled instruction
403
- * @returns Instruction name or null if not found
404
- */
405
- insnName(insnId: number): string | null;
406
-
407
- /**
408
- * Get group name by ID
409
- *
410
- * @param groupId - Group ID from instruction details
411
- * @returns Group name (e.g., "jump", "call", "ret") or null
412
- */
413
- groupName(groupId: number): string | null;
414
-
415
- /**
416
- * Check if the disassembler handle is still open
417
- * @returns true if open
418
- */
419
- isOpen(): boolean;
420
-
421
- /**
422
- * Get the last error code
423
- * @returns Error code (use ERR constants)
424
- */
425
- getError(): number;
426
-
427
- /**
428
- * Get error message string
429
- * @param err - Error code (optional, defaults to last error)
430
- * @returns Error message
431
- */
432
- strError(err?: number): string;
433
- }
434
-
435
- /**
436
- * Get Capstone version
437
- * @returns Version information
438
- */
439
- export function version(): Version;
440
-
441
- /**
442
- * Check if an architecture is supported
443
- * @param arch Architecture constant
444
- * @returns true if supported
445
- */
446
- export function support(arch: number): boolean;
447
-
448
- export default Capstone;