flat assembler
Message board for the users of flat assembler.
Index
> Windows > Why is MSVCRT not found? |
Author |
|
revolution 22 May 2012, 04:43
MSVCRT is not loaded by default. Before you can get a handle to MSVCRT you have to use LoadLibrary to initialise and bind to it.
|
|||
22 May 2012, 04:43 |
|
NanoBytes 22 May 2012, 16:01
Thank you, it works correctly until I try to put it in a function
Code: format PE console include 'win32ax.inc' Library DD ? proc halt invoke GetProcAddress, [Library], "getchar" stdcall EAX ret endp .code start: invoke AllocConsole invoke GetModuleHandle,"MSVCRT.dll" mov [Library],EAX stdcall halt invoke ExitProcess,0 .end start _________________ He is no fool who gives what he cannot keep to gain what he cannot loose. |
|||
22 May 2012, 16:01 |
|
AsmGuru62 22 May 2012, 16:29
Where is "LoadLibrary"?
Also, what is a calling convention for getchar()? Are you sure it is 'stdcall'? Maybe it is 'cinvoke'? |
|||
22 May 2012, 16:29 |
|
NanoBytes 22 May 2012, 16:50
Never mind, i got it
|
|||
22 May 2012, 16:50 |
|
NanoBytes 22 May 2012, 16:54
Nope, i spoke too soon
Code: format PE console include 'win32ax.inc' Input DD ? Memory DD ? Library DD ? String DD ? proc halt invoke GetProcAddress, [Library], "getchar" stdcall EAX ret endp proc ftoa local Float:QWORD fstp [Float] invoke GetProcAddress, [Library], "sprintf" stdcall EAX,String,"%g",double[Float] cinvoke wsprintf,String,'%s',String ret endp .code start: invoke AllocConsole invoke GetProcessHeap mov [Memory],eax invoke LoadLibrary,"MSVCRT.dll" mov [Library],EAX fld1 mov dword[esp],89 fidiv dword[esp] stdcall ftoa invoke GetProcAddress, [Library], "printf" stdcall EAX,String stdcall halt invoke ExitProcess,0 .end start _________________ He is no fool who gives what he cannot keep to gain what he cannot loose. |
|||
22 May 2012, 16:54 |
|
NanoBytes 22 May 2012, 17:01
Apparently the problem comes from ftoa
|
|||
22 May 2012, 17:01 |
|
typedef 22 May 2012, 17:47
sprintf / printf functions are __cdecl not __stdcall
It's fucking up your frame. String is declared as DWORD and your format specifier is %s which will crash your app, unless your string is less than or equal to 3 bytes the 4th byte being the null terminator. Another thing, Code: fld1 mov dword[esp],89 fidiv dword[esp] stdcall ftoa How certain are you that the value at ESP is yours / unwanted? You might want to push a dummy value then work on that space instead of messing around with the unknown. |
|||
22 May 2012, 17:47 |
|
NanoBytes 22 May 2012, 18:44
how do you use __cdecl, could you give me an eample
|
|||
22 May 2012, 18:44 |
|
AsmGuru62 22 May 2012, 18:48
Use cinvoke instead of stdcall:
Code: ftoa DD 0 ... GetProcAddress, [hDLL], "ftoa" mov [ftoa], eax cinvoke ftoa, ... |
|||
22 May 2012, 18:48 |
|
NanoBytes 22 May 2012, 19:00
See, it works correctly when i use the code directly
Code: ... invoke GetProcAddress, [Library], "printf" mov [printf],EAX cinvoke printf,String invoke GetProcAddress, [Library], "getchar" mov [getchar],EAX cinvoke getchar ... But when i call the function with the exact same code in it it screws up Code: .. proc halt invoke GetProcAddress, [Library], "getchar" mov [getchar],EAX cinvoke getchar ret endp ... invoke GetProcAddress, [Library], "printf" mov [printf],EAX cinvoke printf,String stdcall halt ... I dont know why it wont work when it is used as a function |
|||
22 May 2012, 19:00 |
|
AsmGuru62 22 May 2012, 19:33
Use a debugger and see how this call is made.
|
|||
22 May 2012, 19:33 |
|
typedef 23 May 2012, 06:25
NanoBytes wrote: I dont know why it wont work when it is used as a function Did you change your code to what I told you. |
|||
23 May 2012, 06:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.