M
M
mIka012021-12-06 17:06:36
C++ / C#
mIka01, 2021-12-06 17:06:36

Self-modifying c++ code changing variable values ​​for new run?

I need to write a simple application which will store some constant variables. However, as a result of program execution, they can be changed for the next run.

How can I change the value of a variable so that the next time the program is run, it will already be changed?

Using third-party files (like txt) to store anything is forbidden for me.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vasily Melnikov, 2021-12-06
@BacCM

I would say no way. If any third-party storage is prohibited, files, registry, cloud, etc.
In theory, you can fix the executable binary, but this is platform-dependent, and almost nowhere can be done, except for very simple operating systems.
Also, it has nothing to do with benefits.

A
Adamos, 2021-12-06
@Adamos

You can leave the plane and, for example, enter the necessary changing data .... directly into the program file name. Renaming it the way you need and getting this information in the standard way from the program;)

W
Wataru, 2021-12-06
@wataru

On Windows, this can only be done as two executable files. The first one, the outer file, just starts the main second file and waits for it to complete. When the called file is finished, the one who launched it can edit the executable. Here you need to deal with the format of executable files and then you just need to rewrite the bytes in a certain position in the section .rdataor whatever will be there.
But the user can always run the second file directly. This problem can still be somehow dealt with by passing some secret data to the second program (based on the known state of these changing variables). And the main program at startup should check them. Or you can view information about the parent process. And the user can kill all your executable files in the task manager at the same time and the next launch will be with the same data.
In Linux, you can edit the executable file while it is running - so it's easier there. To deal with sigkill, you should edit the file at the very beginning after launch.

E
Evgeny Petryaev, 2021-12-07
@Gremlin92

Try to take the value of the variable from the database, at the end, for example, do update variable ++, run it and the variable has already been changed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question