Finding a function's address in memory

Viewed 1969

For fun I wanted to disassemble my c++ code and I learned how a program call a function, I learned that the byte 0xE8 represent the call instruction followed by 4 bytes which lead to the wanted function first instruction. By using the visual studio Memory viewer the 4 bytes that come after the 0xE8 instruction byte doesn't lead to the function's first instruction aka the function address.

For an example

The printf address is 046FC90h -> What does the "h" mean?

The 4 bytes that I was able to extract are 53 d1 06 00

enter image description here

1 Answers

Hello as your C code is set out like this

void Func() {
    printf("Just a Func");
}

We have a function that we call and it prints Just a Func, To get this functions address we can prefix it with &, Such as &Func

The h you see represents hexadecimal (Base 16) and the number you see can be represented in 3 ways but not all are supported by every compiler, 046FC90h and 0x046FC90 which in decimal means 4652176

But the original question asked was how do we get the function address and that is the & operator.

void Func() {
    printf("Just a Func");
}

int main(int argc, char** args) {
    printf("addr = %i", &Func); // print address to terminal
    return 0;
}
Related