Skip to content
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

Add cs_insn_flags. Breaking API change. #2374

Closed
wants to merge 1 commit into from

Conversation

numas13
Copy link

@numas13 numas13 commented May 29, 2024

Replace cs_insn.is_alias and cs_insn.usesAliasDetails with bitflags.

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

Add instruction bitflags with reserved range for arch-specific usage. For example:

  • E2K speculative mode execution.
  • IA-64 "stop bits".
  • You name it.

This information is critical and must be present even if instruction details is off.

But I'm not sure how many bitflags should be arch-specific.

Test plan

Update bindings and user software.

@@ -354,9 +354,9 @@ static void usage(char *prog)
static void print_details(csh handle, cs_arch arch, cs_mode md, cs_insn *ins)
{
printf("\tID: %u (%s)\n", ins->id, cs_insn_name(handle, ins->id));
if (ins->is_alias) {
if (ins->flags & CS_INSN_FLAG_ALIAS) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a function to check for flags is better for the flag field (something like cs_flag_set(insn->flags, CS_INSN_FLAG_ALIAS)). Bit operations in conditions get messy after a while.

Copy link
Author

@numas13 numas13 May 29, 2024

Choose a reason for hiding this comment

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

I've added some macros to manage flags for more complex cases. See capstone.h.

CS_INSN_FLAGS_ALL -- test if all flags is set
CS_INSN_FLAGS_ANY -- test if any flag is set
CS_INSN_FLAGS_SET -- enable flags if condition is true, disable flags if false

But forgot to add some documentation. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ouh, sorry. Overlooked it. Just took a shallow look.

Copy link
Collaborator

@Rot127 Rot127 May 29, 2024

Choose a reason for hiding this comment

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

Wait. I meant for checking if a flag is set. Like cs_flag_is_set(insn->flags, CS_INSN_FLAG_ALIAS) => true/false.
But I'll review tomorrow again with a clear mind.

Copy link
Author

Choose a reason for hiding this comment

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

You can check it with CS_INSN_FLAGS_ANY(insn, CS_INSN_FLAG_ALIAS).

Replace dedicated cs_insn members for boolean flags with bitflags.
@numas13
Copy link
Author

numas13 commented Jun 1, 2024

I'm closing PRs. We'll think about what can be done.

@numas13 numas13 closed this Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants