News:

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

process32first/next problem....should be easy...

Started by xandaz, May 22, 2012, 11:18:54 AM

Previous topic - Next topic

xandaz

    Can someone tell me why this doesn't work? thanks

xandaz

   there's a problem in dwSize. wrong size but also it works with masm10 but not masm11. I've seen some strange things happening with structures in masm version 11. Does anyone know how to fix it?

Force

Never Stop Until You Are Better Than The Best

dedndave

i don't think that's his problem - at least not his only one (he could have the prototype/lib issue, as well)

his problem is related to the size of the PROCESSENTRY32 structure, which has not changed from v10 to v11
so - i don't know why one works and one doesn't - if that is the case

but - i do know that this is wrong...
process32       PROCESSENTRY32      <36+256,<>>
the correct size of the structure is 296 bytes - not 292 bytes
the reason for this is that MAX_PATH is 260 - not 256

in any event, i would not hard-wire the size of the structure with a numeric expression
if you want to do it, do it with the SIZEOF directive
process32       PROCESSENTRY32      <sizeof PROCESSENTRY32,<>>

i wouldn't do it that way, either   :bg

the size of the structure is 296 bytes
if you define it in the .DATA section, it adds 296 bytes (or more) to the size of the EXE

however, if you define it in the .DATA? section, and fill in the size with code, the EXE will be at least 287 bytes smaller
(assuming it takes ~9 bytes to fill in the structure size with code)
        .DATA?

process32       PROCESSENTRY32      <>

        .CODE

        mov     process32.dwSize,sizeof PROCESSENTRY32


in fact, i would use register base-index addressing because you can use the register twice, like so...
        invoke  CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS+TH32CS_SNAPMODULE,0
        mov     hSnap,eax
        mov     edx,offset process32
        mov     [edx].PROCESSENTRY32.dwSize,sizeof PROCESSENTRY32
        invoke  Process32First,eax,edx

as it happens, the index is for the first member is 0, so it's really register base addressing   :bg

xandaz

   i know dave.... i forgot to clear that when i submitted the file. I was just counting size by myself thinking had miscalculated it. Wrong count tho.

xandaz

 [TYPO]....thinking Masm had miscalculated...

dedndave

then - you probably want to look through the thread that Force linked and use Erol's tools to rebuild the lib

dedndave

while you're at it, the same problem exists in 2 include\lib pairs; kernel32 and kernl32p
and 4 functions; Module32First, Module32Next, Process32First, Process32Next
for a total of 8 fixes   :bg

xandaz

    I already made the changes for process32first/next but still doesn't enumerate. Only does so when i make that change in PROCESSENTRY32. The szExeFile from DB to DW. Can you garantee it works for you?

dedndave

that works - in the ANSI form

i added a structure definition for the UNICODE version

it works also...

MichaelW

A good way to check structure sizes is with a Microsoft C compiler and the structure definitions from the Microsoft header files.

This should be happening in the new forum, where it has a future.
eschew obfuscation