程序相關API

2021-10-09 09:58:42 字數 2346 閱讀 3128

1、每個程序都有一張私有的控制代碼表,系統有一張全域性控制代碼表

2、程序id在所有程序都有意義

演示:3、此**開啟乙個軟體,並列印程序id控制代碼

#include "stdafx.h"

#include "windows.h"

//開啟子程序函式

bool createprocess(ptchar route,ptchar szcommandline)

printf("pid:%d - 程序控制代碼:%x",pi.dwprocessid,pi.hprocess);//列印程序id和控制代碼

//釋放控制代碼

4、嘗試用程序控制代碼結束程序:

terminateprocess函式需要兩個引數

程序控制代碼

什麼原因退出

#include "stdafx.h"

#include int main(int argc, char* ar**)

getchar();

return 0;

}

結果如下6,查詢錯誤**資訊,控制代碼無效

5、可以用程序id來結束程序

openprocess函式需要三個引數

1)、想要獲取的許可權(process_all_access獲取全部許可權)

2)、是否繼承父程序的控制代碼

3)、程序id

#include "stdafx.h"

#include int main(int argc, char* ar**)

getchar();

return 0;

}

任何程序都是別的程序建立的:createprocess()

程序的建立過程

1、對映exe檔案

2、建立核心物件eprocess

3、對映系統dll(ntdll.dll)

4、建立執行緒核心物件ethread

5、如果是掛起的方式建立的:

。。。6、恢復以後再繼續執行

對映dll(ntdll.ldrinitializethunk)

執行緒開始執行

#include "stdafx.h"

#include "windows.h"

//開啟子程序函式

bool createprocess(ptchar route,ptchar szcommandline)

for(int i=0;i<8;i++)

resumethread(pi.hthread);//讓程式繼續跑起來

//釋放控制代碼

closehandle(pi.hprocess);

closehandle(pi.hthread);

return true;

}int main(int argc, char* ar**)

char strmodule[256];

getmodulefilename(null,strmodule, 256); //模組目錄

char strwork[1000];

int i=1000;

getcurrentdirectory(i,strwork); //工作目錄

printf("模組目錄:%s \n工作目錄:%s \n",strmodule,strwork);

獲取程序pid

getcurrentprocessid

獲取程序控制代碼

getcurrentprocess

獲取命令列

getcommandline

獲取啟動資訊

getstartupinfo

遍歷程序id

enumprocesses

快照createtoolhelp32snapshot

程序相關API

示例 include include include intmain else if pid 0 return0 include include include intmain else if pid 0 printf d n data return0 執行結果 return fork 57080 ...

LINUX系統程序相關的API

在linux系統下可以用ps指令來檢視系統的程序 在實際工作中經常使用 ps aux gep 程式名,就可以檢視目標程式的程序。也可以用top指令檢視,相當於windows系統下的任務管理器。每個程序都有自己的程序 用getpid函式可以獲取當前經常的程序號 include include incl...

Win32 程序相關的API

開啟程序控制代碼 通過程序id 開啟模組控制代碼 基址 根據程序控制代碼 模組名 獲取模組的檔案全路徑 根據程序控制代碼 模組控制代碼 獲取模組的檔名 根據程序控制代碼 模組控制代碼 獲取模組的映象大小 入口位址 通過程序控制代碼 模組起始位址 讀取程序的記憶體 獲取程序的所有模組的控制代碼 inc...