通过调用其地址的函数在C / C ++内存 [英] Calling a function through its address in memory in c / c++

查看:123
本文介绍了通过调用其地址的函数在C / C ++内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定函数及其在内存地址的原型的知识,才有可能从另一个调用过程中此功能,或者某些件code,它知道什么,但原型和内存地址?如果可能的话,怎么能返回的类型在code处理了?

Given knowledge of the prototype of a function and its address in memory, is it possible to call this function from another process or some piece of code that knows nothing but the prototype and memory address? If possible, how can a returned type be handled back in the code?

推荐答案

在现代操作系统中,每个 进程都有自己的地址空间和地址是只在一个有效处理。如果你想在其他进程中执行code,你要么为注入一个共享库 附上您的程序作为一个调试器

On modern operating systems, each process has its own address space and addresses are only valid within a process. If you want to execute code in some other process, you either have to inject a shared library or attach your program as a debugger.

一旦你在其他程序的地址空间,这code 在任意地址调用一个函数

Once you are in the other program's address space, this code invokes a function at an arbitrary address:

typedef int func(void);
func* f = (func*)0xdeadbeef;
int i = f();

这篇关于通过调用其地址的函数在C / C ++内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆