This commit is contained in:
nora 2025-02-01 17:06:32 +01:00
parent cec97ff44d
commit 64c30e201d
11 changed files with 4426 additions and 213 deletions

230
Cargo.lock generated
View file

@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.8.0" version = "2.8.0"
@ -31,12 +40,45 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.169" version = "0.2.169"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
name = "log"
version = "0.4.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f"
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]] [[package]]
name = "memmap2" name = "memmap2"
version = "0.9.5" version = "0.9.5"
@ -46,6 +88,34 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "pin-project-lite"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
[[package]] [[package]]
name = "portability" name = "portability"
version = "0.1.0" version = "0.1.0"
@ -54,6 +124,8 @@ dependencies = [
"bytemuck", "bytemuck",
"libc", "libc",
"memmap2", "memmap2",
"tracing",
"tracing-subscriber",
"windows", "windows",
] ]
@ -75,6 +147,65 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.96" version = "2.0.96"
@ -86,12 +217,111 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tracing"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"pin-project-lite",
"tracing-attributes",
"tracing-core",
]
[[package]]
name = "tracing-attributes"
version = "0.1.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"smallvec",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.16" version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"
[[package]]
name = "valuable"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows" name = "windows"
version = "0.59.0" version = "0.59.0"

View file

@ -7,6 +7,8 @@ edition = "2021"
bitflags = { version = "2.8.0", features = ["bytemuck"] } bitflags = { version = "2.8.0", features = ["bytemuck"] }
bytemuck = { version = "1.21.0", features = ["derive"] } bytemuck = { version = "1.21.0", features = ["derive"] }
memmap2 = "0.9.5" memmap2 = "0.9.5"
tracing = { version = "0.1.41", features = ["attributes"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
windows = { version = "0.59.0", features = ["Win32_System_Memory", "Win32_Security", "Win32_System_SystemInformation"] } windows = { version = "0.59.0", features = ["Win32_System_Memory", "Win32_Security", "Win32_System_SystemInformation"] }

3309
missing Normal file

File diff suppressed because it is too large Load diff

View file

@ -15,13 +15,18 @@ macro_rules! define_emulation_entry {
} }
define_emulation_entry!( define_emulation_entry!(
advapi32,
api_ms_win_core_synch_l1_2_0,
api_ms_win_core_winrt_error_l1_1_0,
bcrypt,
bcryptprimitives,
kernel32, kernel32,
vcruntime140, ntdll,
api_ms_win_crt_runtime_l1_1_0, ole32,
api_ms_win_crt_math_l1_1_0, oleaut32,
api_ms_win_crt_stdio_l1_1_0, shell32,
api_ms_win_crt_locale_l1_1_0, userenv,
api_ms_win_crt_heap_l1_1_0, ws2_32,
); );
macro_rules! emulate { macro_rules! emulate {
@ -61,167 +66,810 @@ macro_rules! emulate {
}; };
} }
emulate!(
"advapi32.dll",
mod advapi32 {
fn CryptAcquireContextW() {
todo!("CryptAcquireContextW")
}
fn CryptGenRandom() {
todo!("CryptGenRandom")
}
fn CryptReleaseContext() {
todo!("CryptReleaseContext")
}
fn RegCloseKey() {
todo!("RegCloseKey")
}
fn RegEnumKeyExW() {
todo!("RegEnumKeyExW")
}
fn RegGetValueW() {
todo!("RegGetValueW")
}
fn RegOpenKeyExA() {
todo!("RegOpenKeyExA")
}
fn RegOpenKeyExW() {
todo!("RegOpenKeyExW")
}
fn RegQueryValueExW() {
todo!("RegQueryValueExW")
}
fn SystemFunction036() {
todo!("SystemFunction036")
}
}
);
emulate!(
"api-ms-win-core-synch-l1-2-0.dll",
mod api_ms_win_core_synch_l1_2_0 {
fn WaitOnAddress() {
todo!("WaitOnAddress")
}
fn WakeByAddressAll() {
todo!("WakeByAddressAll")
}
fn WakeByAddressSingle() {
todo!("WakeByAddressSingle")
}
}
);
emulate!(
"api-ms-win-core-winrt-error-l1-1-0.dll",
mod api_ms_win_core_winrt_error_l1_1_0 {
fn RoOriginateErrorW() {
todo!("RoOriginateErrorW")
}
}
);
emulate!(
"bcrypt.dll",
mod bcrypt {
fn BCryptGenRandom() {
todo!("BCryptGenRandom")
}
}
);
emulate!(
"bcryptprimitives.dll",
mod bcryptprimitives {
fn ProcessPrng() {
todo!("ProcessPrng")
}
}
);
emulate!( emulate!(
"kernel32.dll", "kernel32.dll",
mod kernel32 { mod kernel32 {
fn QueryPerformanceCounter() { fn AcquireSRWLockExclusive() {
todo!("QueryPerformanceCounter") todo!("AcquireSRWLockExclusive")
}
fn AcquireSRWLockShared() {
todo!("AcquireSRWLockShared")
}
fn AddVectoredExceptionHandler() {
todo!("AddVectoredExceptionHandler")
}
fn AssignProcessToJobObject() {
todo!("AssignProcessToJobObject")
}
fn CancelIo() {
todo!("CancelIo")
}
fn CloseHandle() {
todo!("CloseHandle")
}
fn CompareStringOrdinal() {
todo!("CompareStringOrdinal")
}
fn CompareStringW() {
todo!("CompareStringW")
}
fn ConvertFiberToThread() {
todo!("ConvertFiberToThread")
}
fn ConvertThreadToFiber() {
todo!("ConvertThreadToFiber")
}
fn CopyFileExW() {
todo!("CopyFileExW")
}
fn CreateDirectoryW() {
todo!("CreateDirectoryW")
}
fn CreateEventA() {
todo!("CreateEventA")
}
fn CreateEventW() {
todo!("CreateEventW")
}
fn CreateFiber() {
todo!("CreateFiber")
}
fn CreateFileMappingW() {
todo!("CreateFileMappingW")
}
fn CreateFileW() {
todo!("CreateFileW")
}
fn CreateHardLinkW() {
todo!("CreateHardLinkW")
}
fn CreateJobObjectW() {
todo!("CreateJobObjectW")
}
fn CreateMutexA() {
todo!("CreateMutexA")
}
fn CreateNamedPipeW() {
todo!("CreateNamedPipeW")
}
fn CreatePipe() {
todo!("CreatePipe")
}
fn CreateProcessW() {
todo!("CreateProcessW")
}
fn CreateSemaphoreA() {
todo!("CreateSemaphoreA")
}
fn CreateSymbolicLinkW() {
todo!("CreateSymbolicLinkW")
}
fn CreateThread() {
todo!("CreateThread")
}
fn CreateWaitableTimerExW() {
todo!("CreateWaitableTimerExW")
}
fn DebugBreak() {
todo!("DebugBreak")
}
fn DecodePointer() {
todo!("DecodePointer")
}
fn DeleteCriticalSection() {
todo!("DeleteCriticalSection")
}
fn DeleteFiber() {
todo!("DeleteFiber")
}
fn DeleteFileW() {
todo!("DeleteFileW")
}
fn DeleteProcThreadAttributeList() {
todo!("DeleteProcThreadAttributeList")
}
fn DeviceIoControl() {
todo!("DeviceIoControl")
}
fn DuplicateHandle() {
todo!("DuplicateHandle")
}
fn EncodePointer() {
todo!("EncodePointer")
}
fn EnterCriticalSection() {
todo!("EnterCriticalSection")
}
fn EnumSystemLocalesW() {
todo!("EnumSystemLocalesW")
}
fn ExitProcess() {
todo!("ExitProcess")
}
fn ExpandEnvironmentStringsW() {
todo!("ExpandEnvironmentStringsW")
}
fn FindClose() {
todo!("FindClose")
}
fn FindFirstFileExW() {
todo!("FindFirstFileExW")
}
fn FindNextFileW() {
todo!("FindNextFileW")
}
fn FlsAlloc() {
todo!("FlsAlloc")
}
fn FlsFree() {
todo!("FlsFree")
}
fn FlsGetValue() {
todo!("FlsGetValue")
}
fn FlsSetValue() {
todo!("FlsSetValue")
}
fn FlushFileBuffers() {
todo!("FlushFileBuffers")
}
fn FlushViewOfFile() {
todo!("FlushViewOfFile")
}
fn FormatMessageA() {
todo!("FormatMessageA")
}
fn FormatMessageW() {
todo!("FormatMessageW")
}
fn FreeEnvironmentStringsW() {
todo!("FreeEnvironmentStringsW")
}
fn FreeLibrary() {
todo!("FreeLibrary")
}
fn GetACP() {
todo!("GetACP")
}
fn GetCPInfo() {
todo!("GetCPInfo")
}
fn GetCommandLineA() {
todo!("GetCommandLineA")
}
fn GetCommandLineW() {
todo!("GetCommandLineW")
}
fn GetComputerNameExW() {
todo!("GetComputerNameExW")
}
fn GetConsoleMode() {
todo!("GetConsoleMode")
}
fn GetConsoleOutputCP() {
todo!("GetConsoleOutputCP")
}
fn GetConsoleScreenBufferInfo() {
todo!("GetConsoleScreenBufferInfo")
}
fn GetCurrentDirectoryW() {
todo!("GetCurrentDirectoryW")
}
fn GetCurrentProcess() {
todo!("GetCurrentProcess")
} }
fn GetCurrentProcessId() { fn GetCurrentProcessId() {
todo!("GetCurrentProcessId") todo!("GetCurrentProcessId")
} }
fn GetCurrentThread() {
todo!("GetCurrentThread")
}
fn GetCurrentThreadId() { fn GetCurrentThreadId() {
todo!("GetCurrentThreadId") todo!("GetCurrentThreadId")
} }
fn GetSystemTimeAsFileTime() { fn GetDateFormatW() {
todo!("GetSystemTimeAsFileTime") todo!("GetDateFormatW")
} }
fn InitializeSListHead() { fn GetDriveTypeW() {
todo!("InitializeSListHead") todo!("GetDriveTypeW")
} }
fn RtlCaptureContext() { fn GetEnvironmentStringsW() {
todo!("RtlCaptureContext") todo!("GetEnvironmentStringsW")
} }
fn RtlLookupFunctionEntry() { fn GetEnvironmentVariableW() {
todo!("RtlLookupFunctionEntry") todo!("GetEnvironmentVariableW")
} }
fn RtlVirtualUnwind() { fn GetExitCodeProcess() {
todo!("RtlVirtualUnwind") todo!("GetExitCodeProcess")
} }
fn IsDebuggerPresent() { fn GetFileAttributesW() {
todo!("IsDebuggerPresent") todo!("GetFileAttributesW")
} }
fn UnhandledExceptionFilter() { fn GetFileInformationByHandle() {
todo!("UnhandledExceptionFilter") todo!("GetFileInformationByHandle")
} }
fn SetUnhandledExceptionFilter() { fn GetFileInformationByHandleEx() {
todo!("SetUnhandledExceptionFilter") todo!("GetFileInformationByHandleEx")
} }
fn IsProcessorFeaturePresent() { fn GetFileSizeEx() {
todo!("IsProcessorFeaturePresent") todo!("GetFileSizeEx")
}
fn GetFileType() {
todo!("GetFileType")
}
fn GetFinalPathNameByHandleW() {
todo!("GetFinalPathNameByHandleW")
}
fn GetFullPathNameW() {
todo!("GetFullPathNameW")
}
fn GetLastError() {
todo!("GetLastError")
}
fn GetLocaleInfoEx() {
todo!("GetLocaleInfoEx")
}
fn GetLocaleInfoW() {
todo!("GetLocaleInfoW")
}
fn GetLogicalProcessorInformation() {
todo!("GetLogicalProcessorInformation")
}
fn GetModuleFileNameW() {
todo!("GetModuleFileNameW")
}
fn GetModuleHandleA() {
todo!("GetModuleHandleA")
}
fn GetModuleHandleExW() {
todo!("GetModuleHandleExW")
} }
fn GetModuleHandleW() { fn GetModuleHandleW() {
todo!("GetModuleHandleW") todo!("GetModuleHandleW")
} }
fn GetNativeSystemInfo() {
todo!("GetNativeSystemInfo")
}
fn GetOEMCP() {
todo!("GetOEMCP")
}
fn GetOverlappedResult() {
todo!("GetOverlappedResult")
}
fn GetProcAddress() {
todo!("GetProcAddress")
}
fn GetProcessHeap() {
todo!("GetProcessHeap")
}
fn GetProcessId() {
todo!("GetProcessId")
}
fn GetProcessTimes() {
todo!("GetProcessTimes")
}
fn GetStartupInfoW() {
todo!("GetStartupInfoW")
}
fn GetStdHandle() {
todo!("GetStdHandle")
}
fn GetStringTypeW() {
todo!("GetStringTypeW")
}
fn GetSystemDirectoryW() {
todo!("GetSystemDirectoryW")
}
fn GetSystemInfo() {
todo!("GetSystemInfo")
}
fn GetSystemTime() {
todo!("GetSystemTime")
}
fn GetSystemTimeAsFileTime() {
todo!("GetSystemTimeAsFileTime")
}
fn GetSystemTimePreciseAsFileTime() {
todo!("GetSystemTimePreciseAsFileTime")
}
fn GetTempPathW() {
todo!("GetTempPathW")
}
fn GetTimeFormatW() {
todo!("GetTimeFormatW")
}
fn GetTimeZoneInformation() {
todo!("GetTimeZoneInformation")
}
fn GetUserDefaultLCID() {
todo!("GetUserDefaultLCID")
}
fn GetVolumePathNameW() {
todo!("GetVolumePathNameW")
}
fn GetWindowsDirectoryW() {
todo!("GetWindowsDirectoryW")
}
fn HeapAlloc() {
todo!("HeapAlloc")
}
fn HeapFree() {
todo!("HeapFree")
}
fn HeapQueryInformation() {
todo!("HeapQueryInformation")
}
fn HeapReAlloc() {
todo!("HeapReAlloc")
}
fn HeapSize() {
todo!("HeapSize")
}
fn HeapValidate() {
todo!("HeapValidate")
}
fn HeapWalk() {
todo!("HeapWalk")
}
fn InitOnceBeginInitialize() {
todo!("InitOnceBeginInitialize")
}
fn InitOnceComplete() {
todo!("InitOnceComplete")
}
fn InitializeCriticalSection() {
todo!("InitializeCriticalSection")
}
fn InitializeCriticalSectionAndSpinCount() {
todo!("InitializeCriticalSectionAndSpinCount")
}
fn InitializeCriticalSectionEx() {
todo!("InitializeCriticalSectionEx")
}
fn InitializeProcThreadAttributeList() {
todo!("InitializeProcThreadAttributeList")
}
fn InitializeSListHead() {
todo!("InitializeSListHead")
}
fn InterlockedFlushSList() {
todo!("InterlockedFlushSList")
}
fn IsDebuggerPresent() {
todo!("IsDebuggerPresent")
}
fn IsProcessorFeaturePresent() {
todo!("IsProcessorFeaturePresent")
}
fn IsThreadAFiber() {
todo!("IsThreadAFiber")
}
fn IsValidCodePage() {
todo!("IsValidCodePage")
}
fn IsValidLocale() {
todo!("IsValidLocale")
}
fn K32EnumProcessModulesEx() {
todo!("K32EnumProcessModulesEx")
}
fn K32GetProcessMemoryInfo() {
todo!("K32GetProcessMemoryInfo")
}
fn LCMapStringEx() {
todo!("LCMapStringEx")
}
fn LCMapStringW() {
todo!("LCMapStringW")
}
fn LeaveCriticalSection() {
todo!("LeaveCriticalSection")
}
fn LoadLibraryA() {
todo!("LoadLibraryA")
}
fn LoadLibraryExA() {
todo!("LoadLibraryExA")
}
fn LoadLibraryExW() {
todo!("LoadLibraryExW")
}
fn LoadLibraryW() {
todo!("LoadLibraryW")
}
fn LocalFree() {
todo!("LocalFree")
}
fn LockFileEx() {
todo!("LockFileEx")
}
fn MapViewOfFile() {
todo!("MapViewOfFile")
}
fn MoveFileExW() {
todo!("MoveFileExW")
}
fn MultiByteToWideChar() {
todo!("MultiByteToWideChar")
}
fn OpenSemaphoreA() {
todo!("OpenSemaphoreA")
}
fn QueryPerformanceCounter() {
todo!("QueryPerformanceCounter")
}
fn QueryPerformanceFrequency() {
todo!("QueryPerformanceFrequency")
}
fn RaiseException() {
todo!("RaiseException")
}
fn ReOpenFile() {
todo!("ReOpenFile")
}
fn ReadConsoleW() {
todo!("ReadConsoleW")
}
fn ReadFile() {
todo!("ReadFile")
}
fn ReadFileEx() {
todo!("ReadFileEx")
}
fn ReleaseMutex() {
todo!("ReleaseMutex")
}
fn ReleaseSRWLockExclusive() {
todo!("ReleaseSRWLockExclusive")
}
fn ReleaseSRWLockShared() {
todo!("ReleaseSRWLockShared")
}
fn ReleaseSemaphore() {
todo!("ReleaseSemaphore")
}
fn RemoveDirectoryW() {
todo!("RemoveDirectoryW")
}
fn ResumeThread() {
todo!("ResumeThread")
}
fn RtlPcToFileHeader() {
todo!("RtlPcToFileHeader")
}
fn RtlUnwind() {
todo!("RtlUnwind")
}
fn SearchPathW() {
todo!("SearchPathW")
}
fn SetConsoleCtrlHandler() {
todo!("SetConsoleCtrlHandler")
}
fn SetConsoleMode() {
todo!("SetConsoleMode")
}
fn SetConsoleTextAttribute() {
todo!("SetConsoleTextAttribute")
}
fn SetCurrentDirectoryW() {
todo!("SetCurrentDirectoryW")
}
fn SetEnvironmentVariableW() {
todo!("SetEnvironmentVariableW")
}
fn SetErrorMode() {
todo!("SetErrorMode")
}
fn SetEvent() {
todo!("SetEvent")
}
fn SetFileAttributesW() {
todo!("SetFileAttributesW")
}
fn SetFileInformationByHandle() {
todo!("SetFileInformationByHandle")
}
fn SetFilePointerEx() {
todo!("SetFilePointerEx")
}
fn SetFileTime() {
todo!("SetFileTime")
}
fn SetHandleInformation() {
todo!("SetHandleInformation")
}
fn SetInformationJobObject() {
todo!("SetInformationJobObject")
}
fn SetLastError() {
todo!("SetLastError")
}
fn SetProcessAffinityMask() {
todo!("SetProcessAffinityMask")
}
fn SetStdHandle() {
todo!("SetStdHandle")
}
fn SetThreadErrorMode() {
todo!("SetThreadErrorMode")
}
fn SetThreadStackGuarantee() {
todo!("SetThreadStackGuarantee")
}
fn SetUnhandledExceptionFilter() {
todo!("SetUnhandledExceptionFilter")
}
fn SetWaitableTimer() {
todo!("SetWaitableTimer")
}
fn Sleep() {
todo!("Sleep")
}
fn SleepConditionVariableSRW() {
todo!("SleepConditionVariableSRW")
}
fn SleepEx() {
todo!("SleepEx")
}
fn SwitchToFiber() {
todo!("SwitchToFiber")
}
fn SwitchToThread() {
todo!("SwitchToThread")
}
fn SystemTimeToFileTime() {
todo!("SystemTimeToFileTime")
}
fn TerminateProcess() {
todo!("TerminateProcess")
}
fn TlsAlloc() {
todo!("TlsAlloc")
}
fn TlsFree() {
todo!("TlsFree")
}
fn TlsGetValue() {
todo!("TlsGetValue")
}
fn TlsSetValue() {
todo!("TlsSetValue")
}
fn TryAcquireSRWLockExclusive() {
todo!("TryAcquireSRWLockExclusive")
}
fn UnhandledExceptionFilter() {
todo!("UnhandledExceptionFilter")
}
fn UnlockFile() {
todo!("UnlockFile")
}
fn UnlockFileEx() {
todo!("UnlockFileEx")
}
fn UnmapViewOfFile() {
todo!("UnmapViewOfFile")
}
fn UpdateProcThreadAttribute() {
todo!("UpdateProcThreadAttribute")
}
fn VirtualProtect() {
todo!("VirtualProtect")
}
fn VirtualQuery() {
todo!("VirtualQuery")
}
fn WaitForMultipleObjects() {
todo!("WaitForMultipleObjects")
}
fn WaitForSingleObject() {
todo!("WaitForSingleObject")
}
fn WaitForSingleObjectEx() {
todo!("WaitForSingleObjectEx")
}
fn WakeAllConditionVariable() {
todo!("WakeAllConditionVariable")
}
fn WideCharToMultiByte() {
todo!("WideCharToMultiByte")
}
fn WriteConsoleW() {
todo!("WriteConsoleW")
}
fn WriteFile() {
todo!("WriteFile")
}
fn WriteFileEx() {
todo!("WriteFileEx")
}
fn lstrlenW() {
todo!("lstrlenW")
}
} }
); );
emulate!( emulate!(
"vcruntime140.dll", "ntdll.dll",
mod vcruntime140 { mod ntdll {
fn __C_specific_handler() { fn NtOpenFile() {
todo!("__C_specific_handler") todo!("NtOpenFile")
} }
fn __current_exception() { fn NtReadFile() {
todo!("__current_exception") todo!("NtReadFile")
} }
fn __current_exception_context() { fn NtWriteFile() {
todo!("__current_exception_context") todo!("NtWriteFile")
} }
fn memset() { fn RtlCaptureContext() {
todo!("memset") todo!("RtlCaptureContext")
} }
fn memcpy() { fn RtlGetLastNtStatus() {
todo!("memcpy") todo!("RtlGetLastNtStatus")
}
fn RtlLookupFunctionEntry() {
todo!("RtlLookupFunctionEntry")
}
fn RtlNtStatusToDosError() {
todo!("RtlNtStatusToDosError")
}
fn RtlPcToFileHeader() {
todo!("RtlPcToFileHeader")
}
fn RtlUnwindEx() {
todo!("RtlUnwindEx")
}
fn RtlVirtualUnwind() {
todo!("RtlVirtualUnwind")
} }
} }
); );
emulate!( emulate!(
"api-ms-win-crt-runtime-l1-1-0.dll", "ole32.dll",
mod api_ms_win_crt_runtime_l1_1_0 { mod ole32 {
fn _initterm_e() { fn CoCreateGuid() {
todo!("_initterm_e") todo!("CoCreateGuid")
} }
fn exit() { fn CoCreateInstance() {
todo!("exit") todo!("CoCreateInstance")
} }
fn _exit() { fn CoInitializeEx() {
todo!("_exit") todo!("CoInitializeEx")
} }
fn _initterm() { fn CoTaskMemFree() {
todo!("_initterm") todo!("CoTaskMemFree")
}
fn __p___argc() {
todo!("__p___argc")
}
fn __p___argv() {
todo!("__p___argv")
}
fn _initialize_narrow_environment() {
todo!("_initialize_narrow_environment")
}
fn _c_exit() {
todo!("_c_exit")
}
fn _register_thread_local_exe_atexit_callback() {
todo!("_register_thread_local_exe_atexit_callback")
}
fn _seh_filter_exe() {
todo!("_seh_filter_exe")
}
fn _configure_narrow_argv() {
todo!("_configure_narrow_argv")
}
fn _set_app_type() {
todo!("_set_app_type")
}
fn _initialize_onexit_table() {
todo!("_initialize_onexit_table")
}
fn _register_onexit_function() {
todo!("_register_onexit_function")
}
fn _crt_atexit() {
todo!("_crt_atexit")
}
fn terminate() {
todo!("terminate")
}
fn _cexit() {
todo!("_cexit")
}
fn _get_initial_narrow_environment() {
todo!("_get_initial_narrow_environment")
} }
} }
); );
emulate!( emulate!(
"api-ms-win-crt-math-l1-1-0.dll", "oleaut32.dll",
mod api_ms_win_crt_math_l1_1_0 { mod oleaut32 {
fn __setusermatherr() { fn GetErrorInfo() {
todo!("__setusermatherr") todo!("GetErrorInfo")
}
fn SetErrorInfo() {
todo!("SetErrorInfo")
}
fn SysAllocStringLen() {
todo!("SysAllocStringLen")
}
fn SysFreeString() {
todo!("SysFreeString")
}
fn SysStringLen() {
todo!("SysStringLen")
} }
} }
); );
emulate!( emulate!(
"api-ms-win-crt-stdio-l1-1-0.dll", "shell32.dll",
mod api_ms_win_crt_stdio_l1_1_0 { mod shell32 {
fn _set_fmode() { fn SHGetKnownFolderPath() {
todo!("_set_fmode") todo!("SHGetKnownFolderPath")
}
fn __p__commode() {
todo!("__p__commode")
} }
} }
); );
emulate!( emulate!(
"api-ms-win-crt-locale-l1-1-0.dll", "userenv.dll",
mod api_ms_win_crt_locale_l1_1_0 { mod userenv {
fn _configthreadlocale() { fn GetUserProfileDirectoryW() {
todo!("_configthreadlocale") todo!("GetUserProfileDirectoryW")
} }
} }
); );
emulate!( emulate!(
"api-ms-win-crt-heap-l1-1-0.dll", "ws2_32.dll",
mod api_ms_win_crt_heap_l1_1_0 { mod ws2_32 {
fn _set_new_mode() { fn WSADuplicateSocketW() {
todo!("_set_new_mode") todo!("WSADuplicateSocketW")
}
fn WSARecv() {
todo!("WSARecv")
}
fn WSASend() {
todo!("WSASend")
}
fn WSASocketW() {
todo!("WSASocketW")
}
fn freeaddrinfo() {
todo!("freeaddrinfo")
}
fn getaddrinfo() {
todo!("getaddrinfo")
} }
} }
); );

View file

@ -141,8 +141,14 @@ struct SectionHeader {
struct SectionName([u8; 8]); struct SectionName([u8; 8]);
impl Debug for SectionName { impl Debug for SectionName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = CStr::from_bytes_until_nul(&self.0).unwrap(); // An 8-byte, null-padded UTF-8 encoded string.
f.write_str(s.to_str().unwrap()) // If the string is exactly 8 characters long, there is no terminating null.
match CStr::from_bytes_until_nul(&self.0) {
Ok(s) => f.write_str(s.to_str().unwrap()),
Err(_) => {
write!(f, "\"{}\"", self.0.escape_ascii())
}
}
} }
} }
@ -224,11 +230,11 @@ pub fn execute(pe: &[u8], executable_path: &Path) {
let entrypoint = let entrypoint =
image.opt_header.image_base as usize + image.opt_header.address_of_entry_point as usize; image.opt_header.image_base as usize + image.opt_header.address_of_entry_point as usize;
eprintln!("YOLO to {:#x}", entrypoint); tracing::debug!("YOLO to {:#x}", entrypoint);
unsafe { unsafe {
let result = sys::call_entrypoint_via_stdcall(entrypoint); let result = sys::call_entrypoint_via_stdcall(entrypoint);
eprintln!("result: {result}"); tracing::info!("result: {result}");
}; };
} }
@ -245,6 +251,7 @@ impl<'pe> Deref for Image<'pe> {
} }
} }
#[tracing::instrument(skip(pe, is_dll))]
fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe> { fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe> {
let (coff_header, after_header) = parse_header(pe); let (coff_header, after_header) = parse_header(pe);
@ -283,11 +290,12 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
panic!("file does not have enough of the required optional header (lol)"); panic!("file does not have enough of the required optional header (lol)");
} }
dbg!(coff_header); tracing::debug!(?coff_header, "Coff header");
let opt_header: &OptionalHeader = let opt_header: &OptionalHeader =
&bytemuck::cast_slice(&pe[after_header..][..size_of::<OptionalHeader>()])[0]; &bytemuck::cast_slice(&pe[after_header..][..size_of::<OptionalHeader>()])[0];
dbg!(opt_header);
tracing::debug!(?opt_header, "Optional header");
if opt_header.magic != 0x20b { if opt_header.magic != 0x20b {
panic!("unsupported, only PE32+ is supported"); panic!("unsupported, only PE32+ is supported");
@ -308,22 +316,19 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
&pe[section_table_offset..] &pe[section_table_offset..]
[..(coff_header.number_of_sections as usize * size_of::<SectionHeader>())], [..(coff_header.number_of_sections as usize * size_of::<SectionHeader>())],
); );
dbg!(section_table);
// let's always load it at the image base for now... tracing::debug!(?section_table, "Section table");
let base = opt_header.image_base as usize;
let allocation_granularity = crate::sys::allocation_granularity(); let allocation_granularity = crate::sys::allocation_granularity();
assert_eq!(base & (allocation_granularity - 1), 0);
let last_section = section_table.last().unwrap(); let last_section = section_table.last().unwrap();
let total_size = (last_section.virtual_address as usize + last_section.virtual_size as usize) let total_size = (last_section.virtual_address as usize + last_section.virtual_size as usize)
.next_multiple_of(allocation_granularity); .next_multiple_of(allocation_granularity);
let loaded = unsafe { let mut loaded = std::mem::ManuallyDrop::new(memmap2::MmapMut::map_anon(total_size).unwrap());
crate::sys::anon_write_map(total_size, std::ptr::with_exposed_provenance(base)).unwrap() let loaded = unsafe { &mut *(&mut **loaded as *mut [u8]) };
};
let base = loaded.as_ptr().addr();
let image = Image { let image = Image {
base, base,
@ -334,9 +339,10 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
// allocate the sections. // allocate the sections.
for section in section_table { for section in section_table {
if section.virtual_size > section.size_of_raw_data { if section.virtual_size > section.size_of_raw_data {
todo!("zero padding") // If the virtual size is larger than the disk size, the virtual data needs to be zero padded.
// This happens automatically via the mmap earlier.
} }
eprintln!("mapping section {:?}", section.name); tracing::debug!("mapping section {:?}", section.name);
let section_a = &mut image.loaded[section.virtual_address as usize..]; let section_a = &mut image.loaded[section.virtual_address as usize..];
@ -351,9 +357,9 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
) )
.to_vec(); .to_vec();
eprintln!("checking imports"); tracing::debug!("checking imports");
for import_directory in import_directory_table { for import_directory in import_directory_table {
dbg!(import_directory); tracing::debug!(?import_directory, "Resolving next import");
let dll_name = let dll_name =
CStr::from_bytes_until_nul(&image.loaded[import_directory.name_rva as usize..]) CStr::from_bytes_until_nul(&image.loaded[import_directory.name_rva as usize..])
@ -362,9 +368,10 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let dll_name = dll_name.to_str().unwrap(); let dll_name = dll_name.to_str().unwrap();
if dll_name.is_empty() { if dll_name.is_empty() {
// Trailing null import directory. // Trailing null import directory.
tracing::debug!("Skipping null import directory");
break; break;
} }
eprintln!("loading dll {dll_name}"); tracing::debug!("loading dll {dll_name}");
enum LoadedDll { enum LoadedDll {
Emulated, Emulated,
@ -374,7 +381,7 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let dll = find_dll(&dll_name, executable_path); let dll = find_dll(&dll_name, executable_path);
let dll = match dll { let dll = match dll {
Some(DllLocation::Emulated) => { Some(DllLocation::Emulated) => {
eprintln!(" emulating {dll_name:?}"); tracing::debug!("emulating {dll_name:?}");
LoadedDll::Emulated LoadedDll::Emulated
} }
Some(DllLocation::Found(path)) => { Some(DllLocation::Found(path)) => {
@ -387,7 +394,9 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let image = load(&mmap, &path, true); let image = load(&mmap, &path, true);
LoadedDll::Real(image) LoadedDll::Real(image)
} }
None => panic!("could not find dll {dll_name:?}"), None => {
panic!("could not find dll {dll_name:?}");
}
}; };
let import_lookups = bytemuck::cast_slice::<u8, u64>( let import_lookups = bytemuck::cast_slice::<u8, u64>(
@ -402,7 +411,7 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let ordinal_name_flag = import_lookup >> 63; let ordinal_name_flag = import_lookup >> 63;
if ordinal_name_flag == 1 { if ordinal_name_flag == 1 {
let ordinal_number = import_lookup & 0xFFFF; let ordinal_number = import_lookup & 0xFFFF;
eprintln!(" import by ordinal: {ordinal_number}"); tracing::debug!(" import by ordinal: {ordinal_number}");
todo!("unsupported, import by ordinal"); todo!("unsupported, import by ordinal");
} else { } else {
let hint_name_table_rva = import_lookup & 0xFFFF_FFFF; let hint_name_table_rva = import_lookup & 0xFFFF_FFFF;
@ -412,12 +421,12 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let func_name = let func_name =
CStr::from_bytes_until_nul(&image.loaded[hint_name_table_rva as usize + 2..]) CStr::from_bytes_until_nul(&image.loaded[hint_name_table_rva as usize + 2..])
.unwrap(); .unwrap();
eprintln!(" import by name: hint={hint} name={func_name:?}"); tracing::debug!("import by name: hint={hint} name={func_name:?}");
let resolved_va = match &dll { let resolved_va = match &dll {
LoadedDll::Emulated => emulated::emulate(dll_name, func_name.to_str().unwrap()) LoadedDll::Emulated => emulated::emulate(dll_name, func_name.to_str().unwrap())
.unwrap_or_else(|| { .unwrap_or_else(|| {
panic!("could not find function {func_name:?} in dll {dll_name:?}") panic!("could not find function {func_name:?} in dll {dll_name:?}");
}), }),
LoadedDll::Real(img) => { LoadedDll::Real(img) => {
// Read the single export directory table from the front // Read the single export directory table from the front
@ -436,7 +445,7 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
&img[img.opt_header.export_table.va as usize..] &img[img.opt_header.export_table.va as usize..]
[..size_of::<ExportDirectoryTable>()], [..size_of::<ExportDirectoryTable>()],
)[0]; )[0];
dbg!(export_directory_table); tracing::debug!(?export_directory_table, "Export Directory Table of {dll_name}");
// This is not aligned..? // This is not aligned..?
let mut names = vec![]; let mut names = vec![];
@ -447,7 +456,7 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
let name = u32::from_ne_bytes(img[name_ptr..][..4].try_into().unwrap()); let name = u32::from_ne_bytes(img[name_ptr..][..4].try_into().unwrap());
let name = CStr::from_bytes_until_nul(&img[name as usize..]).unwrap(); let name = CStr::from_bytes_until_nul(&img[name as usize..]).unwrap();
names.push(name); names.push(name);
dbg!(name); tracing::debug!(?name, "DLL {dll_name} has export");
} }
let idx = if names.get(hint as usize) == Some(&func_name) { let idx = if names.get(hint as usize) == Some(&func_name) {
@ -489,7 +498,7 @@ fn load<'pe>(pe: &'pe [u8], executable_path: &Path, is_dll: bool) -> Image<'pe>
} }
} }
eprintln!("applying section protections"); tracing::debug!("applying section protections");
for section in section_table { for section in section_table {
let mode = if section let mode = if section
.characteristics .characteristics
@ -552,9 +561,6 @@ fn find_dll(name: &str, executable_path: &Path) -> Option<DllLocation> {
// https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-apisets // https://learn.microsoft.com/en-us/windows/win32/apiindex/windows-apisets
return Some(DllLocation::Emulated); return Some(DllLocation::Emulated);
} }
if emulated::supports_dll(name) {
return Some(DllLocation::Emulated);
}
let name_lowercase = name.to_lowercase(); let name_lowercase = name.to_lowercase();
@ -579,5 +585,9 @@ fn find_dll(name: &str, executable_path: &Path) -> Option<DllLocation> {
return Some(DllLocation::Found(path)); return Some(DllLocation::Found(path));
} }
if emulated::supports_dll(name) {
return Some(DllLocation::Emulated);
}
None None
} }

View file

@ -2,7 +2,19 @@
use std::os::windows::fs::OpenOptionsExt; use std::os::windows::fs::OpenOptionsExt;
use std::path::Path; use std::path::Path;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::{field::MakeExt, EnvFilter};
fn main() { fn main() {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
.from_env_lossy(),
)
.map_fmt_fields(|f| f.debug_alt())
.init();
let mut opts = std::fs::OpenOptions::new(); let mut opts = std::fs::OpenOptions::new();
opts.read(true); opts.read(true);
#[cfg(windows)] #[cfg(windows)]

View file

@ -39,42 +39,6 @@ mod imp {
info.dwPageSize as usize info.dwPageSize as usize
} }
pub(crate) unsafe fn anon_write_map<'a>(
size: usize,
address: *const (),
) -> io::Result<&'a mut [u8]> {
let map = windows::Win32::System::Memory::CreateFileMappingA(
INVALID_HANDLE_VALUE,
None,
PAGE_EXECUTE_READWRITE,
(size >> 32) as u32,
size as u32,
None,
)?;
debug_assert_eq!(address.addr() & (allocation_granularity() - 1), 0);
debug_assert_eq!(size & (allocation_granularity() - 1), 0);
let addr = unsafe {
windows::Win32::System::Memory::MapViewOfFileEx(
map,
FILE_MAP_WRITE | FILE_MAP_EXECUTE,
0,
0,
size,
Some(address as *const c_void),
)
};
let _ = unsafe { windows::Win32::Foundation::CloseHandle(map) };
if addr.Value.is_null() {
Err(io::Error::last_os_error())
} else {
Ok(std::slice::from_raw_parts_mut(addr.Value.cast(), size))
}
}
pub(crate) fn protect(address: *const (), size: usize, mode: Mode) -> io::Result<()> { pub(crate) fn protect(address: *const (), size: usize, mode: Mode) -> io::Result<()> {
debug_assert_eq!(address.addr() & (page_size() - 1), 0); debug_assert_eq!(address.addr() & (page_size() - 1), 0);
let mut old = PAGE_PROTECTION_FLAGS::default(); let mut old = PAGE_PROTECTION_FLAGS::default();
@ -113,36 +77,6 @@ mod imp {
allocation_granularity() allocation_granularity()
} }
pub(crate) unsafe fn anon_write_map<'a>(
size: usize,
address: *const (),
) -> io::Result<&'a mut [u8]> {
debug_assert_eq!(address.addr() & (allocation_granularity() - 1), 0);
debug_assert_eq!(size & (allocation_granularity() - 1), 0);
let ret = libc::mmap(
address as _,
size,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
);
if ret == libc::MAP_FAILED {
Err(io::Error::last_os_error())
} else if ret.addr() != address.addr() {
Err(io::Error::new(
io::ErrorKind::AlreadyExists,
"address already taken".to_owned(),
))
} else {
Ok(std::slice::from_raw_parts_mut(
address.cast_mut().cast(),
size,
))
}
}
pub(crate) fn protect(address: *const (), size: usize, mode: super::Mode) -> io::Result<()> { pub(crate) fn protect(address: *const (), size: usize, mode: super::Mode) -> io::Result<()> {
debug_assert_eq!(address.addr() & (page_size() - 1), 0); debug_assert_eq!(address.addr() & (page_size() - 1), 0);
let prot = match mode { let prot = match mode {

View file

@ -1,7 +1,7 @@
SHELL = bash SHELL = bash
RUSTC = rustc --target x86_64-pc-windows-msvc -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB -Clink-arg=/debug:none -Cdebuginfo=0 RUSTC = rustc --target x86_64-pc-windows-msvc -Copt-level=3 -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB -Clink-arg=/debug:none -Cdebuginfo=0
build: empty_exe.exe one_dll.exe build: empty_exe.exe one_dll.exe two_dll.exe
empty_exe.exe: empty_exe.rs empty_exe.exe: empty_exe.rs
$(RUSTC) empty_exe.rs $(RUSTC) empty_exe.rs
@ -12,6 +12,12 @@ one_dll.exe: one_dll.rs small_dll.dll
small_dll.dll: small_dll.rs small_dll.dll: small_dll.rs
$(RUSTC) small_dll.rs $(RUSTC) small_dll.rs
ordinal_dll.dll: ordinal_dll.rs ordinal_dll.def
$(RUSTC) -Clink-arg=/def:ordinal_dll.def ordinal_dll.rs
two_dll.exe: small_dll.dll ordinal_dll.dll
$(RUSTC) two_dll.rs
.PHONY: clean .PHONY: clean
clean: clean:
shopt -s nullglob shopt -s nullglob

4
test2/ordinal_dll.def Normal file
View file

@ -0,0 +1,4 @@
EXPORTS
my_export_ordinal_1 @1
my_export_ordinal_2 @2
my_export_named

28
test2/ordinal_dll.rs Normal file
View file

@ -0,0 +1,28 @@
#![no_std]
#![crate_type = "cdylib"]
#![windows_subsystem = "console"]
#[panic_handler]
fn handle_panic(_: &core::panic::PanicInfo<'_>) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn my_export_ordinal_1() -> u32 {
1
}
#[no_mangle]
pub extern "C" fn my_export_ordinal_2() -> u32 {
2
}
#[no_mangle]
pub extern "C" fn my_export_named() -> u32 {
5
}
#[no_mangle]
pub extern "stdcall" fn _DllMainCRTStartup() -> u32 {
0
}

30
test2/two_dll.rs Normal file
View file

@ -0,0 +1,30 @@
#![no_std]
#![no_main]
#![windows_subsystem = "console"]
#[link(name = "small_dll", kind = "raw-dylib")]
unsafe extern "C" {
safe fn my_export() -> u32;
}
#[link(name = "ordinal_dll", kind = "raw-dylib")]
unsafe extern "C" {
#[link_ordinal(1)]
safe fn my_export_ordinal_1() -> u32;
#[link_ordinal(2)]
safe fn my_export_ordinal_2() -> u32;
safe fn my_export_named() -> u32;
}
#[panic_handler]
fn handle_panic(_: &core::panic::PanicInfo<'_>) -> ! {
loop {}
}
#[no_mangle]
pub extern "stdcall" fn mainCRTStartup() -> u32 {
my_export()
.wrapping_add(my_export_ordinal_1())
.wrapping_add(my_export_ordinal_2())
.wrapping_add(my_export_named())
}