Place a variable in source code and modify later the compiled binary


I currently searching the best solution to solve my "request". I use a struct in the source like:

In the header:

struct my_struct
  unsigned int val;
  char *name;

in the c files:

struct my_struct variable =
  .val = 0xffffffff
  .name = "config_variable_name",

Now after compile I have a binary and I can find the string "config_variable_name" in there. Now another tool is using this binary and like to modfiy this .val. So the tool search also the binary for the string "config_variable_name" and when found it place the new unsigned int to the found position - 4 == location of .val.

This works without any issue. Is there a better way to do such a thing? I have more than one variables what are getting modified from the tool, so each variable does need a own "identifier" that the tool can locate the correct position in the binary.

Maybe a pattern instead of char *name is better? Like a unsingend int 0x38372829 or something else? But this have to be unique in the binary...

asked on Stack Overflow Jan 17, 2020 by Portisch

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0