在sub_401000()主程序中,InternetGetConnectedState函数被调用,由其名字不难猜出这是一个判断网络连接状态的函数,msdn上有其介绍如下:
BOOL InternetGetConnectedState(
_Out_ LPDWORD lpdwFlags,
_In_ DWORD dwReserved
);
两个参数:
lpdwFlags is a Pointer to a variable that receives the connection description,函数通过这个参数判断特定网络是否正常连接,例如LAN、MODEM等,但是没有0,猜测应该是只要有一个可以连接就返回TRUE。
dwReserved为保留字,必须为0
这里逻辑如下:如果存在网络连接,InternetGetConnectedState返回True,cmp将返回值与0比较使ZF置0,从而jz不会跳转。伪代码:
int _main(){
int flag = sub_401000();
if(flag){
//jmp loc_401148;
var_8 = sub_401040();
//test eax,eax;相当于&操作,
if(var_8&var_8) reutrn 0;
//jmp loc_40115C;之前已经分析过sub_40117F为printf,可以在IDA中对sub_40117F进行重命名
printf("Success: Parsed command is %c\n",ecx_command);
Sleep(EA60h);
}
return 0;
}
5、sub_401040()
在图中框出了几个函数调用和跳转,总结分析可知,该函数访问了szUrl,如果访问成功跳到loc_40109D,否则打印失败信息,关闭网络句柄。
1)InternetOpen:Returns a valid handle that the application passes to subsequent WinINet functions. If InternetOpen fails, it returns NULL. To retrieve a specific error message, call GetLastError.
即如果打开成功,它会返回一个有效的句柄。interHandler = InternetOpen(szAgent,0,0,0,0)
2)InternetOpenUrl:Returns a valid handle to the URL if the connection is successfully established, or NULL if the connection fails. To retrieve a specific error message, call GetLastError. To determine why access to the service was denied, callInternetGetLastResponseInfo.
通过1)获得的句柄请求url,获得一个URL的句柄。urlHandler=InternetOpenUrl(interHandler,szUrl,0,0,0,0)
3)cmp [ebp+hFile],0;urlHandler与0比较,如果不为NULL,jmp loc_40109D
伪代码如下:
当urlHandler不为NULL时,首先调用了
1)var_4 = InternetReadFile(hFile,*lpBuffer,256,*lpdwNumberOfBytesRead)
注: hFile [in]:Handle returned from a previous call to InternetOpenUrl.
lpBuffer [out]:Pointer to a buffer that receives the data.
dwNumberOfBytesToRead [in]:Number of bytes to be read.
lpdwNumberOfBytesRead [out]:Pointer to a variable that receives the number of bytes read. InternetReadFile sets this value to zero before doing any work or error checking.
即从hFile中读取512字节的数据存到lpBuffer中,成功返回True,否则返回False
2)接下来判断是否读取成功,成功则跳转到loc_4010E5继续执行,否则打印错误信息,关闭句柄,退出