当前位置: 首页>>代码示例>>C++>>正文


C++ cs_open函数代码示例

本文整理汇总了C++中cs_open函数的典型用法代码示例。如果您正苦于以下问题:C++ cs_open函数的具体用法?C++ cs_open怎么用?C++ cs_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了cs_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: eat_instructions

size_t eat_instructions(void *func, size_t target)
{
  csh handle;
  cs_insn *insn;
  size_t cnt;
  size_t len_cnt = 0;
#ifdef __x86_64__
    if (cs_open(CS_ARCH_X86, CS_MODE_64, &handle) != CS_ERR_OK)
        return 0;
#elif __i386__
    if (cs_open(CS_ARCH_X86, CS_MODE_32, &handle) != CS_ERR_OK)
        return 0;
#endif
  cnt = cs_disasm(handle, func, 0xF, 0x0, 0, &insn);
  for (int k = 0; k < 0xF || !(len_cnt >= target); k++) {
    if (len_cnt < target) {
      len_cnt+=insn[k].size;
    }
  }
    
    if (len_cnt < target) {
        return 0;
    }

  return len_cnt;
}
开发者ID:johndpope,项目名称:harpoon,代码行数:26,代码来源:harpoon.c

示例2: init_plugin

bool init_plugin(void *self) {
#if defined(TARGET_I386)
    if (cs_open(CS_ARCH_X86, CS_MODE_32, &cs_handle_32) != CS_ERR_OK)
#if defined(TARGET_X86_64)
    if (cs_open(CS_ARCH_X86, CS_MODE_64, &cs_handle_64) != CS_ERR_OK)
#endif
#elif defined(TARGET_ARM)
    if (cs_open(CS_ARCH_ARM, CS_MODE_ARM, &cs_handle_32) != CS_ERR_OK)
#elif defined(TARGET_PPC)
    if (cs_open(CS_ARCH_PPC, CS_MODE_32, &cs_handle_32) != CS_ERR_OK)
#endif
        return false;

    // Need details in capstone to have instruction groupings
    cs_option(cs_handle_32, CS_OPT_DETAIL, CS_OPT_ON);
#if defined(TARGET_X86_64)
    cs_option(cs_handle_64, CS_OPT_DETAIL, CS_OPT_ON);
#endif

    panda_cb pcb;

    panda_enable_memcb();
    panda_enable_precise_pc();

    pcb.after_block_translate = after_block_translate;
    panda_register_callback(self, PANDA_CB_AFTER_BLOCK_TRANSLATE, pcb);
    pcb.after_block_exec = after_block_exec;
    panda_register_callback(self, PANDA_CB_AFTER_BLOCK_EXEC, pcb);
    pcb.before_block_exec = before_block_exec;
    panda_register_callback(self, PANDA_CB_BEFORE_BLOCK_EXEC, pcb);

    return true;
}
开发者ID:mewbak,项目名称:panda,代码行数:33,代码来源:callstack_instr.cpp

示例3: _capstone_init

static void _capstone_init()
{
#if __x86_64__
    cs_open(CS_ARCH_X86, CS_MODE_64, &g_capstone);
#else
    cs_open(CS_ARCH_X86, CS_MODE_32, &g_capstone);
#endif
}
开发者ID:Axi0m-S,项目名称:CuckooMon---Calling-address,代码行数:8,代码来源:hooking.c

示例4: cs_open

void Capstone::GlobalInitialize()
{
#ifdef _WIN64
    cs_open(CS_ARCH_X86, CS_MODE_64, &mHandle);
#else //x86
    cs_open(CS_ARCH_X86, CS_MODE_32, &mHandle);
#endif //_WIN64
    cs_option(mHandle, CS_OPT_DETAIL, CS_OPT_ON);
}
开发者ID:neatsun,项目名称:x64dbg,代码行数:9,代码来源:capstone_wrapper.cpp

示例5: disassemble

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
	cs_insn* insn = NULL;
	cs_mode mode = 0;
	int ret, n = 0;
	csh cd;
	mode = (a->bits==16)? CS_MODE_THUMB: CS_MODE_ARM;
	if (a->big_endian)
		mode |= CS_MODE_BIG_ENDIAN;
	else
		mode |= CS_MODE_LITTLE_ENDIAN;

	if (a->cpu && strstr (a->cpu, "m"))
		mode |= CS_MODE_MCLASS;
	if (a->cpu && strstr (a->cpu, "v8"))
		mode |= CS_MODE_V8;
	op->size = 4;
	op->buf_asm[0] = 0;
	ret = (a->bits==64)?
		cs_open (CS_ARCH_ARM64, mode, &cd):
		cs_open (CS_ARCH_ARM, mode, &cd);
	if (ret) {
		ret = -1;
		goto beach;
	}
	if (a->syntax == R_ASM_SYNTAX_REGNUM) {
		cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME);
	} else cs_option (cd, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT);
	cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
	n = cs_disasm (cd, buf, R_MIN (4, len),
		a->pc, 1, &insn);
	if (n<1) {
		ret = -1;
		goto beach;
	}
	if (insn->size<1) {
		ret = -1;
		goto beach;
	}
	op->size = insn->size;
	snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
		insn->mnemonic,
		insn->op_str[0]?" ":"",
		insn->op_str);
	r_str_rmch (op->buf_asm, '#');
	cs_free (insn, n);
	beach:
	cs_close (&cd);
	if (!op->buf_asm[0])
		strcpy (op->buf_asm, "invalid");
	return op->size;
}
开发者ID:pastcompute,项目名称:radare2,代码行数:51,代码来源:asm_arm_cs.c

示例6: disassemble

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
	static int omode = 0;
	int mode, n, ret;
	ut64 off = a->pc;
	cs_insn* insn;

	mode = (a->bits==64)? CS_MODE_64: 
		(a->bits==32)? CS_MODE_32: 0;
	if (handle && mode != omode) {
		cs_close (&handle);
		handle = 0;
	}
	op->size = 0;
	omode = mode;
	if (handle == 0) {
		ret = cs_open (CS_ARCH_PPC, mode, &handle);
		if (ret) return 0;
	}
	cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
	n = cs_disasm_ex (handle, (const ut8*)buf, len, off, 1, &insn);
	if (n>0) {
		if (insn->size>0) {
			op->size = insn->size;
			snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
				insn->mnemonic, insn->op_str[0]?" ":"",
				insn->op_str);
		}
		cs_free (insn, n);
	}
	return op->size;
}
开发者ID:17twenty,项目名称:radare2,代码行数:31,代码来源:asm_ppc_cs.c

示例7: disassemble

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
	csh handle;
	cs_insn* insn;
	int mode, n, ret = -1;
	mode = a->big_endian? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;
	if (a->cpu && *a->cpu) {
		if (!strcmp (a->cpu, "v9")) {
			mode |= CS_MODE_V9;
		}
	}
	memset (op, 0, sizeof (RAsmOp));
	op->size = 4;
	ret = cs_open (CS_ARCH_SPARC, mode, &handle);
	if (ret) goto fin;
	cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
	n = cs_disasm (handle, (ut8*)buf, len, a->pc, 1, &insn);
	if (n<1) {
		strcpy (op->buf_asm, "invalid");
		op->size = 4;
		ret = -1;
		goto beach;
	} else ret = 4;
	if (insn->size<1)
		goto beach;
	op->size = insn->size;
	snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
		insn->mnemonic, insn->op_str[0]? " ": "",
		insn->op_str);
	// TODO: remove the '$'<registername> in the string
	cs_free (insn, n);
	beach:
	cs_close (&handle);
	fin:
	return ret;
}
开发者ID:13572293130,项目名称:radare2,代码行数:35,代码来源:asm_sparc_cs.c

示例8: disassemble

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
	static int omode = 0;
	int mode, n, ret;
	ut64 off = a->pc;
	cs_insn* insn = NULL;
	mode = CS_MODE_BIG_ENDIAN;
	if (cd && mode != omode) {
		cs_close (&cd);
		cd = 0;
	}
	op->size = 0;
	omode = mode;
	if (cd == 0) {
		ret = cs_open (CS_ARCH_SYSZ, mode, &cd);
		if (ret) return 0;
		cs_option (cd, CS_OPT_DETAIL, CS_OPT_OFF);
	}
	n = cs_disasm (cd, (const ut8*)buf, len, off, 1, &insn);
	if (n>0) {
		if (insn->size>0) {
			op->size = insn->size;
			char *ptrstr;
			snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
					insn->mnemonic, insn->op_str[0]?" ":"",
					insn->op_str);
			ptrstr = strstr (op->buf_asm, "ptr ");
			if (ptrstr) {
				memmove (ptrstr, ptrstr+4, strlen (ptrstr+4)+1);
			}
		}
		cs_free (insn, n);
	}
	return op->size;
}
开发者ID:13572293130,项目名称:radare2,代码行数:34,代码来源:asm_sysz.c

示例9: disassemble

static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
	static int omode = 0;
	int n, ret;
	ut64 off = a->pc;
	cs_insn* insn;
	
	int mode = (a->big_endian)? CS_MODE_BIG_ENDIAN: CS_MODE_LITTLE_ENDIAN;

	if (handle && mode != omode) {
		cs_close (&handle);
		handle = 0;
	}
	op->size = 0;
	omode = mode;
	op->buf_asm[0] = 0;
	if (handle == 0) {
		ret = cs_open (CS_ARCH_PPC, mode, &handle);
		if (ret) return 0;
	}
	cs_option (handle, CS_OPT_DETAIL, CS_OPT_OFF);
	n = cs_disasm (handle, (const ut8*)buf, len, off, 1, &insn);
	op->size = 4;
	if (n > 0 && insn->size > 0) {
		snprintf (op->buf_asm, R_ASM_BUFSIZE, "%s%s%s",
			insn->mnemonic, insn->op_str[0]?" ":"",
			insn->op_str);
		cs_free (insn, n);
		return op->size;
	}
	//op->size = -1;
	cs_free (insn, n);
	return 4;
}
开发者ID:AmesianX,项目名称:radare2,代码行数:33,代码来源:asm_ppc_cs.c

示例10: InitBlock

// One time init at runtime per thread we bring into monitoring
PExecutionBlock InitBlock(ULONG ID)
{
	PExecutionBlock pCtx = &CtxTable[ID];

	pCtx->TID = ID;
	pCtx->InternalID = ID;
	pCtx->SEQ = 0;
	pCtx->hThr = INVALID_HANDLE_VALUE;
	pCtx->BlockFrom = 0;

	cs_opt_skipdata skipdata = { "db", };
	if (cs_open(CS_ARCH_X86, CS_MODE_64, &pCtx->handle) != CS_ERR_OK)
		return NULL;

	cs_option(pCtx->handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_INTEL);
	cs_option(pCtx->handle, CS_OPT_DETAIL, CS_OPT_ON);
	cs_option(pCtx->handle, CS_OPT_SKIPDATA, CS_OPT_ON);
	cs_option(pCtx->handle, CS_OPT_SKIPDATA_SETUP, (size_t)&skipdata);

	pCtx->insn = cs_malloc(pCtx->handle);
	pCtx->csLen = 32;

	pCtx->Hooks = HooksConfig;
	pCtx->HookCnt = HookCount;

	return pCtx;
}
开发者ID:K2,项目名称:EhTrace,代码行数:28,代码来源:EhTrace.cpp

示例11: disasm

void disasm(uint64_t addr, uint32_t offset, size_t size, cs_arch arch, cs_mode mode, uint8_t *data)
{
    int i;
    csh handle = 0;
    cs_insn *insn;
    const uint8_t *code;

    if (cs_open(arch, mode, &handle) != CS_ERR_OK) {
        printf("ERROR: Failed to initialize engine!\n");
        exit(EXIT_FAILURE);
    }

    cs_option(handle, CS_OPT_SKIPDATA, CS_OPT_ON);
    cs_option(handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_ATT);   

    printf("Disassembly of section .text:\n");

    for (i = offset; i < offset + size; i++) {
        code = &data[i];
        insn = cs_malloc(handle);

        while(cs_disasm_iter(handle, &code, &size, &addr, insn)) {
            printf("0x%"PRIx64":\t%s\t\t%s\n", insn->address, insn->mnemonic, insn->op_str);
        }
        cs_free(insn, 1);
    }
    cs_close(&handle);
}
开发者ID:Nico01,项目名称:diself,代码行数:28,代码来源:disassemble.c

示例12: malloc

struct asm_handle *asm_initialize(cs_arch arch, cs_mode mode)
{
	struct asm_handle *asm_handle = malloc(sizeof(struct asm_handle));

	if (!asm_handle) {
		error("memory error");
		return NULL;
	}

	asm_handle->pending.size = 0;
	asm_handle->pending.advance = 0;

	if (cs_open(arch, mode, &asm_handle->handle) != CS_ERR_OK) {
		error("cannot initialize asm module");
		free(asm_handle);
		return NULL;
	}

	asm_handle->arch = arch;
	asm_handle->mode = mode;

	cs_option(asm_handle->handle, CS_OPT_DETAIL, CS_OPT_ON);

	stdout_use_colors = colors_supported(fileno(stdout));

    return asm_handle;
}
开发者ID:Cyber-Forensic,项目名称:haka,代码行数:27,代码来源:asm.c

示例13: open_capstone

static bool open_capstone() {
    cs_err res = cs_open(CS_ARCH_ARM64, CS_MODE_ARM, &cshandle);
    if (res != CS_ERR_OK)
        error("Error opening Capstone engine: %s", cs_strerror(res));

    return (res == CS_ERR_OK);
}
开发者ID:Jarlene,项目名称:ADBI-1,代码行数:7,代码来源:disassemble.c

示例14: r_disa_init

/* Init the disassembler */
int r_disa_init(r_disa_s *dis, r_binfmt_arch_e arch) {
  int cs_mode;
  int cs_arch;

  assert(dis != NULL);

  memset(dis, 0, sizeof(*dis));

  if(arch == R_BINFMT_ARCH_X86_64) {
    cs_mode = CS_MODE_64;
    cs_arch = CS_ARCH_X86;
  } else if(arch == R_BINFMT_ARCH_X86) {
    cs_mode = CS_MODE_32;
    cs_arch = CS_ARCH_X86;
  }else if(arch == R_BINFMT_ARCH_ARM) {
    cs_mode = CS_MODE_ARM;
    cs_arch = CS_ARCH_ARM;
  } else if(arch == R_BINFMT_ARCH_ARM64) {
    cs_mode = CS_MODE_ARM;
    cs_arch = CS_ARCH_ARM64;
  } else {
    return 0;
  }

  if(cs_open(cs_arch, cs_mode, &dis->handle) != CS_ERR_OK)
    return 0;

  dis->arch = arch;
  dis->flavor = R_DISA_FLAVOR_INTEL;

  return 1;
}
开发者ID:RanchoIce,项目名称:rop-tool,代码行数:33,代码来源:dis.c

示例15: GetAlignedOpcodeForHook

unsigned int HookFw::GetAlignedOpcodeForHook() {

	csh cshHandle;
	cs_insn *pInsn;
	unsigned int uiIndex;
	unsigned int uiCount;
	unsigned int uiSizeOfStolenOpcode;

	uiSizeOfStolenOpcode = 0;
	if (cs_open(CS_ARCH_X86, ARCH_MODE, &cshHandle) != CS_ERR_OK) {

		return ERR_CANNOT_RESOLVE_ASM;
	}
	uiCount = (unsigned int)cs_disasm(cshHandle, (unsigned char *)this->pvSrc, 0x50, 0x100, 0, &pInsn);
	if (uiCount > 0) {

		uiIndex = 0;
		while ((this->nHookLen > uiSizeOfStolenOpcode) && (uiCount >= uiIndex)) {

			uiSizeOfStolenOpcode += pInsn[uiIndex++].size;
		}
	}
	else return ERR_CANNOT_RESOLVE_ASM;

	return uiSizeOfStolenOpcode;
}
开发者ID:helaibai,项目名称:HookFw,代码行数:26,代码来源:HookFw.cpp


注:本文中的cs_open函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。