ssleay32.dll
ssleay32.dll
I just find this great site, I'm really new in this dll injecting area.
I would like to control the SSL_read() and SSL_write() methods of this dll from delphi.
But each of these methods have an SSL typed parameter. I found this dll source, but I can't translate this c++ type to delphi.
int SSL_read(SSL *s,void *buf,int num)
int SSL_write(SSL *s,const void *buf,int num)
Anybody could help me how can I start?
In the first step I don't need this first parameter, but later I would like to call the original methods in the original dll with these parameters.
I would like to control the SSL_read() and SSL_write() methods of this dll from delphi.
But each of these methods have an SSL typed parameter. I found this dll source, but I can't translate this c++ type to delphi.
int SSL_read(SSL *s,void *buf,int num)
int SSL_write(SSL *s,const void *buf,int num)
Anybody could help me how can I start?
In the first step I don't need this first parameter, but later I would like to call the original methods in the original dll with these parameters.
Thanks. I try, but something wrong.madshi wrote:Just use "pointer".
This is my code, maybe you can help me:
Code: Select all
unit ssl_hack;
interface
uses Windows, madCodeHook;
const
ssleay32_dll : PChar = 'C:\Program Files\...\ssleay32.dll';
type
TSSL_read = function (ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
//TSSL_write = function (ssl: Pointer; const buf: PChar; num: Integer):Integer; cdecl;
TSSL_write = function (ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
var
SSL_readNextHook : TSSL_read;
SSL_writeNextHook : TSSL_write;
ssl_readlog : TSSL_read;
ssl_writelog : TSSL_write;
function SSL_readHookProc(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
function SSL_writeHookProc(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
procedure InstallHook;
procedure UninstallHook;
procedure SetLogFunctions(r:TSSL_read;w:TSSL_write);
implementation
procedure read_log(ssl: Pointer; buf: PChar; num: Integer);
begin
if assigned(ssl_writelog) then
ssl_writelog(ssl,buf,num);
end;
procedure write_log(ssl: Pointer; buf: PChar; num: Integer);
begin
if assigned(ssl_readlog) then
ssl_readlog(ssl,buf,num);
end;
procedure SetLogFunctions(r:TSSL_read;w:TSSL_write);
begin
ssl_readlog := r;
ssl_writelog := w;
end;
function SSL_readHookProc(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
begin
// Log
read_log(ssl,buf,num);
// Call original
result := SSL_readNextHook(ssl,buf,num);
end;
function SSL_writeHookProc(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
begin
// Log
write_log(ssl,buf,num);
// Call original
result := SSL_writeNextHook(ssl,buf,num);
end;
procedure InstallHook;
begin
HookAPI(ssleay32_dll, 'SSL_read', @SSL_readHookProc, @SSL_readNextHook);
HookAPI(ssleay32_dll, 'SSL_write', @SSL_writeHookProc, @SSL_writeNextHook);
end;
procedure UninstallHook;
begin
UnhookAPI(@SSL_readNextHook);
UnhookAPI(@SSL_writeNextHook);
end;
initialization
ssl_readlog := nil;
ssl_writelog := nil;
end.
Code: Select all
unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ssl_hack;
type
TfrmMain = class(TForm)
Hook: TButton;
memoLog: TMemo;
Unhook: TButton;
procedure HookClick(Sender: TObject);
procedure UnhookClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
function OnFormRead(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
function OnFormWrite(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
implementation
{$R *.dfm}
function OnFormRead(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
begin
frmMain.memoLog.Lines.Add('Read:');
frmMain.memoLog.Lines.Add(buf);
result := 0;
end;
function OnFormWrite(ssl: Pointer; buf: PChar; num: Integer):Integer; cdecl;
begin
frmMain.memoLog.Lines.Add('Write:');
frmMain.memoLog.Lines.Add(buf);
result := 0;
end;
procedure TfrmMain.HookClick(Sender: TObject);
begin
//
SetLogFunctions(OnFormRead,OnFormWrite);
InstallHook;
end;
procedure TfrmMain.UnhookClick(Sender: TObject);
begin
UninstallHook;
end;
end.
Thanks.madshi wrote:Replace this:
const
ssleay32_dll : PChar = 'C:\Program Files\...\ssleay32.dll';
With this:
const
ssleay32_dll : pchar = 'ssleay32.dll';
If that still doesn't work check out whether you named the APIs correctly when calling HookAPI. The API names are case sensitive.
But still doesn't work.
What do you mean "API names"?
(Or what document I need to read to understand this?)
Both call return with true. I already verify it.madshi wrote:What does HookAPI return? True or false?
But I found the problem:
After the call:
Code: Select all
HookAPI(ssleay32_dll, 'SSL_read', @SSL_readHookProc, @SSL_readNextHook);
A was afraid from this, because i would like to hook in other process.madshi wrote:In which process do you want to hook those APIs? In your own process or in another process? Your code only hooks those APIs in the current (= your own) process. Is that what you want? If not, please check out the madCodeHook demos to see who to hook APIs system wide.
So, in this case I need to create an inject dll inject it and I need IPC functions (what is not really undertandable for me yet) to communicate with my main program.
Thanks again for the help and congratulation for this great collection.