News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Used to work

Started by Magnum, April 03, 2013, 10:37:30 AM

Previous topic - Next topic

Magnum

Vertograd,

Tried this, but it doesn't work.
Getting the error to show sure is a P.I.T.A.



.IF (eax == 0)
               invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
               .IF (eax)
                   invoke TerminateProcess, eax,0
                   invoke Sleep,2000 ; Delay to give time to terminate process
                     .IF eax==0
                          invoke MessageBox, NULL,ADDR err,ADDR Box,MB_OK or MB_ICONERROR
                     .ENDIF
               .ELSEIF eax == ERROR_NO_MORE_FILES
                 invoke MessageBox, NULL,ADDR err,ADDR Box,MB_OK or MB_ICONERROR
               
                   
           .ENDIF

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Quote from: vertograd on April 05, 2013, 11:31:19 PM
Does Sleep function modify eax?

Who knows?  ::)

include \masm32\include\masm32rt.inc

.code
start:   mov eax, 12345
   invoke Sleep, 123
   MsgBox 0, str$(eax), "Should be 12345:", MB_OK
   exit

end start

dedndave

i have used GetExitCodeProcess to retrieve the exit code of the process to determine if it has terminated
if you think there is a possibility that it may not terminate, you could use a loop count to establish a "time-out"

after you have called TerminateProcess....
        jmp short Term01

Term00: INVOKE  Sleep,200

Term01: push    0
        INVOKE  GetExitCodeProcess,hProcess,esp
        pop     eax
        cmp     eax,STILL_ACTIVE
        jz      Term00

Magnum

The code terminates the program fine, I can't find out how to display a message if the program is not running.

Ollydbg shows ERROR_NO_MORE_FILES, but testing for it fails.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

I even tried testing after OpenProcess.

I think Windows is dame bramaged.  :t
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

GoneFishing

#20
QuoteWho knows?  ::)

include \masm32\include\masm32rt.inc

.code
start:   mov eax, 12345
   invoke Sleep, 123
   MsgBox 0, str$(eax), "Should be 12345:", MB_OK
   exit

end start
Ok, you're right. EAX is 0 after Sleep call :icon_confused:
But that's exactly what we want to achieve to let our error message box to appear  :biggrin: 

QuoteVertograd,

Tried this, but it doesn't work.
Getting the error to show sure is a P.I.T.A.

Could you post that error?
It's quite strange.I just tested this code on my machine.All worked - I saw an error message box.
I tried it both without push eax-pop eax  and with them .

include \masm32\include\masm32rt.inc

.data
  ... ... ...
.code
start:   
   invoke OpenProcess, PROCESS_TERMINATE,FALSE, calcPID         ;  cmd -> CALC &  TASKLIST -> calc PID
               .IF (eax)
                   invoke TerminateProcess, eax,0
                   ;push eax
                   invoke Sleep,2000 ; Delay to give time to terminate process
                   ;pop eax
                     .IF eax==0
                          invoke MessageBox, NULL,ADDR err,ADDR Box,MB_OK or MB_ICONERROR
                     .ENDIF
               .ENDIF
   exit

end start



Magnum


; terminate.asm   Terminate any application   
;
; Help from Tedd,sinsi,Nordwind64,AsmGuru62,Jongware,DednDave,vertograd

;

.586
.model flat, stdcall
option casemap:none

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

.data

AppName         db "Terminator",0
Item            db "firefox.exe",0

errSnapshot     db "CreateToolhelp32Snapshot failed.",0
errProcFirst    db "Process32First failed.",0
err             db "TerminateProcess failed !",0
NoMore          db "ERROR_NO_MORE_FILES",0
Box             db " ",0

.data?

hSnapshot   HANDLE ?
ProcEnt     PROCESSENTRY32 <?>
hProcess    HANDLE ?

.code

start:
   invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS,0
   .IF (eax != INVALID_HANDLE_VALUE)
       mov hSnapshot,eax
       mov [ProcEnt.dwSize],SIZEOF ProcEnt
       invoke Process32First, hSnapshot,ADDR ProcEnt
       .IF (eax)
         @@:
           invoke lstrcmpi, ADDR Item ,ADDR [ProcEnt.szExeFile]
           .IF (eax == 0)
               invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
               
             .IF (eax)
                   invoke TerminateProcess, eax,0
                   ;push eax
                   invoke Sleep,2000 ; Delay to give time to terminate process
                   ;pop eax
                     .IF eax==0
                          invoke MessageBox, NULL,ADDR err,ADDR Box,MB_OK or MB_ICONERROR
                     .ENDIF
                                   
           .ENDIF

        .endif         

           invoke Process32Next, hSnapshot,ADDR ProcEnt
           test eax,eax
           jnz @B

       .ELSE
           invoke MessageBox, NULL,ADDR errProcFirst,ADDR AppName,MB_OK or MB_ICONERROR
       .ENDIF
       invoke CloseHandle, hSnapshot
   .ELSE
       invoke MessageBox, NULL,ADDR errSnapshot,ADDR AppName,MB_OK or MB_ICONERROR
   .ENDIF
   invoke ExitProcess, NULL

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum


; terminate.asm   Terminate any application   
;
; Help from Tedd,sinsi,Nordwind64,AsmGuru62,Jongware,DednDave,vertograd

;

.586
.model flat, stdcall
option casemap:none

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

.data

AppName         db "Terminator",0
Item            db "firefox.exe",0

errSnapshot     db "CreateToolhelp32Snapshot failed.",0
errProcFirst    db "Process32First failed.",0
err             db "TerminateProcess failed !",0
NoMore          db "ERROR_NO_MORE_FILES",0
Box             db " ",0

.data?

hSnapshot   HANDLE ?
ProcEnt     PROCESSENTRY32 <?>
hProcess    HANDLE ?

.code

start:
   invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS,0
   .IF (eax != INVALID_HANDLE_VALUE)
       mov hSnapshot,eax
       mov [ProcEnt.dwSize],SIZEOF ProcEnt
       invoke Process32First, hSnapshot,ADDR ProcEnt
       .IF (eax)
         @@:
           invoke lstrcmpi, ADDR Item ,ADDR [ProcEnt.szExeFile]
           .IF (eax == 0)
               invoke OpenProcess, PROCESS_TERMINATE,FALSE,[ProcEnt.th32ProcessID]
               
             .IF (eax)
                   invoke TerminateProcess, eax,0
                   ;push eax
                   invoke Sleep,2000 ; Delay to give time to terminate process
                   ;pop eax
                     .IF eax==0
                          invoke MessageBox, NULL,ADDR err,ADDR Box,MB_OK or MB_ICONERROR
                     .ENDIF
                                   
           .ENDIF

        .endif         

           invoke Process32Next, hSnapshot,ADDR ProcEnt
           test eax,eax
           jnz @B

       .ELSE
           invoke MessageBox, NULL,ADDR errProcFirst,ADDR AppName,MB_OK or MB_ICONERROR
       .ENDIF
       invoke CloseHandle, hSnapshot
   .ELSE
       invoke MessageBox, NULL,ADDR errSnapshot,ADDR AppName,MB_OK or MB_ICONERROR
   .ENDIF
   invoke ExitProcess, NULL

end start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Sorry for the double post, my browser just hung.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

qWord

I'm curios, why should the thread wait for an asynchronous process (TerminateProcess())? Also, why is the return value of Sleep() used for testing if TerminateProcess() fails :dazzled:
MREAL macros - when you need floating point arithmetic while assembling!

Magnum

It isn't when push and pop were used.

Even OpenProcess can't be used.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

qWord

Quote from: Magnum on April 06, 2013, 06:09:27 AM
It isn't when push and pop were used.
OK - that makes sense.

Quote from: Magnum on April 06, 2013, 06:09:27 AMEven OpenProcess can't be used.
of course  it can be used.
MREAL macros - when you need floating point arithmetic while assembling!

Magnum

Can you give a working example ?

I got the same result as with TerminateProcess.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

qWord

Quote from: Magnum on April 06, 2013, 06:15:17 AM
Can you give a working example ?
sry, I'm not your Google replacement  :t
MREAL macros - when you need floating point arithmetic while assembling!

Magnum

No, I don't think you know the answer.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org