Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8123283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:07:53+00:00 2026-06-06T06:07:53+00:00

I’ve injected a DLL into a program to implement a chat UI over the

  • 0

I’ve injected a DLL into a program to implement a chat UI over the applications main window. I figured I can get the applications main window handle, then get it’s DC, and draw onto it. The window has a predictable title, which means I can use FindWindow to get the handle. The only problem is, the DLL is injected when the process starts. At that time, the window hasn’t been created. Which means FindWindow finds nothing!

What are some solutions to this? Could I create a thread in the DLL and sleep for a while until I know the window is created? This seems very unstable so I’d rather not do it.

What I tried to do was use SetWindowsHookEx in the DLL to hook the global WndProc. I could scan the messages until I find one from my window (which means it was created). Then I could save the handle and go on with my program. I’m not too worried about there being multiple windows with the same name at the time. The only problem is that my hook never gets called.

I create the hook like this:

m_hWndProcHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)WndProc, m_hModule, 0);
if(!m_hWndProcHook)
{
    oss << "Failed to set wndproc hook. Error code: " << GetLastError();
    Log(oss.str().c_str());
    return false;
} 

Which returns a valid hook. The WndProc look like this:

LRESULT CALLBACK CChatLibrary::WndProc(int code, WPARAM wParam, LPARAM lParam)
{
    CWPSTRUCT* pData;
    ostringstream oss;
    char wndName[256];

    gChatLib->Log("WNDPROC");

    if(code < 0)
        return CallNextHookEx(gChatLib->GetWndProcHookHandle(), code, wParam, lParam);
    else
    {
        //Get the data for the wndproc
        pData = (CWPSTRUCT*)lParam;

        //Log the message
        GetWindowText(pData->hwnd, wndName, 256);
        oss << "Message from window \"" << wndName << "\"";
        gChatLib->Log(oss.str().c_str());

        return CallNextHookEx(gChatLib->GetWndProcHookHandle(), code, wParam, lParam);
    }
}

But no “WNDPROC” messages are logged into my log file… Earlier, I had a MessageBox instead of a log to see if it worked, which turned out to be a terrible idea. All the programs froze because they were waiting for me to click “OK”, and I had to do a hard reset… When I turned my computer back on and replaced the MessageBox with a log command, it didn’t work. I know my log works, though, because it works everywhere else. I’m extremely confused with whats happening with this.

Are there any other methods of obtaining the main window (preferably when it is created)? Or is my hook method good, but just executed wrong? Thank you for any feedback.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:07:54+00:00Added an answer on June 6, 2026 at 6:07 am

    You can always inject the DLL when application has already started. It’s quite complicated nowadays because of ASLR in Windows Vista/7, but not impossible. You would have to write a short application which would inject selected DLL into the process with given PID. Here is what should be done in order to inject DLL into the running process:

    Write a shellcode which would find address of the kernel32.dll library. Here is my old code in NASM:

    [BITS 32]
    
    _main:
        xor     eax,    eax
        mov     esi,    [FS:eax+0x30]   ; ESI points at PEB
        mov     esi,    [esi+0x0C]  ; ESI points at PEB->Ldr
        mov     esi,    [esi+0x1C]  ; ESI points at PEB->Ldr.InInitOrder
        mov     edx,    -1          ; EDX is now the current letter pointer
    
    check_dll:
        mov     ebp,    [esi+0x08]  ; EBP points at base address InInitOrder[i]
        mov     edi,    [esi+0x20]  ; EDI points at InInitOrder[X] name
        mov     esi,    [esi]       ; ESI points at flink
        mov     edx,    -1      ; set letter pointer at InInitOrder name
        mov     ebx,    0       ; set pattern letter pointer to null
    
    check_small_name:
        inc     edx             ; go to the next letter in InInitOrder name
        cmp     ebx,    0x7     ; check if we have checked all letters
        je      library_found       ; if so and no error kernel32.dll found
        mov     al, BYTE[edi+edx]   ; load byte to EAX from InInitOrder name
        cmp     al,     0x0 ; check if unicode complement
        je      check_small_name    ; ignore if so
        jmp     s_kernel32
    
    back1:
        pop     ecx
        cmp     BYTE[ecx+ebx],  al  ; compare characters
        jne     check_big_name      ; if not equal check upper size
        inc     ebx         ; if equal then go to the next letter in pattern
        jmp     check_small_name    ; loop  
    
    check_big_name:
        jmp     b_kernel32
    
    back2:
        pop     ecx
        cmp     BYTE[ecx+ebx],  al  ; check characters
        jne     check_dll       ; if not equal then go to the next module
        inc     ebx         ; if equal go increment the pattern pointer
        jmp     check_small_name    ; loop
    
    library_found:
        mov     eax,    ebp         ; move kernel32 base address into ECX
    
    loop:
        jmp loop    
    
    s_kernel32:
        call    back1
        db      "kernel32",10,0 
    
    b_kernel32:
        call    back2
        db      "KERNEL32",10,0
    
    1. Load compiled shellcode into memory from file.
    2. Attach to the target process as a debugger. Stop all threads in application. Allocate some memory and set ‘read, write, execute’ permissions and inject shellcode there.
    3. Get main thread handle. Open thread, create thread context backup and then set new context with EIP register modified (set to the allocated memory – shellcode – address).
    4. Resume threads for some time (e.g. 5 s). Make sure that the process was activated and our shellcode had a chance to execute.
    5. Again attach as a debugger to the target process. Read the EAX register which should now store kernel32.dll base address in target process (thanks to the ASLR it might be not the same as in your injector process).
    6. Check the offset of LoadLibraryA function in kernel32.dll from your process.
    7. The offset should be the same in target process so you have to add remote kernel32.dll base address to the offset in order to compute base address of LoadLibraryA function in the remote process.
    8. Call CreateRemoteThread function giving the computed address of LoadLibraryA as a function to call and DLL path as it’s parameter.

    I had to figure this all on my own some time ago (I couldn’t find any description), but recently I found something similiar: http://syprog.blogspot.com/2012/05/createremotethread-bypass-windows.html

    Happy hacking!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.