0

How to read a value from an absolute address through C code here someone simply converts the memory address of a string literal into the program. Is this process possible for functions, say I had the address of a specific functions like 'print' (As I have the address, 0x8a537bb543d52a11, how would I convert THAT into the function to run in C++?) for example then how would I go about getting that into a C++ program and calling it from C++, and if it's even possible?

Sorry if this question is stupid haha, I'm new as I'm sure you can tell.

Mini-Yip
  • 1
  • 1
  • 1
    You can cast it to a pointer to a function. More info in a [similar question](https://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work). – c4pQ Jun 27 '22 at 08:41
  • c4pQ how would I go about doing that with just the address, so far from what I've read everything has required a previous definition in the C++ code. I know for example 0x8a537bb543d52a11 that is the memory address, and the function is a void(string), so how would I go about doing something like void (*cppPrint)(string) = 0x8a537bb543d52a11? – Mini-Yip Jun 27 '22 at 08:47
  • 1
    Pretty much, yes. You will have to add another cast to convince the compiler it is okay, which is why the linked question introduces a typedef first. – Botje Jun 27 '22 at 10:25
  • it's not fully about definition. Definition = function signature = return type + name + parameters. Here we need only return type and parameters. It's enough to cast correctly and use it later. – c4pQ Jun 27 '22 at 11:02
  • 1
    I see, I was able to perform the operation but it appears I hadn't realised that the program I was trying to modify used a custom VM at runtime, so I was unable to access their addresses and only print out their addresses in the VM, not in my OS, I'd have to first access the VM to modify it unfortunately, but I was able to access the function without errors which is good! Never programmed in C++ but it seems cool so I'll start, anyway thanks for the help man. Appreciate it. – Mini-Yip Jun 27 '22 at 11:05

0 Answers0