mirror of
https://github.com/xavo95/repak.git
synced 2025-01-18 19:04:07 +00:00
trying to figure out what's borking entry
This commit is contained in:
parent
c571865d94
commit
cd9f5ba98d
4 changed files with 52 additions and 56 deletions
|
@ -7,7 +7,7 @@ pub struct Entry {
|
||||||
pub offset: u64,
|
pub offset: u64,
|
||||||
pub compressed: u64,
|
pub compressed: u64,
|
||||||
pub uncompressed: u64,
|
pub uncompressed: u64,
|
||||||
pub compression_method: Compression,
|
pub compression: Compression,
|
||||||
pub timestamp: Option<u64>,
|
pub timestamp: Option<u64>,
|
||||||
pub hash: [u8; 20],
|
pub hash: [u8; 20],
|
||||||
pub compression_blocks: Option<Vec<Block>>,
|
pub compression_blocks: Option<Vec<Block>>,
|
||||||
|
@ -23,7 +23,7 @@ impl Entry {
|
||||||
let offset = reader.read_u64::<LE>()?;
|
let offset = reader.read_u64::<LE>()?;
|
||||||
let compressed = reader.read_u64::<LE>()?;
|
let compressed = reader.read_u64::<LE>()?;
|
||||||
let uncompressed = reader.read_u64::<LE>()?;
|
let uncompressed = reader.read_u64::<LE>()?;
|
||||||
let compression_method = match reader.read_u32::<LE>()? {
|
let compression = match reader.read_u32::<LE>()? {
|
||||||
0x01 | 0x10 | 0x20 => Compression::Zlib,
|
0x01 | 0x10 | 0x20 => Compression::Zlib,
|
||||||
_ => Compression::None,
|
_ => Compression::None,
|
||||||
};
|
};
|
||||||
|
@ -31,14 +31,14 @@ impl Entry {
|
||||||
offset,
|
offset,
|
||||||
compressed,
|
compressed,
|
||||||
uncompressed,
|
uncompressed,
|
||||||
compression_method,
|
compression,
|
||||||
timestamp: match version == Version::Initial {
|
timestamp: match version == Version::Initial {
|
||||||
true => Some(reader.read_u64::<LE>()?),
|
true => Some(reader.read_u64::<LE>()?),
|
||||||
false => None,
|
false => None,
|
||||||
},
|
},
|
||||||
hash: reader.read_guid()?,
|
hash: reader.read_guid()?,
|
||||||
compression_blocks: match version >= Version::CompressionEncryption
|
compression_blocks: match version >= Version::CompressionEncryption
|
||||||
&& compression_method != Compression::None
|
&& compression != Compression::None
|
||||||
{
|
{
|
||||||
true => Some(reader.read_array(Block::new)?),
|
true => Some(reader.read_array(Block::new)?),
|
||||||
false => None,
|
false => None,
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct Footer {
|
||||||
pub size: u64,
|
pub size: u64,
|
||||||
pub hash: [u8; 20],
|
pub hash: [u8; 20],
|
||||||
pub frozen: bool,
|
pub frozen: bool,
|
||||||
pub compression: Option<Vec<Compression>>,
|
pub compression: Vec<Compression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Footer {
|
impl Footer {
|
||||||
|
@ -31,29 +31,26 @@ impl Footer {
|
||||||
size: reader.read_u64::<LE>()?,
|
size: reader.read_u64::<LE>()?,
|
||||||
hash: reader.read_guid()?,
|
hash: reader.read_guid()?,
|
||||||
frozen: version == Version::FrozenIndex && reader.read_bool()?,
|
frozen: version == Version::FrozenIndex && reader.read_bool()?,
|
||||||
compression: match version >= Version::FNameBasedCompression {
|
compression: {
|
||||||
true => {
|
let mut compression = Vec::with_capacity(match version {
|
||||||
let mut compression =
|
ver if ver < Version::FNameBasedCompression => 0,
|
||||||
Vec::with_capacity(match version == Version::FNameBasedCompression {
|
Version::FNameBasedCompression => 4,
|
||||||
true => 4,
|
_ => 5,
|
||||||
false => 5,
|
});
|
||||||
});
|
for _ in 0..compression.capacity() {
|
||||||
for _ in 0..compression.capacity() {
|
compression.push(
|
||||||
compression.push(
|
Compression::from_str(
|
||||||
Compression::from_str(
|
&reader
|
||||||
&reader
|
.read_len(32)?
|
||||||
.read_len(32)?
|
.iter()
|
||||||
.iter()
|
// filter out whitespace and convert to char
|
||||||
// filter out whitespace and convert to char
|
.filter_map(|&ch| (ch != 0).then_some(ch as char))
|
||||||
.filter_map(|&ch| (ch != 0).then_some(ch as char))
|
.collect::<String>(),
|
||||||
.collect::<String>(),
|
|
||||||
)
|
|
||||||
.unwrap_or_default(),
|
|
||||||
)
|
)
|
||||||
}
|
.unwrap_or_default(),
|
||||||
Some(compression)
|
)
|
||||||
}
|
}
|
||||||
false => None,
|
compression
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if super::MAGIC != footer.magic {
|
if super::MAGIC != footer.magic {
|
||||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -24,7 +24,6 @@ pub enum Version {
|
||||||
EncryptionKeyGuid, // include key GUID
|
EncryptionKeyGuid, // include key GUID
|
||||||
FNameBasedCompression, // compression names included
|
FNameBasedCompression, // compression names included
|
||||||
FrozenIndex, // frozen index byte included
|
FrozenIndex, // frozen index byte included
|
||||||
PathHashIndex, // more compression methods
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// strum shouldn't need to be installed by users
|
// strum shouldn't need to be installed by users
|
||||||
|
@ -32,6 +31,32 @@ impl Version {
|
||||||
pub fn iter() -> VersionIter {
|
pub fn iter() -> VersionIter {
|
||||||
<Version as strum::IntoEnumIterator>::iter()
|
<Version as strum::IntoEnumIterator>::iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn size(self) -> i64 {
|
||||||
|
// (magic + version): u32 + (offset + size): u64 + hash: [u8; 20]
|
||||||
|
let mut size = 4 + 4 + 8 + 8 + 20;
|
||||||
|
if self >= Version::EncryptionKeyGuid {
|
||||||
|
// encryption uuid: u128
|
||||||
|
size += 16;
|
||||||
|
}
|
||||||
|
if self >= Version::IndexEncryption {
|
||||||
|
// encrypted: bool
|
||||||
|
size += 1;
|
||||||
|
}
|
||||||
|
if self == Version::FrozenIndex {
|
||||||
|
// frozen index: bool
|
||||||
|
size += 1;
|
||||||
|
}
|
||||||
|
if self >= Version::FNameBasedCompression {
|
||||||
|
// compression names: [[u8; 32]; 4]
|
||||||
|
size += 32 * 4;
|
||||||
|
}
|
||||||
|
if self >= Version::FrozenIndex {
|
||||||
|
// extra compression name: [u8; 32]
|
||||||
|
size += 32
|
||||||
|
}
|
||||||
|
size
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, strum::Display, strum::EnumString)]
|
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug, strum::Display, strum::EnumString)]
|
||||||
|
|
32
src/pak.rs
32
src/pak.rs
|
@ -17,15 +17,15 @@ impl Pak {
|
||||||
version: super::Version,
|
version: super::Version,
|
||||||
mut reader: R,
|
mut reader: R,
|
||||||
) -> Result<Self, super::Error> {
|
) -> Result<Self, super::Error> {
|
||||||
reader.seek(io::SeekFrom::End(-footer_size(&version)))?;
|
reader.seek(io::SeekFrom::End(-version.size()))?;
|
||||||
let footer = super::Footer::new(&mut reader, version)?;
|
let footer = super::Footer::new(&mut reader, version)?;
|
||||||
reader.seek(io::SeekFrom::Start(footer.offset))?;
|
reader.seek(io::SeekFrom::Start(footer.offset))?;
|
||||||
let mount_point = reader.read_string()?;
|
let mount_point = reader.read_string()?;
|
||||||
let mut entries = hashbrown::HashMap::with_capacity(reader.read_u32::<LE>()? as usize);
|
let mut entries = hashbrown::HashMap::with_capacity(reader.read_u32::<LE>()? as usize);
|
||||||
for _ in 0..entries.capacity() {
|
for _ in 0..entries.capacity() {
|
||||||
entries.insert(
|
entries.insert(
|
||||||
reader.read_string()?,
|
dbg!(reader.read_string()?),
|
||||||
super::Entry::new(&mut reader, version)?,
|
dbg!(super::Entry::new(&mut reader, version)?),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -35,29 +35,3 @@ impl Pak {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer_size(version: &Version) -> i64 {
|
|
||||||
// (magic + version): u32 + (offset + size): u64 + hash: [u8; 20]
|
|
||||||
let mut size = 4 + 4 + 8 + 8 + 20;
|
|
||||||
if version >= &Version::EncryptionKeyGuid {
|
|
||||||
// encryption uuid: u128
|
|
||||||
size += 16;
|
|
||||||
}
|
|
||||||
if version >= &Version::IndexEncryption {
|
|
||||||
// encrypted: bool
|
|
||||||
size += 1;
|
|
||||||
}
|
|
||||||
if version == &Version::FrozenIndex {
|
|
||||||
// frozen index: bool
|
|
||||||
size += 1;
|
|
||||||
}
|
|
||||||
if version >= &Version::FNameBasedCompression {
|
|
||||||
// compression names: [[u8; 32]; 4]
|
|
||||||
size += 32 * 4;
|
|
||||||
}
|
|
||||||
if version >= &Version::FrozenIndex {
|
|
||||||
// extra compression name: [u8; 32]
|
|
||||||
size += 32
|
|
||||||
}
|
|
||||||
size
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue