Add catsystem2 int archive support

This commit is contained in:
2025-06-29 13:27:04 +08:00
parent 63286fe5a0
commit 0a6ac0afcb
12 changed files with 654 additions and 4 deletions

48
src/utils/crc32.rs Normal file
View File

@@ -0,0 +1,48 @@
use lazy_static::lazy_static;
fn get_crc32normal_table() -> [u32; 256] {
let mut table = [0; 256];
for i in 0..256u32 {
let mut c = i << 24;
for _ in 0..8 {
if c & 0x80000000 != 0 {
c = (c << 1) ^ 0x04C11DB7; // Polynomial for CRC-32
} else {
c <<= 1;
}
}
table[i as usize] = c;
}
table
}
lazy_static! {
pub static ref CRC32NORMAL_TABLE: [u32; 256] = get_crc32normal_table();
}
pub struct Crc32Normal {
crc: u32,
}
impl Crc32Normal {
pub fn new() -> Self {
Crc32Normal { crc: 0xFFFFFFFF }
}
pub fn update_crc(init_crc: u32, data: &[u8]) -> u32 {
let mut crc = init_crc;
for &byte in data {
let index = ((crc >> 24) ^ byte as u32) & 0xFF;
crc = (crc << 8) ^ CRC32NORMAL_TABLE[index as usize];
}
crc ^ 0xFFFFFFFF
}
pub fn update(&mut self, data: &[u8]) {
self.crc = Self::update_crc(self.crc, data);
}
pub fn value(&self) -> u32 {
self.crc
}
}

View File

@@ -1,6 +1,8 @@
#[cfg(feature = "utils-bit-stream")]
pub mod bit_stream;
pub mod counter;
#[cfg(feature = "utils-crc32")]
pub mod crc32;
pub mod encoding;
#[cfg(windows)]
mod encoding_win;