Hakan
Hakan

Reputation: 21

What does this C syntax do: iVar = (*DAT)(param_2,PTR_s);

i am quite new to reverse engineering and using Ghidra. Recently i have decompiled some arduino code. When i was looking at the decompiled code i noticed the following line.

iVar = (*DAT)(param_2,PTR_s);

I have cut of some parts of the variables. But i really wonder what this piece of code is doing. It is supposed to be decompiled c code. I have worked a bit with C, 2 years ago, but i cannot figure out what is happening here. PTR_s is supposed to be a pointer to a string and param_2 is a byte*. Havent figured out what *DAT exactly is.

Upvotes: 0

Views: 1067

Answers (1)

unwind
unwind

Reputation: 399843

DAT is a pointer to a function, which is being (needlessly) deferenced, then called with the two arguments param_2 and PTR_s. The return value is then stored in the variable iVar.

Here is a very short and rather silly sample program in which the above statement appears:

#include <stdio.h>

static int add(int x, int y)
{
    return x + y;
}

int main(void)
{
    int (*DAT)(int, int) = add;
    const int param_2 = 17;
    const int PTR_s = 25;
    const int iVar = (*DAT)(param_2, PTR_s);
    printf("I got %d\n", iVar);
    return 0;
}

It prints the sum of 17 and 25, i.e. the output is:

I got 42

Upvotes: 2

Related Questions