Because I got no replies, I started to at alternatives, specifically in winsock. I've successfully hooked the gethostbyname() but i now need to hook getaddrinfo(). I've got my hook working and my IPC notification but i don't seem to be able to touch the return structure that holds the data about the intended / target IP address. Every time I try to access the structure, the target process crashes with an Access Violation.
Does anyone have any suggestions or examples - I'm in desperate need of some help. I'm running 2.5.7.1 beta, and Delphi 7 Enterprise. My code looks like this:
Code: Select all
function WSGetAddrInfoCallback(const nodename : PAnsiChar; const servname : PAnsiChar; const hints : PAddrInfo; var res : PAddrInfo) : Integer; stdcall;
var
iIPCRtn : Integer;
szPacket : string;
iIPAddr : Cardinal;
AI : PAddrInfo;
begin
if (nodename <> nil) then
begin
result := WSGetAddrInfoNxt(nodename, servname, hints, res);
if ((result <> 0)) then
begin
iIPCRtn := 0;
AI := res;
if ((AI^.ai_family = PF_INET) or (AI^.ai_family = PF_INET6)) then
begin
move(AI^.ai_addr.sin_addr.S_addr, iIPAddr, sizeof(iIPAddr));
szPacket := string(IntToStr(QUERY_URL_EXEC_ID)+ #01 +
IntToStr(ACTION_QUERY_) + #01 +
IntToStr(API_GET_ADDR_INFO) + #01 +
IntToStr(GetCurrentProcessId())+ #01 +
string(nodename) + #01 +
IntToStr(iIPAddr) + #0D);
if (not (SendIpcMessage(IPC_QUEUE_CONTROL_NAME, PChar
(szPacket), Length(szPacket), @iIPCRtn,
sizeof(iIPCRtn), SEND_IPC_TIMEOUT))
or (iIPCRtn = 0)) then
begin;
//freeaddrinfo(res);
SetLastError(ERROR_ACCESS_DENIED);
WSASetLastError(WSAEACCES);
result := WSAEACCES;
end;
end;
end;
end
else
result := WSGetAddrInfoNxt(nodename, servname, hints, res)
end;
WSGetAddrInfoNxt : function(const nodename : PAnsiChar;
const servname : PAnsiChar;
const hints : PAddrInfo;
var res : PAddrInfo
) : Integer; stdcall;
HookAPI('ws2_32.dll', 'getaddrinfo', @WSGetAddrInfoCallback, @WSGetAddrInfoNxt);