Hi,
These are the functions I used to send and read from the console.
Sending [UTF-16]:
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);
HWND MohaaConsole = FindWindowW(0, L"MOHAA Console"); //Find the console windows
EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)"say This is a test cmd !");//loop through it's children.
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //Find the text editor for input.
{
wchar_t className[1024];
GetClassNameW(hwnd,className,sizeof(className));
if (wcscmp(className , L"Edit")) //If it's not a text editor we don't need it.
{
return true;
}
if (ES_READONLY & GetWindowLongW(hwnd,GWL_STYLE))
{
return true;
}
//At this point we found a text editor that isn't readonly.
//Which is what we're searching for.
SendMessageW(hwnd,WM_SETTEXT,0,lParam);//Send the command.
SendMessageW(hwnd,WM_CHAR,VK_RETURN,0);//This is like pressing enter after you type something in the window.
return false;
}
Sending [ANSI]:
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);
HWND MohaaConsole = FindWindowA(0, "MOHAA Console"); //Find the console windows
EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)"say This is a test cmd !");//loop through it's children.
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //Find the text editor for input.
{
char className[1024];
GetClassNameA(hwnd,className,sizeof(className));
if (strcmp(className , "Edit")) //If it's not a text editor we don't need it.
{
return true;
}
if (ES_READONLY & GetWindowLongA(hwnd,GWL_STYLE))
{
return true;
}
//At this point we found a text editor that isn't readonly.
//Which is what we're searching for.
SendMessageA(hwnd,WM_SETTEXT,0,lParam); //Send the command.
SendMessageA(hwnd,WM_CHAR,VK_RETURN,0); //This is like pressing enter after you type something in the window.
return false;
}
Reading [UTF-16]:
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);
wchar_t buff[8192];
HWND MohaaConsole = FindWindowW(0, L"MOHAA Console"); //Find the console windows
EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)buff);//loop through it's children.
MessageBoxW(NULL , buff , NULL , NULL);
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //find the text editor and read from it.
{
wchar_t className[1024];
GetClassNameW(hwnd,className,1024);
if (wcscmp(className , L"Edit"))//If it's not a text editor we don't need it.
{
return true;
}
if (ES_READONLY & GetWindowLongW(hwnd,GWL_STYLE)) //If it's read only then it's our guy.
{
SendMessageW(hwnd,WM_GETTEXT,8192,lParam);
return false;
}
return true;
}
Reading [ANSI]:
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam);
char buff[8192];
HWND MohaaConsole = FindWindowA(0, "MOHAA Console"); //Find the console windows
EnumChildWindows(MohaaConsole, EnumChildSendCommandProc, (LPARAM)buff);//loop through it's children.
MessageBoxA(NULL , buff , NULL , NULL);
BOOL CALLBACK EnumChildSendCommandProc(HWND hwnd,LPARAM lParam) //find the text editor and read from it.
{
char className[1024];
GetClassNameA(hwnd,className,1024);
if (strcmp(className , "Edit"))//If it's not a text editor we don't need it.
{
return true;
}
if (ES_READONLY & GetWindowLongA(hwnd,GWL_STYLE)) //If it's read only then it's our guy.
{
SendMessageA(hwnd,WM_GETTEXT,8192,lParam);
return false;
}
return true;
}
The main concept is to Find the Console of MOHAA With FindWindow().
Next loop through it's children (buttons , text editors, etc) and find the text editor that is involved for input/output.
Then send a message to read from/write to that text editor.
This works with MOHAA , BT , SH , and all the server versions.Just replace the "MOHAA Console" with "MOHAAS Console" or "MOHAAB Console".
Hope it helps .