当前位置:编程学习 > C/C++ >>

64bit下关闭启用文件重定向功能,支持多线程,简单易用

BOOL DisableWow64FsRedirection(BOOL disable){
	typedef BOOL (__stdcall *FuncIsWow64Process)(HANDLE, PBOOL);
	typedef BOOL (__stdcall *FuncWow64DisableWow64FsRedirection)(PVOID*);
	typedef BOOL (__stdcall *FuncWow64RevertWow64FsRedirection)(PVOID);
	static FuncIsWow64Process xIsWow64Process = NULL;
	static FuncWow64DisableWow64FsRedirection xDisableFsRedirection = NULL;
	static FuncWow64RevertWow64FsRedirection xRevertFsRedirection = NULL;
	static BOOL iswow64 = 0;
	if(!xIsWow64Process){
		xIsWow64Process = (FuncIsWow64Process)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "IsWow64Process");
		if(!xIsWow64Process)
			return TRUE;
		if(!xIsWow64Process(GetCurrentProcess(), &iswow64))
			return FALSE;
	}
	if(!iswow64)
		return TRUE;
	if(!xDisableFsRedirection){
		xDisableFsRedirection = (FuncWow64DisableWow64FsRedirection)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "Wow64DisableWow64FsRedirection");
		if(!xDisableFsRedirection)
			return FALSE;
	}
	if(!xRevertFsRedirection){
		xRevertFsRedirection = (FuncWow64RevertWow64FsRedirection)::GetProcAddress(::GetModuleHandleA("kernel32.dll"), "Wow64RevertWow64FsRedirection");
		if(!xRevertFsRedirection)
			return FALSE;
	}
	static __declspec(thread) void* old_value = NULL;
	static __declspec(thread) BOOL disabled = FALSE;
	if(disable){
		if(disabled)
			return TRUE;
		if(xDisableFsRedirection(&old_value)){
			disabled = TRUE;
			return TRUE;
		}else
			return FALSE;
	}else{
		if(!disabled)
			return TRUE;
		if(xRevertFsRedirection(old_value)){
			disabled = FALSE;
			return TRUE;
		}else
			return FALSE;
	}
}

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,