본문 바로가기

C/Reference

[C] system32 경로 syswow64로 리다이렉트 되지 않도록 하는 예제 코드

반응형

출처 - http://www.codeproject.com/tips/55290/Disabling-Windows-file-system-redirection-on-a-CFi.aspx

 

int _tmain()
{
	FILE *fp = NULL;
	BOOL bOpenFile = TRUE;
	PVOID oldValue;
	Wow64DisableWow64FsRedirection(&oldValue);
	fp = _tfopen(SYSTEM32_FILE_PATH, _T("r") );
	Wow64RevertWow64FsRedirection(&oldValue);
	if(fp == NULL){
		_tprintf(_T("fp is null.\n"));
	}
	else{
		_tprintf(_T("fp is not null.\n"));
		fclose(fp);
	}
	return EXIT_SUCCESS;
}

 

typedef BOOL (WINAPI *FWOW64DISABLEWOW64FSREDIRECTION)(PVOID *);
typedef BOOL (WINAPI *FWOW64REVERTWOW64FSREDIRECTION)(PVOID);
 
FWOW64DISABLEWOW64FSREDIRECTION fWow64DisableWow64FsRedirection = NULL;
FWOW64REVERTWOW64FSREDIRECTION fWow64RevertWow64FsRedirection = NULL;
HMODULE hMod = NULL;
PVOID pOldValue = NULL;
 
hMod = GetModuleHandle("Kernel32.dll");
if( !hMod )
{
	printf("GetModuleHandle : %d\n", GetLastError());
 
	return 0;
}
 
fWow64DisableWow64FsRedirection = (FWOW64DISABLEWOW64FSREDIRECTION)GetProcAddress(hMod, "Wow64DisableWow64FsRedirection");
if( fWow64DisableWow64FsRedirection )
{
	// Disable Redirection
	if( !fWow64DisableWow64FsRedirection(&pOldValue) )
	{
		printf("fWow64DisableWow64FsRedirection : %d\n", GetLastError());
 
		return 0;
	}
}
 
 
 
fWow64RevertWow64FsRedirection = (FWOW64REVERTWOW64FSREDIRECTION)GetProcAddress(hMod, "Wow64RevertWow64FsRedirection");
if( fWow64RevertWow64FsRedirection )
{
	// Revert Redirection
	if( !fWow64RevertWow64FsRedirection(&pOldValue) )
	{
		printf("fWow64RevertWow64FsRedirection : %d\n", GetLastError());
 
		return 0;
	}
}
반응형