MCPcopy Create free account
hub / github.com/capstone-engine/capstone / cs_open

Function cs_open

cs.c:466–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

464
465CAPSTONE_EXPORT
466cs_err CAPSTONE_API cs_open(cs_arch arch, cs_mode mode, csh *handle)
467{
468 cs_err err;
469 struct cs_struct *ud;
470 if (!cs_mem_malloc || !cs_mem_calloc || !cs_mem_realloc || !cs_mem_free || !cs_vsnprintf)
471 // Error: before cs_open(), dynamic memory management must be initialized
472 // with cs_option(CS_OPT_MEM)
473 return CS_ERR_MEMSETUP;
474
475 if (arch < CS_ARCH_MAX && arch_configs[arch].arch_init) {
476 // verify if requested mode is valid
477 if (mode & arch_configs[arch].arch_disallowed_mode_mask) {
478 *handle = 0;
479 return CS_ERR_MODE;
480 }
481
482 ud = cs_mem_calloc(1, sizeof(*ud));
483 if (!ud) {
484 // memory insufficient
485 return CS_ERR_MEM;
486 }
487
488 ud->errnum = CS_ERR_OK;
489 ud->arch = arch;
490 ud->mode = mode;
491 // by default, do not break instruction into details
492 ud->detail = CS_OPT_OFF;
493
494 // default skipdata setup
495 ud->skipdata_setup.mnemonic = SKIPDATA_MNEM;
496
497 err = arch_configs[ud->arch].arch_init(ud);
498 if (err) {
499 cs_mem_free(ud);
500 *handle = 0;
501 return err;
502 }
503
504 *handle = (uintptr_t)ud;
505
506 return CS_ERR_OK;
507 } else {
508 *handle = 0;
509 return CS_ERR_ARCH;
510 }
511}
512
513CAPSTONE_EXPORT
514cs_err CAPSTONE_API cs_close(csh *handle)

Callers 15

mainFunction · 0.85
mainFunction · 0.85
testFunction · 0.85
setup_MCFunction · 0.85
setup_issueFunction · 0.85
test_invalidsFunction · 0.85
test_validsFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.85
LLVMFuzzerTestOneInputFunction · 0.85
mainFunction · 0.85
cs_driver_helloFunction · 0.85
bs_openFunction · 0.85

Calls

no outgoing calls

Tested by 15

mainFunction · 0.68
testFunction · 0.68
test_invalidsFunction · 0.68
test_validsFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68
testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…