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 Serialize and Deserialize for Instruction<AllOperands> #40

Open
KosBeg opened this issue Jul 9, 2024 · 0 comments
Open

Add Serialize and Deserialize for Instruction<AllOperands> #40

KosBeg opened this issue Jul 9, 2024 · 0 comments

Comments

@KosBeg
Copy link

KosBeg commented Jul 9, 2024

When trying to serialize or deserialize the Instruction<AllOperands> type from the zydis-rs crate using serde, compilation fails with trait implementation errors. This issue occurs because the Instruction<AllOperands> type does not implement the Serialize and Deserialize traits required by serde.

Steps to Reproduce

  1. Create a new Rust project with serde and zydis-rs as dependencies:
    [dependencies]
    serde = { version = "1.0.204", features = ["derive"] }
    zydis = { version = "4.1.1", features = ["serialization"] }
  2. Use the following minimal code to define a struct with Instruction<AllOperands>:
    use serde::{Deserialize, Serialize};
    use zydis::{AllOperands, Instruction};
    
    #[derive(Serialize, Deserialize, Debug)]
    struct Node {
        name: u64,
        data: Vec<Instruction<AllOperands>>,
    }
    
    fn main() {}
  3. Attempt to compile the code:
    cargo build

Expected Behavior

The code should compile successfully, and the Node struct should be able to serialize and deserialize Instruction<AllOperands> instances using serde.

Actual Behavior

Compilation fails with the following error messages:

error[E0277]: the trait bound `Instruction<OperandArrayVec<10>>: Serialize` is not satisfied
...
error[E0277]: the trait bound `Instruction<OperandArrayVec<10>>: Deserialize<'_>` is not satisfied
...

Additional Information

The error messages suggest adding #[derive(serde::Serialize)] and #[derive(serde::Deserialize)] to the Instruction<OperandArrayVec<10>> type, but since this type is defined in the zydis-rs crate, it is not possible to directly modify it.

To demonstrate that the issue is specific to Instruction<AllOperands>, here is an example using zydis::ffi::DecodedOperandKind which compiles without issues:

use serde::{Deserialize, Serialize};
use zydis::{ffi::DecodedOperandKind, AllOperands, Instruction};

#[derive(Serialize, Deserialize, Debug)]
struct Node {
    name: u64,
    data: Vec<DecodedOperandKind>,
}

fn main() {}

Suggested Solution

Please add optional Serialize and Deserialize trait implementations for the Instruction<AllOperands> type in the zydis-rs crate

Environment

  • Rust version: 1.81.0-nightly (35b658fb1 2024-07-08)
  • serde version: 1.0.204
  • zydis-rs version: 4.1.1

Relevant Error Logs

error[E0277]: the trait bound `Instruction<OperandArrayVec<10>>: Serialize` is not satisfied
...
error[E0277]: the trait bound `Instruction<OperandArrayVec<10>>: Deserialize<'_>` is not satisfied
...

We appreciate your attention to this matter and look forward to the inclusion of the necessary serde trait implementations in the zydis-rs crate.

Thank you.

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

No branches or pull requests

1 participant