Add implicit oodle feature

This commit is contained in:
Truman Kilen 2024-02-24 15:12:15 -06:00
parent abda6dae9f
commit 96410d664a
5 changed files with 20 additions and 11 deletions

View file

@ -104,8 +104,6 @@ fn fetch_oodle() -> Result<std::path::PathBuf> {
mod windows_oodle {
use super::*;
use anyhow::Context;
static DECOMPRESS: OnceLock<(OodleLZ_Decompress, libloading::Library)> = OnceLock::new();
pub fn decompress_wrapper_windows(comp_buf: &[u8], raw_buf: &mut [u8]) -> i32 {
@ -126,7 +124,6 @@ mod windows_oodle {
mod linux_oodle {
use super::*;
use anyhow::Result;
use object::pe::{
ImageNtHeaders64, IMAGE_REL_BASED_DIR64, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ,
IMAGE_SCN_MEM_WRITE,

View file

@ -11,6 +11,8 @@ default = ["compression", "encryption"]
compression = ["dep:flate2", "dep:zstd"]
oodle = []
oodle_loader = ["dep:oodle_loader"]
oodle_explicit = ["oodle"]
oodle_implicit_dynamic = ["dep:oodle_loader", "oodle"]
encryption = ["dep:aes"]
[dependencies]

View file

@ -7,7 +7,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, LE};
use std::collections::BTreeMap;
use std::io::{self, Read, Seek, Write};
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct PakBuilder {
key: super::Key,
oodle: super::Oodle,
@ -16,14 +16,21 @@ pub struct PakBuilder {
impl PakBuilder {
pub fn new() -> Self {
Self::default()
Self {
key: Default::default(),
#[cfg(not(feature = "oodle_implicit_dynamic"))]
oodle: super::Oodle::None,
#[cfg(feature = "oodle_implicit_dynamic")]
oodle: super::Oodle::Some(oodle_loader::decompress),
allowed_compression: Default::default(),
}
}
#[cfg(feature = "encryption")]
pub fn key(mut self, key: aes::Aes256) -> Self {
self.key = super::Key::Some(key);
self
}
#[cfg(feature = "oodle")]
#[cfg(feature = "oodle_explicit")]
pub fn oodle(mut self, oodle_getter: super::oodle::OodleGetter) -> Self {
self.oodle = super::Oodle::Some(oodle_getter);
self

View file

@ -17,9 +17,12 @@ eula = false
name = "repak"
path = "src/main.rs"
[features]
default = ["oodle"]
oodle = ["repak/oodle_implicit_dynamic"]
[dependencies]
oodle_loader = { path = "../oodle_loader" }
repak = { path = "../repak", features = ["oodle"] }
repak = { path = "../repak" }
aes = { workspace = true }
base64 = { workspace = true }
clap = { version = "4.1.4", features = ["derive"] }

View file

@ -238,7 +238,7 @@ fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::E
}
fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(), repak::Error> {
let mut builder = repak::PakBuilder::new().oodle(oodle_loader::decompress);
let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key {
builder = builder.key(aes_key);
}
@ -311,7 +311,7 @@ impl Output {
fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repak::Error> {
for input in &action.input {
let mut builder = repak::PakBuilder::new().oodle(oodle_loader::decompress);
let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key.clone() {
builder = builder.key(aes_key);
}
@ -506,7 +506,7 @@ fn pack(args: ActionPack) -> Result<(), repak::Error> {
fn get(aes_key: Option<aes::Aes256>, args: ActionGet) -> Result<(), repak::Error> {
let mut reader = BufReader::new(File::open(&args.input)?);
let mut builder = repak::PakBuilder::new().oodle(oodle_loader::decompress);
let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key {
builder = builder.key(aes_key);
}