Skip to content

Commit

Permalink
refactor: made cargo happy
Browse files Browse the repository at this point in the history
  • Loading branch information
standard3 committed Nov 14, 2024
1 parent 7cfd5d6 commit c29845e
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 470 deletions.
86 changes: 23 additions & 63 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//! - [ ] Implement the `DataBlock` struct and Block trait
//! - [ ] Implement the `ProxyBlock` struct and Block trait

use crate::node::Node;
// use crate::node::Node;

use uuid::{uuid, Uuid};
use uuid::Uuid;

/// Block represents a base trait for blocks. [`Symbol`] objects may have references to any kind of Block.
// pub trait Block {
Expand All @@ -17,79 +17,39 @@ use uuid::{uuid, Uuid};
// fn get_references(&self) -> Vec<Symbol>;
// }

#[derive(Clone, PartialEq)]
pub struct Block {
pub offset: u64,
pub value: Option<BlockValue>,
}

#[derive(Clone, PartialEq)]
pub enum BlockValue {
Code(CodeBlock),
Data(DataBlock),
}

#[derive(Clone, PartialEq)]
pub struct ProxyBlock {
pub uuid: Vec<u8>,
pub uuid: Uuid,
}

#[derive(Clone, PartialEq)]
pub struct CodeBlock {
pub uuid: Vec<u8>,

pub uuid: Uuid,
pub size: u64,

pub decode_mode: i32,
pub decode_mode: DecodeMode,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(i32)]
pub enum DecodeMode {
AllDefault = 0,
ArmThumb = 1,
}
impl DecodeMode {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::AllDefault => "All_Default",
Self::ArmThumb => "ARM_Thumb",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"All_Default" => Some(Self::AllDefault),
"ARM_Thumb" => Some(Self::ArmThumb),
_ => None,
}
}
}
#[derive(Clone, PartialEq)]
pub struct DataBlock {
pub uuid: Vec<u8>,

pub size: u64,
}

#[derive(Clone, PartialEq)]
pub struct Block {
pub offset: u64,

pub value: ::core::option::Option<block::Value>,
AllDefault,
ArmThumb,
}
/// Nested message and enum types in `Block`.
pub mod block {
#[derive(Clone, PartialEq)]
pub enum Value {
Code(super::CodeBlock),

Data(super::DataBlock),
}
}
#[derive(Clone, PartialEq)]
pub struct ByteInterval {
pub uuid: Vec<u8>,

pub blocks: Vec<Block>,

pub symbolic_expressions: ::std::collections::HashMap<u64, SymbolicExpression>,

pub has_address: bool,

pub address: u64,

pub struct DataBlock {
pub uuid: Uuid,
pub size: u64,

pub contents: Vec<u8>,
}
16 changes: 16 additions & 0 deletions src/byte_interval.rs
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
use std::collections::HashMap;

use crate::block::Block;
use crate::symbolic_expression::SymbolicExpression;

use uuid::Uuid;

#[derive(Clone, PartialEq)]
pub struct ByteInterval {
pub uuid: Uuid,
pub blocks: Vec<Block>,
pub symbolic_expressions: HashMap<u64, SymbolicExpression>,
pub has_address: bool,
pub address: u64,
pub size: u64,
pub contents: Vec<u8>,
}
70 changes: 21 additions & 49 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,60 +1,32 @@
#[derive(Clone, Copy, PartialEq)]
pub struct EdgeLabel {
pub conditional: bool,
use uuid::Uuid;

pub direct: bool,

pub r#type: i32,
#[derive(Clone, PartialEq)]
pub struct Cfg {
pub vertices: Vec<Vec<u8>>,
pub edges: Vec<Edge>,
}

#[derive(Clone, PartialEq)]
pub struct Edge {
pub source_uuid: Vec<u8>,

pub target_uuid: Vec<u8>,

pub label: ::core::option::Option<EdgeLabel>,
pub source_uuid: Uuid,
pub target_uuid: Uuid,
pub label: Option<EdgeLabel>,
}
#[derive(Clone, PartialEq)]
pub struct Cfg {
pub vertices: Vec<Vec<u8>>,

pub edges: Vec<Edge>,
#[derive(Clone, Copy, PartialEq)]
pub struct EdgeLabel {
pub conditional: bool,
pub direct: bool,
pub r#type: EdgeType,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(i32)]
pub enum EdgeType {
TypeBranch = 0,
TypeCall = 1,
TypeFallthrough = 2,
TypeReturn = 3,
TypeSyscall = 4,
TypeSysret = 5,
}
impl EdgeType {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Self::TypeBranch => "Type_Branch",
Self::TypeCall => "Type_Call",
Self::TypeFallthrough => "Type_Fallthrough",
Self::TypeReturn => "Type_Return",
Self::TypeSyscall => "Type_Syscall",
Self::TypeSysret => "Type_Sysret",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"Type_Branch" => Some(Self::TypeBranch),
"Type_Call" => Some(Self::TypeCall),
"Type_Fallthrough" => Some(Self::TypeFallthrough),
"Type_Return" => Some(Self::TypeReturn),
"Type_Syscall" => Some(Self::TypeSyscall),
"Type_Sysret" => Some(Self::TypeSysret),
_ => None,
}
}
Branch,
Call,
Fallthrough,
Return,
Syscall,
Sysret,
}
18 changes: 11 additions & 7 deletions src/ir.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#[derive(Clone, PartialEq)]
pub struct Ir {
pub uuid: Vec<u8>,
use crate::auxdata::AuxData;
use crate::cfg::Cfg;
use crate::module::Module;

pub modules: Vec<Module>,
use std::collections::HashMap;

pub aux_data: ::std::collections::HashMap<String, AuxData>,
use uuid::Uuid;

#[derive(Clone, PartialEq)]
pub struct Ir {
pub uuid: Uuid,
pub modules: Vec<Module>,
pub aux_data: HashMap<String, AuxData>,
pub version: u32,

pub cfg: ::core::option::Option<Cfg>,
pub cfg: Option<Cfg>,
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub mod cfg;
pub mod ir;
pub mod module;
pub mod node;
pub mod offset;
pub mod section;
pub mod symbol;
pub mod symbolic_expression;
Loading

0 comments on commit c29845e

Please sign in to comment.