News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

masm32 versus flat assembler

Started by clamicun, February 03, 2017, 11:25:15 AM

Previous topic - Next topic

clamicun

This program (with some syntax changes) compiles 'flat' with flat assembler.

MASM gives the error...
"INVOKE requires prototype for procedure"

INVOKE Process32First, hSnapShot, offset ProcessEntry
INVOKE Process32Next, hSnapShot, offset ProcessEntry

In kernel32.inc I find only
Process32FirstW
Process32NextW

What to do ?

Here the source for masm32
The zipfile has the source for flatassembler and masm32
 
include \masm32\include\masm32rt.inc

PROCESSENTRY32 STRUCT
dwSize               dd ?
cntUsage             dd ?
th32ProcessID        dd ?
th32DefaultHeapID    dd ?
th32ModuleID         dd ?
cntThreads           dd ?
th32ParentProcessID  dd ?
pcPriClassBase       dd ?
dwFlags              dd ?
szExeFile            db MAX_PATH dup(?)
PROCESSENTRY32 ENDS

TH32CS_SNAPPROCESS equ 2

.data
success   db "Runs"
chkfor    db "mysqld.exe", 0
hSnapShot dd ?
ProcessEntry PROCESSENTRY32<>


.code
Start:

  mov ProcessEntry.dwSize, SIZEOF PROCESSENTRY32
  INVOKE CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
  mov hSnapShot, eax

  INVOKE Process32First, hSnapShot, offset ProcessEntry

NextProcess:
  INVOKE lstrcmpi, ProcessEntry.szExeFile, offset chkfor
  .if eax ==  0
  jmp Found
  .else
  INVOKE Process32Next, hSnapShot, offset ProcessEntry
  show_value eax,"next"
  jmp NextProcess
  .endif

Found:   
INVOKE MessageBox, 0,offset success, offset chkfor, MB_ICONQUESTION
jmp Exit
 
Exit:
  INVOKE ExitProcess, 0

end Start


clamicun


jj2007

It's a long story. Check http://masm32.com/board/index.php?action=search;advanced;search=Process32First

clamicun

JJ,
yes - seems like a long story. I am reading.
Does the story have a happy end ?
If not, I forget the story and use flat assembler for this peace ...

jj2007

Quote from: clamicun on February 03, 2017, 12:11:01 PMDoes the story have a happy end ?

Not really; there is a reason why I used LoadLibrary & GetProcAddress in my recent example.

You could rebuild your Kernel32.lib with the correct definitions, but it means that any code based on the new version will be incompatible with the current Masm32 installation :(

hutch--

It is not really a competition between MASM and FASM, both can produce high quality binary code when written correctly. Which one you use is a matter of experience and taste.

clamicun

JJ,
your recent example is excellent.
I changed it a bit. It hasn't any output. Only quits with Exitcode 666 if mysqld.exe doesn't run. 

jj2007

Quote from: clamicun on February 03, 2017, 01:00:31 PM
your recent example is excellent.
I changed it a bit. It hasn't any output. Only quits with Exitcode 666 if mysqld.exe doesn't run.

Thanks, but how did Lucifer get involved in this??? For me, it just returns 0=not found or 1=found ::)

Vortex

Hi clamicun,

Some additional features. You can query any process using the command-line :

test.bat :

@QueryProcess explorer.exe
@echo %ERRORLEVEL%


Process explorer.exe is running.
1


The environment variable ERRORLEVEL is set to 1 if the process is running :

include     QueryProcess.inc

.data

text1       db 'Process %s is not running.',13,10,0
text2       db 'Process %s is running.',13,10,0
strtable    dd OFFSET text1,OFFSET text2

.data?

buffer      db 512 dup(?)

.code

start:

    call    main
    invoke  ExitProcess,eax

main PROC USES esi edi

LOCAL pe32:PROCESSENTRY32
LOCAL hProcessSnap:DWORD

    invoke  ParseCmdLine,OFFSET buffer
    cmp     eax,2
    je      @f
    ret
@@:   
    mov     eax,OFFSET buffer
    mov     edi,DWORD PTR [eax+4]
    invoke  crt__strlwr,edi

    lea     esi,pe32
    invoke  CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,0
    mov     hProcessSnap,eax
    mov     pe32.dwSize,SIZEOF PROCESSENTRY32
    invoke  Process32First,eax,esi
@@:
    invoke  crt__strlwr,ADDR PROCESSENTRY32.szExeFile[esi]
    invoke  szCmp,eax,edi
    test    eax,eax
    jnz     process_found

    invoke  Process32Next,hProcessSnap,esi
    test    eax,eax
    jnz     @b
   
    invoke  CloseHandle,hProcessSnap

    xor     eax,eax

process_found:

    xor     edx,edx
    xor     ecx,ecx
    sub     ecx,eax
    adc     edx,edx
    push    edx
    shl     edx,2

    lea     eax,[strtable+edx]
   
    invoke  crt_printf,DWORD PTR [eax],edi
    pop     eax
    ret

main ENDP

END start

clamicun

jj,
that is my special relationhip with Luzifer