winsock hooking
hi
hi
now i am very happy for finding the solution by myself.
i am also surprised by solution.it's so simple.i understand now you wouldn't give me it.
i needed just to chnage a bit of code. thank you madshi for that.
now i am working with the size adjustement.i try to change an string with another one which have an different lenght.
did you think is it possible ?
i have tried one but i receive the following error.
thank you
@+
now i am very happy for finding the solution by myself.
i am also surprised by solution.it's so simple.i understand now you wouldn't give me it.
i needed just to chnage a bit of code. thank you madshi for that.
now i am working with the size adjustement.i try to change an string with another one which have an different lenght.
did you think is it possible ?
i have tried one but i receive the following error.
Code: Select all
invalid pointer operation
@+
hi
hi
here is my code
here is my code
Code: Select all
function sendHookProc(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
var
i1 : integer;
newdata : pchar;
begin
result:=0;
i1 := 0;
while true do begin
i1 := PosPchar('helo', @Buf, 4, result, true, i1);
if i1 >= 0 then
begin
GETMEM(newdata,len*2);
copymemory(newdata,@buf,len*2);
newdata :=pchar(newdata+#0);
Move(pchar(string('realcool'))^, (pchar(@newdata) + i1)^, 8);
zeromemory(@buf,len);
copymemory(@buf,pointer(newdata),length(newdata));
freemem(newdata,len*2)
end
else
break;
end;
Result := sendNextHook(s, Buf, len, flags);
end;
YOu do not need to use
pointer(newdata)
because NewData is alread a Pointer. And do not need to do this
pchar(@newdata)
because NewData is reald a Pointer to a char (PChar). And this is not correct:
length(newdata)
You should use SizeOf instrad of Length, in this case, because its not exatly a String...
I hope I am helping you to find the right way
pointer(newdata)
because NewData is alread a Pointer. And do not need to do this
pchar(@newdata)
because NewData is reald a Pointer to a char (PChar). And this is not correct:
length(newdata)
You should use SizeOf instrad of Length, in this case, because its not exatly a String...
I hope I am helping you to find the right way
hi
hi
here is my code after doing change mentioned by nildo
but the error is not solved.
thank you
here is my code after doing change mentioned by nildo
but the error is not solved.
Code: Select all
function sendHookProc(s: TSocket; var Buf; len, flags: Integer): Integer; stdcall;
var
i1 : integer;
newdata : pchar;
begin
result:=0;
i1 := 0;
while true do begin
i1 := PosPchar('helo', @Buf, 4, result, true, i1);
if i1 >= 0 then
begin
GETMEM(newdata,len*2);
copymemory(newdata,@buf,len*2);
Move(pchar(string('realcool'))^, (pchar(@newdata) + i1)^, 8);
zeromemory(@buf,len);
copymemory(@buf,newdata,sizeof(newdata));
freemem(newdata,len*2)
end
else
break;
end;
Result := sendNextHook(s, Buf, len, flags);
end;
thank you
Re: hi
Try this code, it worked for me
But look, I've used "Buf: Pointer" instead of "var Buf". And on this case, I do not write into the original Buffer, I just replace the Pointer to a Pointer that is pointing at NewData, so If you FreeMem of NewData, it won't work. Its just for you see it "working". Now that you get it working, do it in a way that you do not need to do this:
Buf := newdata;
Do in a way that you copy one buffer to another, but then you need to realloc the Buf. I am with no time for that now, try it!
Code: Select all
function SendCallback( s: Integer; Buf: Pointer; len, flags: Integer): Integer; stdcall;
var
i1 : integer;
newdata : pchar;
begin
Result := 0;
i1 := 0;
while true do
begin
i1 := PosPchar('halo', Buf, 4, len, true, i1);
if i1 >= 0 then
begin
newdata := GetMemory( 8 );
Move(pchar(string('realcool'))^, (PChar(newdata) + i1)^, 8);
Buf := newdata;
len := 8;
end
else
break;
end;
Result := sendNextHook(s, Buf, len, flags);
end;
Buf := newdata;
Do in a way that you copy one buffer to another, but then you need to realloc the Buf. I am with no time for that now, try it!
hi
hi
thank you man for the code and help
the code doesn't work.
any error is occured when i inject it but all the data that i receive are changed and become unreadable even the halo string.
did you know why ?
are you tried the code ?
explication or help are welcome
@+
thank you man for the code and help
the code doesn't work.
any error is occured when i inject it but all the data that i receive are changed and become unreadable even the halo string.
did you know why ?
are you tried the code ?
explication or help are welcome
@+
Here's a different approach using dynamic strings:
Code: Select all
function SendCallback( s: Integer; Buf: Pointer; len, flags: Integer): Integer; stdcall;
var s1 : string;
begin
SetString(s1, Buf, len);
ReplaceStr(s1, 'hello', 'reallycool');
result := sendNextHook(s, pointer(s1), length(s1), flags);
end;