Skip to content

Commit

Permalink
Rename Inno block reader
Browse files Browse the repository at this point in the history
  • Loading branch information
russellbanks committed Jan 30, 2025
1 parent a5324ca commit 06b52f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/installers/inno/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::installers::inno::header::Header;
use crate::installers::inno::loader::{
SetupLoader, SetupLoaderOffset, SETUP_LOADER_OFFSET, SETUP_LOADER_RESOURCE,
};
use crate::installers::inno::read::block_filter::{InnoBlockFilter, INNO_BLOCK_SIZE};
use crate::installers::inno::read::block::{InnoBlockReader, INNO_BLOCK_SIZE};
use crate::installers::inno::read::crc32::Crc32Reader;
use crate::installers::inno::version::{InnoVersion, KnownVersion};
use crate::installers::inno::wizard::Wizard;
Expand Down Expand Up @@ -168,14 +168,14 @@ impl Inno {
});
}

let mut block_filter = InnoBlockFilter::new(cursor.take(u64::from(*stored_size)));
let mut block_reader = InnoBlockReader::new(cursor.take(u64::from(*stored_size)));
let mut reader: Box<dyn Read> = match stored_size {
Compression::LZMA1(_) => {
let stream = read_lzma_stream_header(&mut block_filter)?;
Box::new(XzDecoder::new_stream(block_filter, stream))
let stream = read_lzma_stream_header(&mut block_reader)?;
Box::new(XzDecoder::new_stream(block_reader, stream))
}
Compression::Zlib(_) => Box::new(ZlibDecoder::new(block_filter)),
Compression::Stored(_) => Box::new(block_filter),
Compression::Zlib(_) => Box::new(ZlibDecoder::new(block_reader)),
Compression::Stored(_) => Box::new(block_reader),
};

let mut codepage = if known_version.is_unicode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use byteorder::{ReadBytesExt, LE};
use crc32fast::Hasher;
use std::cmp::min;
use std::io::{Error, ErrorKind, Read, Result};

pub const INNO_BLOCK_SIZE: u16 = 1 << 12;

pub struct InnoBlockFilter<R: Read> {
pub struct InnoBlockReader<R: Read> {
inner: R,
buffer: [u8; INNO_BLOCK_SIZE as usize],
pos: usize,
length: usize,
}

impl<R: Read> InnoBlockFilter<R> {
impl<R: Read> InnoBlockReader<R> {
pub const fn new(inner: R) -> Self {
Self {
inner,
Expand All @@ -39,9 +38,7 @@ impl<R: Read> InnoBlockFilter<R> {
));
}

let mut hasher = Hasher::new();
hasher.update(&self.buffer[..self.length]);
let actual_crc32 = hasher.finalize();
let actual_crc32 = crc32fast::hash(&self.buffer[..self.length]);

if actual_crc32 != block_crc32 {
return Err(Error::new(
Expand All @@ -56,7 +53,7 @@ impl<R: Read> InnoBlockFilter<R> {
}
}

impl<R: Read> Read for InnoBlockFilter<R> {
impl<R: Read> Read for InnoBlockReader<R> {
fn read(&mut self, dest: &mut [u8]) -> Result<usize> {
let mut total_read = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/installers/inno/read/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod block_filter;
pub mod block;
pub mod crc32;
4 changes: 2 additions & 2 deletions src/installers/inno/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ impl KnownVersion {
parts.next().unwrap_or_default(),
);

// Inno Setup 6 and above is always only Unicode
if inno_version >= (6, 0, 0) {
// Inno Setup 6.3.0 and above is always only Unicode
if inno_version >= (6, 3, 0) {
return Some(Self {
version: inno_version,
variant: VersionFlags::UNICODE,
Expand Down

0 comments on commit 06b52f9

Please sign in to comment.