I have a C++ DLL that works I would like to convert to a PB DLL.
The function works fine in the C btw.
What it does is hooks/injects (dunno which this really is considered)
a function that is pointed to a functions address retrieved from PE Explorer.
For instance: 74B4FF is the address the function we're replacing in the outside
application. The function declares an identical version but directs the address
of this new function to 74B4FF so when the original program uses that function,
it calls our custom version instead.
Orig function example: (in C++)
Our custom function: (in C++)
The two functions addresses are swapped using: (in C++)
The next is the handling of our custom function:
And here is where it gets initiated in the DLL
How can I get this to do the same in PB? Here's how I interpret the above:
And it doesn't work (surprise!) - Any help would be greatly appreciated...
Thanks!!
------------------
[This message has been edited by Joey Burgett (edited August 24, 2005).]
The function works fine in the C btw.
What it does is hooks/injects (dunno which this really is considered)
a function that is pointed to a functions address retrieved from PE Explorer.
For instance: 74B4FF is the address the function we're replacing in the outside
application. The function declares an identical version but directs the address
of this new function to 74B4FF so when the original program uses that function,
it calls our custom version instead.
Orig function example: (in C++)
Code:
int __stdcall replacement_recvfrom(SOCKET s,char *buf,int len,int flags,struct sockaddr *from,int *fromlen)
Code:
typedef int (__stdcall *recvfunc)(SOCKET s,char *buf,int len,int flags,struct sockaddr *from,int *fromlen); recvfunc oldproc;
Code:
void replaceref(long* loc, long what) { if(IsBadWritePtr(loc, 4)) { DWORD dwOld, dw; VirtualProtect(loc, 4, PAGE_EXECUTE_READWRITE, &dwOld); oldproc=(recvfunc)(*loc); *(loc)=what; VirtualProtect(loc, 4, dwOld, &dw); }else { *(loc)=what; } }
Code:
int __stdcall replacement_recvfrom(SOCKET s,char *buf,int len,int flags,struct sockaddr *from,int *fromlen) { //We call the original function as we're only interested in the //parameter values the original function receives. int res=oldproc(s,buf,len,flags,from,fromlen); if (res>0) { cout << "Recieved info (%i"<<len<<" bytes)."<<endl; return(res); } }
Code:
case DLL_PROCESS_ATTACH: //0x1234FF example base function address to replace id=0; AllocConsole(); replaceref((long*)0x1234FF,(long)replacement_recvfrom);
Code:
SUB ReplaceRef (BYREF mLoc AS LONG POINTER, BYREF what AS LONG POINTER) DIM dwOld AS LONG PTR DIM dw AS LONG PTR DIM oldproc AS LONG PTR VirtualProtect(mLoc,4,%PAGE_EXECUTE_READWRITE,dwOld) oldproc=mloc& ' Since we want the ptr we do reference?? mloc=what& msgbox str$(mloc&) & " " & str$(what&) VirtualProtect(mloc&, 4, dwOld, dw) END SUB FUNCTION replacement_recvfrom(BYVAL s AS DWORD,BYVAL buf AS BYTE, BYVAL buflen AS LONG, BYVAL flags AS LONG, saFrom AS SOCKADDR, fromlen AS LONG) AS LONG res=recvfrom(s,buf,buflen,flags,safrom,fromlen) MSGBOX STR$(buflen) END FUNCTION FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH ghInstance = hInstance replaceref(&H1234FF,CODEPTR(replacement_recvfrom)) END SELECT END FUNCTION
Thanks!!
------------------
[This message has been edited by Joey Burgett (edited August 24, 2005).]
Comment