Skip to content

Commit

Permalink
- pending changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeaduran committed Feb 28, 2024
1 parent dc2ea20 commit 1bb0a92
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/extractor/smda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl Extractor {
res.push((
crate::rules::features::Feature::String(
crate::rules::features::StringFeature::new(
&trimmed.trim_end_matches('\x00'),
trimmed.trim_end_matches('\x00'),
"",
)?,
),
Expand Down Expand Up @@ -1093,7 +1093,7 @@ pub fn read_string(report: &DisassemblyReport, offset: &u64) -> Result<String> {
let alen = detect_ascii_len(report, offset)?;
if alen > 1 {
let bytes = read_bytes(report, offset, alen)?;
return Ok(std::str::from_utf8(&bytes)?.to_string());
return Ok(std::str::from_utf8(bytes)?.to_string());
}
let ulen = detect_unicode_len(report, offset)?;
if ulen > 2 {
Expand All @@ -1109,16 +1109,17 @@ pub fn read_string(report: &DisassemblyReport, offset: &u64) -> Result<String> {

pub fn detect_ascii_len(report: &DisassemblyReport, offset: &u64) -> Result<usize> {
let buffer_len = report.buffer.len() as u64;
let rva = offset.checked_sub(report.base_addr)
.ok_or_else(|| std::io::Error::new(
let rva = offset.checked_sub(report.base_addr).ok_or_else(|| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Offset is out of bounds relative to the base address"
))?;
"Offset is out of bounds relative to the base address",
)
})?;

if rva as usize >= report.buffer.len() {
return Err(std::io::Error::new(
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"RVA is beyond buffer length"
"RVA is beyond buffer length",
))?;
}

Expand All @@ -1131,7 +1132,7 @@ pub fn detect_ascii_len(report: &DisassemblyReport, offset: &u64) -> Result<usiz
if rva + ascii_len as u64 >= buffer_len {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Buffer overflow detected while detecting ASCII length"
"Buffer overflow detected while detecting ASCII length",
))?;
}

Expand Down

0 comments on commit 1bb0a92

Please sign in to comment.