為了對(duì)黑客常用的Windows API有個(gè)更全面的了解以及方便日后使用API方法的查詢(xún),特將這些常用的API按照7大分類(lèi)進(jìn)行整理如下,希望對(duì)大家的學(xué)習(xí)有所幫助。
一、進(jìn)程
創(chuàng)建進(jìn)程:
CreateProcess("C:\\windows\\notepad.exe",0,0,0,0,0,0,0,&si,&pi);
WinExec("notepad",SW_SHOW);
ShellExecute(0,"open","notepad","c:\\a.txt","",SW_SHOW);
ShellExecuteEx(&sei);
遍歷進(jìn)程:
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
Process32First(hsnap,&pe32);
Process32Next(hsnap,&pe32);
終止進(jìn)程:
ExitProcess(0);
TerminateProcess(hProc,0);
打開(kāi)進(jìn)程:
OpenProcess(PROCESS_ALL_ACCESS,0,pid);\
獲取進(jìn)程ID:
GetCurrentProcesssId();
獲取進(jìn)程可執(zhí)行文件路徑:
GetModuleFileName(NULL,buf,len);
GetProcessImageFileName(hproc,buf,len);
遍歷進(jìn)程模塊信息:
CreateToolhelp32Snapshot(TH32CS_SNAPMODILE,pid);
Module32First(hsnap,&mdl32);
Module32Next(hsnap,&mdl2);
獲取指定模塊句柄:
GetModuleHandle(“kernel32.dll”);
獲取模塊內(nèi)函數(shù)地址:
GetProcessAddr(hmdl,”MessageBox”);
動(dòng)態(tài)加載DLL:
LoadLibrary(“user32.dll”);
卸載DLL:
FreeLibrary(hDll);
獲取進(jìn)程命令行參數(shù):
GetCommandLine();
任何進(jìn)程GetCommandLine函數(shù)地址后偏移一個(gè)字節(jié)后的4字節(jié)地址為命令行地址。
讀寫(xiě)遠(yuǎn)程進(jìn)程數(shù)據(jù):
ReadProcessMemory(hproc,baseAddr,buf,len,&size);
WriteProcessMemory(hproc,baseAddr,buf,len,&size);
申請(qǐng)內(nèi)存:
VirtualAlloc(0,size,MEM_COMMIT, PAGE_EXECUTE_READWRITE);
VirtualAllocEx(hproc,0,size,MEM_COMMIT, PAGE_EXECUTE_READWRITE);
修改內(nèi)存屬性:
VirtualProtect(addr,size,PAGE_EXECUTE_READWRITE,&oldAddr);
VirtualProtectEx(hproc,addr,size,PAGE_EXECUTE_READWRITE,&oldAddr);
釋放內(nèi)存:
VirtualFree( addr, size, MEM_RELEASE);
VirtualFreeEx(hproc, addr, size, MEM_RELEASE);
獲取系統(tǒng)版本(Win NT/2K/XP<0x80000000):
getVersion();
讀寫(xiě)進(jìn)程優(yōu)先級(jí):
SetPriorityClass(hproc,Normal);
GetPriority(hproc);
SetProcessPriorityBoost(hproc,true);
GetProcessPriorityBoost(hproc,pBool);
二、線程
創(chuàng)建線程(CreateThread的線程函數(shù)調(diào)用了strtok、rand等需使用_endthread()釋放內(nèi)存):
CreateThread(0,0,startAddr,?,0,&tid);
_beginthread(startAddr,0,0);
_beginthreadex(0,0,startAddr,0,0,&tid);
CreateRemoteThread(hproc,0,0,func,?,0,&tid);
獲取線程ID:
GetCurrentThreadId();
關(guān)閉線程句柄(減少內(nèi)核對(duì)象使用次數(shù),防止內(nèi)存泄漏):
CloseHandle(hthread);
掛起與激活線程(維護(hù)暫停次數(shù)):
SuspendThread(hthread);
ResumeThread(hthread);
獲取線程退出代碼:
GetExitCode(hthread,&code);
等待線程退出(線程受信狀態(tài)或超時(shí)):
WaitForSignleObject(htread,1000);
WaitForMultipleObjects(num,handles,true,INFINITE);
遍歷線程:
CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
Thread32First(hsnap,&mdl32);
Thread32Next(hsnap,&mdl2);
獲取線程函數(shù)入口:
ZwQueryInfomationThread(hthread,ThreadQuerySetWin32StartAddress,&buf,4,NULL);
打開(kāi)線程:
OpenThread(THREAD_ALL_ACCESS,false,&tid);
獲取線程函數(shù)地址所屬模塊:
GetMappedFileName(hproc,addr,buf,256);
讀寫(xiě)線程優(yōu)先級(jí):
SetThreadPriority(hthread,Normal);
GetThreadPriority(hthread);
SetThreadPriorityBoost(hproc,true);
GetThreadPriorityBoost(hproc,pBool);
終止線程:
ExitThread(5);
TerminateThread(hthread,5);
線程同步臨界區(qū)對(duì)象:
InitializeCriticalSection(&cs);
EnterCriticalSection(&cs);
LeaveCriticalSection(&cs);
DeleteCriticalSection(&cs);
線程同步事件內(nèi)核對(duì)象:
OpenEvent(EVENT_ALL_ACCESS,false,name);
CreateEvent(NULL,false,true,NULL);
WaitForSingleObject(hevnt,INFINITE);
SetEvent(hevnt);
ResetEvent(hevnt);
線程同步互斥內(nèi)核對(duì)象:
CreateMutex(NULL,false,NULL);
WaitForSingleObject(hmutex,INFINITE);
ReleaseMutex(hmutex);
OpenMutex(MUTEX_ALL_ACCESS,false,name);
三、注冊(cè)表
創(chuàng)建鍵:
RegCreateKeyEx(HKEY_CURRENT_USER,”TestNewKey”,0,0,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,0,&subkey,&state);
打開(kāi)鍵:
RegCreateKeyEx(HKEY_CURRENT_USER,”Control Panel”,0,KEY_ALL_ACCESS,&subkey);
關(guān)閉鍵:
RegCloseKey(hkey);
遍歷鍵:
RegEnumKeyEx(hsubkey,index,keyname,&nameSize,0,0,0,&time);
FileTimeToSystemTime(&time,&systime);
RegQueryInfo(hsubkey,0,0,0,&count,0,0,0,0,0,0,0);
刪除鍵:
RegDeleteKeyEx(hmainkey,subkeyName);
創(chuàng)建值:
RegSetValueEx(hsubkey,”test”,0,REG_WORD,(BYTE*)&value,4);
遍歷值:
RegEnumValue(hsubkey,index,name,&nameSize,0,&type,valuebuf,valueLen);
RegQueryValueEx(hsubkey,name,0,type,buf,&size);
刪除值:
RegDeleteValue(hsubkey,valuename);
四、文件
創(chuàng)建/打開(kāi)文件:
CreateFile(“a.txt”,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
設(shè)置文件指針:
SetFilePointer(hFile,0,NULL,FILE_END);
讀寫(xiě)文件:
ReadFile(hFile,buf,len,&size,0);
WriteFile(hFile,buf,len,&size,0);
強(qiáng)制文件寫(xiě)入磁盤(pán),清空文件高速緩沖區(qū):
FlushFileuffers(hFile);
[解]鎖文件區(qū)域:
LockFile(hFile,0,0,100,0);
UnlockFile(hFile,0,0,100,0);
復(fù)制文件:
CopyFile(src,des,true);
CopyFileEx(src,des,func,?,false, COPY_FILE_FAIL_IF_EXISTS);
移動(dòng)文件:
MoveFile(src,des);
MoveFileEx(src,des,false);
MoveFileWithProgress(src,des,fun,?, MOVEFILE_COPY_ALLOWED);
刪除文件:
DeleteFile(filename);
獲取文件類(lèi)型(FILE_TYPE_PIPE):
GetFileType(hFile);
獲取文件大?。?/p>
GetFileSize(hFile,&high);
獲取文件屬性(例如FILE_ATTRIBUTE_DIRECTORY進(jìn)行&運(yùn)算):
GetFileAttributes(hFile);
遍歷文件:
FindFirstFile(nameMode,&wfd);
FindNextFile(hFile,&wfd);
創(chuàng)建管道:
CreatePipe(&hRead,&hWrite,&sa,0);
創(chuàng)建內(nèi)存映射文件:
CreateFile(“d:\\a.txt”,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,”myMap”);
加載內(nèi)存映射文件:
MapViewOfFile(hmap,FILE_MAP_ALL_ACCESS,0,0,0);
打開(kāi)內(nèi)存映射文件:
OpenFileMapping(FILE_AMP_ALL_ACCESS,false,”myMap”);
卸載內(nèi)存映射文件:
UnmapViewOfFile(baseAddr);
強(qiáng)制寫(xiě)入內(nèi)存映射文件到磁盤(pán):
FlushViewOfFile(baseAddr,len);
創(chuàng)建文件夾(只能創(chuàng)建一層):
CreateDirectory(“D:\\a”,NULL);
CreateDirectory(“C:\\a”,”D:\\b”,NULL);
刪除文件夾(只能刪除空文件夾):
RemoveDirectory(“C:\\a”);
GetLogicalDrives();
GetLogicalDriveStrings(len,buf);
獲取驅(qū)動(dòng)器類(lèi)型(DRIVE_CDROM):
GetDriveType(“D:\\”);
打開(kāi)網(wǎng)絡(luò)資源枚舉過(guò)程(winnetwk.h、Mpr.lib):
WNetOpenEnum(RESOURCE_GLOBAL,RESOURCETYPE_ANY,0,NULL,hnet);
枚舉網(wǎng)絡(luò)資源:
WNetEnumResource(hnet,&count,pNetRsc,&size);
關(guān)閉網(wǎng)絡(luò)資源枚舉過(guò)程:
WNetCloseEnum(hnet);
打開(kāi)關(guān)閉WinSocket庫(kù):
WSAStartup(version,&wsa);
WSACleanup();
創(chuàng)建套接字:
socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
綁定套接字IP和端口:
bind(sock,&addr,len);
監(jiān)聽(tīng)TCP連接:
listen(sock,10);
接收TCP連接請(qǐng)求:
accept(sock,&addr,&len);
客戶(hù)端連接:
connect(sock,&addr,len);
發(fā)送TCP數(shù)據(jù):
send(sock,buf,len,0);
接收TCP數(shù)據(jù):
recv(sock,buf,len,0);
發(fā)送UDP數(shù)據(jù):
sendto(sock,buf,len,0,&addr,len);
接收UDP數(shù)據(jù):
recvfrom(sock,buf,len,0,&addr,&len);
六、服務(wù)
打開(kāi)SCM服務(wù)控制管理器:
OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
創(chuàng)建服務(wù):
CreateService(mgr,"MyService"," MyService",SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START,SERVICE_ERROR_IGNORE,path,NULL,NULL,NULL,NULL,NULL);
打開(kāi)服務(wù)對(duì)象:
OpenService(mgr," MyService ",SERVICE_START);
啟動(dòng)服務(wù):
StartService(serv,0,NULL);
查詢(xún)服務(wù)狀態(tài):
QueryServiceStatus(serv,&state);
關(guān)閉服務(wù)句柄:
CloseServiceHandle(hdl);
連接到SCM:
StartServiceCtrlDispatcher(DispatchTable);
注冊(cè)服務(wù)控制函數(shù):
RegisterServiceCtrlHandler("MyServicer",ServiceCtrl);
設(shè)置服務(wù)狀態(tài):
SetServiceStatus(hss,&ServiceStatus);
控制服務(wù):
ControlService(serv,SERVICE_CONTROL_STOP,&state);
刪除服務(wù):
DeleteService(serv);
遍歷服務(wù):
EnumServicesStatus(hscm,SERVICE_WIN32|SERVICE_DRIVER,SERVICE_STATE_ALL,&srvSts,len,&size,&count,NULL);
查詢(xún)服務(wù)配置:
QueryServiceConfig(hserv,&srvcfg,size,&size);
七、消息
發(fā)送消息:
SendMessage(HWND_BROADCAST,WM_LBUTTONDOWN,0,0);
接收消息:
GetMessage(&msg,NULL,0,0);
投遞消息:
PostMessage(HWND_BROADCAST,WM_LBUTTONDOWN,0,0);
獲取消息:
PeekMessage(&msg,NULL,0,0);
轉(zhuǎn)換消息:
TranslateMessage (&msg);
分發(fā)消息:
DispatchMessage (&msg);
等待消息:
WaitMessage();
發(fā)送退出消息:
PostQuitMessage(0);
安裝消息鉤子:
SetWindowsHookEx(WH_KEYBOARD,keyBoardProc,0,tid);
卸載消息鉤子:
UnhookWindowsHookEx(hhk);
以上是作者目前就相關(guān)技術(shù)所接觸的最常用的一批API函數(shù),這肯定不是最完整的,但是都是博主從一份份資料中挖掘出來(lái)的,也希望讀者能多多補(bǔ)充,相互進(jìn)步!
-
API
+關(guān)注
關(guān)注
2文章
1510瀏覽量
62327 -
API函數(shù)
+關(guān)注
關(guān)注
0文章
15瀏覽量
8086
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論