gh0st中讀取配置檔案的方法

2021-08-21 10:08:56 字數 3373 閱讀 9415

gh0st監聽的埠和服務端最大連線的數量是通過配置檔案進行讀取的。

在gh0st.cpp檔案中,

函式中,有如下****

int	nport = m_inifile.getint("settings", "listenport");

int nmaxconnection = m_inifile.getint("settings", "maxconnection");

if (nport == 0)

nport = 80;

if (nmaxconnection == 0)

nmaxconnection = 10000;

可以看到,使用m_inifile變數獲取

gh0st

監聽的埠和最大連線數量,如果這兩個變數值是

0,則為其賦初值。

從「1

相關**」提到的**中,

m_initfile

變數是自定義類

cinifile

類的物件。通過該類的

getint()

函式獲取在配置檔案中的埠號和最大連線數。

getint()

函式的**如下所示:

在「2 cinifile

類」中提到,該類的

getint()

函式使用

api函式

getprivateprofileint()

函式獲取了配置檔案中的資訊。該系列的函式含包括

getprivateprofilestring()

和writeprivateprofilestring()

函式。以上三個函式都是對配置檔案中指定節的指定鍵進行讀寫操作。

相關鏈結

配置檔案一般是ini格式的檔案。這種配置檔案的內容格式一般為

[section]

key1=content1

key2=content2

key3=content3

其中,section是為節;

key是鍵。而上述三個引數就是對配置檔案中指定

section

的指定key

的content

進行讀寫操作。

getprivateprofileint()函式的作用是從指定節的指定鍵中讀取整數。該函式的格式為:

lpkeyname

是指定鍵的名稱;如果在指定節上找不到指定的鍵,則使用

ndefault

值作為獲取到的的值;第四個引數

lpfilename

指定了配置檔案的路徑。該函式的返回值即為獲取到的鍵的內容。

getprivateprofilestring()函式的作用是從指定節的指定鍵中讀取字串。該函式的格式為

其中,前三個引數與getprivateprofileint()函式相同;第四個引數

lpreturnedstring

用於儲存獲取到的字串;第五個引數

nsize

指定了lpreturnedstring

的大小;第六個引數

lpfilename

指定了配置檔案的路徑。

該函式的作用是將字串寫入到指定節的指定鍵中。該函式的格式為

該函式四個引數分別表示節的名稱、鍵的名稱、寫入的內容和配置檔案的絕對路徑。如果寫入成功,則返回值是true,否則是

false

。在cinifile類的建構函式中,獲取了

gh0st

程式的名稱,並且根據程式名稱指定了程式的配置檔案名稱。

int len;

for(int i=len; i>0; i--)

}以上**通過getmodulefilename()函式獲取

gh0st

程式的名稱,該名稱的格式為

gh0st.exe

。之後在

for迴圈中找到獲取到名稱中的「

.」的位置,並且進行擷取,只取「

.」之前的名字,即

gh0st

。最後,將配置檔名設定為

gh0st.ini

。操作配置檔案的函式主要分為讀取配置檔案和寫入配置檔案兩類。其中,讀取配置檔案的函式包括getstring()/getint()/getdword(),寫入配置檔案的函式包括

setstring()/setint()/setdouble()/setdword()

。這些函式使用「

2.1相關函式

」中提到的api

函式對「

2.2.1

建構函式」中獲取的配置檔名進行操作。

在vs2015中新建乙個控制台程式。輸入以下**

wchar_t name[20] = ;

unsigned int age = 0;

wchar_t ***[10] = ;

::getprivateprofilestring(_t("yang1"), _t("name"), _t("unname"), name, 20, _t("e:\\yang.ini"));

age = ::getprivateprofileint(_t("yang1"), _t("age"), 18, _t("e:\\yang.ini"));

::getprivateprofilestring(_t("yang1"), _t("***"), _t("man"), ***, 10, _t("e:\\yang.ini"));

::writeprivateprofilestring(_t("yang2"), _t("name"), _t("hehe"), _t("e:\\yang.ini"));

::writeprivateprofilestring(_t("yang2"), _t("age"),_t("34"), _t("e:\\yang.ini"));

::writeprivateprofilestring(_t("yang2"), _t("***"), _t("man"), _t("e:\\yang.ini"));

其中,配置檔案的位置是e:\yang.ini,其內容為

[yang1]

name=hou

age=27

***=man

經過以上**,從配置檔案yang.ini中讀取了

name

、age

和***

的值。而經過最後三行**之後,

e:\yang.ini

配置檔案的內容變為

[yang1]

name=hou

age=27

***=man

[yang2]

name=hehe

age=34

***=man

Gh0st上線更新專用ASP檔案

if request.form str and request.form file then if request.form pass gh0st then set fso server.createobject scripting.filesystemobject zy.writeline req...

讀取配置檔案的方法

public static listhosts new arraylist static properties pros new properties staticelse catch ioexception e 總結 首先把名為main config.properties的配置檔案放在src下即可...

shell 讀取配置檔案的方法

乙個bbs的問答。配置檔案config內容如下 id 123 ip 192.168.3.154 name test方法一,利用sed解析文字,提取配置資訊 id sed id d s urfile ip sed ip d s urfile name sed name d s urfile echo ...