gpt4 book ai didi

c - 如何在没有调用或跳转的情况下调用ASM中的函数?

转载 作者:太空宇宙 更新时间:2023-11-04 01:01:28 25 4
gpt4 key购买 nike

我目前正在尝试调用这个名为“super_secret_function”的函数,它在文件 main.c 的 main 之外定义。我正在使用 ASM,无法使用 jmp 或 call 来访问这个“super_secret_function”。 main 内部是一个名为 stack_hack 的函数,我可以通过该函数更改地址以达到 super secret 函数。

使用 GDB,我已经能够确定“super_secret_function”的地址,并通过从函数中跳转到它来成功调用它。如何操作指针的返回值返回到该地址?

.globl stack_hack

stack_hack:
pushq %rbp # push the base pointer on the stack
movq %rsp, %rbp # move the previous stack pointer to the new base poi

##MyCode
movq $0x00000000004005b4, %rbp
jmp *%rbp
##EndMyCode

movq %rbp, %rsp # move the stack pointer to the base pointer
popq %rbp # pop the base pointer and load it into %rbp
ret # pop the instruction pointer into %rip

最佳答案

因为这听起来像是一项家庭作业,所以我不会给你一个确切的答案,但我会尽力为你指明正确的方向。

您说您不能使用jmpcall,但是函数末尾的ret 也会更新程序计数器。您如何影响它将程序计数器更新到的值?

关于c - 如何在没有调用或跳转的情况下调用ASM中的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37265426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com