

Departure wrote:what do you mean anyone daring to subclass??
All the paltalk programs on here are made because of subclassing down to the richedit box, thats what every single pal app is based on (subclassing)

BOOL Inject(HWND hTarget, LPTSTR dll)
{
DWORD procID;
GetWindowThreadProcessId(hTarget, &procID);
// Find the address of the LoadLibrary api
HMODULE hLocKernel32 = GetModuleHandle("Kernel32");
FARPROC hLocLoadLibrary = GetProcAddress(hLocKernel32, "LoadLibraryA");
//Adjust token privileges to open system processes
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, 0, &tkp, sizeof(tkp), NULL, NULL);
}
//Open the process with all access
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
//Allocate memory to hold the path to the dll File in the process's memory
dll += '\0'; //Add the null-terminator just in case
LPVOID hRemoteMem = VirtualAllocEx(hProc, NULL, strlen(dll)+1, MEM_COMMIT, PAGE_READWRITE);
//Write the path to the Dll File in the location just created
DWORD numBytesWritten;
WriteProcessMemory(hProc, hRemoteMem, dll, strlen(dll)+1, &numBytesWritten);
//Create a remote thread that starts begins at the LoadLibrary function and is passed are memory pointer
HANDLE hRemoteThread = CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)hLocLoadLibrary, hRemoteMem, 0, NULL);
//Wait for the thread to finish
BOOL res = FALSE;
if (hRemoteThread)
res = (BOOL)WaitForSingleObject(hRemoteThread, MAXWAIT) != WAIT_TIMEOUT;
else
{
VirtualFreeEx(hProc, hRemoteMem, strlen(dll)+1, MEM_RELEASE);
MessageBox(NULL, "Failed to create remote thread!", "", MB_OK);
}
//Free the memory created on the other process
VirtualFreeEx(hProc, hRemoteMem, strlen(dll)+1, MEM_RELEASE);
//Release the handle to the other process
CloseHandle(hProc);
return res;
}
DWORD MyCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
// cb is the number of bytes you need to read
// pcb needs to be set to the number of bytes you actually read
// pbBuff is a pointer to the buffer that contains the RTF data
// dwCookie is the same value that you passed with the SendMessage call
// If you read all the data, use *pcb = cb
// If you read, say 10 bytes, use *pcb = 10
return 0; // Return 0 to indicate success, non-zero for error
}
EDITSTREAM es;
es.dwCookie = NULL; // This is an unsigned long value that is sent to callback, basically just app-defined data
es.dwError = NULL; // This contains the last error that occured, 0 means success
es.pfnCallback = (EDITSTREAMCALLBACK)MyCallback;
SendMessage(hTargetRichEditBox, EM_STREAMOUT, SF_RTF, (LPARAM)&es);

HMODULE hDll = ::LoadLibrary("testhookptwin.dll");
FnPtrTInstallDLL FnPtr = (FnPtrTInstallDLL)::GetProcAddress(hDll,"InstallCBThook");
if(FnPtr)
(FnPtr)(dwID,rich20,parent);
::FreeLibrary(hDll);



my code work fine but I want to understand your method
BOOL Inject(HWND hTarget, LPTSTR dll)
hTarget is the the parent window or the child and your const MAXWAIT is how many miliseconds.
and how i can call my function in my dll like my code on top after de dll is injected
thanks in advance



Return to Visual Basic Programming
Users browsing this forum: No registered users and 0 guests