Results 1 to 5 of 5

Thread: Push local variable address

  1. #1
    To crash or not to crash
    Join Date
    Dec 2001
    Posts
    120

    Push local variable address

    Ok, I'm in the process of converting high level code to asm to speed up some operations on binary trees. Now I've come to some situation where the asm code I wrote is so stupid looking that I thought that there MUST be a way to do it better

    What I have is this routine entry code:
    Code:
    Delete1ItemByPosition:
    
    	%define snNodeData 	ebp + 8
    	%define lStartIndex	ebp + 12	
    	%define Item 		ebp + 16
    	
    	%define RebuildTreeFromIndex 	ebp - 4
    	%define CurrentParentIndex 		ebp - 8
    	%define bDone			ebp - 12
    	%define ArrayPointer 		ebp - 16
    	%define LastIndex			ebp - 20
    
    	push ebp
    	mov ebp, esp
    	sub esp, 20
    Now I want to push a local variable memory location for another function that wants some of it's variables as reference instead of value.

    So for example the local variable 'LastIndex' I did this:
    Code:
    	mov ebx, ebp
    	sub ebx, 20
    	push ebx
    The problem with that code is that
    a) It doesn't clearly reference my local variable 'LastIndex'
    b) It's 3 instructions

    This code looks so stupid that I came here to ask for a better solution. I only learned asm from reversing so I hope I'm missing a very obvious instruction here...

    I already looked through some dll's to find a similiar situation but I couldn't find one.

    HELP!

    Thanks in advance, I-Warez

  2. #2
    Registered User
    Join Date
    Feb 2004
    Location
    France
    Posts
    99
    Hi,

    (As it seems that you're using nasm) This assembler has a way to define local variables through the %local directive:

    http://www.nasm.us/doc/nasmdoc4.html#section-4.8.3

    Sorry for not providing a better example than the manual as I'm not really a nasm expert.

    Hope it helps.
    Omne tulit punctum qui miscuit utile dulci

  3. #3
    To crash or not to crash
    Join Date
    Dec 2001
    Posts
    120
    Hi Neitsa,

    Thanks for your link, but I'm afraid it won't answer my question. I did however show me a nice way to let nasm calculate the amount of stack space I need for local variables. Thanks for that!

    Let me rephrase my question:
    If you have a localvariable defined as ebp-8 you can access it from within your routine as mov eax, [LocalVar] and if you need to push the value of the variable for another routine you simple push the variable like push [LocalVar].

    What if you want to push the memorylocation? push ebp-8 doesn't exists...

    EDIT:
    I just realized I could use this
    Code:
    lea ebx, [LocalVar]
    push ebx
    SOLVED!
    Last edited by Iwarez; August 21st, 2010 at 05:36.

  4. #4
    Registered User
    Join Date
    Feb 2004
    Location
    France
    Posts
    99
    I'm sorry I did not understand your question , I could have answered it earlier.

    Yep, 'LEA' each time you want an address rather than a value. Glad you found it!
    Omne tulit punctum qui miscuit utile dulci

  5. #5
    To crash or not to crash
    Join Date
    Dec 2001
    Posts
    120
    Well you helped me a lot with the %local compiler directive. That simplified my routine declaration a lot. Also it helped to get rid of the arguments defines by using the %arg directive. So I learned some more and it looks nicer too. Thanks!

Similar Threads

  1. Replies: 12
    Last Post: December 24th, 2009, 11:34
  2. Analyzing local privilege escalations in win32k
    By Uninformed Journal in forum Blogs Forum
    Replies: 0
    Last Post: October 19th, 2008, 01:01
  3. Unlocking Windows XP System (local policies etc)
    By peterg70 in forum Mini Project Area
    Replies: 13
    Last Post: November 6th, 2005, 21:15
  4. Getting hardware infos about the local computer
    By SynApsus in forum Advanced Reversing and Programming
    Replies: 12
    Last Post: March 10th, 2004, 14:02
  5. NE1 :: Got a local copy of CrackZ site b4 it went down????
    By gadget in forum Tools of Our Trade (TOT) Messageboard
    Replies: 18
    Last Post: November 29th, 2001, 14:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •