Skip to content

Commit

Permalink
More rust cleanup
Browse files Browse the repository at this point in the history
- Remove under_construction.png from the build.rs it has been removed
- Use InstructionIndex in more places
- Add missing PartialOrd and Ord impls for id types
  • Loading branch information
emesare committed Jan 15, 2025
1 parent e470e44 commit 9f4b673
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 0 additions & 4 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ fn main() {
let _ = std::fs::create_dir("target");
let _ = std::fs::create_dir("target/doc");
let _ = std::fs::copy("../docs/img/favicon.ico", "target/doc/favicon.ico");
let _ = std::fs::copy(
"assets/under_construction.png",
"target/doc/under_construction.png",
);
let _ = std::fs::copy("../docs/img/logo.png", "target/doc/logo.png");

let link_path =
Expand Down
2 changes: 1 addition & 1 deletion rust/src/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub use binaryninjacore_sys::BNLowLevelILFlagCondition as FlagCondition;

macro_rules! newtype {
($name:ident, $inner_type:ty) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct $name(pub $inner_type);

impl From<$inner_type> for $name {
Expand Down
6 changes: 6 additions & 0 deletions rust/src/llil/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ use crate::architecture::Architecture;
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct InstructionIndex(pub usize);

impl InstructionIndex {
pub fn next(&self) -> Self {
Self(self.0 + 1)
}
}

impl Display for InstructionIndex {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_fmt(format_args!("{}", self.0))
Expand Down
4 changes: 2 additions & 2 deletions rust/src/llil/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ where
Expression::new(self.function, ExpressionIndex(self.op.operands[0] as usize))
}

pub fn target_list(&self) -> BTreeMap<u64, usize> {
pub fn target_list(&self) -> BTreeMap<u64, InstructionIndex> {
let mut result = BTreeMap::new();
let count = self.op.operands[1] as usize / 2;
let mut list = TargetListIter {
Expand All @@ -425,7 +425,7 @@ where

for _ in 0..count {
let value = list.next();
let target = list.next() as usize;
let target = InstructionIndex(list.next() as usize);
result.insert(value, target);
}

Expand Down

0 comments on commit 9f4b673

Please sign in to comment.