Skip to content

Commit

Permalink
wip: temporary give back ProgramFilesDir
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Sep 12, 2024
1 parent 8f9ed72 commit 1fe6e44
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions cli/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl win32::Host for EnvRef {

fn set_current_dir(&self, path: &WindowsPath) -> Result<(), u32> {
let path = windows_to_host_path(path);
log::info!("set_current_dir {:?}", path);
std::env::set_current_dir(path).map_err(|e| io_error_to_win32(&e))
}

Expand Down
34 changes: 33 additions & 1 deletion win32/src/winapi/advapi32.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#![allow(non_snake_case)]

use memory::ExtensionsMut;

use super::types::Str16;
use crate::machine::Machine;

const TRACE_CONTEXT: &'static str = "advapi32";

const REG_SZ: u32 = 0x00000001; // A string.

pub type HKEY = u32;

#[win32_derive::dllexport]
Expand Down Expand Up @@ -40,14 +44,42 @@ pub fn RegCloseKey(_machine: &mut Machine, hKey: HKEY) -> u32 {

#[win32_derive::dllexport]
pub fn RegQueryValueExA(
_machine: &mut Machine,
machine: &mut Machine,
hKey: HKEY,
lpValueName: Option<&str>,
lpReserved: u32,
lpType: Option<&mut u32>,
lpData: u32,
lpcbData: Option<&mut u32>,
) -> u32 {
if matches!(lpValueName, Some("ProgramFilesDir")) {
// const PROGRAM_FILES: &str = "C:\\Program Files";
const PROGRAM_FILES: &str = "C:\\Users\\linus\\Program Files";

if let Some(lpType) = lpType {
*lpType = REG_SZ;
}

if lpData != 0 {
let in_out_len = lpcbData.unwrap();

if *in_out_len <= PROGRAM_FILES.len() as u32 {
return 234; // ERROR_MORE_DATA
}

*in_out_len = (PROGRAM_FILES.len() as u32) + 1;

let buf = machine.mem().sub32_mut(lpData, *in_out_len);

buf[..PROGRAM_FILES.len()].copy_from_slice(PROGRAM_FILES.as_bytes());
buf[PROGRAM_FILES.len()] = 0;
} else if let Some(lpcbData) = lpcbData {
*lpcbData = (PROGRAM_FILES.len() as u32) + 1;
}

return 0;
}

2 // ERROR_FILE_NOT_FOUND
}

Expand Down

0 comments on commit 1fe6e44

Please sign in to comment.