Kernel API to access UEFI NVRAM variables on Windows 7

Hi All,

I require to access NVRAM variable in my driver, So on Windows 8 I am using API ExGetFirmwareEnvironmentVariable, but unfortunately that API is not available on Windows 7.

Further GetFirmwareEnvironmentVariableW which is a usermode API is available starting from Windows XP SP1, but surprisingly there is no documented API available in kernel.

So I have gone through ntoskrnl eports on Windows 7 and found NtGetEnvironmentVariableEx API which seems to be helpful for me. NtGetEnvironmentVariableEx is available from Windows Vista SP1 onwords. But unfortunately it is not documented.

So can I use it to solve my perpose on Windows 7? If yes what is the prototype of NtGetEnvironmentVariableEx? If not can anyone help me to access NVRAM variable in my driver atleast on Windows 7?

Thanks & Regards,
Amit

GetFirmwareEnvironmentVariableW is not available in xp
it will simply return Error Not Implemented

see below

lkd> !grep -i -e “imp__nt” -c “uf KERNEL32!GetFirmwareEnvironmentVariableW”
7c85f45a ff158812807c call dword ptr
[KERNEL32!_imp__NtQuerySystemEnvironmentValueEx (7c801288)]
lkd> ln poi(7c801288)
(7c90d91e) ntdll!NtQuerySystemEnvironmentValueEx | (7c90d92e)
ntdll!ZwQuerySystemInformation
Exact matches:
ntdll!NtQuerySystemEnvironmentValueEx =
ntdll!ZwQuerySystemEnvironmentValueEx =
lkd> uf ntdll!NtQuerySystemEnvironmentValueEx
ntdll!NtQuerySystemEnvironmentValueEx:
7c90d91e b8ac000000 mov eax,0ACh
7c90d923 ba0003fe7f mov edx,offset
SharedUserData!SystemCallStub (7ffe0300)
7c90d928 ff12 call dword ptr [edx]
7c90d92a c21400 ret 14h
lkd> uf nt!NtQuerySystemEnvironmentValueEx
nt!NtQuerySystemEnvironmentValueEx:
8060cbd0 b8020000c0 mov eax,0C0000002h
8060cbd5 c21400 ret 14h
lkd> uf nt!ZwQuerySystemEnvironmentValueEx
nt!ZwQuerySystemEnvironmentValueEx:
804feb18 b8ac000000 mov eax,0ACh
804feb1d 8d542404 lea edx,[esp+4]
804feb21 9c pushfd
804feb22 6a08 push 8
804feb24 e878e90300 call nt!KiSystemService (8053d4a1)
804feb29 c21400 ret 14h

lkd> !error 0C0000002
Error code: (NTSTATUS) 0xc0000002 (3221225474) - {Not Implemented}
The requested operation is not implemented.

if this is required for your debugging or some sort of non production code use
scour the net for alex ionescu’s native nt toolkit

iirc takes a guid and returns an attribute

On 7/15/13, xxxxx@yahoo.com wrote:
> Hi All,
>
> I require to access NVRAM variable in my driver, So on Windows 8 I am using
> API ExGetFirmwareEnvironmentVariable, but unfortunately that API is not
> available on Windows 7.
>
> Further GetFirmwareEnvironmentVariableW which is a usermode API is available
> starting from Windows XP SP1, but surprisingly there is no documented API
> available in kernel.
>
> So I have gone through ntoskrnl eports on Windows 7 and found
> NtGetEnvironmentVariableEx API which seems to be helpful for me.
> NtGetEnvironmentVariableEx is available from Windows Vista SP1 onwords. But
> unfortunately it is not documented.
>
> So can I use it to solve my perpose on Windows 7? If yes what is the
> prototype of NtGetEnvironmentVariableEx? If not can anyone help me to access
> NVRAM variable in my driver atleast on Windows 7?
>
> Thanks & Regards,
> Amit
>
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

Thanks for reply Raj, Currently I don’t care about XP, I am more consern about Windows 7.

> Thanks for reply Raj, Currently I don’t care about XP,
> I am more consern about Windows 7.

I believe Win7 will be just as unsupported as WinXP. EFI really kicked
in for Windows starting in Win8, perhaps a bit earlier on some 64-bit
server buildss.

You might need to write a driver to do it yourself, if possible, in
older OS versions.

this answer is just for records
i wrote a blanket statement earlier that
GetFirmwareEnvironmentVariableW is not available in xp
it will simply return Error Not Implemented

i browsed through the documents after posting that and the documents state that
this api is available in windows xp sp1 onwards if the os was NOT
booted with legacy bios

On 7/16/13, Blibbet wrote:
>> Thanks for reply Raj, Currently I don’t care about XP,
> > I am more consern about Windows 7.
>
> I believe Win7 will be just as unsupported as WinXP. EFI really kicked
> in for Windows starting in Win8, perhaps a bit earlier on some 64-bit
> server buildss.
>
> You might need to write a driver to do it yourself, if possible, in
> older OS versions.
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>