From d0227a00e8707a99ff1dcd6666a41ebc3a8385d9 Mon Sep 17 00:00:00 2001 From: Aursen Date: Thu, 28 Aug 2025 15:42:24 +0700 Subject: [PATCH 1/2] Bump Rust dependencies --- crates/ezbpf-cli/Cargo.toml | 12 ++++---- crates/ezbpf-cli/src/main.rs | 19 ++++++++++-- crates/ezbpf-core/Cargo.toml | 12 ++++---- crates/ezbpf-core/src/cursor.rs | 3 +- crates/ezbpf-core/src/elf_header.rs | 4 +-- crates/ezbpf-core/src/errors.rs | 2 +- crates/ezbpf-core/src/program.rs | 29 ++++++++++--------- crates/ezbpf-core/src/section_header_entry.rs | 15 ++++------ crates/ezbpf-wasm/src/lib.rs | 2 +- 9 files changed, 55 insertions(+), 43 deletions(-) diff --git a/crates/ezbpf-cli/Cargo.toml b/crates/ezbpf-cli/Cargo.toml index 4792aea..c1836fb 100644 --- a/crates/ezbpf-cli/Cargo.toml +++ b/crates/ezbpf-cli/Cargo.toml @@ -5,9 +5,9 @@ edition = "2021" authors = ["Dean Little <@deanmlittle>"] [dependencies] -anyhow = "1.0.86" -clap = { version = "4.5.4", features = ["derive"] } -clap_derive = { version = "4.5.5" } -serde = { version = "1.0.203", features = ["derive"] } -serde_json = "1.0.117" -ezbpf-core = { path = "../ezbpf-core" } \ No newline at end of file +anyhow = "1.0" +clap = { version = "4.5", features = ["derive"] } +clap_derive = { version = "4.5" } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +ezbpf-core = { path = "../ezbpf-core" } diff --git a/crates/ezbpf-cli/src/main.rs b/crates/ezbpf-cli/src/main.rs index 2bf339a..bc9b102 100644 --- a/crates/ezbpf-cli/src/main.rs +++ b/crates/ezbpf-cli/src/main.rs @@ -1,6 +1,5 @@ use anyhow::Result; use clap::Parser; -use ezbpf_core::errors::EZBpfError; use ezbpf_core::program::Program; use std::fs::File; use std::io::Read; @@ -22,8 +21,22 @@ fn main() -> Result<()> { file.read_to_end(&mut b)?; let program = Program::from_bytes(b.as_ref())?; match args.asm { - Some(_) => println!("{}", program.section_header_entries.iter().map(|h| h.ixs.clone()).filter(|ixs| !ixs.is_empty()).map(|ixs| ixs.iter().map(|i| i.to_asm().unwrap()).collect::>().join("\n")).collect::>().join("\n")), - None => println!("{}", serde_json::to_string_pretty(&program)?) + Some(_) => println!( + "{}", + program + .section_header_entries + .iter() + .map(|h| h.ixs.clone()) + .filter(|ixs| !ixs.is_empty()) + .map(|ixs| ixs + .iter() + .map(|i| i.to_asm().unwrap()) + .collect::>() + .join("\n")) + .collect::>() + .join("\n") + ), + None => println!("{}", serde_json::to_string_pretty(&program)?), } Ok(()) } diff --git a/crates/ezbpf-core/Cargo.toml b/crates/ezbpf-core/Cargo.toml index 95fe92c..a79bb81 100644 --- a/crates/ezbpf-core/Cargo.toml +++ b/crates/ezbpf-core/Cargo.toml @@ -8,11 +8,11 @@ authors = ["Dean Little <@deanmlittle>"] name = "ezbpf_core" [dependencies] -anyhow = "1.0.86" -hex = "0.4.3" -thiserror = "1.0.61" -serde = { version = "1.0.203", features = ["derive"] } -serde_json = "1.0.117" +anyhow = "1.0" +hex = "0.4" +thiserror = "2.0" +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" [dev-dependencies] -hex-literal = "0.4.1" \ No newline at end of file +hex-literal = "1.0" diff --git a/crates/ezbpf-core/src/cursor.rs b/crates/ezbpf-core/src/cursor.rs index aed11a4..2b0fb16 100644 --- a/crates/ezbpf-core/src/cursor.rs +++ b/crates/ezbpf-core/src/cursor.rs @@ -2,7 +2,8 @@ use std::io::{Cursor, Read, Seek, SeekFrom}; use crate::{ elf_header::{ - ELFHeader, EI_ABIVERSION, EI_CLASS, EI_DATA, EI_MAGIC, EI_OSABI, EI_PAD, EI_VERSION, E_MACHINE, E_MACHINE_SBPF, E_TYPE, E_VERSION + ELFHeader, EI_ABIVERSION, EI_CLASS, EI_DATA, EI_MAGIC, EI_OSABI, EI_PAD, EI_VERSION, + E_MACHINE, E_MACHINE_SBPF, E_TYPE, E_VERSION, }, errors::EZBpfError, instructions::Ix, diff --git a/crates/ezbpf-core/src/elf_header.rs b/crates/ezbpf-core/src/elf_header.rs index c3b5138..1f22e0a 100644 --- a/crates/ezbpf-core/src/elf_header.rs +++ b/crates/ezbpf-core/src/elf_header.rs @@ -95,11 +95,11 @@ mod tests { let h = ELFHeader::from_bytes(&b).unwrap(); assert_eq!(h.to_bytes(), &b) } - + #[test] fn serialize_sbpf_machine_e2e() { let b = hex!("7F454C46020101000000000000000000030007010100000020010000000000004000000000000000680200000000000000000000400038000300400006000500"); let h = ELFHeader::from_bytes(&b).unwrap(); assert_eq!(h.to_bytes(), &b) } -} \ No newline at end of file +} diff --git a/crates/ezbpf-core/src/errors.rs b/crates/ezbpf-core/src/errors.rs index ce43d3f..3fc0ad4 100644 --- a/crates/ezbpf-core/src/errors.rs +++ b/crates/ezbpf-core/src/errors.rs @@ -17,5 +17,5 @@ pub enum EZBpfError { #[error("Invalid data length")] InvalidDataLength, #[error("Invalid string")] - InvalidString + InvalidString, } diff --git a/crates/ezbpf-core/src/program.rs b/crates/ezbpf-core/src/program.rs index 994a0c2..7498a0d 100644 --- a/crates/ezbpf-core/src/program.rs +++ b/crates/ezbpf-core/src/program.rs @@ -38,19 +38,23 @@ impl Program { let mut indices: Vec = section_headers.iter().map(|h| h.sh_name).collect(); indices.push(shstrndx.sh_size as u32); indices.sort_unstable(); - - let section_header_entries = section_headers.iter().map(|s| { - let current_offset = s.sh_name as usize; - let next_index = indices.binary_search(&s.sh_name).unwrap() + 1 as usize; - let next_offset = *indices.get(next_index).ok_or(EZBpfError::InvalidString)? as usize; - let label = String::from_utf8( - shstrndx_value[current_offset..next_offset].to_vec(), - ).unwrap_or("default".to_string()); - let data = b[s.sh_offset as usize..s.sh_offset as usize + s.sh_size as usize].to_vec(); + let section_header_entries = section_headers + .iter() + .map(|s| { + let current_offset = s.sh_name as usize; + let next_index = indices.binary_search(&s.sh_name).unwrap() + 1_usize; + let next_offset = + *indices.get(next_index).ok_or(EZBpfError::InvalidString)? as usize; - SectionHeaderEntry::new(label, s.sh_offset as usize, data) - }).collect::, _>>()?; + let label = String::from_utf8(shstrndx_value[current_offset..next_offset].to_vec()) + .unwrap_or("default".to_string()); + let data = + b[s.sh_offset as usize..s.sh_offset as usize + s.sh_size as usize].to_vec(); + + SectionHeaderEntry::new(label, s.sh_offset as usize, data) + }) + .collect::, _>>()?; Ok(Self { elf_header, @@ -61,7 +65,6 @@ impl Program { } } - #[cfg(test)] mod tests { use hex_literal::hex; @@ -73,4 +76,4 @@ mod tests { let program = Program::from_bytes(&hex!("7F454C460201010000000000000000000300F700010000002001000000000000400000000000000028020000000000000000000040003800030040000600050001000000050000002001000000000000200100000000000020010000000000003000000000000000300000000000000000100000000000000100000004000000C001000000000000C001000000000000C0010000000000003C000000000000003C000000000000000010000000000000020000000600000050010000000000005001000000000000500100000000000070000000000000007000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007912A000000000007911182900000000B7000000010000002D21010000000000B70000000000000095000000000000001E0000000000000004000000000000000600000000000000C0010000000000000B0000000000000018000000000000000500000000000000F0010000000000000A000000000000000C00000000000000160000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000120001002001000000000000300000000000000000656E747279706F696E7400002E74657874002E64796E737472002E64796E73796D002E64796E616D6963002E73687374727461620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000010000000600000000000000200100000000000020010000000000003000000000000000000000000000000008000000000000000000000000000000170000000600000003000000000000005001000000000000500100000000000070000000000000000400000000000000080000000000000010000000000000000F0000000B0000000200000000000000C001000000000000C001000000000000300000000000000004000000010000000800000000000000180000000000000007000000030000000200000000000000F001000000000000F0010000000000000C00000000000000000000000000000001000000000000000000000000000000200000000300000000000000000000000000000000000000FC010000000000002A00000000000000000000000000000001000000000000000000000000000000")).unwrap(); println!("{:?}", program.section_header_entries); } -} \ No newline at end of file +} diff --git a/crates/ezbpf-core/src/section_header_entry.rs b/crates/ezbpf-core/src/section_header_entry.rs index ceb6aef..3e2d93e 100644 --- a/crates/ezbpf-core/src/section_header_entry.rs +++ b/crates/ezbpf-core/src/section_header_entry.rs @@ -1,7 +1,6 @@ use std::{fmt::Debug, io::Cursor}; -use serde::{ser::Error, Deserialize, Serialize, Serializer}; -use serde_json::{error, Map, Value}; +use serde::{Deserialize, Serialize}; use crate::{cursor::ELFCursor, errors::EZBpfError, instructions::Ix}; @@ -13,17 +12,17 @@ pub struct SectionHeaderEntry { #[serde(skip_serializing_if = "Vec::is_empty")] pub ixs: Vec, #[serde(skip_serializing_if = "String::is_empty")] - pub utf8: String + pub utf8: String, } impl SectionHeaderEntry { pub fn new(label: String, offset: usize, data: Vec) -> Result { let mut h = SectionHeaderEntry { label, - offset: offset, + offset, data, ixs: vec![], - utf8: String::new() + utf8: String::new(), }; if &h.label == ".text\0" { @@ -70,11 +69,7 @@ mod test { 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ]; - let h = SectionHeaderEntry::new( - ".text\0".to_string(), - 128, - data.clone() - ).unwrap(); + let h = SectionHeaderEntry::new(".text\0".to_string(), 128, data.clone()).unwrap(); let ixs = vec![ Ix { diff --git a/crates/ezbpf-wasm/src/lib.rs b/crates/ezbpf-wasm/src/lib.rs index 7e325d0..9882c01 100644 --- a/crates/ezbpf-wasm/src/lib.rs +++ b/crates/ezbpf-wasm/src/lib.rs @@ -22,4 +22,4 @@ impl Program { pub fn to_json(&self) -> Result { to_value(&self.inner).map_err(|e| JsValue::from_str(&e.to_string())) } -} \ No newline at end of file +} From a10dca9852cd6c6fc5bf732efae197ed0366892f Mon Sep 17 00:00:00 2001 From: Aursen Date: Thu, 28 Aug 2025 15:44:44 +0700 Subject: [PATCH 2/2] Update the wasm crate --- crates/ezbpf-wasm/Cargo.toml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/ezbpf-wasm/Cargo.toml b/crates/ezbpf-wasm/Cargo.toml index 846078f..afeb352 100644 --- a/crates/ezbpf-wasm/Cargo.toml +++ b/crates/ezbpf-wasm/Cargo.toml @@ -9,14 +9,14 @@ name = "ezbpf_wasm" crate-type = ["cdylib", "rlib"] [dependencies] -anyhow = "1.0.86" -wasm-bindgen = "0.2.92" -hex = "0.4.3" +anyhow = "1.0" +wasm-bindgen = "0.2" +hex = "0.4" ezbpf-core = { path = "../ezbpf-core" } -thiserror = "1.0.61" -serde = { version = "1.0.203", features = ["derive"] } -serde-wasm-bindgen = "0.6.5" -serde_json = "1.0.117" +thiserror = "2.0" +serde = { version = "1.0", features = ["derive"] } +serde-wasm-bindgen = "0.6" +serde_json = "1.0" [dev-dependencies] -hex-literal = "0.4.1" \ No newline at end of file +hex-literal = "1.0"