flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > pushd in win32w[x[p]].inc

Author
Thread Post new topic Reply to topic
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 30 Dec 2008, 08:49
macro doesn't align unicode strings declared in
Code:
invoke   somefunc, "somestring"    

on 2 byte natural alignment as it required by some APIs. RCE showed STATUS_DATATYPE_MISALIGNMENT on such 1-byte aligned strings.


WIN32W[X[P]].INC
Should be changed to
Code:
ALIGN 2
nop
    call ..continue
    du value,0
    ..continue:
    

_________________
Any offers?
Post 30 Dec 2008, 08:49
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 30 Dec 2008, 09:00
I think this is a good suggestion.

However this may be missed by Tomasz in this thread. Perhaps a mod can move and sticky it into Compiler Internals?
Post 30 Dec 2008, 09:00
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 Dec 2008, 09:55
asmfan,

times 1 - ($ and 1) nop
instead of
align 2
nop
,
may be?

_________________
"Don't belong. Never join. Think for yourself. Peace." – Victor Stone.
Post 30 Dec 2008, 09:55
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 30 Dec 2008, 11:41
baldr confirm, this is better.
Post 30 Dec 2008, 11:41
View user's profile Send private message Reply with quote
CoolCmd



Joined: 27 Dec 2023
Posts: 11
CoolCmd 27 Feb 2024, 19:31
With "ms coff" format this line
Code:
times 1 - ($ and 1) nop    

generates "error: invalid use of symbol".

This line works:
Code:
times 1 - (($ - $$) and 1) nop    
Post 27 Feb 2024, 19:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 27 Feb 2024, 19:43
Make sure that $$ is aligned accordingly.
Code:
; ...
org 0xff ; $$ = 0xff
times 1 - (($ - $$) and 1) nop
; here the alignment might not be what you wanted
;...    
Post 27 Feb 2024, 19:43
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 28 Feb 2024, 01:27
If you want to avoid redundant nops a macro can help:
Code:
~ cat wac.asm ; fasm wac.asm && hd wac.exe | tail
macro word_aligned_call destination {
        local   ..even_alignment, ..have_nop
        if ..even_alignment
                nop
                ..have_nop = 1
        else
                ..have_nop = 0
        end if
        call destination
        virtual
                align 2
                ..even_alignment = ($ - $$) xor ..have_nop
        end virtual
}

format pe

section '' code

        word_aligned_call       thing
                        du      'text',0
        word_aligned_call       thing
                        du      'text',0
                        db      -1 ; make odd alignment test
        word_aligned_call       thing
                        du      'text',0
        word_aligned_call       thing
                        du      'text',0
        ;...

thing:
        ;...
        ret
flat assembler  version 1.73.31  (16384 kilobytes memory)
6 passes, 1024 bytes.
000001a0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200  90 e8 3a 00 00 00 74 00  65 00 78 00 74 00 00 00  |..:...t.e.x.t...|
00000210  90 e8 2a 00 00 00 74 00  65 00 78 00 74 00 00 00  |..*...t.e.x.t...|
00000220  ff e8 1a 00 00 00 74 00  65 00 78 00 74 00 00 00  |......t.e.x.t...|
00000230  90 e8 0a 00 00 00 74 00  65 00 78 00 74 00 00 00  |......t.e.x.t...|
00000240  c3 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000250  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000400    
Post 28 Feb 2024, 01:27
View user's profile Send private message Visit poster's website Reply with quote
CoolCmd



Joined: 27 Dec 2023
Posts: 11
CoolCmd 29 Feb 2024, 07:52
Quote:

Make sure that $$ is aligned accordingly.

i do not use ORG in code.

Quote:

If you want to avoid redundant nops a macro can help:

why is it better than "times 1 - (($ - $$) and 1) nop" ?
Post 29 Feb 2024, 07:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 29 Feb 2024, 13:46
CoolCmd wrote:
Quote:

Make sure that $$ is aligned accordingly.

i do not use ORG in code.
With the macro you can if ever need to. It gives you flexibility.
CoolCmd wrote:

Quote:

If you want to avoid redundant nops a macro can help:

why is it better than "times 1 - (($ - $$) and 1) nop" ?
Because the length of call varies.
Code:
        word_aligned_call       dword[thing] ; 6 byte call
                        du      'text',0
        word_aligned_call       dword[fs:thing] ; 7 byte call
                        du      'text',0
        word_aligned_call       eax ; 2 byte call
                        du      'text',0    
Post 29 Feb 2024, 13:46
View user's profile Send private message Visit poster's website Reply with quote
CoolCmd



Joined: 27 Dec 2023
Posts: 11
CoolCmd 06 Mar 2024, 16:43
I see, but in this thread we are talking about "invoke" macro which always uses "call labelname". I hope WIN32WX.INC will be updated... someday.
Post 06 Mar 2024, 16:43
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8396
Location: Kraków, Poland
Tomasz Grysztar 06 Mar 2024, 17:09
CoolCmd wrote:
I hope WIN32WX.INC will be updated... someday.
The alignment for embedded strings had been added there years ago. You undug a thread from 2008.
Post 06 Mar 2024, 17:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20631
Location: In your JS exploiting you and your system
revolution 06 Mar 2024, 18:43
CoolCmd wrote:
I see, but in this thread we are talking about "invoke" macro which always uses "call labelname".
Still applies. "labelname" can be "eax", "dword[thing]", etc.
Post 06 Mar 2024, 18:43
View user's profile Send private message Visit poster's website Reply with quote
CoolCmd



Joined: 27 Dec 2023
Posts: 11
CoolCmd 06 Mar 2024, 19:10
Tomasz Grysztar wrote:
The alignment for embedded strings had been added there years ago. You undug a thread from 2008.

As i said above, this "added years ago" alignment does not work with "ms coff" format.
Try to assemble this code:
Code:
format ms coff
include "win32wx.inc"
include "encoding\win1251.inc"
stdcall eax, "1"    

Are you happy that the basic functionality (stdcall, invoke) doesn’t work?

revolution wrote:
Still applies. "labelname" can be "eax", "dword[thing]", etc.

No, always 5 bytes:
Code:
local ..continue
times 1 - (rva $ and 1) nop
call ..continue
du value,0
..continue:    
Post 06 Mar 2024, 19:10
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8396
Location: Kraków, Poland
Tomasz Grysztar 06 Mar 2024, 19:22
CoolCmd wrote:
As i said above, this "added years ago" alignment does not work with "ms coff" format.
The extended headers have been designed for PE format, as implied by their documentation. Nonetheless...

CoolCmd wrote:
Try to assemble this code:
Code:
format ms coff
include "win32wx.inc"
include "encoding\win1251.inc"
stdcall eax, "1"    
This does in fact assemble with fasm2.
Post 06 Mar 2024, 19:22
View user's profile Send private message Visit poster's website 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.