本文介绍了在目标进程中分配内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切正常,直到我调用VirtualAllocEx,它总是返回一个GetLastError代码1300.我无法弄清楚原因。任何建议?



 processId = wcstod(argv [ 1 ], _T('  \ 0')); 
MEMORY_BASIC_INFORMATION memInfo;
SYSTEM_INFO si;
std :: cout<< 开始阅读<<的std :: ENDL;
hdnlProc = OpenProcess(PROCESS_ALL_ACCESS, false ,processId);



if 0 == hdnlProc )
{
std :: cout<< 发生错误:<< GetLastError()<<的std :: ENDL;
}

如果(OpenProcessToken(hdnlProc,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,& hndlTok)== 0
{
std :: cout<< 无法访问进程令牌:<< GetLastError()<<的std :: ENDL;
}

if (LookupPrivilegeValue(NULL,SE_TCB_NAME,& luid)== 0
{
std :: cout<< 无法查找值:<< GetLastError()<<的std :: ENDL;
}
std :: cout<< 尝试创建虚拟内存:<< GetLastError()<<的std :: ENDL;
// std :: cout<< LUID:<< luid<< std :: endl;

priv.PrivilegeCount = 1 ;
priv.Privileges [ 0 ]。Luid = luid;
priv.Privileges [ 0 ]。属性= SE_PRIVILEGE_ENABLED;

if (AdjustTokenPrivileges(hndlTok,FALSE,& priv, 0 , NULL,NULL)== 0
{
std :: cout<< 无法调整权限:<< GetLastError()<<的std :: ENDL;
}

VirtualAllocEx(hdnlProc,NULL, 10240 ,MEM_COMMIT,PAGE_READWRITE);
std :: cout<< 尝试创建虚拟内存:<< GetLastError()<< std :: endl;
解决方案

Everything works until I call VirtualAllocEx, which always returns a GetLastError Code of 1300. I can't figure out why. Any Suggestions?

processId = wcstod(argv[1], _T('\0'));
	MEMORY_BASIC_INFORMATION memInfo;
	SYSTEM_INFO si;
	std::cout << "Begining Proc Reading" << std::endl;
	hdnlProc = OpenProcess(PROCESS_ALL_ACCESS,false,processId);



	if (0 == hdnlProc)
	{
		std::cout << "An Error has occured: " << GetLastError() << std::endl;
	}

	if (OpenProcessToken(hdnlProc,TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hndlTok) == 0)
	{
			std::cout << "Failed to access process token: " << GetLastError() << std::endl;
	}

	if (LookupPrivilegeValue(NULL, SE_TCB_NAME , &luid) == 0)
	{
		std::cout << "Failed to lookup value: " << GetLastError() << std::endl;
	}
	std::cout << "Attempted to create virtual memory: " << GetLastError() << std::endl;
	//std::cout << " LUID: " << luid << std::endl;

	priv.PrivilegeCount  = 1;
	priv.Privileges[0].Luid = luid;
	priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

	if (AdjustTokenPrivileges(hndlTok,FALSE,&priv,0,NULL,NULL) == 0)
	{
			std::cout << "Failed to adjust privledges: " << GetLastError() << std::endl;
	}

	VirtualAllocEx(hdnlProc,NULL,10240,MEM_COMMIT, PAGE_READWRITE);
	std::cout << "Attempted to create virtual memory: " << GetLastError() << std::endl;
解决方案


这篇关于在目标进程中分配内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:09