diff --git a/src/common_file_operations.rs b/src/common_file_operations.rs index 9d766f7..61b8335 100644 --- a/src/common_file_operations.rs +++ b/src/common_file_operations.rs @@ -56,19 +56,20 @@ pub(crate) fn strings_parser( #[binrw::parser(reader)] pub(crate) fn string_from_offset(start: u64) -> BinResult { + let offset: u32 = reader.read_le::()?; + let mut string = String::new(); let old_pos = reader.stream_position()?; + reader.seek(SeekFrom::Start(start + offset as u64))?; reader.seek(SeekFrom::Start(start as u64))?; let mut next_char = reader.read_le::().unwrap() as char; while next_char != '\0' { string.push(next_char); next_char = reader.read_le::().unwrap() as char; } - reader.seek(SeekFrom::Start(old_pos))?; - Ok(string) } diff --git a/src/layer/mod.rs b/src/layer/mod.rs index 21609b9..a3b8cc3 100644 --- a/src/layer/mod.rs +++ b/src/layer/mod.rs @@ -183,7 +183,20 @@ impl StringHeap { where R: Read + Seek, { - string_from_offset(reader, Endian::Little, (self.pos + offset as u64,)).unwrap() + let offset = self.pos + offset as u64; + + let mut string = String::new(); + + let old_pos = reader.stream_position().unwrap(); + + reader.seek(SeekFrom::Start(offset as u64)).unwrap(); + let mut next_char = reader.read_le::().unwrap() as char; + while next_char != '\0' { + string.push(next_char); + next_char = reader.read_le::().unwrap() as char; + } + reader.seek(SeekFrom::Start(old_pos)).unwrap(); + string } }