![](/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.