繁体   English   中英

如何将汇编代码修补到exe文件的末尾

[英]How to patch assembly code to the end of exe file

我正在尝试将 x86 程序集中编写的代码修补到作为参数给出的文件的末尾。

具体在我的代码中:

function code_start将消息打印到标准输出。

function code_end的目的是将代码从code_start修补到作为 C 程序的参数给出的文件名的末尾。

我的问题是:

我应该填写什么(我放问号的地方)或更改 function code_end以便它按我的意愿工作。 我的想法是通过 append 系统调用打开文件,编写 function code_start ,关闭文件。

重要提示:不使用任何导入函数,仅使用系统调用

代码片段:

code_start:

    pushad
    mov eax,4   ;system call number (sys_write)            
    mov ebx,1   ;file descriptor (stdout)
    mov ecx, msg    ;message to write
    mov edx, len    ;message length   
    int 0x80    ;call kernel
    popad
    ret

code_end:
    push ebp             ; Save caller state
    mov ebp, esp
    sub esp, 4          ; Leave space for local var on stack
    pushad                  ; Save some more caller state

    mov eax,4   ;system call number (sys_write)          
    mov ebx, [ebp+8]    ; Copy function args to registers: leftmost -> fileName  
    mov ecx, 1024   ;system call number O_APPEND
    int 0x80    ;call kernel

    ;eax has the pointer to end of file

    mov ebx, eax ;move the file pointer to second argument
    mov eax, 4 ;move the code of SYS_WRITE 
    mov ecx, ?? ;from where to write 
    mov edx, ?? ;how much to write
    int 0x80    ;call kernel

    mov eax,6   ;system call number (SYS_CLOSE)          
    mov ebx, [ebp+8]    ; Copy function args to registers: leftmost -> fileName 
    int 0x80    ;call kernel

    popad
    add esp, 4
    pop     ebp ; Restore caller state
    ret

首先而不是: mov ecx 1024它应该是mov ecx, 1025以便打开它进行写入和追加。 第二个而不是问号应该是: mov ecx, code_start mov edx code_end sub edx, code_start

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM