News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

USE directive error

Started by 2B||!2B, June 03, 2019, 02:41:19 PM

Previous topic - Next topic

aw27

This is the list of bugs I have found so far. The most important (i.e. require too much creative alternative) is the impossibility to write to the .data section either from 32-bit or from 64-bit (I thought it was only 64-bit but is from both).


OPTION FLAT:1
; Some features of LITERALS:ON do not work with FLAT:1, See examples at the bottom
OPTION LITERALS:ON

USE32 ; USE32 is required to be here, otherwise the stack will be incorrectly restored after INVOKE printf
includelib \masm32\lib\msvcrt.lib
printf proto C :ptr,:vararg

.data
msg db "Received: 0x%.8x%.8x",10,0
somevalue dd 0 ; Can't write to .data either from 32-bit or 64-bit. And if we don't initialize values it believes it is a BSS segment

; Default Prologue and Epilogue do not work properly.
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
X64_Start macro
USE32
push 33h
call @F
@@:
add dword ptr [esp], @F-$
retf
@@:
USE64
endm

X64_End MACRO
USE64
    call   @F
@@:
    mov dword ptr [rsp + 4], 23h
    add dword ptr [rsp], @F-@B
    retf
@@:
USE32
ENDM

.code
main proc C
mov somevalue, 10 ; Writing to .data do not work either in 32-bit or 64-bit
X64_Start
; do something in 64-bit
X64_End
mov eax, 1
mov edx, 2
;invoke printf, CSTR("Received: 0x%.8x%.8x"),edx, eax ; does not work
;printf("Received: 0x%.8x%.8x",edx, eax ) ; does not work
invoke printf, offset msg, edx, eax
        ret
main endp

end

COMMENT #
Build with:
\masm32\bin\uasm64  -c -coff test.asm
\masm32\bin\link /entry:main /MACHINE:X86 /FIXED test.obj
#


johnsa

Bugs in general or if you're trying to use it to create a PE?

If in general I'll add a list to the 2.49 update of fixes.

aw27

#17
I did not explore properly PE creation using the new features of UASM. I made that small example but expanding on it proved difficult when compared with previous inroads - namely here: http://masm32.com/board/index.php?topic=6601.0

Now, I am working on dynamic processor mode switching, namely the Heaven's Gate. As mentioned, we can work with the bugs, but is difficult to explain to others that we are using a memory mapped file to write data because the .data section does not allow writing (allows reading, though).

In the following code I show that exists a possibility to have write access to a data section, if we don't call it .data.  :tongue:, by using indirect addressing  :rolleyes:


OPTION FLAT:1

USE32
.data
somevalue1 dd 0

_DATA2 SEGMENT PARA PUBLIC 'DATA'
somevalue2 dd 0
_DATA2 ENDS

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
X64_Start macro
USE32
push 33h
call @F
@@:
add dword ptr [esp], @F-$
retf
@@:
USE64
endm

X64_End MACRO
USE64
    call   @F
@@:
    mov dword ptr [rsp + 4], 23h
    add dword ptr [rsp], @F-@B
    retf
@@:
USE32
ENDM

USE32
.code
main proc C

; **** WRITING ***
;1- Does not work
;mov somevalue1, 1 ; crash

;2- Does not work
;lea edi, somevalue1
;mov dword ptr [edi], 1 ; crash

;3- Does not work
; mov somevalue2, 1 ; Can not access label

;4- Works
lea edi, somevalue2
mov dword ptr [edi], 1 ; works

; **** READING ***
;1- Works
mov eax, somevalue1

;2- Does not work
;mov eax, somevalue2 ; Can not access label

;3- Works
lea edi, somevalue2
mov eax, [edi]

;4- Works
lea edi, somevalue1
mov eax, [edi]

X64_Start

; **** WRITING ***
;1 - Does not work
;mov somevalue1, 1 ; crashes

;2 - Does not work
;lea rdi, somevalue1
;mov dword ptr [rdi], 1 ; crash

;3 - Does not work
;mov somevalue2, 1 ; Can not access label

;4- Works
lea rdi, somevalue2
mov dword ptr [rdi], 1 ; works

; **** READING ***
;1- Works
mov eax, somevalue1

;2- Does not work
;mov eax, somevalue2 ; Can not access label

;3- Works
lea rdi, somevalue2
mov eax, [rdi]

;4- Works
lea rdi, somevalue1
mov eax, [rdi]

X64_End

ret
main endp

end

COMMENT #
Build with:
\masm32\bin\uasm64  -c -coff test.asm
\masm32\bin\link /entry:main /MACHINE:X86 /FIXED test.obj
#



Something interesting, when we add a second DATA section the .data becomes .rdata (may be this is its true personality)

Dump of file test.exe

File Type: EXECUTABLE IMAGE

  Summary

        1000 .rdata
        1000 _DATA2
        1000 _flat