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

How to get operand info of ZydisEncodableInstruction? #559

Open
loveandkindess opened this issue Mar 17, 2025 · 6 comments
Open

How to get operand info of ZydisEncodableInstruction? #559

loveandkindess opened this issue Mar 17, 2025 · 6 comments
Labels
C-question Category: Question and assistance with usage

Comments

@loveandkindess
Copy link

loveandkindess commented Mar 17, 2025

ZydisEncodableInstruction_ has this member:
ZyanU16 operand_mask;

How do I get the operand count?
How do I get the exact info of each operand, like register type (or memory type), count, size, and addressing mode?

I see you can only get it via decoding an instruction, how do i get it while encoding?

edit: in other words, how can I decode the operand mask

@mappzor
Copy link
Contributor

mappzor commented Mar 17, 2025

ZydisEncodableInstruction is an internal structure. It's not exposed by any API. Encodes uses operand_mask for optimization to quickly reject instruction variants that don't have a chance to match encoder request.

I see you can only get it via decoding an instruction, how do i get it while encoding?

What are you trying to achieve exactly?

@loveandkindess
Copy link
Author

@mappzor I am trying to decode the operand mask..

@mappzor
Copy link
Contributor

mappzor commented Mar 17, 2025

You are not meant to access it at all. What's your use case?

@loveandkindess
Copy link
Author

To generate random instructions with more constraints. example:
generate random instruction with 64 bit memory or register operands

@mappzor
Copy link
Contributor

mappzor commented Mar 17, 2025

Using internal structures for this is possible to an extent but you might want to just parse zydis-db in a way that's more suitable for you. Operand masks are just operand counts + basic operand types (register, memory, immediate or pointer). Accessing more detailed information about additional constraints can be rather convoluted.

Table generation scripts for encoder are open-sourced here.

@ZehMatt
Copy link
Contributor

ZehMatt commented Mar 17, 2025

Perhaps this can help you a little bit understand it, I also use the internal structures https://github.com/ZehMatt/x86Tester/blob/36532119a757e596256b99b29e22aeb01095d854/src/generator/generator.cpp#L519-L566

@mappzor mappzor added the C-question Category: Question and assistance with usage label Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-question Category: Question and assistance with usage
Projects
None yet
Development

No branches or pull requests

3 participants