Author Topic: undefined symbol : crt__itow_s  (Read 390 times)

laomms

  • Regular Member
  • *
  • Posts: 4
undefined symbol : crt__itow_s
« on: February 01, 2023, 01:53:17 PM »
Code: [Select]
                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--

  • Administrator
  • Member
  • ******
  • Posts: 10573
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: undefined symbol : crt__itow_s
« Reply #1 on: February 01, 2023, 03:48:20 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2768
Re: undefined symbol : crt__itow_s
« Reply #2 on: February 02, 2023, 04:47:56 AM »
Hello laomms,

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

msvcrt.def :

Code: [Select]
LIBRARY msvcrt
EXPORTS
"_itow_s"
"wprintf"

itow_s.asm :

Code: [Select]
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 :

Code: [Select]
\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

  • Regular Member
  • *
  • Posts: 4
Re: undefined symbol : crt__itow_s
« Reply #3 on: February 02, 2023, 03:37:29 PM »
finally, I changed to the LoadLibrary method

Code: [Select]
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

  • Member
  • *****
  • Posts: 13873
  • Assembly is fun ;-)
    • MasmBasic
Re: undefined symbol : crt__itow_s
« Reply #4 on: February 02, 2023, 08:35:33 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

  • Member
  • *****
  • Posts: 2768
Re: undefined symbol : crt__itow_s
« Reply #5 on: February 03, 2023, 08:03:56 AM »
Hi laomms,

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