News:

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

Main Menu

undefined symbol : crt__itow_s

Started by laomms, February 01, 2023, 01:53:17 PM

Previous topic - Next topic

laomms


                push    0Ah             ; Radix
                push    2               ; fSizeInWords
                lea     eax, [ebp+DstBuf]
                and     dword ptr [ebp+DstBuf], 0
                push    eax             ; DstBuf
                push    7
                pop     ecx
                xor     edx, edx
                mov     eax, ebx
                div     ecx
                push    edx             ; Val
                call    crt__itow_s


how to  pass the _itow_s function in masm32 ?

hutch--

I would have a look here for reference.

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/itoa-s-itow-s?view=msvc-170

It is a C runtime function and you can load it with LoadLibrary() and GetProcAddress().

Unless you have good reason to use the security enhancements, I would use the _itoa function as it is a lot simpler to use.

Vortex

Hello laomms,

You can create your own import library to use that function :

msvcrt.def :

LIBRARY msvcrt
EXPORTS
"_itow_s"
"wprintf"


itow_s.asm :

include     \masm32\include\masm32rt.inc
includelib  msvcrt.lib

_itow_s     PROTO C :DWORD,:DWORD,:DWORD,:DWORD

.data

.data?

buffer      db 8 dup(?)

.code

start:


    invoke  _itow_s,1000,ADDR buffer,8,10

    invoke  crt_wprintf,ADDR buffer

    invoke  ExitProcess,0

END start


Build.bat :

\masm32\bin\polib.exe /OUT:msvcrt.lib /DEF:msvcrt.def /MACHINE:x86
\masm32\bin\ml /c /coff itow_s.asm
\masm32\bin\polink /SUBSYSTEM:CONSOLE itow_s.obj msvcrt.lib

laomms

finally, I changed to the LoadLibrary method

LibName       db "ntdll.dll",0
ProcName      db "_itow_s",0

                ...
                push    0Ah             ; Radix
                push    2               ; fSizeInWords
                lea     eax, [ebp+DstBuf]
                and     dword ptr [ebp+DstBuf], 0
                push    eax             ; DstBuf
                push    7
                pop     ecx
                xor     edx, edx
                mov     eax, ebx
                div     ecx
                push    edx             ; Val
                ;call    _itow_s
                invoke LoadLibrary,ADDR LibName
                invoke GetProcAddress,eax,ADDR ProcName
                call    eax

jj2007

Quote from: laomms on February 02, 2023, 03:37:29 PM
                lea     eax, [ebp+DstBuf]
                and     dword ptr [ebp+DstBuf], 0
                push    eax             ; DstBuf

Dumb compilers: and dword ptr [eax], 0 would be equally fast but 4 bytes shorter.

So you are re-assembling a disassembled program. Nice. What's the purpose of the exercise?

Vortex

Hi laomms,

Any specific reason to prefer ntdll.dll over msvcrt.dll to import that function?