flat assembler
Message board for the users of flat assembler.

Index > Windows > Local Variable Troubles...

Author
Thread Post new topic Reply to topic
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
Okay Im having serious trouble here with local variables.

Code:
proc ListProcesses
        .SnapShot dd 0
        .cProcess PROCESSENTRY32
        enter
        invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
        mov [.SnapShot],eax
        ;setup code for processentry crap here, it works.
        invoke Process32First,[.SnapShot], .cProcess
                 ;code here
    _bListProc:
                   ;code here
          jmp     _bListProc
    _eListProc:
                   ;code here
  return
    


Now my problem is i always get "invalid value".... Im so lost. when i declare this stuff in data section... no problems what so ever, everything works flawlessly, but when i invoke a procedure using local variables, the locals always turn up errors. I'd like to know if there is a way to fix this, as I really want to implement local variables into this project im working on so that i can clean up the code alot.

one way i was thinking was if i...
Code:
push .cProcess
push .SnapShot
call [Process32First]
...
    


but its late right now, im real frustrated and i must sleep. I hope someone can help me here with this.

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.
Post 23 Dec 2003, 04:13
View user's profile Send private message Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
Try:
Code:
.cProcess rb sizeof.PROCESSENTRY32    


And should you not lea .cProcess when passing it to Process32First?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 23 Dec 2003, 04:45
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
I found problem, this happen because you define PROCESSENTRY32 after code, and before data. That is why it work in data section and not in code.

Strange, but I thought FASM would do additional passes to resolve this structure definition... But this is parser (?) stage and passes are done in assembly stage only?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 23 Dec 2003, 04:48
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Code:
proc ListProcesses
  .SnapShot dd 0
  .cProcess PROCESSENTRY32
        enter
        invoke CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, 0
        mov [.SnapShot],eax
        ;setup code for processentry crap here, it works.
        lea     eax, [.cProcess]
        invoke Process32First,[.SnapShot], .cProcess
                     ;code here
    .bListProc:
                   ;code here
          jmp     .bListProc
    .eListProc:
                   ;code here
  return
    


Hi. Try above. It should work.
Note that you can't get the address of local variable in assembly time, because this address is simply unknown (local variables are in the stack).
Other assemblers work the same way, but simply hides this from you.

Regards.
Post 23 Dec 2003, 06:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
John, ain't
Code:
lea     eax, [.cProcess] 
invoke Process32First,[.SnapShot], .cProcess    
going to be:
Code:
lea     eax, [.cProcess] 
invoke Process32First,[.SnapShot], eax    
?

Tommy
Post 23 Dec 2003, 07:54
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Hi, Tommy.
Of course you are right. I am still sleeping this morning. Very Happy

Regards.
Post 23 Dec 2003, 08:18
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
Very Happy Hehe...
Post 23 Dec 2003, 08:38
View user's profile Send private message Visit poster's website Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Kevin_Zheng
One Error: The local variable can't initalize on complier period.
So the define is invalid:
Code:
.SnapShot dd 0     


It should be the belowing :
Code:
.SnapShot dd  ?    


or

Code:
.SnapShot rd 1     
Post 23 Dec 2003, 13:33
View user's profile Send private message MSN Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Kevin_Zheng wrote:
One Error: The local variable can't initalize on complier period.


Of course local variables can not be initialized on compile time, but actually this is not an error. The compilation will pass normally, only you should know that this variable will be initialized with random (even on every call of procedure) value.

Regards.
Post 23 Dec 2003, 13:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
Thanks guys, I'll try this out when I get home. If it works I'll be able to make the code for a project im working on( and even future windows oriented projects) that much more efficient, when it comes to procedures. Once again thanks everyone for the replys.

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.
Post 23 Dec 2003, 14:40
View user's profile Send private message Reply with quote
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
comrade wrote:
Try:
Code:
.cProcess rb sizeof.PROCESSENTRY32    


And should you not lea .cProcess when passing it to Process32First?


Hmm, so when i do this, could i do as they do in nasm and go

Code:
mov [.cProcess+PROCESSENTRY32.dwSize],sizeof.PROCESSENTRY32
    


would that work when filling that or what?

Thanks everyone for the advice, i'll answer back here with my results.

EDIT EDIT EDIT EDIT NEW NEW NEW EDIT EDIT EDIT EDIT
New problem arising now.

Code:
proc ListProcesses, sck
        .SnapShot rd 1
        .Process32 rb sizeof.PROCESSENTRY32
        .Process rb 256
        .PID rb 12
        .Threads rb 12
 enter
        invoke CreateToolhelp32Snapshot,2,0
        mov     [.SnapShot],eax
        mov  dword [.Process32+PROCESSENTRY32.dwSize],sizeof.PROCESSENTRY32
        lea   eax,[.Process32]
        invoke      Process32First,[.SnapShot],eax
    _bListProc:
       cmp     eax,1
       jne     _eListProc
        lea       eax,[.Process] ;the error is occuring here.
        invoke   lstrcpyn,eax,szCmd3,2
        ;code here
         jmp     _bListProc
    _eListProc:
   ;code here
  return
    


on the line lea eax,[.Process]

i get "undefined symbol"... yet the freaking symbol is declared in the local right there.

Now as i test renaming the variable to something else its the exact same thing, so im coming to the conclusion that maybe these lea instructions aren't gonna work with the proc? I hope im not forced to make all these global variables, thereby wasting memory in the prog....

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.
Post 23 Dec 2003, 20:10
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
It is not because of local variables.
You simply forget to define some of the structures. You MUST define them in your source if they are not defined in standard include files.

Regards.
Post 24 Dec 2003, 16:07
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
i've used the processentry32 structure before, as ive included it myself inside the kernel equates. I know that the structure is there because when using *cough* global variables, it worked perfectly, but here we go again with this local variable crap. =(

nm now though, I think im just gonna use all gloval variables for this. the next thing I work on (which will be the flat assembler instant messenger(FAIM)) I will try this again.... Crying or Very sad

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.


Last edited by GuyonAsm on 24 Dec 2003, 17:43; edited 1 time in total
Post 24 Dec 2003, 16:24
View user's profile Send private message Reply with quote
silkodyssey



Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
silkodyssey
GuyonAsm,

Will the instant messenger use existing protocols like msn's or yahoo's?

_________________
silkodyssey
Post 24 Dec 2003, 17:05
View user's profile Send private message MSN Messenger Reply with quote
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
Its something VeSCeRa and I are gonna put together, perhaps with the help of others. So far it'll be Icq and Aim. Perhaps if we get documentation on other protocols, we could include those later on also.

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.
Post 24 Dec 2003, 17:16
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
GuyonAsm: no harm, but i think you shouldnt be using macros unless you know how they are working. I advice you to study 'proc', 'enter', 'return', 'invoke' and mainly 'pushd' which will tell you about 'addr' pseudo operator which can be used instead of lea.
Post 24 Dec 2003, 21:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Dunduk



Joined: 08 Sep 2003
Posts: 38
Location: Russia
Dunduk
GuyonAsm wrote:


on the line lea eax,[.Process]

i get "undefined symbol"...

Try
Code:
lea eax,[ListProcesses.Process]
    

It should work. ".Process" - is local label IMHO and after " _bListProc" label fasm didn't see it (oh, my english...). I think so.
Post 25 Dec 2003, 04:53
View user's profile Send private message Reply with quote
GuyonAsm



Joined: 27 Sep 2003
Posts: 45
GuyonAsm
Well gosh darn, I think your right. And yes sir it works. Thanks alot. Now i can continue on with my project. To discontinue any temptation of abandoning fasm to use another assembler (such as masm or etc.) I've just deleted all the assemblers i had on my comp etc. fasm. I will depend on fasm now =).

Ahh im so happy, this is a christmas present in itself. Thank you sooo much. Very Happy

_________________
I shall not evade what is predestined
because every battle, is another lesson
- GuyonAsm.

A Believer of The System.
Post 25 Dec 2003, 06:01
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.