Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results
The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
I'm trying to run Windows native application (i.e subsystem: NATIVE) on Windows 10 and 8.1. The application signed with a test certificate and test sign mode was set on Windows. I've created the application based on "Enpty WDM Driver" template in Visual Studio with the latest WDK. I've compiled an exe file. Except ntdll.lib no default libs had been used. The test certificate of the application was placed in trusted Root Certification Authorities storage.
The executable of the application was placed in C:\Windows\System32 directory and the approipriate value (application name) was added to the registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute. So, the application must be executed on a boot time. But the BSOD is occured with the error code 0xC0000145. This NTSTATUS value has a name STATUS_APP_INIT_FAILURE. But when I try to start this application on Windows 7 application is correctly executed.
I assume something is wrong with a certificate. Maybe I had placed it into inappropriate storage. How can I start a native application in Windows 10 and 8.1?
The code of the application:
#include <ntifs.h> #include <ntdef.h> NTSYSCALLAPI NTSTATUS NTAPI NtDisplayString(PUNICODE_STRING DisplayString); NTSYSAPI NTSTATUS NTAPI NtTerminateProcess(HANDLE ProcessHandle, NTSTATUS ExitStatus); VOID NtProcessStartup(PVOID StartupArgument) { UNICODE_STRING str; RtlInitUnicodeString(&str, L"Hello, world!\n"); NtDisplayString(&str); NtTerminateProcess((HANDLE)(-1), 0); }
Upcoming OSR Seminars | ||
---|---|---|
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead! | ||
Writing WDF Drivers | 7 Dec 2020 | LIVE ONLINE |
Internals & Software Drivers | 25 Jan 2021 | LIVE ONLINE |
Developing Minifilters | 8 March 2021 | LIVE ONLINE |
Comments
I've never dealt with that kind of software but I believe anything that runs early boot must have a valid certificate and secure boot disabled if not.
The test certificate had been added to the System storage.
Secure Boot is not present in virtual machine with windows 8.1 and is not enabled in virtual machine with Windows 10.
As I remember, boot drivers must have additional security attributes such as integritychecks. Maybe same approaches are required to native applications. So, I've added /INTEGRITYCHECK parameter to linker options. It sets the IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY in DllCharactersitic field.
But nothing has changed.
Maybe, some additional options required?
hook up a debugger and see where it fails?
I've attached WinDBG to Windows 8.1 virtual machine.
NativeApp.exe is the name of the compiled native application, discussed above.
Here is the output:
Arg1 is 0xC000007B, which is STATUS_INVALID_IMAGE_FORMAT. Are you quite sure you compiled this as a 64-bit application? Did you compile it to target 8.1? Unlike user-mode, the native loader checks all of those obscure PE headers.
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
Hmmmm... I haven't done this for a very, very, long time.
Let's start at the beginning, shall we? It seems you've managed to create an executable that's not properly formatted to run on Win 8 or Win 10.
So, I think we should ask: How, exactly, are you building this?
Peter
Peter Viscarola
OSR
@OSRDrivers
I've attached WinDBG to Windows 8.1 virtual machine.
NativeApp.exe is the name of the compiled native application, discussed above.
Here is the output:
And answering my questions would be helpful.
Peter
Peter Viscarola
OSR
@OSRDrivers
Do a "link /dump /headers xxx.exe" and post the output.
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
Sorry for multiposting. The problem was on my side. The web-page was not responded in my browser. I updated it and a draft was sent.
2Tim_Roberts:
Yes, application compiled for x64.
Target OS Version: Windows 8.1
_NT_TARGET_VERSION: Windows 8.1
The output of link /dump /headers:
2Peter_Viscarola_(OSR):
I've created project with a type "Empty WDM Driver" in Visual Studio 2019.
Then I 've changed Configuration Properties->Configuration Type from sys to Application (.exe)
Then Linker->Input->Additional Dependencies set only ntdll.lib
Then Linker->Advanced->Entry Point set to NtProcessStartup
Here is a link to this project:
https://github.com/KrnlDeveloper/NativeApp
The only odd thing is that the operating system version in the header is 10.00. The user mode loader cares about that, so I wouldn't be surprised if the kernel was at least as picky. Have you checked the linker properties in your Visual Studio project to make sure it's not set to Windows 10?
Tim Roberts, [email protected]
Providenza & Boekelheide, Inc.
What happens when you try to run the app from the command line? In other words, without having it auto run.
Peter
Peter Viscarola
OSR
@OSRDrivers
This is an application not a driver so you don't want a WDM project...I got this to work:
With the following vcxproj file that I hacked together...Note that I don't claim this to be definitive (haven't had the need for a production native app in a very long time) but should put you on the right path:
-scott
OSR
Scott_Noone_(OSR), thanks a lot! It works.
I used incorrect headers ntifs.h and ntdef.h.
The good news is that the application does not have to be signed with a certificate.
Thanks again!