Skip to content

Add Serialize and Deserialize for Instruction<AllOperands> #40

@KosBeg

Description

@KosBeg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions