-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from willox/ckey_override
add guest_override command
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use region::Protection; | ||
use std::{ffi::CString, os::raw::c_char}; | ||
|
||
use auxtools::*; | ||
|
||
static mut STRING_PTR: *mut *const c_char = std::ptr::null_mut(); | ||
|
||
#[init(full)] | ||
fn ckey_override_init() -> Result<(), String> { | ||
let byondcore = sigscan::Scanner::for_module(BYONDCORE).unwrap(); | ||
|
||
// This feature soft-fails | ||
#[cfg(windows)] | ||
if let Some(ptr) = byondcore.find(signature!( | ||
"68 ?? ?? ?? ?? 50 E8 ?? ?? ?? ?? 83 C4 0C 8D 8D ?? ?? ?? ?? E8 ?? ?? ?? ?? 8B 85 ?? ?? ?? ??" | ||
)) { | ||
unsafe { | ||
STRING_PTR = ptr.add(1) as *mut *const c_char; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
UnsupportedByondVersion, | ||
InvalidString, | ||
} | ||
|
||
pub fn override_guest_ckey(name: &str) -> Result<(), Error> { | ||
unsafe { | ||
if STRING_PTR.is_null() { | ||
return Err(Error::UnsupportedByondVersion); | ||
} | ||
} | ||
|
||
let name = name.replace('%', "%%"); | ||
|
||
let new_ptr = CString::new(name) | ||
.map_err(|_| Error::InvalidString)? | ||
.into_raw(); | ||
|
||
unsafe { | ||
region::protect(STRING_PTR as *const u8, 4, Protection::READ_WRITE_EXECUTE).unwrap(); | ||
|
||
// Leak is fine | ||
*STRING_PTR = new_ptr; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod assemble_env; | ||
mod ckey_override; | ||
mod disassemble_env; | ||
mod instruction_hooking; | ||
mod server; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters