Change few parameters in PE exeutable

L

liveline

I want create small Win32 program which is a standalone PE executable, no
GUI-less, just does it job and exit when finished. These program can have a
few different parameters(arguments) which should be defined in program code.
Main functionality of program does not change, only this few arguments. I
don't want recompile program code every time when I need to change these
arguments. Instead, I want to make an EXE builder where I will specify these
arguments, then builder will build exe with required parameters. How to make
this better?
 
J

Jonathan Lee

Instead, I want to make an EXE builder where I will specify these
arguments, then builder will build exe with required parameters.

It's called a compiler.

Though I suspect you want to go through the EXE and change every
instance of parameter v from 5 to 10, say. The possibility of v
being inlined in the executable makes this a nightmare if not
outright impossible.
How to make this better?

Spend the two minutes to recompile your small win32 app. If these
are program wide constants they are surely specified in a header,
passed as defines to your compiler, or are otherwise neatly
together in one place. It should be trivial to change them if you
have good programming practices.

--Jonathan

PS If your question is a disguise for "how to I crack
copy protection", don't bother. We aren't interested.
 
L

liveline

Instead, I want to make an EXE builder where I will specify these
arguments, then builder will build exe with required parameters.

It's called a compiler.

Though I suspect you want to go through the EXE and change every
instance of parameter v from 5 to 10, say. The possibility of v
being inlined in the executable makes this a nightmare if not
outright impossible.
How to make this better?

Spend the two minutes to recompile your small win32 app. If these
are program wide constants they are surely specified in a header,
passed as defines to your compiler, or are otherwise neatly
together in one place. It should be trivial to change them if you
have good programming practices.

--Jonathan

PS If your question is a disguise for "how to I crack
copy protection", don't bother. We aren't interested.
--------

No, it what I don't want to do this at all. Do you think to re-compile the
code every time is better way? I dont think so. I know many programs that
use my approach. As I said, I need to change just three parameters (path,
file type, days). Sure, this can be done without recompiling full source
code. Especially if this need to do end user. I know probably I can to
change this in Resource section of PE. My question was how to make this
correctly, set size, where, etc
 
K

Kai-Uwe Bux

liveline said:
I want create small Win32 program which is a standalone PE executable, no
GUI-less, just does it job and exit when finished. These program can have
a few different parameters(arguments) which should be defined in program
code. Main functionality of program does not change, only this few
arguments. I don't want recompile program code every time when I need to
change these arguments. Instead, I want to make an EXE builder where I
will specify these arguments, then builder will build exe with required
parameters. How to make this better?

Wow, that sounds rather wicked. As a first approximation to this EXE
builder, you could have a script rig the parameters in the source code and
call the compiler automatically. However, that is still wicked.

I would rewrite the program so that it accepts those arguments via switches
from the command line. That entails, of course, turning them from constant
expressions in the program code into variables. Usually that is a problem
only in a few places where the language requires a constant expression
(e.g., you might have to turn built-in arrays into std::vector).


Best

Kai-Uwe Bux
 
A

Alf P. Steinbach

* liveline:
I want create small Win32 program which is a standalone PE executable, no
GUI-less, just does it job and exit when finished. These program can have a
few different parameters(arguments) which should be defined in program code.
Main functionality of program does not change, only this few arguments. I
don't want recompile program code every time when I need to change these
arguments. Instead, I want to make an EXE builder where I will specify these
arguments, then builder will build exe with required parameters. How to make
this better?

Nowadays the line between incompetence, malfeasance, trolling, young age and
mental retardation/illness is so blurred that it's near impossible to tell them
apart; on the internet nobody can see you that you're a kid, and so you risk
pretty harsh responses when you don't tell that up front.

But anyways, as an alternative to recompiling or re-linking (check out Windows'
support for "resources" in executables, it's off-topic here but see MSDN) you
can simply use some external initialization settings; it can be as simple as a
shortcut that invokes your program or as complicated as a full-fledged XML-based
ini file scheme.

Please also note that this group isn't really relevant to your question. It's a
good idea to read a group's FAQ before posting. Thank you.


Cheers & hth.,

- Alf
 
Ö

Öö Tiib

No, it what I don't want to do this at all. Do you think to re-compile the
code every time is better way? I dont think so. I know many programs that
use my approach. As I said, I need to change just three parameters (path,
file type, days). Sure, this can be done without recompiling full source
code. Especially if this need to do end user. I know probably I can to
change this in Resource section of PE. My question was how to make this
correctly, set size, where, etc

Tons of options:
* Write a configuration file.
http://en.wikipedia.org/wiki/Configuration_file
* Give your parameters from command line.
http://en.wikipedia.org/wiki/Command-line_interface
* Use environment variables.
http://en.wikipedia.org/wiki/Environment_variable
* etc.

All programs do something of it. No one hacks with binary executable
code prior to running it.
 
J

Jonathan Lee

Do you think to re-compile the code every time is better way?

Yes. I think with a Makefile or similar build system that changing
a compile time constant should be fairly trivial.
As I said, I need to change just three parameters (path,
file type, days).

Honestly, if changing three variables is affecting your entire source
tree, I would reconsider your approach.
I know probably I can to change this in Resource section of
PE. My question was how to make this correctly, set size,
where, etc

The PE file format is fairly well documented. It isn't specified
by C++, however. Keep in mind, too, what I originally said about
inlined values. Consider your "days" parameter. Presumably this
is an integer and unchanging through the source. When the source
was compiled, the compiler could have chosen to substitute
the value in place of the variable address. So if days was 5, it
would just put 5 into the machine code instead of referring
directly to "days". You'd have to go through and change all the
5s. But then how do you know which 5s came from "days" and not
some other variable? Even if debug info were present I can't
imagine wading through all that to avoid recompilation.

--Jonathan
 
L

liveline

Öö Tiib said:
Tons of options:
* Write a configuration file.
http://en.wikipedia.org/wiki/Configuration_file
* Give your parameters from command line.
http://en.wikipedia.org/wiki/Command-line_interface
* Use environment variables.
http://en.wikipedia.org/wiki/Environment_variable
* etc.

All programs do something of it. No one hacks with binary executable
code prior to running it.
----------

Öö Tiib, your advice is bullshit and crap. Have you ever created any worth
program yourself?

However, I don't expected someone give me good advice here..
But not this bullshit and crap..
 
L

liveline

Kai-Uwe Bux said:
Wow, that sounds rather wicked. As a first approximation to this EXE
builder, you could have a script rig the parameters in the source code and
call the compiler automatically. However, that is still wicked.

I would rewrite the program so that it accepts those arguments via switches
from the command line. That entails, of course, turning them from constant
expressions in the program code into variables. Usually that is a problem
only in a few places where the language requires a constant expression
(e.g., you might have to turn built-in arrays into std::vector).


Best

Kai-Uwe Bux ----------

rewrite the program so that it accepts those arguments via switches
from the command line.

This is completely Bullshit and Crap.
 
L

liveline

Alf P. Steinbach said:
* liveline:

Nowadays the line between incompetence, malfeasance, trolling, young age and
mental retardation/illness is so blurred that it's near impossible to tell them
apart; on the internet nobody can see you that you're a kid, and so you risk
pretty harsh responses when you don't tell that up front.

But anyways, as an alternative to recompiling or re-linking (check out Windows'
support for "resources" in executables, it's off-topic here but see MSDN) you
can simply use some external initialization settings; it can be as simple as a
shortcut that invokes your program or as complicated as a full-fledged XML-based
ini file scheme.

Please also note that this group isn't really relevant to your question. It's a
good idea to read a group's FAQ before posting. Thank you.


Cheers & hth.,

- Alf
=========

I am sorry, but this your "advice" is entirely Bullshit and Crap. Yes,
Bullshit and Crap
 
B

Brian

This is completely Bullshit and Crap.

I encourage people to refrain from swearing in public.

Recently I was having a problem with this line:

name_.swap(lil_string(buf)); // if I remember right.

I dug around in the archives and Kai-Uwe had a post
that mentioned it would work to write it like this:

lil_string(buf).swap(name_);


Based on that and reading other posts he wrote, I think he
usually has good advice.


Brian Wood
http://webEbenezer.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top