Skip to content

Commit 1902413

Browse files
committed
[K32] Unify TIB/PEB
1 parent eab49b2 commit 1902413

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

dlls/kernel32/kernel32.hexa

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,16 @@ fun findDllByName(dllName ConstArrayPointer<ClangWideChar>) HModule {
188188
// Get the PEB from the TEB (Thread Environment Block)
189189
// TODO 32-bit
190190
tofitaDebugLog("findDllByName(%S)".utf16(), dllName as! UInt64)
191-
let teb = ntCurrentTeb() as! TIB64
192-
let peb = teb.peb as! PEB64
191+
192+
#if bit32
193+
let teb = ntCurrentTeb() as! TIB32
194+
let peb = teb.peb as! PEB32
195+
#end
196+
197+
#if bit64
198+
let teb = ntCurrentTeb() as! TIB64
199+
let peb = teb.peb as! PEB64
200+
#end
193201

194202
tofitaDebugLog("> teb %8".utf16(), teb as! UInt64)
195203
tofitaDebugLog("> peb %8".utf16(), peb as! UInt64)
@@ -237,8 +245,16 @@ fun getModuleHandleW(lpLibFileName ConstArrayPointer<ClangWideChar>) HModule {
237245
// Does not increase the DLL's reference count
238246
tofitaDebugLog("getModuleHandleW(%S)".utf16(), lpLibFileName as! UInt64)
239247
if lpLibFileName == null {
240-
let teb = ntCurrentTeb() as! TIB64
241-
let peb = teb.peb as! PEB64
248+
#if bit32
249+
let teb = ntCurrentTeb() as! TIB32
250+
let peb = teb.peb as! PEB32
251+
#end
252+
253+
#if bit64
254+
let teb = ntCurrentTeb() as! TIB64
255+
let peb = teb.peb as! PEB64
256+
#end
257+
242258
let base = peb.imageBaseAddress
243259
tofitaDebugLog("getModuleHandleW(NULL) is %8 with header %s".utf16(), base as! UInt64, base as! UInt64)
244260
return base as! HModule

0 commit comments

Comments
 (0)