![](/img/trans.png)
[英]x86 assembly - how to use Windows API _WriteConsole@4 - masm32 syntax
[英]x86 assembly (masm32) - Can I use int 21h on windows xp to print things?
只是想知道,关于我的帖子Alternatives to built-in Macros ,是否可以通过使用int 21h windows API 来避免使用StdOut宏? 如:
.data
msg dd 'This will be displayed'
;original macro usage:
invoke StdOut, addr msg
;what I want to know will work
push msg
int 21h ; If this does what I think it does, it should print msg
是否存在这样的东西(如使用 int 21h 打印东西),或者是否存在类似的东西,但不完全是 int 21h。 或者我完全错了。
有人可以为我澄清这一点吗?
谢谢,
程序
中断 21h 是MS-DOS函数的入口点。
例如,要在 stdout 上打印某些内容,您必须:
mov ah, 09h ; Required ms-dos function
mov dx, msg ; Address of the text to print
int 21h ; Call the MS-DOS API entry-point
字符串必须以 '$' 字符结尾。
但:
然后......是的,你不能用它来打印消息,没有类似的东西存在:你必须调用操作系统函数来打印你的消息,并且它们不能通过中断获得。
DOS 中断不能在 Windows 的保护模式下使用。
您可以使用WriteFile
Win32 API 函数写入控制台,或改用 MASM 宏。
其他说你不能在 Windows 中使用中断的答案是完全错误的。 如果你真的想要,你可以(不推荐)。 至少在 32 位 x86 Windows 上,有基于int 2Eh
的系统调用接口。 有关 x86 和 x86_64 Windows 上的系统调用机制的一些讨论,请参见此页面。
这是一个非常简单的程序示例(使用 FASM 编译),该程序使用int 0x2e
在 Windows 7 上立即退出(并在大多数其他版本上崩溃):
format PE
NtTerminateProcess_Wind7=0x172
entry $
; First call terminates all threads except caller thread, see for details:
; http://www.rohitab.com/discuss/topic/41523-windows-process-termination/
mov eax, NtTerminateProcess_Wind7
mov edx, terminateParams
int 0x2e
; Second call terminates current process
mov eax, NtTerminateProcess_Wind7
mov edx, terminateParams
int 0x2e
ud2 ; crash if we failed to terminate
terminateParams:
dd 0, 0 ; processHandle, exitStatus
但请注意,这是一种不受支持的 Windows 使用方式:系统调用号经常变化,通常不能依赖。 在此页面上,您可以看到例如 Windows XP 上的NtCreateFile
调用系统调用号0x25
,而在 Windows Server 2003 上,此编号对应于NtCreateEvent
,而在 Vista 上它是NtAlpcRevokeSecurityContext
。
支持(尽管没有太多记录)进行系统调用的方式是通过本机 API库ntdll.dll
的函数。
但即使你使用 Native API,“打印东西”仍然非常依赖于版本。 也就是说,如果您重定向到文件,则必须使用NtWriteFile
,但是在写入真正的控制台窗口时,您必须使用 LPC ,其中目标进程取决于 Windows 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.