aboutsummaryrefslogtreecommitdiff
path: root/crates/rsli/src/compress/xor.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-02-10 11:38:58 +0300
committerValentin Popov <valentin@popov.link>2026-02-10 11:38:58 +0300
commit842f4a85693b418af81560738aa3136ac500d9b1 (patch)
treed18cf54120294a312bf90d2a5282e3d640c43c57 /crates/rsli/src/compress/xor.rs
parentce6e30f7272fd0c064ef52ac85cad1c0f05fd323 (diff)
downloadfparkan-842f4a85693b418af81560738aa3136ac500d9b1.tar.xz
fparkan-842f4a85693b418af81560738aa3136ac500d9b1.zip
Implement LZSS decompression with optional XOR decryption
- Added `lzss_decompress_simple` function for LZSS decompression in `lzss.rs`. - Introduced `XorState` struct and `xor_stream` function for XOR decryption in `xor.rs`. - Updated `mod.rs` to include new LZSS and XOR modules. - Refactored `parse_library` function in `parse.rs` to utilize the new XOR decryption functionality. - Cleaned up and organized code in `lib.rs` by removing redundant functions and structures. - Added tests for new functionality in `tests.rs`.
Diffstat (limited to 'crates/rsli/src/compress/xor.rs')
-rw-r--r--crates/rsli/src/compress/xor.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/crates/rsli/src/compress/xor.rs b/crates/rsli/src/compress/xor.rs
new file mode 100644
index 0000000..c4c3d7d
--- /dev/null
+++ b/crates/rsli/src/compress/xor.rs
@@ -0,0 +1,29 @@
+/// XOR cipher state for RsLi format
+pub struct XorState {
+ lo: u8,
+ hi: u8,
+}
+
+impl XorState {
+ /// Create new XOR state from 16-bit key
+ pub fn new(key16: u16) -> Self {
+ Self {
+ lo: (key16 & 0xFF) as u8,
+ hi: ((key16 >> 8) & 0xFF) as u8,
+ }
+ }
+
+ /// Decrypt a single byte and update state
+ pub fn decrypt_byte(&mut self, encrypted: u8) -> u8 {
+ self.lo = self.hi ^ self.lo.wrapping_shl(1);
+ let decrypted = encrypted ^ self.lo;
+ self.hi = self.lo ^ (self.hi >> 1);
+ decrypted
+ }
+}
+
+/// Decrypt entire buffer with XOR stream cipher
+pub fn xor_stream(data: &[u8], key16: u16) -> Vec<u8> {
+ let mut state = XorState::new(key16);
+ data.iter().map(|&b| state.decrypt_byte(b)).collect()
+}