News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Out of order push by invoke

Started by jimg, June 24, 2017, 12:44:25 PM

Previous topic - Next topic

jimg

Finally found this one :)

It looks like UAsm is pushing in the wrong order for this example-

.686
.model Flat, Stdcall
option Casemap :None   ; case sensitive

SetGridSize equ 15

.data
hGrid1 dd 123

.code
GridMsg proc SYSCALL Public uses esi edi ebx GridHandle:dword,Request:dword,Parms:vararg
ret
GridMsg endp

.code
Program:

invoke GridMsg,hGrid1,SetGridSize,14,14

ret
end Program


UAsm produces-
UASM v2.37, Jun 20 2017
test.asm
                                .686
                                .model Flat, Stdcall
00000000                    *   _TEXT segment PARA FLAT PUBLIC 'CODE'
                            *   _TEXT ends
00000000                    *   _DATA segment PARA FLAT PUBLIC 'DATA'
                            *   _DATA ends
                            *   assume cs:flat,ds:flat,ss:flat,es:flat,fs:ERROR,gs:ERROR
                                option Casemap :None   ; case sensitive

= F                            SetGridSize equ 15

                                .data
00000000                    *   _DATA segment
                            *   assume cs:ERROR
00000000  7B000000              hGrid1 dd 123

00000000                        .code
00000004                    *   _DATA ends
00000000                    *   _TEXT segment
                            *   assume cs:FLAT
00000000                        GridMsg proc SYSCALL Public uses esi edi ebx GridHandle:dword,Request:dword,Parms:vararg
00000000  56                *   push ebp
00000001  57                *   mov ebp, e00000002  53                    *   push e00000003                        *   pu00000003  5B                        *   p00000004  5F                             00000005  5E                      *   pop00000006  C3                      *   pop edi
00000008                    *   pop esi
00000009                    *   pop ebp
0000000A                    *   retn
00000007                        GridMsg endp

00000000                        .code
00000007                    *   _TEXT ends
00000007                    *   _TEXT segment
                            *   assume cs:FLAT
00000007                        Program:

00000007                         invoke GridMsg,hGrid1,SetGridSize,14,14
00000007  6A0E              *    push 14
00000009  6A0E              *    push 14
0000000B  FF3500000000      *    push hGrid1
00000011  6A0F              *    push SetGridSize
00000013  E8E8FFFFFF        *    call GridMsg
00000018  83C410            *    add esp, 16

0000001B  C3                    ret
                                end Program
0000001C                    test.asm: 21 lines, 3 passes, 0 ms, 0 warnings, 0 errors


while masm 6.15 produces-

Microsoft (R) Macro Assembler Version 6.15.8803     06/23/17 19:36:47
test.asm      Page 1 - 1


.686
.model Flat, Stdcall
option Casemap :None   ; case sensitive

= 0000000F SetGridSize equ 15

00000000 .data
00000000 0000007B hGrid1 dd 123

00000000 .code
00000000 GridMsg proc SYSCALL Public uses esi edi ebx GridHandle:dword,Request:dword,Parms:vararg
00000000  55    *     push   ebp
00000001  8B EC    *     mov    ebp, esp
00000003  56    *     push   esi
00000004  57    *     push   edi
00000005  53    *     push   ebx
ret
00000006  5B    *     pop    ebx
00000007  5F    *     pop    edi
00000008  5E    *     pop    esi
00000009  C9    *     leave 
0000000A  C3    *     ret    00000h
0000000B GridMsg endp

0000000B .code
0000000B Program:

invoke GridMsg,hGrid1,SetGridSize,14,14
0000000B  6A 0E    *     push   +00000000Eh
0000000D  6A 0E    *     push   +00000000Eh
0000000F  6A 0F    *     push   +00000000Fh
00000011  FF 35 00000000 R *     push   hGrid1
00000017  E8 FFFFFFE4    *     call   GridMsg
0000001C  83 C4 10    *     add    esp, 000000010h

0000001F  C3 ret
end Program


All files in attachment.

I probably could have stripped it down a little more, but you get the idea :)

jj2007

This bug was introduced between 31 March and 4 April 2017.

For testing (modified to make spotting easier in Olly):
.686
.model Flat, Stdcall
option Casemap :None   ; case sensitive

SetGridSize equ 22222222h

.data
hGrid1 dd 12345678h

.code
GridMsg proc SYSCALL Public uses esi edi ebx GridHandle:dword, Request:dword, Parms:vararg
mov eax, GridHandle
ret
GridMsg endp

.code
Program:
int 3
invoke GridMsg, hGrid1, SetGridSize, 33333333h, 44444444h
REPEAT 100
nop
ENDM

ret
end Program


If you replace SYSCALL with C, it produces the desired result.