Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need some guidance with this code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
denismu321
Newbie cheater
Reputation: 0

Joined: 24 Dec 2018
Posts: 20

PostPosted: Wed Jun 02, 2021 1:38 pm    Post subject: Need some guidance with this code Reply with quote

Hi there , I could need some guidance with this code of mine.

I am injecting a dll into a process and allocate a console.
Now I want to print some specifics of the target process.

Here is the code :
Code:

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    TCHAR buff[256];
    int length = ::GetWindowTextLengthA(hwnd);
    ::GetWindowTextA(hwnd, (LPSTR)buff, length);
    int nCtrlID = ::GetDlgCtrlID(hwnd);
    printf("ID is %d\n", nCtrlID);
    return TRUE;
}


void OnEnumerateChildCtrls(HWND window)
{
    EnumChildWindows(window, EnumWindowsProc, 0);
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:

       
        GetStdHandle(STD_OUTPUT_HANDLE);
        AllocConsole();
        fprintf(stdout, "Test!");
        fflush(stdout);
        HWND hwnd = (HWND)0x00B407E2;
        const char* szBuf;
        LRESULT res;
        char buff[255];

        WNDENUMPROC wndenum;
        int returnPointer{};
        SendMessageTimeoutA(hwnd, WM_GETTEXT, NULL, NULL, SMTO_NORMAL, 10000, (PDWORD_PTR)returnPointer);
        int length = GetWindowTextLengthA(hwnd);
        GetWindowTextA(hwnd, (LPSTR)buff, length);
        printf("Copied %d characters.  Contents: %s\n", length, buff);
        //printf("buffer contains %s\n", buff);*/


        OnEnumerateChildCtrls(hwnd);

        break;

   
   
    }
    return TRUE;
}




All it gives me is a black console with this caption, "Valve.Steam.Client"
Perhaps there is some advice ?

Thank you in advance .
Back to top
View user's profile Send private message Send e-mail
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Wed Jun 02, 2021 9:04 pm    Post subject: Reply with quote

You need to reroute the standard input handles to the console. The process may have altered them to a different output or are swallowing them in general. You may also need to call AttachConsole afterward to attach it to the process properly depending on any counter-measures or alterations they may be doing.

The stream related things you need to reroute would be:

"CONIN$" (read) -> stdin - Used for input from the user into the console.
"CONOUT$" (write) -> stderr - Used for error related output.
"CONOUT$" (write) -> stdout - Used for standard output.

There are multiple ways to redirect/set these such as using freopen/freopen_s or the direct 'std' stream objects.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
denismu321
Newbie cheater
Reputation: 0

Joined: 24 Dec 2018
Posts: 20

PostPosted: Thu Jun 03, 2021 6:49 am    Post subject: Thanks for replying so fast Reply with quote

Hi ,thank you for reaching out to me so fast.

Could you provide some little code to help grasp
the concept ?

I'd be rather thankful for that.
Back to top
View user's profile Send private message Send e-mail
denismu321
Newbie cheater
Reputation: 0

Joined: 24 Dec 2018
Posts: 20

PostPosted: Fri Jun 04, 2021 4:12 pm    Post subject: Hi again Reply with quote

I found out what function you meant atom0s.
It was freopen("CONOUT$","w",stdout);

Now I have another problem.
Do you know of a simple way to hook WS32_send functions.

The DLL Injector I wrote works (most of the time).
But I cannot hook WS32_send ,and I am doing this with detours
library on Visual Studio c++.

Any guidance would be appreciated.
Back to top
View user's profile Send private message Send e-mail
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Tue Jun 08, 2021 2:52 pm    Post subject: Reply with quote

At this point it's pretty clear you're just piecing stuff you find around the web together. I'm not going to hand you code that you aren't going to understand, there's no point.

I'd suggest you take the time to learn what you are doing. There are thousands of libraries, tutorials, etc. on hooking things with C++, and so many different copy-paste examples of hooking the exact thing you are requesting.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
denismu321
Newbie cheater
Reputation: 0

Joined: 24 Dec 2018
Posts: 20

PostPosted: Tue Jun 08, 2021 11:39 pm    Post subject: Hi Reply with quote

Sorry ,I did not request anything.
Even if it may have seemed so.
I just asked for some advice.

I am going to try my luck on my own, like you suggested.

Thanks for replying.

Kind regards,

Denis.
Back to top
View user's profile Send private message Send e-mail
HotHeap
!BEWARE! Deletes post on answer
Ban
Reputation: 2

Joined: 06 Oct 2018
Posts: 4

PostPosted: Tue Jun 22, 2021 9:08 pm    Post subject: Reply with quote

https://github.com/67-6f-64/WinSockHook
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites