modified: Cargo.lock

modified:   Cargo.toml
	deleted:    src/7zip/7za.dll
	deleted:    src/7zip/7zxa.dll
	modified:   src/lib.rs
This commit is contained in:
Michael Wain 2025-03-18 17:58:41 +03:00
parent d5ac96d2c9
commit efc4b40421
5 changed files with 30 additions and 153 deletions

105
Cargo.lock generated
View File

@ -353,10 +353,8 @@ dependencies = [
[[package]]
name = "nicotine"
version = "0.1.9"
version = "0.1.10"
dependencies = [
"walkdir",
"zip",
"zip-extract",
]
@ -418,15 +416,6 @@ version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.219"
@ -564,16 +553,6 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
@ -640,88 +619,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "winapi-util"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
"windows-sys",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"

View File

@ -1,6 +1,6 @@
[package]
name = "nicotine"
version = "0.1.9"
version = "0.1.10"
edition = "2024"
description = "A small rust crate for patching mojang's Authlib"
authors = ["alterwain"]
@ -9,6 +9,4 @@ authors = ["alterwain"]
crate-type = ["staticlib", "cdylib", "lib"]
[dependencies]
zip-extract = "0.2.1"
zip = { version = "2.4.1", features = ["deflate"] }
walkdir = "2"
zip-extract = "0.2.1"

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,6 @@
use std::{error::Error, fs::File, io::{Cursor, Read, Seek, Write}, path::{Path, PathBuf}};
use std::{error::Error, io::Cursor, path::{Path, PathBuf}, process::Command};
use zip::{write::SimpleFileOptions, CompressionMethod, ZipWriter};
const ZIP_BIN: &[u8; 1327616] = include_bytes!("7zip/7za.exe");
fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Vec<usize> {
haystack.windows(needle.len())
@ -12,14 +12,12 @@ fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Vec<usize> {
fn recursively_find_classes(path: PathBuf) -> Vec<PathBuf> {
let e = std::fs::read_dir(path).unwrap();
let mut classes = Vec::new();
for entry in e {
if let Ok(entry) = entry {
match entry.metadata().unwrap().is_dir() {
true => classes.append(&mut recursively_find_classes(entry.path())),
false => {
if entry.file_name().to_str().unwrap().ends_with(".class") {
classes.push(entry.path());
}
for entry in e.flatten() {
match entry.metadata().unwrap().is_dir() {
true => classes.append(&mut recursively_find_classes(entry.path())),
false => {
if entry.file_name().to_str().unwrap().ends_with(".class") {
classes.push(entry.path());
}
}
}
@ -29,7 +27,14 @@ fn recursively_find_classes(path: PathBuf) -> Vec<PathBuf> {
// patch_jar(r#"D:\Documents\RustroverProjects\XCraft\xcraft\libraries\com\mojang\authlib\1.5.22\authlib-1.5.22__.jar"#, "authlib_patched.jar", "http://localhost:8999/api/")
fn write_7za() {
let _ = std::fs::write("tmp/7za.exe", ZIP_BIN);
}
pub fn patch_jar(input_jar: &str, output_jar: &str, endpoint: &str) -> Result<(), Box<dyn Error + Sync + Send>> {
write_7za();
let mut target_dir = PathBuf::new();
target_dir.push("out");
@ -58,47 +63,24 @@ pub fn patch_jar(input_jar: &str, output_jar: &str, endpoint: &str) -> Result<()
std::fs::write(path, haystack)?;
}
let jar = File::create(output_jar)?;
zip_dir(&target_dir, output_jar)?;
zip_dir(&target_dir, &target_dir, jar)?;
//std::fs::remove_dir_all(&target_dir)?;
std::fs::remove_dir_all(&target_dir)?;
Ok(())
}
fn zip_dir<T: Write + Seek>(
fn zip_dir(
src_dir: &Path,
prefix: &Path,
writer: T,
) -> zip::result::ZipResult<()> {
let mut zip = ZipWriter::new(writer);
let file_options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Deflated);
let dir_options = SimpleFileOptions::default()
.compression_method(CompressionMethod::Deflated);
let mut buffer = Vec::new();
for entry in walkdir::WalkDir::new(src_dir).same_file_system(true).min_depth(1) {
let entry = entry.unwrap();
let path = entry.path();
let name = path.strip_prefix(prefix).unwrap();
let dos_path = name.to_string_lossy().replace("/", "\\");
if path.is_file() {
let mut f = File::open(path)?;
f.read_to_end(&mut buffer)?;
zip.start_file(dos_path, file_options)?;
zip.write_all(&buffer)?;
buffer.clear();
} else if path.is_dir() {
zip.add_directory(dos_path, dir_options)?;
}
}
zip.finish()?;
writer: &str,
) -> Result<(), Box<dyn Error + Sync + Send>> {
let _a = Command::new("tmp/7za.exe")
.arg("a")
.arg("-tzip")
.arg("-mx=0")
.arg(writer)
.arg([src_dir.to_str().unwrap(), "/", "*"].concat())
.spawn()?;
Ok(())
}