modified: Cargo.toml
This commit is contained in:
parent
dfcdc18df8
commit
df6981e34d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -353,7 +353,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "nicotine"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
dependencies = [
|
||||
"zip-extract",
|
||||
]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nicotine"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
edition = "2024"
|
||||
description = "A small rust crate for patching mojang's Authlib"
|
||||
authors = ["alterwain"]
|
||||
|
26
src/lib.rs
26
src/lib.rs
@ -30,7 +30,7 @@ fn write_7za() {
|
||||
let _ = std::fs::write("tmp/7za.exe", ZIP_BIN);
|
||||
}
|
||||
|
||||
pub fn patch_jar(input_jar: &str, output_jar: &str, needle: &[u8], endpoint: &str) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||
pub fn patch_jar(input_jar: &str, output_jar: &str, needles: &[&[u8]], endpoint: &str) -> Result<(), Box<dyn Error + Sync + Send>> {
|
||||
|
||||
write_7za();
|
||||
|
||||
@ -45,17 +45,19 @@ pub fn patch_jar(input_jar: &str, output_jar: &str, needle: &[u8], endpoint: &st
|
||||
|
||||
for path in recursively_find_classes(PathBuf::from(".\\out")) {
|
||||
let mut haystack = std::fs::read(&path).unwrap();
|
||||
let mut v = find_subsequence(&haystack, needle);
|
||||
if v.is_empty() { continue; }
|
||||
while let Some(g) = v.first() {
|
||||
let (a,b) = haystack.split_at(*g);
|
||||
let l = a[a.len()-1];
|
||||
let mut a = a[..a.len()-1].to_vec();
|
||||
a.push( if l as usize > needle.len() { (replacement.len() + (l as usize - needle.len())) as u8 } else { replacement.len() as u8 });
|
||||
a.append(&mut replacement.to_vec());
|
||||
a.append(&mut b[needle.len()..].to_vec());
|
||||
haystack = a;
|
||||
v = find_subsequence(&haystack, needle);
|
||||
for needle in needles {
|
||||
let mut v = find_subsequence(&haystack, needle);
|
||||
if v.is_empty() { continue; }
|
||||
while let Some(g) = v.first() {
|
||||
let (a,b) = haystack.split_at(*g);
|
||||
let l = a[a.len()-1];
|
||||
let mut a = a[..a.len()-1].to_vec();
|
||||
a.push( if l as usize > needle.len() { (replacement.len() + (l as usize - needle.len())) as u8 } else { replacement.len() as u8 });
|
||||
a.append(&mut replacement.to_vec());
|
||||
a.append(&mut b[needle.len()..].to_vec());
|
||||
haystack = a;
|
||||
v = find_subsequence(&haystack, needle);
|
||||
}
|
||||
}
|
||||
|
||||
std::fs::write(path, haystack)?;
|
||||
|
Loading…
x
Reference in New Issue
Block a user