From 405fad8bd193a33dca9f0388ad165cdbeb017799 Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Wed, 22 Nov 2023 01:34:19 +0100 Subject: [PATCH 1/4] Update logging --- src/udk_log.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/udk_log.rs b/src/udk_log.rs index 01d5dab..5148796 100644 --- a/src/udk_log.rs +++ b/src/udk_log.rs @@ -1,6 +1,4 @@ //! This module contains functionality relevant to UDK logging. -use widestring::WideCStr; - use crate::get_udk_slice; use crate::udk_offsets::{DEBUG_FN_OFFSET, DEBUG_LOG_OFFSET}; @@ -11,24 +9,24 @@ type UDKLogFn = unsafe extern "C" fn(usize, u32, *const widestring::WideChar); /// This enum represents the UDK message types. #[repr(u32)] pub enum LogType { - Init = 762, - Warning = 767, + Init = 0x2fa, + //Debug = 0x36c, + //Log = 0x2f8, + Warning = 0x2ff, + //Error = 0x315, + //Critical = 0x2f9, } -pub fn log_wide(typ: LogType, wmsg: &WideCStr) { +/// Log a message via the UDK logging framework. +pub fn log(typ: LogType, msg: &str) { let udk_slice = get_udk_slice(); let log_obj = unsafe { udk_slice.as_ptr().add(DEBUG_LOG_OFFSET) }; let log_fn: UDKLogFn = unsafe { std::mem::transmute(udk_slice.as_ptr().add(DEBUG_FN_OFFSET)) }; + // Convert the UTF-8 Rust string into an OS wide string. + let wmsg: widestring::U16CString = widestring::WideCString::from_str(format!("discord.dll: {}", msg)).unwrap(); + unsafe { (log_fn)(log_obj as usize, typ as u32, wmsg.as_ptr()); } } - -/// Log a message via the UDK logging framework. -pub fn log(typ: LogType, msg: &str) { - // Convert the UTF-8 Rust string into an OS wide string. - let wmsg = widestring::WideCString::from_str(&msg).unwrap(); - - log_wide(typ, &wmsg) -} From e8180c560e5487f9911f61a049c902d1cdb61a1f Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Wed, 22 Nov 2023 01:36:02 +0100 Subject: [PATCH 2/4] Add target architecture offsets --- src/udk_offsets.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/udk_offsets.rs b/src/udk_offsets.rs index 5e31775..d8a94fc 100644 --- a/src/udk_offsets.rs +++ b/src/udk_offsets.rs @@ -2,9 +2,18 @@ // Logging offsets. /// Offset from the beginning of UDK64.exe to the debug log object. -pub const DEBUG_LOG_OFFSET: usize = 0x0355_1720; +#[cfg(target_arch = "x86_64")] +const DEBUG_LOG_OFFSET: usize = 0x0355_1720; /// Address of UDK's log function. -pub const DEBUG_FN_OFFSET: usize = 0x0024_6A20; +#[cfg(target_arch = "x86_64")] +const DEBUG_FN_OFFSET: usize = 0x0024_6A20; + +/// Offset from the beginning of UDK64.exe to the debug log object. +#[cfg(target_arch = "x86")] +const DEBUG_LOG_OFFSET: usize = 0x029a_31a8; +/// Address of UDK's log function. +#[cfg(target_arch = "x86")] +const DEBUG_FN_OFFSET: usize = 0x0002_1c500; // XAudio2 offsets. // pub const UDK_INITHW_OFFSET: usize = 0x0171_1ED0; From 8e5bed8d88431c9833d0a8c5c97060fbbae5bd32 Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Wed, 22 Nov 2023 01:37:04 +0100 Subject: [PATCH 3/4] Update lib.rs --- src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index c3b9c3e..446cabf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,11 +7,18 @@ mod udk_log; mod udk_offsets; mod udk_xaudio; +#[cfg(target_arch = "x86_64")] const UDK_KNOWN_HASH: [u8; 32] = [ 0x0D, 0xE6, 0x90, 0x31, 0xEA, 0x41, 0x01, 0xF2, 0x18, 0xB6, 0x61, 0x27, 0xFD, 0x14, 0x3A, 0x8E, 0xC3, 0xF7, 0x48, 0x3E, 0x31, 0x9C, 0x3D, 0x8D, 0xD5, 0x1F, 0xA2, 0x8D, 0x7C, 0xBF, 0x08, 0xF5, ]; +#[cfg(target_arch = "x86")] +const UDK_KNOWN_HASH: [u8; 32] = [ + 0xEF, 0xAF, 0xBA, 0x91, 0xD3, 0x05, 0x2D, 0x07, 0x07, 0xDD, 0xF2, 0xF2, 0x14, 0x15, 0x00, 0xFA, + 0x6C, 0x1E, 0x8F, 0x9E, 0xF0, 0x70, 0x40, 0xB8, 0xF9, 0x96, 0x73, 0x8A, 0x00, 0xFB, 0x90, 0x07, +]; + use anyhow::Context; use sha2::{Digest, Sha256}; From 999c1bb28ebc8b0dcc05e7257ae938367e9e27e9 Mon Sep 17 00:00:00 2001 From: Randy von der Weide Date: Wed, 22 Nov 2023 01:39:32 +0100 Subject: [PATCH 4/4] Update udk_log.rs --- src/udk_log.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/udk_log.rs b/src/udk_log.rs index 5148796..251d967 100644 --- a/src/udk_log.rs +++ b/src/udk_log.rs @@ -24,7 +24,7 @@ pub fn log(typ: LogType, msg: &str) { let log_fn: UDKLogFn = unsafe { std::mem::transmute(udk_slice.as_ptr().add(DEBUG_FN_OFFSET)) }; // Convert the UTF-8 Rust string into an OS wide string. - let wmsg: widestring::U16CString = widestring::WideCString::from_str(format!("discord.dll: {}", msg)).unwrap(); + let wmsg: widestring::U16CString = widestring::WideCString::from_str(format!("TotemArts Extensions: {}", msg)).unwrap(); unsafe { (log_fn)(log_obj as usize, typ as u32, wmsg.as_ptr());