Thanks to visit codestin.com
Credit goes to github.com

Skip to content

SetCPUModel go binding for setting the CPU model #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2021

Conversation

zznop
Copy link
Contributor

@zznop zznop commented Dec 2, 2021

I added a SetCPUModel method to the unicorn interface in the go bindings to address #1502. CGO does not support calling C functions with varargs so I also added a uc_ctl_set_cpu_model_helper function to uc.c to call uc_ctl

Usage:

emu, _ := uc.NewUnicorn(uc.ARCH_M68K, uc.MODE_BIG_ENDIAN) emu.SetCPUModel(uc.CPU_M68000_CPU)

@@ -23,3 +23,7 @@ uc_err uc_reg_write_batch_helper(uc_engine *handle, int *regs, uint64_t *val_in,
free(val_ref);
return ret;
}

void uc_ctl_set_cpu_model_helper(uc_engine *handle, int model) {
uc_ctl(handle, UC_CTL_CPU_MODEL, model);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, you have to use uc_ctl_set_cpu_model macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -1,2 +1,3 @@
uc_err uc_reg_read_batch_helper(uc_engine *handle, int *regs, uint64_t *val_out, int count);
uc_err uc_reg_write_batch_helper(uc_engine *handle, int *regs, uint64_t *val_in, int count);
void uc_ctl_set_cpu_model_helper(uc_engine *handle, int model);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also wrong, the type of the return value is uc_err.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Go cannot use C macros directly, so I followed existing convention and
added a helper to uc.c to call the uc_ctl_set_cpu_model macro
@wtdcode wtdcode merged commit 1923c12 into unicorn-engine:dev Dec 4, 2021
@wtdcode
Copy link
Member

wtdcode commented Dec 4, 2021

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants