flat assembler
Message board for the users of flat assembler.
Index
> High Level Languages > Using libc in assembly |
Author |
|
vid 15 Dec 2006, 16:02
This example demonstrates how to write portable 32bit app in assembly, by using libc (standard C library).
|
|||||||||||
15 Dec 2006, 16:02 |
|
ChaperonNoir 03 Jan 2008, 03:33
Learned quite a few things here about FASM, thank you.
Nice example code... |
|||
03 Jan 2008, 03:33 |
|
revolution 11 Jun 2012, 08:23
sleepsleep wrote: does it means, we need to convert every those functions inside KERNEL.INC file to |
|||
11 Jun 2012, 08:23 |
|
sleepsleep 11 Jun 2012, 09:35
i was thinking about assemble asm file to obj and do static link with windows lib or mingw .a file.
so, how to use invoke windowsapi inside the MS COFF file? |
|||
11 Jun 2012, 09:35 |
|
revolution 11 Jun 2012, 09:46
Did you check the "examples" folder?
Code: ; example of making Win32 COFF object file format MS COFF extrn '__imp__MessageBoxA@16' as MessageBox:dword section '.text' code readable executable public _demo _demo: push 0 push _caption push _message push 0 call [MessageBox] ret section '.data' data readable writeable _caption db 'Win32 assembly',0 _message db 'Coffee time!',0 |
|||
11 Jun 2012, 09:46 |
|
sleepsleep 11 Jun 2012, 10:04
hi, revolution,
but where could i get the Code: extrn '__imp__MessageBoxA@16' as MessageBox:dword ? (does it means i need to convert everything to extrn with param count? and how could i use include 'win32ax.inc' ? please forgive me for my confusion. |
|||
11 Jun 2012, 10:04 |
|
revolution 11 Jun 2012, 10:14
sleepsleep wrote: but where could i get the Note that each library is different. Some will have different names. You can't simply assume that all the libraries out there for use with HLL's are the same. Last edited by revolution on 11 Jun 2012, 10:40; edited 1 time in total |
|||
11 Jun 2012, 10:14 |
|
sleepsleep 11 Jun 2012, 10:32
so, what tool could help me to extract the external labels name from .lib file and .a file?
|
|||
11 Jun 2012, 10:32 |
|
sleepsleep 11 Jun 2012, 11:05
ok, i got some clue after using google,
i could use nm.exe (mingw32) tools to extract the .a information but the output need more process. nm -g libkernel32.a Code: dchdt.o: 00000000 I __libkernel32_a_iname dchdh.o: 00000000 I __head_libkernel32_a U __libkernel32_a_iname dchds01308.o: U __head_libkernel32_a 00000000 I __imp__lstrlenW@4 00000000 T _lstrlenW@4 dchds01307.o: U __head_libkernel32_a 00000000 I __imp__lstrlenA@4 00000000 T _lstrlenA@4 dchds01306.o: U __head_libkernel32_a 00000000 I __imp__lstrlen@4 00000000 T _lstrlen@4 dchds01305.o: U __head_libkernel32_a 00000000 I __imp__lstrcpynW@12 00000000 T _lstrcpynW@12 |
|||
11 Jun 2012, 11:05 |
|
sleepsleep 11 Jun 2012, 12:21
idk where the faults.
i tried to link the example file but to no avail. Code: D:\Fasm\EXAMPLES\MSCOFF>ld -v -b pe-i386 -e "_demo" -L D:/MinGW/lib -lcrtdll -lm svcrt -lkernel32 -luser32 MSCOFF.OBJ -o MSCOFF.EXE GNU ld (GNU Binutils) 2.22 MSCOFF.OBJ.text+0x10): undefined reference to `_imp__MessageBoxA@16' notice the shorten one underscore `_imp__MessageBoxA@16' compare the one we import extrn '__imp__MessageBoxA@16' as MessageBox:dword |
|||
11 Jun 2012, 12:21 |
|
revolution 11 Jun 2012, 12:33
Try the shorter version: _MessageBoxA@16
|
|||
11 Jun 2012, 12:33 |
|
sleepsleep 11 Jun 2012, 12:41
no luck still
Code: D:\Fasm\EXAMPLES\MSCOFF>fasm MSCOFF.ASM flat assembler version 1.70.01 (1572863 kilobytes memory) 3 passes, 271 bytes. D:\Fasm\EXAMPLES\MSCOFF>ld -v -b pe-i386 -e "_demo" -L D:/MinGW/lib -lkernel32 -luser32 MSCOFF.OBJ -o MSCOFF.EXE GNU ld (GNU Binutils) 2.22 MSCOFF.OBJ.text+0x10): undefined reference to `MessageBoxA@16' i tried the following, maybe the way how to use ld.exe is the culprit, but afaik, i am using it correctly. Code: #include <windows.h> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nShowCmd) { MessageBox (NULL, "Hello World!", "hello", MB_OK | MB_ICONINFORMATION); return 0; } gcc a.c resulted functional windows program but if i gcc -c a.c then i do D:\Fasm\EXAMPLES\MSCOFF>ld -v -b pe-i386 -L D:/MinGW/lib -lkernel32 -luser32 A.O -o A.EXE GNU ld (GNU Binutils) 2.22 A.O:a.c.text+0x26): undefined reference to `MessageBoxA@16' it still results same error, anyone know how to use this ld.exe ? |
|||
11 Jun 2012, 12:41 |
|
sleepsleep 12 Jun 2012, 16:36
i figure out what the problem.
it just kinda stupid, damn it, i wanna blame the ld.exe but i guess whatever. Code: D:\Fasm\EXAMPLES\MSCOFF>ld --help Usage: ld [options] file... Options: the usage shows, ld [options] then only file... but it doesn't seem so. Code: ld -v --subsystem windows -L D:/MinGW/lib -luser32 a.o will result a.o:a.c.text+0x26): undefined reference to `MessageBoxA@16' but Code: ld -v --subsystem windows a.o -L D:/MinGW/lib -luser32 will works the --subsystem windows just to prevent the console pop up. i find it weird, but who am i to say anything. btw, the correct import is Code: extrn '__imp__MessageBoxA@16' as MessageBox:dword |
|||
12 Jun 2012, 16:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.