News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

message posting from app1 to app2 . see the src.

Started by marco1974, March 01, 2005, 10:44:38 PM

Previous topic - Next topic

marco1974

Hello, 


*********************  basicly i want this:
=-run the app1.exe that controls for example Notepad and post a WM_QUIT to notepad.-=


[continued] ;-)


I am working on a WAY to send a message from my FIRST window to a OTHER aplications MAIN window.
For example i was trying notedpad BTW the CLASSNAME=db 'Notepad',0

I am planning to build some kind of intelligent tool that can START and STOP various stuff
in Other aplications. I am just lazy and don`t want to work in 4 apps when i can AUTOMATE tasks.

If this could work REALLY interesting things could be made; combine OUTPUT/INPUT from different
applications that are running by posting messages to them.
see my code what i mean.

;################## clean.asm code (main file!!) ###################
Quote

    .486
    .model flat, stdcall
    option casemap :none   ; case sensitive

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD



    include c:\masm32\include\windows.inc
    include c:\masm32\include\masm32.inc
    include c:\masm32\include\kernel32.inc
    include c:\masm32\include\user32.inc
    include c:\masm32\include\gdi32.inc

    includelib c:\masm32\lib\masm32.lib
    includelib c:\masm32\lib\kernel32.lib
    includelib c:\masm32\lib\gdi32.lib
    includelib c:\masm32\lib\user32.lib

.data
;################# STRING DATA SECTION ###############
string  db  "                ",0     ;256 dup (?)
string2 db  "some str",0
;------------01234567-------+1 0
strL    dword ?

;#external functions
;------------------------------------
strcpy proto
strcat proto
strlen proto


;#---------------#debugging:
error   db 'error CMP failed!',0
dword_safe_cmp dword 10d; value unknown
error_handle db 'error, HWND handle== NULL !!!',0
;-----------01234567890123456 =16+0  =17




;############### NEEDED DATA #############
char WPARAM 20h
space db "               ",0


;############# coords for text font
xcoord dword 10d;  sword,dword
ycoord dword 10d;


;###################----------------WINDOW HACKS:
;window_found_handle:HWND  ?
find_ClassName_hacked db "AVG Monitor",0
;find_WindowName  db NULL ;  ////"               ;//Edit",0



;############### WINDOWS DATA ##############
ClassName db "window1",0
AppName  db "Our 2nth Window",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?

    .code



start:


   invoke GetModuleHandle, NULL
   mov    hInstance,eax
   invoke GetCommandLine
   invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
   invoke ExitProcess,eax




WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND
       
   mov   wc.cbSize,SIZEOF WNDCLASSEX
   mov   wc.style, CS_HREDRAW or CS_VREDRAW
   mov   wc.lpfnWndProc, OFFSET WndProc
   mov   wc.cbClsExtra,NULL
   mov   wc.cbWndExtra,NULL
   push  hInst
   pop   wc.hInstance
   mov   wc.hbrBackground,COLOR_WINDOW+1
   mov   wc.lpszMenuName,NULL
   mov   wc.lpszClassName,OFFSET ClassName
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov   wc.hIcon,eax
   mov   wc.hIconSm,eax
   invoke LoadCursor,NULL,IDC_ARROW
   mov   wc.hCursor,eax
   invoke RegisterClassEx, addr wc
   INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
   mov   hwnd,eax



   INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
   INVOKE UpdateWindow, hwnd
   .WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
   .ENDW
   mov     eax,msg.wParam
   ret
WinMain endp




WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
   LOCAL hdc:HDC
   LOCAL ps:PAINTSTRUCT



        .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
   .ELSEIF uMsg==WM_CHAR
      push wParam
      pop  char
      invoke InvalidateRect, hWnd,NULL,TRUE
        .ELSEIF uMsg==WM_QUIT
         invoke PostQuitMessage,0


   .ELSEIF uMsg==WM_PAINT
      invoke BeginPaint,hWnd, ADDR ps
      mov    hdc,eax
             invoke TextOut,hdc,0,0,ADDR char,1
       
; test for hkey

cmp char,'s'
je s_key
cmp char,'h'
je h_key

jmp nokey

; key found display message
;invoke MessageBoxA ,hWnd,string,string2,MB_OK

;############# string TEST ##############
s_key:

;push strcpy
push offset string2
push OFFSET string
call strcpy

push offset error;


;-----------------test condition of value
;xor eax,eax
mov eax,dword ptr ycoord
cmp eax,dword ptr dword_safe_cmp


;----------jump if test_ok ==10 decimal
je test_ok


;--------error condition :
push offset error
call strlen
;mov  strL,eax
invoke TextOut,hdc,20,20,ADDR error,eax ;strL  ;error condition
jmp error_continue; error found so BAIL out


;###########-------test ok
test_ok:  ;hmm ycoord=10
push offset string
call strlen
;mov  strL,eax

invoke TextOut,hdc, dword ptr xcoord,dword ptr ycoord,ADDR string,eax ;strL
;mov al,90d;

add dword_safe_cmp,1d
add ycoord,1d
inc ecx   ;add 1 each time
error_continue:



;pop string
;pop string2


;############# string TEST ##############





jmp nokey;  also exit!!!

;#--------FINDWINDOW HACK

h_key:
;xor eax,eax  ;new
mov esi,offset find_ClassName_hacked
call do_it;

do_it:

push esi  ;esi ;eax has handle!!!
push 0
call FindWindowA
test eax,eax

jz error_hwnd

push 0
push 0
push 12h ;WM_QUIT ;12H
push eax ; offset find_ClassName_hacked
call PostMessageA
jmp nokey




;#--------ERROR HANDLE
error_hwnd:
push offset error_handle
call strlen
invoke TextOut,hdc,20,20,ADDR error_handle,eax


;################# end interesting stuf
nokey:
;invoke TextOut,hdc,0,0,ADDR char,1

      invoke EndPaint,hWnd, ADDR ps

   .ELSE
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam
      ret
   .ENDIF
   xor    eax,eax
   ret
WndProc endp
end start




;########## rewritten visual c 6.0 string routines :) ###################

:===========FILE STRCPY.ASM ===============================
Quote
I am verry sorry but the file strcpy.asm i can`t post it due to copyrights.
You can if u have visual c++ 6 get the strcpy.asm file and port uhh rework it!

It contains the routines strcpy and strcat they return a buffer in eax!


:===========FILE STRLEN.ASM ===============================
Quote
I am verry sorry but the file strlen.asm i can`t post it due to copyrights.
You can if u have visual c++ 6 get the strcpy.asm file and port uhh rework it!

It contains the routine: strlen, it returns len in hmmmm eax or ecx!


Some help would be cool becouse i am a little stuck here!

Bye





Vortex

Terminating an application:

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
msg         db 'Click OK to terminate the notepad application',0
title1      db 'Hello',0
app         db 'notepad.exe',0
wndclass    db 'Notepad',0

.code
start:

  invoke    WinExec,ADDR app,SW_SHOW
  invoke    MessageBox,0,ADDR msg,ADDR title1,MB_OK
  invoke    FindWindow,ADDR wndclass,0
  invoke    SendMessage,eax,WM_DESTROY,0,0 
  invoke    ExitProcess,0

END start

marco1974

Thanx again Vortex!

what if i use openprocces to open the running proccess of notepad.exe.
I mean how do i detect a running process?

Its the next step I need to take. :-)
Then i can first send some text the normal way to notepad and then open the process memory
and replace it INmemory with openproccess etc.

I have thoughts about learning more about process memory and how aplications use that.
Stretching the os to see whats loaded.

If i am some time ahead i can then hook/read/write to system memory.
The purpose could be to write driver code that does not need to be a service or a vxd.

I am verry fasinated with OLD DOS, and any way i can make a hack to get interupts working SHOULD BE explored!

Bye for now my friend!