//#include <stdio.h> #include <stdlib.h> #include <windows.h> #include <iostream> #include <fstream> #include <iomanip> using namespace std; //#define _DEBUG_ long read4Bit(ifstream& f); long read3Bit(ifstream& f); int readString(ifstream& f, long exeOffset, char *str); int read2Zero(ifstream& f, char*buf); int findIPLocation(char*dat, long exeOffset, DWORD searchIpNum); void printHelp(char* exePath); DWORD convertIP(char*sip); void printIpNum(DWORD ip); int main(int argc, char**argv)...{ char *sip; char *dat; long offSet; DWORD intIP; #if defined _DEBUG_ //for(int i=0;i<argc; i++){ // cout<<\"argv[\"<<i<<\"/\"<<argc<<\"]=\"<<argv[i]<<\" \"; //} #endif dat=new char[256]; memset(dat, 0, 256); if( argc==3 )...{ strcpy(dat, argv[2]); offSet=0L; }else...{ delete[]dat; printHelp(argv[0]); return 1; } sip=new char[16]; memset(sip, 0, 16); strcpy(sip, argv[1]); intIP = convertIP(sip); findIPLocation(dat, offSet, intIP); delete[]dat; delete[]sip; return 0; } //第一個參數 是數據文件 //第二個參數 是如果合併成一個文件的話,開始的偏移 //第三個參數 是查找的IP的十進制表達 //第四個參數 是返回的結果 int findIPLocation(char*dat, long exeOffset,DWORD searchIpNum) ...{ #if defined _DEBUG_ int times=0; //查找了多少次 #endif DWORD ipBeginPos, ipEndPos; //開始的偏移,結束的偏移 [Page] DWORD midNum, beginNum, endNum, totalNum; //中間的個數,開始的個數,結束的個數,總共的個數 DWORD ip1Num, ip2Num; //開始IP的十進制值,結束IP的十進制值 long pos, iRead; //當前的文件的指針的位置 char *ipAddr; //*ipAddr2, *ipAddr1, *ipAddr; if(searchIpNum<0xFF)...{ return -1; } ifstream fs; fs.open(dat, ios::binary | ios::in, 0); if((!fs.is_open()) || (!fs.good())) ...{ return -2; } #if defined _DEBUG_ cout<<\" searchIpNum=\"<<searchIpNum<<\", exeOffset=\"<<exeOffset<<endl; #endif fs.seekg(exeOffset, ios_base::beg); ipBeginPos=read4Bit(fs); #if defined _DEBUG_ cout<<\" ipBeginPos=\"<<ipBeginPos<<endl; #endif ipEndPos=read4Bit(fs); #if defined _DEBUG_ cout<<\" ipEndPos=\"<<ipEndPos<<endl; #endif totalNum = (ipEndPos - ipBeginPos) / 7; #if defined _DEBUG_ cout<<\" totalNum=\"<<totalNum<<endl; #endif if(totalNum<1)...{ return -3; } beginNum = 0; endNum = totalNum; while( 1 ) ...{ //IP的索引是有順序的,按照個數來二分查找. |