So I noticed a very subtle use of LoadLibrary, namely LoadLibraryEx with the flag to load the exe/dll as a data file in some code posted by @also here
Last night, I kept getting random or intermittent Error 998’s with LoadLibraryA
System Error Codes (500-999) (WinError.h) - Win32 apps | Microsoft Learn
ERROR_NOACCESS
998 (0x3E6)
Invalid access to memory location.
I knew this worked, I knew the code had not been changed, and its worked reliably for months after all how many ways can you mess up LoadLibraryA?
This was intermittent, but probably because of the speed I was working at, anyway, what it appears to be is, but I could be wrong, is the /NXCOMPAT switch aka Data Execution Prevention or DEP.
/NXCOMPAT (Compatible with Data Execution Prevention) | Microsoft Learn
Now using LoadLibraryA to load the Clarion 11\bini\c4otSDX.dll aka the Developers edition of the ODBC driver addon, causes the SV window to popup, reminding everyone its the developer edition. However using LoadLibraryExA with the LOAD_LIBRARY_AS_DATAFILE flag means the SV ODBC developers edition window doesnt appear on screen, first clue that differences with the way a DLL or EXE is loaded is taking place. I code on a virtual XP with C6 for expediency before porting to C11 currently until I’m up to speed with the C11 IDE.
So this got me thinking, what else is LoadLibraryA calling? Could this be triggering Data Execution Prevention and thus causing the intermittent error 998 I’m seeing?
Bit of digging turns up
Data Execution Prevention - Win32 apps | Microsoft Learn
Data Execution Prevention (DEP) is a system-level memory protection feature that is built into the operating system starting with Windows XP and Windows Server 2003. DEP enables the system to mark one or more pages of memory as non-executable. Marking memory regions as non-executable means that code cannot be run from that region of memory, which makes it harder for the exploitation of buffer overruns
Part 3: Memory Protection Technologies | Microsoft Learn
Beginning with Windows XP Service Pack 2, the 32-bit version of Windows utilizes the no-execute page-protection (NX) processor feature as defined by AMD or the Execute Disable bit feature as defined by Intel. In order to use these processor features, the processor must be running in Physical Address Extension (PAE) mode. The 64-bit versions of Windows XP uses the NX processor feature on 64-bit extensions and certain values of the access rights page table entry (PTE) field on IPF processors.
So the Execute Disable bit, is something mentioned in computer BIOSes, certainly earlier ones but not always visible in the latest UEFI bioses.
Execute Disable Bit for Intel® Processors
Intel call it XD in the bios short for Execute Disable.
AMD call it NX in the bios short for No Execute.
Its recommended this bios option is switched on or enabled if your bios or your customers computer bios has this, its an old setting not always seen in newer UEFI bios versions, Intel consider it legacy, but their wording is such that it still exists but wont be mentioned.
But then you also need the Windows DEP to be switched on to see these LoadLibrary 998 errors. If one of them is not switched on or enabled, you wont see the 998 error. If its not a bios option, then it needs to be switched on in Windows:
XP, Control Panel, System Icon, Advanced Tab, Performance Setting button, Data Execution Prevention tab, toggle option accordingly & Reboot
Win10, Start buttio, Gear Icon called Settings, Update & Security, Windows Security, Open Windows Security, App & Browser control, Exploit Protection Settings, System Settings, Data Execution Prevention dopdown list toggle accordingly & Reboot
One of the things I noticed, despite running this on a virtual pc, namely XP, even rebooting the virtual PC didnt stop the behaviour! So I suspect DEP on the host, ie my Win10 machine is affecting the virtual PC and it was switched on by default.
But here is gets weird. So this morning again reliably able to get the 998 error by triggering an access violation. Switched off DEP in Win10, 998 no longer appears. Switch off DEP in XP, 998 still doesnt appear. Switch it DEP back on in XP to see if the virtual pc is running fully independent of the Win10 host, trigger the access violation, cant get the 998 to appear. Switch on DEP in Win10, repeat access violation and it still doesnt appear.
So not only is this an intermittent problem, its a standalone pc and whilst I’m aware that RAM chips can be made to transmit over wifi frequencies over a range of 180cm with some malware for one way snooping purposes, I’m fairly certain this pc is properly air gapped!
So I’m now wondering if there is some other malware I’ve yet to load in my resource editor.
TLDR, I thought an access violation with DEP triggered Windows error 998 when using LoadLibraryA after an access violation, found it to be reproducible but then find its not!
Edit. Sometimes being a dog has its advantages!