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 890795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:47:25+00:00 2026-05-15T13:47:25+00:00

I have injected my DLL into a target application where I’ve hooked few WINAPI-functions

  • 0

I have injected my DLL into a target application where I’ve hooked few WINAPI-functions
as well. One of them is DrawTextExW. I’m trying to replace all ‘l’ letters to ‘!’ before
it prints it out. My solution works fine for a few seconds, but then the target application crashes. I really don’t understand why.

Here’s the function:

Edit – Working solution:

int WINAPI DetouredDrawTextExW(__in    HDC hdc,
                               __inout LPWSTR lpchText,
                               __in    int cchText,
                               __inout LPRECT lprc,
                               __in    UINT dwDTFormat,
                               __in    LPDRAWTEXTPARAMS lpDTParams)
{
    std::wstring s_wc(lpchText, cchText);

    std::replace(s_wc.begin(), s_wc.end(), L'l', L'!');

    return ::DrawTextExW(hdc, const_cast<wchar_t *>(s_wc.c_str()), 
        s_wc.length(), lprc, dwDTFormat, lpDTParams);
}

So, can somebody point it out to me what I’m doing wrong?

  • 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-05-15T13:47:26+00:00Added an answer on May 15, 2026 at 1:47 pm

    I see that you ignore cchText, could you be receiving an non-NULL-terminated string with a positive value for cchText, resulting in reading past the end of the string into invalid memory? That error would present as a Win32 exception in the constructor of s_wc, though.

    Also, you aren’t checking for DT_MODIFYSTRING in the dwDTFormat parameter. If that flag is present, then ::DrawTextExW() could be overwriting invalid memory. That would present as a Win32 exception in ::DrawTextExW() or perhaps as a C++ exception in the s_wc destructor.

    edit

    Here’s uncompiled, untested code that I believe obeys the contract of ::DrawTextExW()

    int WINAPI DetouredDrawTextExW(__in    HDC hdc,
                                   __inout LPWSTR lpchText,
                                   __in    int cchText,
                                   __inout LPRECT lprc,
                                   __in    UINT dwDTFormat,
                                   __in    LPDRAWTEXTPARAMS lpDTParams)
    {
        std::vector<wchar_t> v_wc;
        int strSize = cchText == -1 ? wcslen(lpchText) : cchText;
        v_wc.resize(strSize + 4);
        std::copy(lpchText, lpchText + strSize, &v_wc.front());
        std::replace(v_wc.begin(), v_wc.end() - 4, L'l', L'!');
    
        int result = ::DrawTextExW(hdc, &v_wc.front(), 
            strSize, lprc, dwDTFormat, lpDTParams);
        if (dwDTFormat & DT_MODIFYSTRING)
        {
          std::copy(&v_wc.front(), &v_wc.front() + v_wc.size(), lpchText);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.