News:

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

Main Menu

Unicode string alignment bug

Started by Yuri, December 28, 2013, 04:34:30 AM

Previous topic - Next topic

Yuri

If a literal Unicode string is passed to a function, GoAsm may place it at an odd address. Some APIs apparently don't like this. RegSetValueExW returns ERROR_NOACCESS because of it (tested on Win 7 and 8.1).

dedndave

unicode registry functions require 16-alignment
i think raymond chen wrote a page on that

Yuri

If he meant 16 bits, then it's exactly what I found out. If 16 bytes, then I don't know. Those that I have used work well with 2-byte alignment.

dedndave

my mistake - it does say 16-bit, not 16-byte

in the Community Additions section, Raymond Chen makes a comment...

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724911%28v=vs.85%29.aspx

Yuri

Quote
[Raymond Chen (MSFT)] Alignment requirements are implied by the data type LPCWSTR. If unaligned data were permitted, then it would have been declared as UNALIGNED. This requirement applies to all functions which take Unicode strings, not just registry functions.

Well, at least MessageBoxW worked fine for the misaligned string, which added to my confusion.

dedndave

i wrote some UNICODE string functions that 16-byte aligned strings - lol
now, i have to go back and update them   :(

wjr

GoAsm does this alignment for the 64-bit case. Removing two lines of code looks like a quick fix for the 32-bit case, which will be in version 0.58.0.5 relatively soon. I just want to make sure that there are no other repercussions...

Yuri

Thanks, Wayne, but that doesn't work if you make the strings Unicode by saving the source as UTF-8 or UTF-16.


D:\PROG\TEST\GoAsm>stralign32
Error: 998
D:\PROG\TEST\GoAsm>stralign64
Error: 998



#define UNICODE
#define LINKFILES
#define LINKVCRT
#include <windows.h>

DATA SECTION

hKey    PTR 0
a       DB 0

CODE SECTION

Start:
    invoke RegCreateKeyEx, HKEY_CURRENT_USER, "TestKey", 0, NULL, 0, \
                            KEY_WRITE, NULL, addr hKey, NULL
    cmp eax,ERROR_SUCCESS
    jne >.error

    invoke printf, A"Success"
#if x86
    add esp,4
#endif
.exit
    ret
.error
    invoke printf, A"Error: %d", eax
#if x86
    add esp,8
#endif
    jmp .exit

wjr

So close, I tested with the string overrides and the STRINGS UNICODE directive, but I missed that possibility, so a few more lines get added back in. GoAsm version 0.58.0.6 on its way soon...

Yuri

Yes, 0.58.0.6 fixed it. Thanks! :icon_cool: