Almost similarly, you can check if the program is running under Wow64 emulation in the following way:
Code:
[plain]#include <Windows.h>
#include <stdio.h>
BOOL __declspec(naked) WINAPI IsWow64(void)
{
__asm
{
MOV EAX, FS:[0xC0] ; wow64cpu!X86SwitchTo64BitMode
SHR EAX, 30
RET
}
}
int main(void)
{
printf("IsWow64: %s\n", IsWow64() ? "True" : "False");
return 0;
}[/plain]
wow64cpu!X86SwitchTo64BitMode is a jmp to wow64cpu!CpupReturnFromSimulatedCode for Wow64. For people who don't want to use inline assembly, there's also the C/C++ intrinsic __readfsdword for the FS register from <intrin.h>..
Hi,
can you please make a tutorial about __declspec(naked) vs export?
I don't understand it.
And also explains what are you doing here:
MOV EAX, FS:[0xC0] ; wow64cpu!X86SwitchTo64BitMode
SHR EAX, 30
RET is returning address or variable?
MOV EAX, FS:[0xC0]; I know it's put FS:[0xC0] into EAX but what is the dots and bracets?
SHR is shift right i think. Shift right EAX by 30. Why to do that?
A tutorial is not required, if you look up information on each you should find plenty of information..
Also, they aren't even related so I don't think a tutorial about the two would make much sense. _declspec(dllexport) refers to data that is meant to be exported (EAT), and naked has to due with what assembly code is NOT generated for a function marked as __declspec(naked), but it is Microsoft specific too.
RET is mainly just returning back to the caller the value within the EAX register. No stack frame is necessary to set up, the first line populates the EAX register with the value of the FS register at offset 0xC0. You won't understand much if you don't know anything about x64 and x86, along with assembly, and how Wow64 works.
Read this if you're interested:
Mixing x86 with x64 code
CS register = 0x23 (35) = x86 mode
CS register = 0x33 (51) = x64 mode