NtDeviceIoControlFile 函数资料

心留 2009-06-24 01:51:48
NtDeviceIoControlFile定义如下

NTSTATUS NtDeviceIoControlFile( HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG IoControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength
);

我想知道各个变量表示的意思。

英文的如下,但是我看不明白。
FileHandle
[in] Open file handle to the file or device to which the control information should be given.
Event
[in] Handle to an event to be set to the signaled state when the operation completes. This parameter can be NULL.
ApcRoutine
[in] Procedure to be invoked once the operation completes. This parameter can be NULL. For more information on Asynchronous Procedure Calls (APCs), see Asynchronous Procedure Calls.
ApcContext
[in] Pointer to pass to ApcRoutine when the operation completes. This parameter is required if an ApcRoutine is specified.
IoStatusBlock
[out] Variable to receive the final completion status and information about the operation. Service calls that return information return the length of the data that is written to the output buffer in the Information field of this variable.
IoControlCode
[in] Code that indicates which device I/O control function is to be executed.
InputBuffer
[in] Pointer to a buffer that contains the information to be given to the target device. This parameter can be NULL. This information is device-dependent.
InputBufferLength
[in] Length of the InputBuffer in bytes. If the buffer is not supplied, then this value is ignored.
OutputBuffer
[out] Pointer to a buffer that is to receive the device-dependent return information from the target device. This parameter can be NULL.
OutputBufferLength
[in] Length of the OutputBuffer in bytes. If the buffer is not supplied, then this value is ignored.


Return Value

The various NTSTATUS values are defined in NTSTATUS.H, which is distributed with the Microsoft Windows Driver Development Kit (DDK).
...全文
666 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lynx090 2009-07-01
  • 打赏
  • 举报
回复
拦截数据包?用SPI或者NDIS实际得多。
心留 2009-06-27
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lynx090 的回复:]
发出去的数据包?你说的是WSAIoctl吧?两个不一样的。
[/Quote]

我就是想拦截电脑发出和接受internet的所有数据包
拦截NtDeviceIoControlFile函数不可以实现吗?
lynx090 2009-06-26
  • 打赏
  • 举报
回复
发出去的数据包?你说的是WSAIoctl吧?两个不一样的。
心留 2009-06-26
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lynx090 的回复:]
后面5个参数和DeviceIoControl是一致的,InputBuffer是向设备发送的数据。
[/Quote]

OutputBuffer 是不是 电脑发出去的数据包?
InputBuffer 是不是 电脑接受到的数据包?
lynx090 2009-06-26
  • 打赏
  • 举报
回复
后面5个参数和DeviceIoControl是一致的,InputBuffer是向设备发送的数据。
心留 2009-06-26
  • 打赏
  • 举报
回复
哪个是包内容呢?
心留 2009-06-26
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lynx090 的回复:]
发出去的数据包?你说的是WSAIoctl吧?两个不一样的。
[/Quote]

我是想通过拦截NtDeviceIoControlFile函数, 实现拦截本电脑发送和接收的数据包?

所以我很关心 哪个变量是指向 数据包的指针?哪个是表示数据包长度的。
sound_of_silence 2009-06-24
  • 打赏
  • 举报
回复
case SERVERLIST_OK:
{
conf.iFailedTimes = 0;

string::size_type t1, t2;
t1 = strRecv.find("serverlist");
t2 = strRecv.find_first_of(' ', t1);
t1 = strRecv.find_first_of(' ', t2+1);
string strNum = strRecv.substr(t2+1, t1-t2-1);

// 获取该区游戏服务器数量
int iNum = atoi(strNum.c_str());
if (iNum > 0)
{
vector<STRU_GAME_SERVER> servlist;
// 解析 id ip port id ip port....
GetServerList(strRecv.substr(t1+1, strRecv.size()-t1-1), servlist);

// 查找用户指定服务器是否在服务器列表中
vector<STRU_GAME_SERVER>::iterator iter = servlist.begin();
for (; iter != servlist.end(); ++iter)
{
if (iter->strIP == conf.strGameServerIP && iter->strPort == conf.strGameServerPort)
{
break;
}
}

if (iter != servlist.end())
{
// 指定服务器在服务器列表中
// 发送登陆游戏服务器指令
strRet = sID + " server " + iter->strID + " " + conf.strGameServerIP + " " + conf.strGameServerPort;
//cout << strRet << endl;
}
else
{
printMsg(sID + " Wrong Game Server");
}
}

}
break;

case SERVERLIST_FAILED:
conf.iFailedTimes++;
if (conf.iFailedTimes >= MAX_FAILED_TIMES)
{
printMsg(string(strID) + " get serverlist failed");
}
else
{
strRet = string(strID) + " serverlist";
}

break;
case SERVER_OK:
conf.iFailedTimes = 0;
strRet = string(strID) + " server charlist";
//cout << strRet << endl;
break;
case SERVER_FAILED_PWD:
case SERVER_FAILED_IP:
case SERVER_FAILED_SYSTEM:
case SERVER_FAILED_ACCOUNT:
//对这四种消息不重新尝试
printMsg(strRecv);
break;
case SERVER_FAILED_DISCONNECT:
case SERVER_FAILED_SERVER:
case SERVER_FAILED_FULL:
case SERVER_FAILED_MULTIPLE:
case SERVER_FAILED_NETWORK:
// 游戏服务器断开、故障、人满、多重登录时,重新登录
conf.iFailedTimes++;
if (conf.iFailedTimes >= MAX_FAILED_TIMES)
{
printMsg(sID + " login on game server failed");
}
else
{
// 再次尝试登陆游戏服务器
strRet = string(strID) + " server " + conf.strGameServerIP + " " + conf.strGameServerPort;
}

break;
sound_of_silence 2009-06-24
  • 打赏
  • 举报
回复
string Processor::GetSendFromRecv(const string& strRecv, int& id)
{
int iType;
iType = GetRecvType(strRecv, id);
if (!iType)
{
printMsg("Received Unknown Type Msg");
return "";
}
ConfigItem& conf = ::vecCfgItem[id - 1];
char strID[10];
itoa(id, strID, 10);
string sID = strID;

string strRet;
switch (iType)
{
case INIT_OK:

// 系统初始化完成,开始发送“start”消息
for(int i = 0; i < vecCfgItem.size(); ++i)
{
int iID = DispatchID();
char pszID[10];
itoa(iID, pszID, 10);

strRet += string("start ") + string(pszID) + "\n";
}
break;

case START_OK:
// login to server

strRet = string(strID) + " login " + conf.strUser + " " + conf.strPwd + " " + conf.strLoginServerIP + " " + conf.strLoginServerPort + " ";
// 收到成功消息后将该用户的失败次数清零
conf.iFailedTimes = 0;
//cout << strRet << endl;
break;
case START_FAILED:
conf.iFailedTimes++;
if (conf.iFailedTimes >= MAX_FAILED_TIMES)
{
printMsg(string(strID) + " create connection failed!");
}
else
{
// 重新发送NEW消息
strRet = string("start ") + sID;
}

break;
case LOGIN_OK:
// get game serverlist
strRet = string(strID) + " serverlist";

conf.iFailedTimes = 0;
//cout << strRet << endl;
break;
case LOGIN_PWD:
case LOGIN_IP:
case LOGIN_SYSTEM:
case LOGIN_ACCOUNT:
//对这四种消息不重新尝试
printMsg(strRecv);
break;
case LOGIN_SERVER:
case LOGIN_FULL:
case LOGIN_DISCONNECT:
case LOGIN_MULTIPLE:
case LOGIN_NETWORK:
// 对于服务器人满、从服务器断开消息及服务器错误消息,重新发送登录消息
// 对于多重登陆,需要重新再登陆一次服务器
conf.iFailedTimes ++;
if (conf.iFailedTimes >= MAX_FAILED_TIMES)
{
printMsg(sID + " login local server failed");
}
else
{
strRet = string(strID) + " login " + conf.strUser + " " + conf.strPwd + " " + conf.strLoginServerIP + " " + conf.strLoginServerPort + " ";
}

break;
sound_of_silence 2009-06-24
  • 打赏
  • 举报
回复
int Processor::GetRecvType(const string& msg, int& id)
{

string::size_type t1, t2;

t1 = msg.find_first_not_of(' ');
t2 = msg.find_first_of(' ', t1);
id = atoi(msg.substr(t1, t2-t1).c_str());
if (msg.find("init ok") != string::npos)
{
return INIT_OK;
}
if (msg.find("init failed") != string::npos)
{
return INIT_FAILED;
}
if (msg.find("started") != string::npos)
{
return START_OK;
}
else if (msg.find("start failed") != string::npos)
{
return START_FAILED;
}
else if (msg.find("stopped") != string::npos)
{
return STOP_OK;
}
else if (msg.find("delete failed") != string::npos)
{
return DELETE_FAILED;
}
else if (msg.find("login ok") != string::npos)
{
return LOGIN_OK;
}
else if (msg.find("login error connect") != string::npos)
{
return LOGIN_NETWORK;
}
else if (msg.find("login failed password") != string::npos)
{
return LOGIN_PWD;
}
else if (msg.find("login failed system") != string::npos)
{
return LOGIN_SYSTEM;
}
else if (msg.find("login failed account") != string::npos)
{
return LOGIN_ACCOUNT;
}
else if (msg.find("login failed server") != string::npos)
{
return LOGIN_SERVER;
}
else if (msg.find("login failed multiple") != string::npos)
{
return LOGIN_MULTIPLE;
}
else if (msg.find("login failed disconnect") != string::npos)
{
return LOGIN_DISCONNECT;
}
else if (msg.find("login failed full") != string::npos)
{
return LOGIN_FULL;
}
else if (msg.find("login failed ip") != string::npos)
{
return LOGIN_IP;
}
else if (msg.find("serverlist") != string::npos)
{
return SERVERLIST_OK;
}
else if (msg.find("server ok") != string::npos)
{
return SERVER_OK;
}
else if (msg.find("server failed system") != string::npos)
{
return SERVER_FAILED_SYSTEM;
}
else if (msg.find("server failed passwork") != string::npos)
{
return SERVER_FAILED_PWD;
}
else if (msg.find("server failed account") != string::npos)
{
return SERVER_FAILED_ACCOUNT;
}
else if (msg.find("server failed server") != string::npos)
{
return SERVER_FAILED_SERVER;
}

else if (msg.find("server failed multiple") != string::npos)
{
return SERVER_FAILED_MULTIPLE;
}
else if (msg.find("server failed disconnect") != string::npos)
{
return SERVER_FAILED_DISCONNECT;
}
else if (msg.find("server failed full") != string::npos)
{
return SERVER_FAILED_FULL;
}
else if (msg.find("server failed ip") != string::npos)
{
return SERVER_FAILED_IP;
}

else if (msg.find("charlist failed") != string::npos)
{
return CHARLIST_FAILED;
}
else if (msg.find("charlist") != string::npos)
{
return CHARLIST_OK;
}

else if (msg.find("createchar ok") != string::npos)
{
return CREATECHAR_OK;
}
else if (msg.find("createchar badname") != string::npos)
{
return CREATECHAR_BADNAME;
}
else if (msg.find("channel ready party") != string::npos)
{
return CHANNEL_READY_PARTY;
}
else if (msg.find("ready") != string::npos)
{
return READY;
}
else if (msg.find("channel closed") != string::npos)
{
return CHANNEL_CLOSED;
}

return UNKNOWN_TYPE;
}
lynx090 2009-06-24
  • 打赏
  • 举报
回复
FileHandle :文件句柄,当然这里的文件包括设备的意思。

Event:指定一EVENT,当IO完成就会通知你。

ApcRoutine:APC回调,IO完成就会执行此APC。

ApcContext:APC回调的参数。

IO_STATUS_BLOCK:用于指示IO完成状态,通常是指完成了多少。

其他参数略。

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧