flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 20 Jan 2023, 10:12
The struct macro doesn't support Align. Unless you are using your own version of struct where you define Align?
Sections in Windows are always aligned to the next page, which is usually 4k. So you get that alignment for free. |
|||
![]() |
|
Tomasz Grysztar 20 Jan 2023, 10:18
The "struct" macro as implemented in fasm's standard headers does not support "align" statements, the way it was designed makes these statements completely ignored. ProMiNick has been working on some advanced "struct" macro variants - they might be able to solve your problem.
The re-implementation of "struct" for fasmg should be able to handle it, although it may still behave unexpectedly if whole structure is instantiated misaligned. Do you expect it to align relative to the start of the structure, or do you expect the actual address to be aligned? AE wrote: It seems like there used to be a "bug" with the inability to make the alignment greater than that of the section, but I can't add alignment to the section because I always got an error |
|||
![]() |
|
AE 20 Jan 2023, 11:02
Tomasz Grysztar wrote: Do you expect it to align relative to the start of the structure, or do you expect the actual address to be aligned? As far as I understand, I need to align the structure with "paddings" manually or migrate to fasmg. By the way, a question a bit off topic - is fasm automatically aligns some structures? AFAIK both of this will work: Code: struct UNICODE_STRING Length dw ? MaximumLength dw ? dd ? ; manual padding Buffer dq ? ends struct UNICODE_STRING Length dw ? MaximumLength dw ? Buffer dq ? ends |
|||
![]() |
|
Tomasz Grysztar 20 Jan 2023, 11:12
AE wrote: As far as I understand, I need to align the structure with "paddings" manually or migrate to fasmg. AE wrote: By the way, a question a bit off topic - is fasm automatically aligns some structures? |
|||
![]() |
|
AE 20 Jan 2023, 11:29
Tomasz Grysztar wrote: ProMiNick's macros It can't handle 'union' ![]() |
|||
![]() |
|
Tomasz Grysztar 20 Jan 2023, 11:41
AE wrote:
|
|||
![]() |
|
AE 20 Jan 2023, 12:51
Thank you very much for the links, I tried all the solutions and only fasmg was able to do it right without changing the source.
Although I was confused by the garbage generation in code section if there is 'Align XX'. Does it make sense to switch to fasmg (only for PE x64)? |
|||
![]() |
|
AE 20 Jan 2023, 13:58
Quote: garbage generation in code section if there is 'Align XX' Here is the code and disassembled instructions of the "strange" area Code: ... fastcall GetPath ; Align 16 ML: invoke GetMessage,msg,NULL,0,0 ; msg loop start here ... --------------------------------------------------------------------------------------- 00000000004023D0 | 48:83EC 20 | sub rsp, 0x20 00000000004023D4 | E8 47090000 | call win32_.402D20 00000000004023D9 | 48:83C4 20 | add rsp, 0x20 --------------------------------------------------------------------------------------- 00000000004023DD | 48:83EC 20 | sub rsp, 0x20 00000000004023E1 | 48:C7C1 20104000 | mov rcx, win32_.401020 00000000004023E8 | 48:C7C2 00000000 | mov rdx, 0x0 --------------------------------------------------------------------------------------- 00000000004023EF | 49:C7C0 00000000 | mov r8, 0x0 00000000004023F6 | 49:C7C1 00000000 | mov r9, 0x0 00000000004023FD | FF15 850D0000 | call qword ptr ds:[<&GetMessageW>] --------------------------------------------------------------------------------------- Code: ... fastcall GetPath Align 16 ML: invoke GetMessage,msg,NULL,0,0 ; msg loop start here ... --------------------------------------------------------------------------------------- 00000000004023D0 | 48:83EC 20 | sub rsp, 0x20 00000000004023D4 | E8 47090000 | call win32_.402D20 00000000004023D9 | 48:83C4 20 | add rsp, 0x20 --------------------------------------------------------------------------------------- 00000000004023DD | 0000 | add byte ptr ds:[rax], al 00000000004023DF | 0048 83 | add byte ptr ds:[rax - 0x7D], cl 00000000004023E2 | EC | in al, dx 00000000004023E3 | 2048 C7 | and byte ptr ds:[rax - 0x39], cl 00000000004023E6 | C120 10 | shl dword ptr ds:[rax], 0x10 00000000004023E9 | 40:0048 C7 | add byte ptr ds:[rax - 0x39], cl 00000000004023ED | C2 0000 | ret 0x0 00000000004023F0 | 0000 | add byte ptr ds:[rax], al --------------------------------------------------------------------------------------- 00000000004023F2 | 49:C7C0 00000000 | mov r8, 0x0 00000000004023F9 | 49:C7C1 00000000 | mov r9, 0x0 0000000000402400 | FF15 820D0000 | call qword ptr ds:[<&GetMessageW>] --------------------------------------------------------------------------------------- Pay attention to the middle section of the code, in the presence of an alignment macro, it turns into garbage |
|||
![]() |
|
revolution 20 Jan 2023, 14:11
Pad with 0x90 bytes (nop).
|
|||
![]() |
|
Tomasz Grysztar 20 Jan 2023, 14:20
With "align" macro that comes with PE formatter for fasmg you can specify the pad bytes this way:
Code: align 16, 90h |
|||
![]() |
|
AE 20 Jan 2023, 14:37
Tomasz Grysztar wrote: align 16, 90h Thx! |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.