Modifing a constant in a compiled file.

Hi everyone. I have an aplication compiled. I would like to modify a constant in that application, but the constant is of type char *, so it could have different sizes. So with ifstream and ofstream I can read the file, modify that constant, and write it, but I only can write another constant with the same size. Could I write any size of constant? How could I do it?
Not without some significant work -- it would be simpler just to recompile.
You can always make a smaller constant, but not larger.

Perhaps you could store the value in some form of resource?
You could make it larger - but at the cost of destroying the string constant(s) that come after it.
Still, if those happen to be unimportant, it would be viable.
I want to do a LUA "compiler". I have an executable that executes a chunk of lua, stored in a constant string. So if I want to do another executable with another chunk of code larger, I can't because it will push the rest of data away from their pointers are looking at. And it must be in the same executable, it could not be in a resource.

By the way thank you for the replies.
One way you might consider is creating a new object file containing a DUPLICATE symbol to the one you want to change.

Then modify the symbol name of the original to be different (not colliding with another symbol).

If you link your new object along with all the others then the linker should ignore the original and pick up the new one.

Windows executable resources are stored in the executable. The same thing can easily be done in ELFs (on *nix).

Question, though, why not just invoke the LUA shell directly?
Topic archived. No new replies allowed.