use*_*758 0 string assembly printf
我试图通过调用printf在程序集中打印一个字符串.
我的汇编代码:
mov dword[ebx + 0], '"'
mov dword[ebx + 4], 'h'
mov dword[ebx + 8], 'e'
mov dword[ebx + 12], 'l'
mov dword[ebx + 16], 'l'
mov dword[ebx + 20], 'o'
mov dword[ebx + 24], '"'
mov dword[ebx + 28], 0
push ebx
push formatString
call printf
add esp, 8
...
formatString db '%s', 10, 0
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,它只打印第一个字符 - '"',而不是整个字("你好").
非常感谢
我的装配是生锈的,但那些应该是按字节顺序移动的.你需要一个内存中的字节数组,因为这是printfa期望的%s.内存中的字符串可能是"\0\0\0h\0\0\0e\0\0\0l\0\0\0l\0\0\0o\0\0\0"\0\0\0\0\0\0\0.
mov dword[ebx + 0], '"' ; moves the 32-bit value 0x22000000 to EBX
mov dword[ebx + 4], 'h' ; moves the 32-bit value 0x68000000 to EBX + 4
...
Run Code Online (Sandbox Code Playgroud)
因此,如果ebx包含地址0x123456,那么您将在内存中具有以下内容:
0123456 | 22 00 00 00 68 00 00 00 65 00 00 00 6c 00 00 00 | "...h...e...l... |
0123466 | 6c 00 00 00 6f 00 00 00 22 00 00 00 00 00 00 00 | l...o..."....... |
Run Code Online (Sandbox Code Playgroud)
即使您将0x123456 printf作为地址传递,它也只能在遇到第一个NUL字节之前看到一个字符.以下应该有效:
mov dword[ebx + 0], 577267052 ; 0x2268656c = "hel
mov dword[ebx + 4], 1819222528 ; 0x6c6f2200 = lo"\0
push ebx
push formatString
call printf
add esp, 8
Run Code Online (Sandbox Code Playgroud)
可能有一种更好的方法可以将字节加载到间接地址中,ebx但是我没有比我可以计算更多年来查看汇编.