修改ipsearcher.dll代码为bcb编译,但无法在BCB中正确加载.

od4ys 2007-12-21 03:55:39
修改后的代码如下:

#include <vcl.h>
#include <windows.h>

#pragma hdrstop
#pragma argsused

extern "C" __declspec(dllexport) void* __stdcall _GetAddress(const char *IPstr);

void *ret[2]; //for return
char *ptr = NULL; //ptr of image
char *p = NULL; //point to index
unsigned int total; //ip count

inline unsigned int get_3b(const char *mem)
{
return 0x00ffffff & *(unsigned int*)(mem);
}

inline void Load(void)
{
HANDLE hnd; //file handle
DWORD NumberOfBytesRead; //len
char text[2048]; //patch
char *temp;
unsigned int len;

//get patch
if( !GetModuleFileName(0, text, 2048) )
return;
temp = strrchr(text, 92); // 92 = '\'
*(temp + 1) = NULL;
strcat(temp, "QQwry.dat");

//CreateFile
hnd = CreateFile(text, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

if(INVALID_HANDLE_VALUE == hnd)
{
::MessageBox(NULL, text, "Can't Open QQWry.dat!", NULL);
return;
}

//get len
len = SetFilePointer(hnd, NULL, NULL, FILE_END);
SetFilePointer(hnd, NULL, NULL, FILE_BEGIN);

//malloc
ptr = (char*)malloc(len+9);
if(!ptr)
{
CloseHandle(hnd);
::MessageBox(NULL, "Can't Malloc Memory!", NULL, NULL);
return;
}

//read
if(!ReadFile(hnd, ptr, len, &NumberOfBytesRead, NULL))
{
CloseHandle(hnd);
free(ptr);
::MessageBox(NULL, text, "Can't Read QQWry.dat!", NULL);
return;
}
CloseHandle(hnd);

//calc total - 1
total = (*((unsigned int*)ptr+1) - *(unsigned int*)ptr);

//check file
if(total % 7 != 0)
{
free(ptr);
::MessageBox(NULL, text, "QQwry.dat is Bad!", NULL);
return;
}

total /= 7;
++total;
p = ptr + *(unsigned int*)ptr; //ptr of index area
}

inline unsigned int str2ip(const char *lp)
{
unsigned int ret = 0;
unsigned int now = 0;

while(*lp)
{
if('.' == *lp)
{
ret = 256 * ret + now;
now = 0;
}
else
now = 10 * now + *lp - '0';
++lp;
}

ret = 256 * ret + now;
return ret;
}

void* __stdcall _GetAddress(const char *IPstr)
{
if(NULL == p)
{
ret[0] = "Can't Open Data!";
ret[1] = "";
return ret;
}

unsigned int ip = str2ip(IPstr);
char *now_p;

unsigned int begin = 0, end = total;
while(1)
{
if( begin >= end - 1 )
break;
if( ip < *(unsigned int*)(p + (begin + end)/2 * 7) )
end = (begin + end)/2;
else
begin = (begin + end)/2;
}

unsigned int temp = get_3b(p + 7 * begin + 4);
if(ip <= *(unsigned int*)(ptr + temp)) //ok, found
{
now_p = ptr + temp + 4;
if( 0x01 == *now_p )
now_p = ptr + get_3b(now_p + 1);
//country
if( 0x02 == *now_p ) //jump
{
ret[0] = ptr + get_3b(now_p + 1);
now_p += 4;
}
else
{
ret[0] = now_p;
for(; *now_p; ++now_p)
;
++now_p;
}
//local
if( 0x02 == *now_p ) //jump
ret[1] = ptr + get_3b(now_p + 1);
else
ret[1] = now_p;
}
else
{
ret[0] = "Unkown";
ret[1] = "";
}
return ret;
}




int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
switch(reason)
{

case DLL_PROCESS_ATTACH: //attach
{
Load();
}
break;

case DLL_PROCESS_DETACH: //detach
{
free(ptr);
}
}
return 1;
}
//---------------------------------------------------------------------------
在bds2007
void __fastcall TfrmMain::btnClick(TObject *Sender)
{
HANDLE hDll = LoadLibrary("FindIPDLL.dll");
if (hDll == NULL) {
mm->Lines->Add("Error:Load dll!" + Now());
FreeLibrary(hDll);
}


}
都是错误的!
怎么解决呢?
...全文
59 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
od4ys 2007-12-22
  • 打赏
  • 举报
回复
问题解决了,修改成EXE来执行就行了..

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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