flat assembler
Message board for the users of flat assembler.
Index
> Windows > newbie question about stack |
Author |
|
bitshifter 23 Jun 2011, 16:06
Hi kot3245, welcome to the forum.
I asked similiar question once... http://board.flatassembler.net/topic.php?p=92372#92372 Just allocate as much as needed in your case. |
|||
23 Jun 2011, 16:06 |
|
kot3245 23 Jun 2011, 16:31
Thanks a lot for your answer. I hope that it will help me.
|
|||
23 Jun 2011, 16:31 |
|
kot3245 23 Jun 2011, 23:04
Structure definition are dummy. The second member of structure can have variable length. Memory for structure should be allocated dynamically. Whether the question is required stack alignment on 4 bytes or not?
|
|||
23 Jun 2011, 23:04 |
|
LocoDelAssembly 24 Jun 2011, 00:26
You need to adjust the stack pointer to 4 bytes (or 8 bytes for 64-bit code), to avoid troubles (not to improve performance only).
One chance here would be defining DevicePath with an explicit size, the other would be using LocalAlloc API (or whatever). If you still need this on stack then, assuming you will going to use this with SetupDiGetDeviceInterfaceDetail, then (for 32-bit code): Code: proc playWithDeviceInfo, hDev, pDeviceInterfaceData, local reqSize:DWORD push ebx invoke SetupDiGetDeviceInterfaceDetail, [hDev], [pDeviceInterfaceData], NULL, 0, addr reqSize, NULL test eax, eax jz .fail sub esp, [reqSize] and esp, -4 mov ebx, esp ; For convenience, since ESP changes at every PUSH (something that occurs when invoke passes parameters) ; This is needed only if the information could be several pages long to force allocation of the guard pages mov eax, ebp .touch: test byte [eax], 0 sub eax, 4096 cmp esp, eax jb .touch ; Now time to get the data! mov eax, [reqSize] mov [ebx+PSP_DEVICE_INTERFACE_DETAIL_DATA.cbSize], eax invoke SetupDiGetDeviceInterfaceDetail, [hDev], [pDeviceInterfaceData], ebx, [reqSize], NULL, NULL test eax, eax jz .fail ; Example of using the data invoke MessageBox, 0, addr ebx+PSP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath, .caption, 0 pop ebx .fail: ; I do nothing on error but just getting out of here ret .caption db "Device Path", 0 ; Use "du" instead of "db" if you are using Unicode APIs (i.e. win32w*.inc or MesageBoxW). endp |
|||
24 Jun 2011, 00:26 |
|
kot3245 24 Jun 2011, 08:10
Thanks for an example. I will try to understand a code.
Code: .... sub esp, [reqSize] and esp, -4 mov ebx, esp ; .... and esp, -4 - This alignment of a stack, isn't it? |
|||
24 Jun 2011, 08:10 |
|
AsmGuru62 24 Jun 2011, 12:58
Yes.
|
|||
24 Jun 2011, 12:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.