pub fn decode_config(file_path: &str) {
let mut file_bytes = std::fs::read(file_path).unwrap();
let mut dst = vec![0u8; 2048];
decode_dat(&mut file_bytes, dst.as_mut_slice());
let mut config = String::new();
for i in 0..dst.len() {
if dst[i] == 0 {
break;
}
config.push(dst[i] as char);
}
info!("解密成功,原文如下:\n{}", config);
}
fn decode_dat(src: &mut [u8], dst: &mut [u8]) {
let mut tmp = vec![0x20u8; 0x8000];
for i in 0..src.len() {
src[i] = 255 - src[i];
}
let mut m = 0;
let mut n = 0;
let mut d = 0;
let mut si = 0;
let mut di = 0;
let mut s;
s = src[si];
si += 1;
loop {
if si >= src.len() {
return;
}
for i in 0..8 {
d = 1 << i;
if (s & d) == 0 {
d = src[si];
si += 1;
if si >= src.len() {
return;
}
tmp[(m << 7) ^ n] = d;
} else {
d = tmp[(m << 7) ^ n];
}
dst[di] = d;
di += 1;
if di >= dst.len() {
return;
}
m = n;
n = d as usize;
}
s = src[si];
si += 1;
}
}