- #include <stdio.h>
- #include <Windows.h>
- #include <tchar.h>
- /*Code By Pnig0s1992*/
- int main(void){
- SIZE_T sizeVirtual = 4000;
- LPVOID lpRound = (LPVOID)0x100000FF;
- MEMORY_BASIC_INFORMATION mbi;
- LPVOID lpAddress = VirtualAlloc(lpRound,sizeVirtual,MEM_COMMIT|MEM_RESERVE,PAGE_READWRITE);
- if(lpAddress == NULL){
- printf("内存分配失败:%d\n",GetLastError());
- return 1;
- }
- printf("Alloc:MEM_COMMIT|MEM_RESERVE\n");
- CopyMemory(lpAddress,"pnig0s1992",strlen("pnig0s1992"));
- printf("分配,复制成功,地址:0x%.8x\n内容:%s\n",lpAddress,lpAddress);
- VirtualQuery(lpAddress,&mbi,sizeof(mbi));
- printf("使用VirtualQuery()获得信息:\n");
- printf("BaseAddress:0x%.8x\tAllocationBase:0x%.8x\tAllocationProtect:0x%.8x\tReginSize:%u\tState:0x%.8x\tProtect:0x%.8x\tType:0x%.8x\n",mbi.BaseAddress,mbi.AllocationBase
- ,mbi.AllocationProtect
- ,mbi.RegionSize,mbi.State
- ,mbi.Protect,mbi.Type);
- printf("Free:DEDOMMIT.\n");
- if(!VirtualFree(lpRound,sizeVirtual,MEM_DECOMMIT)){
- printf("Virtual free error:%d\n",GetLastError());
- return 1;
- }
- VirtualQuery(lpAddress,&mbi,sizeof(mbi));
- printf("使用VirtualQuery()获得信息:\n");
- printf("BaseAddress:0x%.8x\tAllocationBase:0x%.8x\tAllocationProtect:0x%.8x\tReginSize:%u\tState:0x%.8x\tProtect:0x%.8x\tType:0x%.8x\n",mbi.BaseAddress,mbi.AllocationBase
- ,mbi.AllocationProtect
- ,mbi.RegionSize,mbi.State
- ,mbi.Protect,mbi.Type);
- printf("Free:RELEASE.\n");
- if(!VirtualFree(lpAddress,0,MEM_RELEASE)){
- printf("Virtual free error:%d\n",GetLastError());
- return 1;
- }
- system("pause");
- return 0;
- }
本文转hackfreer51CTO博客,原文链接:http://blog.51cto.com/pnig0s1992/625126,如需转载请自行联系原作者