コード例 #1
0
ファイル: engine.go プロジェクト: postfix/gapstone
// Enables capstone CS_OPT_SKIPDATA. If no SkipDataConfig is passed ( nil )
// the default behaviour will be enabled. It is valid to pass any combination
// of the SkipDataConfig options, although UserData without a Callback will be
// ignored.
func (e *Engine) SkipDataStart(config *SkipDataConfig) {

	if config != nil {

		e.skipdata = &C.cs_opt_skipdata{}

		if config.Callback != nil {
			e.skipdata.callback = (C.cs_skipdata_cb_t)(C.trampoline)
			// Happily, we can use the opaque user_data pointer in C to hold both
			// the Go callback function and the Go userData
			e.skipdata.user_data = unsafe.Pointer(
				&cbWrapper{
					fn: config.Callback,
					ud: config.UserData,
				},
			)
		}

		if config.Mnemonic != "" {
			e.skipdata.mnemonic = C.CString(config.Mnemonic)
		} else {
			e.skipdata.mnemonic = C.CString(".byte")
		}

		C.cs_option(e.handle, CS_OPT_SKIPDATA_SETUP, C.size_t(uintptr(unsafe.Pointer(e.skipdata))))
	}

	// If there's no config, just turn on skipdata with the default behaviour
	C.cs_option(e.handle, CS_OPT_SKIPDATA, CS_OPT_ON)
}
コード例 #2
0
ファイル: engine.go プロジェクト: postfix/gapstone
// Disable CS_OPT_SKIPDATA. Removes any registered callbacks and frees
// resources.
func (e *Engine) SkipDataStop() {
	C.cs_option(e.handle, CS_OPT_SKIPDATA, CS_OPT_OFF)
	if e.skipdata == nil {
		return
	}
	C.free(unsafe.Pointer(e.skipdata.mnemonic))
	e.skipdata = nil
}
コード例 #3
0
ファイル: engine.go プロジェクト: postfix/gapstone
// Setter for Engine options CS_OPT_*
func (e *Engine) SetOption(ty, value uint) error {
	res := C.cs_option(
		e.handle,
		C.cs_opt_type(ty),
		C.size_t(value),
	)

	if Errno(res) == ErrOK {
		return nil
	}
	return Errno(res)
}