fuz*_*uzz 13 windows assembly mingw nasm
我正在使用nasm来编译以下程序集.但是,代码在Windows下的控制台中崩溃.
C:\> nasm -f win32 test.asm -o test.o
C:\> ld test.o -o test.exe
section .data
msg db 'Hello world!', 0AH
len equ $-msg
section .text
global _WinMain@16
_WinMain@16:
mov edx, len
mov ecx, msg
mov ebx, 1
mov eax, 4
int 80h
mov ebx, 0
mov eax, 1
int 80h
Run Code Online (Sandbox Code Playgroud)
根据这篇文章.该main功能在Windows下不可用,必须替换为WinMain.
因此,如果您的入口点是_start或main,则应将其更改为_WinMain@16并将ret过程结束时更改为ret 16:
我的工作范例:
section .text
global _WinMain@16
_WinMain@16:
mov eax, 0
ret 16
Run Code Online (Sandbox Code Playgroud)
Gun*_*ner 30
最大的问题是你试图在Windows上使用Linux interupts!int 80不适用于Windows.
我们正在使用汇编,因此您的入口点可以是您想要的任何标签.ld寻找的标准入口点是_start,如果你想使用另一个标签,你需要告诉ld使用-e选项所以如果你想要你的开始标签是主要的,那么你需要
global main
ld -e main test.o -o test.exe
Run Code Online (Sandbox Code Playgroud)
如果您打算在Windows上使用NASM,我建议您使用GoLink作为链接器.这是一个简单的Windows控制台应用程序:
STD_OUTPUT_HANDLE equ -11
NULL equ 0
global GobleyGook
extern ExitProcess, GetStdHandle, WriteConsoleA
section .data
msg db "Hello World!", 13, 10, 0
msg.len equ $ - msg
section .bss
dummy resd 1
section .text
GobleyGook:
push STD_OUTPUT_HANDLE
call GetStdHandle
push NULL
push dummy
push msg.len
push msg
push eax
call WriteConsoleA
push NULL
call ExitProcess
Run Code Online (Sandbox Code Playgroud)
生成文件:
hello: hello.obj
GoLink.exe /console /entry GobleyGook hello.obj kernel32.dll
hello.obj: hello.asm
nasm -f win32 hello.asm -o hello.obj
Run Code Online (Sandbox Code Playgroud)
虽然,同样的程序可能会在Linux上的WINE中运行,就像魅力一样.:)
WINE不会阻止在Windows PE二进制文件中使用Linux系统调用; 机器指令本机运行,WINE仅提供DLL函数.