All pastes #279781 Raw Edit

Gopneg

public text v1 · immutable
·published 2006-12-15 09:36 UTC
rendered paste body
type TFunctionInfo = record
       FunctionName: PChar;
       hLibModule: HMODULE;
       Parametrs: array of DWORD;
     end;

function InterceptFunctions(FunctionInfo: TFunctionInfo): DWORD; stdcall;
var pFunction: Pointer;
    Size: DWORD;
begin
  pFunction := GetProcAddress(FunctionInfo.hLibModule, FunctionInfo.FunctionName);
  Size := Length(FunctionInfo.Parametrs);
  asm
    mov       eax, Size
    or        eax, eax
    jz        @@2
    mov       edx, FunctionInfo.Parametrs
    @@1:
    dec       eax
    push      dword ptr [edx+eax*4]
    jnz       @@1
    @@2:
    call      pFunction
    mov       Result, eax
  end;
  pFunction := nil;
end;

function sendtoInter( const s: TSocket; var Buf; const len, flags: Integer;
                      const addrto: PSockAddr;
                      const tolen: Integer ): Integer; stdcall;
var FunctionInfo: TFunctionInfo;
    b: array of byte;
begin
  SetLength(b, len);
  CopyMemory(b, @Buf, len);
  FunctionInfo.hLibModule := hLibModulews2_32;
  FunctionInfo.FunctionName := 'sendto';
  SetLength(FunctionInfo.Parametrs, 6);
  FunctionInfo.Parametrs[5] := DWORD(s);
  FunctionInfo.Parametrs[4] := DWORD(Buf);
  FunctionInfo.Parametrs[3] := DWORD(len);
  FunctionInfo.Parametrs[2] := DWORD(flags);
  FunctionInfo.Parametrs[1] := DWORD(@addrto);
  FunctionInfo.Parametrs[0] := DWORD(tolen);

  Result := Integer(InterceptFunctions(FunctionInfo));
  Log(['sendtoInter: ', s, ' ', BufToHex(b), ' ', len, ' ', flags, ' ',
       addrto^.sin_family, ' ',
       addrto^.sin_port, ' ',
       dword(addrto^.sin_addr), ' ',
       addrto^.sin_zero, ' ',
       tolen, ' ', Result, ' ', SysErrorMessage(WSAGetLastError), CRLF], LogFile);

  FunctionInfo.FunctionName := nil;
  FunctionInfo.Parametrs := nil;
end;