Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-08

Editing resource of executable

23 messages · 10 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Krzysztof

Hi,

I have some problem. Example:

I created some exec using free pascal and lazarus. It is placed on http server. User in webbrowser click download, and server should attach link from where it is clicked into this exec. So when user run downloaded exec, this exec can read this link. The idea is that everything is in one file (and must be). My question is, exists any commandline tool which can edit executable file for edit some resource (like ResEdit or Restorator for Windows) which can be used by http server? By resource I mean some const (or resourcestring section, free pascal binary can replace it in runtime, can some tool do this same outside?). So main problem is in server side. Finally we can use free pascal compiler and compile modified source by server, but this solution we use when everything fails (admins, restrictions etc.). I need this only for windows (for now), so I'm considering some commandline installer makers like InnoSetup or something. Any idea?

Regards

Reply by email

Mark Morgan Lloyd
to Krzysztof
Krzysztof wrote 18 lines
Hi, I have some problem. Example: I created some exec using free pascal and lazarus. It is placed on http server. User in webbrowser click download, and server should attach link from where it is clicked into this exec. So when user run downloaded exec, this exec can read this link. The idea is that everything is in one file (and must be). My question is, exists any commandline tool which can edit executable file for edit some resource (like ResEdit or Restorator for Windows) which can be used by http server? By resource I mean some const (or resourcestring section, free pascal binary can replace it in runtime, can some tool do this same outside?). So main problem is in server side. Finally we can use free pascal compiler and compile modified source by server, but this solution we use when everything fails (admins, restrictions etc.). I need this only for windows (for now), so I'm considering some commandline installer makers like InnoSetup or something. Any idea?

Let's see if we can get this straight. What you're basically looking for is something which can take one or more of the environment variables (or equivalent) that the web server knows about, and use it to "brand" the executable.

This is probably going to be very much specific to the version of Windows that the client is running: it used to be possible to simply append data to an executable since there was an unambiguous file length in the header, but this obviously won't work if the file is checksummed or signed.

Unless you're doing it by re-linking the program when sending it to the client, this is probably outside the remit of FPC and you'd be better off looking for non-specific tools.

In any case, you've obviously got the problem of copying the unbranded binary to a working area before manipulating it, unless you can serialise the CGI or whatever you're using.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Reinier Olislagers
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 16 lines
Krzysztof wrote: everything is in one file (and must be). My question is, exists any > commandline tool which can edit executable file for edit some resource > (like ResEdit or Restorator for Windows) which can be used by http > server? Let's see if we can get this straight. What you're basically looking for is something which can take one or more of the environment variables (or equivalent) that the web server knows about, and use it to "brand" the executable. This is probably going to be very much specific to the version of Windows that the client is running: it used to be possible to simply append data to an executable since there was an unambiguous file length in the header, but this obviously won't work if the file is checksummed or signed.

For my CheckRide remote control/end user screen sharing program, I wanted to be able to let admins create a personalized copy that connects to their own server, so I had the same problem.

Although FPC does provide functions to modify resources on Windows, I didn't have much luck with it. Perhaps the situation has improved since I last tried, it - haven't looked.

I turned to what Mark suggested: just slapping on some (zipped) extra data after the exe. And yes, this messes with signing the executable etc.

If you want to investigate this path, have a look at https://bitbucket.org/reiniero/checkride/src
Source
CheckRideResourceZipper.lpi (which is used to create the "unbranded", standard resources in the build process)
CheckRideHelper.lpi (which demonstrates stamping/branding the resources) CheckRide.lpi (which demonstrates unpacking and using the resources) they all use the poormansresource.pas file

Reply by email

Jonas Maebe
to Krzysztof

Krzysztof wrote on Thu, 30 Aug 2012:

Maybe I can write own commandline tool for server admins, which can edit resource of another (written in FPC too) executable?

I think the easiest is to add the data at the end of the binary, as has been suggested earlier. It breaks signed applications, but so does changing a resource, so there's no difference as far as that is concerned. And adding/reading data at the end of the binary is much easier than changing a resource.

Jonas

Reply by email

Jonas Maebe
to Krzysztof

Krzysztof wrote on Thu, 30 Aug 2012:

Hmm sounds good. So I can normally open another exec in for example TFileStream and write something at the end and this exec run without error?

Yes. Do keep in mind that the original exe has to be able to find the length of the data you appended to it. So it's easiest if you add a 4 byte length or so after the appended data, which the original exe then can read to find the start of that data.

Jonas

Reply by email

Reinier Olislagers
to Jonas Maebe
Jonas Maebe wrote 11 lines
Krzysztof wrote on Thu, 30 Aug 2012: > Hmm sounds good. So I can normally open another exec in for example > TFileStream and write something at the end and this exec run without > error? Yes. Do keep in mind that the original exe has to be able to find the length of the data you appended to it. So it's easiest if you add a 4 byte length or so after the appended data, which the original exe then can read to find the start of that data.

... or just use my readymade code that does exactly that instead of writing your own ;) It's released under a very liberal MIT license (so compatible with closed-source development, (L)GPL etc)

Reply by email

waldo kitty
to Krzysztof: I have some problem. Example: I created some exec using free pascal and lazarus. It is…
Krzysztof wrote 18 lines
Hi, I have some problem. Example: I created some exec using free pascal and lazarus. It is placed on http server. User in webbrowser click download, and server should attach link from where it is clicked into this exec. So when user run downloaded exec, this exec can read this link. The idea is that everything is in one file (and must be). My question is, exists any commandline tool which can edit executable file for edit some resource (like ResEdit or Restorator for Windows) which can be used by http server? By resource I mean some const (or resourcestring section, free pascal binary can replace it in runtime, can some tool do this same outside?). So main problem is in server side. Finally we can use free pascal compiler and compile modified source by server, but this solution we use when everything fails (admins, restrictions etc.). I need this only for windows (for now), so I'm considering some commandline installer makers like InnoSetup or something. Any idea?

i think i know what you are asking for and my thought actually matches what mark loyd seemed to be saying... with that in mind, i remember reading about some sort of resource editor to allow editing of resources in a binary... it was posted in this area back in jan 2012... i don't know if this is what you are looking for but here's what i found...

[QUOTE]
Date: Mon, 30 Jan 2012 09:09:42 +0100
From: Reinier Olislagers
To: FPC Mailing list ,
Lazarus mailing list
Subject: [fpc-pascal] Poor man's resource code available and CheckRide update: now with editor

Hi all,

(Cross posted to Lazarus+FPC lists)

Thanks to UPayload (http://www.delphidabbler.com/articles?article=7) and some help on the forum, I could implement an alternative way of storing files in an executable file (basically it just appends them with a footer). See source: poormansresource.pas in https://bitbucket.org/reiniero/checkride/src/, and the CheckRideResourceZipper project for sample code

This method allows me to edit such a "resource" using an FPC/Lazarus program. As
- I think - DoDi predicted, I had a lot of trouble trying to work with regular Windows resources, but whether that is due to bugs in FPC, Windows or me, I don't know ;)

I updated my CheckRide remote control package with this functionality: a helper can edit CheckRide.exe with his hostname and port number and distribute that single exe to his clients/helped persons. This allows 1 click operation at the helped side.

I also tested operation with a Linux helper running stunnel+vncviewer and a WIndows helped party running CheckRide.exe

See the site mentioned above.

Comments, patches, as well as criticism welcome ;)

Thanks,
Reinier
[/QUOTE]

if i'm reading the above correctly, it would appear that it can possibly do what you are looking for... maybe...

Reply by email

Reinier Olislagers
to waldo kitty
waldo kitty wrote 5 lines
On 8/29/2012 17:46, Krzysztof wrote: > Hi, > > I have some problem. Example: >

<snip>

Show quoted text 11 lines
i think i know what you are asking for and my thought actually matches what mark loyd seemed to be saying... with that in mind, i remember reading about some sort of resource editor to allow editing of resources in a binary... it was posted in this area back in jan 2012... i don't know if this is what you are looking for but here's what i found... [QUOTE] Date: Mon, 30 Jan 2012 09:09:42 +0100 From: Reinier Olislagers

<snip>

Show quoted text 9 lines
Subject: [fpc-pascal] Poor man's resource code available and CheckRide update: now with editor Hi all, (Cross posted to Lazarus+FPC lists) Thanks to UPayload (http://www.delphidabbler.com/articles?article=7) and some help on the forum, I could implement an alternative way of storing

<snip>

See source: poormansresource.pas in https://bitbucket.org/reiniero/checkride/src/, and the CheckRideResourceZipper project for sample code

<snip>

Show quoted text 6 lines
Thanks, Reinier [/QUOTE] if i'm reading the above correctly, it would appear that it can possibly do what you are looking for... maybe...

I'd say it can definitely do what he's asking for - but I'm biased: you did notice the guy posting that message is me? And that I again posted the link to my CheckRide code project in this thread? ;)

Thanks for looking up that post and kudos to your memory of ancient threads.

Regards,
Reinier

Reply by email

waldo kitty
to Reinier Olislagers
Reinier Olislagers wrote
On 31-8-2012 17:48, waldo kitty wrote: > if i'm reading the above correctly, it would appear that it can possibly > do what you are looking for... maybe... I'd say it can definitely do what he's asking for - but I'm biased:

as well you should be :)

you did notice the guy posting that message is me? And that I again posted the link to my CheckRide code project in this thread? ;)

yup... i've been jumping back and forth thru several things while catching up on my emails...

Thanks for looking up that post and kudos to your memory of ancient threads.

you are welcome and thanks :)

your original posting and Krzysztof's reminded me so much of what i use in some of my TP6 stuff... but what i use is slightly different in that it uses typed constants and modifies them in the executable during execution...

one purpose of this would be to limit the execution of a trial program to only X executions or that it will only run for Y days after it is first executed or even a combination of those such that only X executions are allowed within Y days and if either is reached, then the program stops...

i also used this technique to store registration data and options settings directly in the executable instead of having a separate and external configuration file...

i can post those old sources if anyone is interested... they only need ask... the sources are dated May 1993 and i likely saved them from the Fidonet PASCAL echo (message area)... they might have even ended up in the SWAG archives but i don't know ;) -=B-)

Reply by email

José Mejuto
to waldo kitty: i think i know what you are asking for and my thought actually matches what mark loyd…
waldo kitty wrote 5 lines
i think i know what you are asking for and my thought actually matches what mark loyd seemed to be saying... with that in mind, i remember reading about some sort of resource editor to allow editing of resources in a binary... it was posted in this area back in jan 2012... i don't know if this is what you are looking for but here's what i found...

Hello,

If you need to access dynamic data in a single file, maybe my code may help you. Basically it is a filesystem that can be embedded in a single file, so you can create, delete, open, read, write and seek any individual file inside. The "problem" is that in write mode only a test filesystem (not very usefull), Excel filesystem and ZIP filesystem are supported. The ZIP one is cool but to rebuild the final ZIP once updated it could need some temp files as it can not be edited in place. Maybe the BCF (Binary Coumpound File, the one that Excel uses) is a good choice as it has quite small initial tables (like a format) and grow as more data is being added.

The virtual filesystem can be mounted over an encrypted TFileStream derivate to allow transparent encryption of the whole virtual filesystem. It can read also raw images in FAT16 and FAT32 but can not write them.

Reply by email

Mark Morgan Lloyd
to waldo kitty: as well you should be :) yup... i've been jumping back and forth thru several things…
waldo kitty wrote 8 lines
i also used this technique to store registration data and options settings directly in the executable instead of having a separate and external configuration file... i can post those old sources if anyone is interested... they only need ask... the sources are dated May 1993 and i likely saved them from the Fidonet PASCAL echo (message area)... they might have even ended up in the SWAG archives but i don't know ;) -=B-)

I did this sort of thing back in the days of MZ files, where there was a simple length field in the header. I believe that NE files similarly had an accessible overall length, but they also had a checksum field even though this was rarely (if ever) used. Later Windows formats (PE etc.) might use signing/blessing/branding/checksumming to varying extents, and I also think there was discussion of unix-style signing in this (or a related) list a few weeks ago.

Which leaves me thinking that the safest way of doing it would be to look for an "official" program, i.e. from MS or from unix binutils, which- if a program was already signed- might request some sort of key before it would change anything.

Of course, an even safer way would be to leave the executable alone and to put an early check in the startup code that a subsidiary key file existed, and for that key to include something that identified the machine or site on which the program was entitled to run.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Graeme Geldenhuys
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Of course, an even safer way would be to leave the executable alone and to put an early check in the startup code that a subsidiary key file existed, and for that key to include something that identified the machine or site on which the program was entitled to run.

Take a has many ways of doing this. We use it in our commercial software (linux and windows) to lease our software on a yearly basis, or to enabled a 1 month trial etc. You can even lock your application down to a specific PC.

https://github.com/graemeg/onguard

Graeme.

Reply by email

waldo kitty
to Mark Morgan Lloyd: I did this sort of thing back in the days of MZ files, where there was a simple length…
Mark Morgan Lloyd wrote 13 lines
waldo kitty wrote: > i also used this technique to store registration data and options settings > directly in the executable instead of having a separate and external > configuration file... > > i can post those old sources if anyone is interested... they only need ask... > the sources are dated May 1993 and i likely saved them from the Fidonet PASCAL > echo (message area)... they might have even ended up in the SWAG archives but > i don't know ;) -=B-) I did this sort of thing back in the days of MZ files, where there was a simple length field in the header.

and that's one of the thing this main routine uses to jump to the end real quickly... but there's also a set of starting and ending markers... plus the fact that the data is a "Typed Constant" is another factor... i don't recall for sure, but i think i've been told that FPC doesn't have typed constants???

I believe that NE files similarly had an accessible overall length, but they also had a checksum field even though this was rarely (if ever) used.

interesting... this routine has a checksum item built into it... IIRC, it was so we could detect if the executable had been modified and abort operation if true...

Show quoted text 12 lines
Later Windows formats (PE etc.) might use signing/blessing/branding/checksumming to varying extents, and I also think there was discussion of unix-style signing in this (or a related) list a few weeks ago. Which leaves me thinking that the safest way of doing it would be to look for an "official" program, i.e. from MS or from unix binutils, which- if a program was already signed- might request some sort of key before it would change anything. Of course, an even safer way would be to leave the executable alone and to put an early check in the startup code that a subsidiary key file existed, and for that key to include something that identified the machine or site on which the program was entitled to run.

true... but as i recall, one of the goals of this capability was to not have extra files laying about... i remember the days of dongles and never liked them at all...

Reply by email

Graeme Geldenhuys
to waldo kitty
waldo kitty wrote
true... but as i recall, one of the goals of this capability was to not have extra files laying about... i remember the days of dongles and never liked them at all...

+1
I hated those dongles too.

The OnGuard code we use, I simply store the unique unlock code in the same .ini file I store other application settings like window position and size in the GetAppConfigDir() location. You can even have a site unlock key, where the unlock code is then stored in the database (if your app is a Client/Server app). Thus if one client is unlocked, all other clients are automatically good to go.

Graeme.

Reply by email

Mark Morgan Lloyd
to waldo kitty: and that's one of the thing this main routine uses to jump to the end real quickly... but…
waldo kitty wrote 11 lines
> Of course, an even safer way would be to leave the executable alone > and to put > an early check in the startup code that a subsidiary key file existed, > and for > that key to include something that identified the machine or site on > which the > program was entitled to run. true... but as i recall, one of the goals of this capability was to not have extra files laying about... i remember the days of dongles and never liked them at all...

Oh yes. And all those copy-protection systems that transferred a token from a floppy to a file on disc.

But if the choice was between having an extra file or patching the executable, and if the patched executable failed on 5% of customer systems due to an OS or anti-virus check, I'd settle for the extra file and count myself lucky.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Rainer Stratmann
to Krzysztof: I have some problem. Example: I created some exec using free pascal and lazarus. It is…
Krzysztof wrote 9 lines
I have some problem. Example: I created some exec using free pascal and lazarus. It is placed on http server. User in webbrowser click download, and server should attach link from where it is clicked into this exec. So when user run downloaded exec, this exec can read this link. The idea is that everything is in one file (and must be).

This can be achieved easily with including data as I suggest some times here. (Including binary data making easy).

Then you can do with your included data what you want. You are more independend than relying to (an) additional tool(s).

My question is, exists any commandline tool which can edit executable file for edit some resource (like ResEdit or Restorator for Windows) which can be used by http server?

Complicated in comparison to the solution above.

Show quoted text 7 lines
By resource I mean some const (or resourcestring section, free pascal binary can replace it in runtime, can some tool do this same outside?). So main problem is in server side. Finally we can use free pascal compiler and compile modified source by server, but this solution we use when everything fails (admins, restrictions etc.). I need this only for windows (for now), so I'm considering some commandline installer makers like InnoSetup or something. Any idea?

Reply by email

waldo kitty
to Mark Morgan Lloyd: Oh yes. And all those copy-protection systems that transferred a token from a floppy to a…
Mark Morgan Lloyd wrote 13 lines
waldo kitty wrote: >> Of course, an even safer way would be to leave the executable alone and to put >> an early check in the startup code that a subsidiary key file existed, and for >> that key to include something that identified the machine or site on which the >> program was entitled to run. > > true... but as i recall, one of the goals of this capability was to not have > extra files laying about... i remember the days of dongles and never liked > them at all... Oh yes. And all those copy-protection systems that transferred a token from a floppy to a file on disc.

yup! plus there were also those floppy and some CD based ones that insisted on the floppy or CD being in the drive so they could check for a specific flaw or data in a specific place that couldn't normally be read by standard tools...

But if the choice was between having an extra file or patching the executable, and if the patched executable failed on 5% of customer systems due to an OS or anti-virus check, I'd settle for the extra file and count myself lucky.

agreed... i run an old(er) firewall product that performs MD5 checksums on all executable files so that it can alert when a file has changed since its last execution... when i'm updating lazarus from SVN, i like that this firewall pops up a box alerting me when svn2inc, fpmake, and a few others change during the build... this lets me know, without having to go hunting, that my new stuff is up to date... or, at least i think it is... the process will hold everything until i acknowledge the file update... it gets in the way sometimes but more often than not, i'm happy to see its alerts...

Reply by email

印場 乃亜
to Graeme Geldenhuys: Take a has many ways of doing this. We use it in our commercial software (linux and…

Hi,

Does anyone know if the version of OnGuard listed below is working on OS X? I started customizing it myself to work on OS X, but due to lack of time, I haven't finished. (It compiled, but not everything works 100% yet).

If they don't have it working, perhaps I should contribute my changes, if they are still compatible.

Thank you,
Noah Silva

Graeme Geldenhuys wrote 15 lines
On 31/08/12 21:18, Mark Morgan Lloyd wrote: > Of course, an even safer way would be to leave the executable alone and > to put an early check in the startup code that a subsidiary key file > existed, and for that key to include something that identified the > machine or site on which the program was entitled to run. Take a has many ways of doing this. We use it in our commercial software (linux and windows) to lease our software on a yearly basis, or to enabled a 1 month trial etc. You can even lock your application down to a specific PC. https://github.com/graemeg/onguard Graeme. _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Graeme Geldenhuys
to 印場 乃亜
印場 乃亜 wrote
Does anyone know if the version of OnGuard listed below is working on OS X?

Unfortunately, no, I haven't done any work on OS X support yet. Most things should work relatively easy. The most work would be on the Machine Identifier code I believe - retrieving CPU information, Hard Drive serial numbers etc.

If they don't have it working, perhaps I should contribute my changes, if they are still compatible.

That would be much appreciated. Do you have a public git branch I can pull from? Github doesn't show any forks of the onguard project at the moment.

Regards,
- Graeme -

Reply by email

Noah Silva
to Jonas Maebe: Krzysztof wrote on Thu, 30 Aug 2012: Yes. Do keep in mind that the original exe has to be…

Hi,

Not directly relevant to the web server problem at hand, but... Interestingly enough, I used to do this on Atari ST systems with PurePascal, but the reason was different.

I wanted to have things like Mac OS had (meta-data like icons, extension of files the app could open, friendly application name, etc.), but there was no standard place to store this that the desktop or other tools could reliably find it. I figured out that I could add data to the end of .PRG/.APP files (executables), and the system wouldn't blink, so I basically appended some pascal records.

The challenges here were:
1. The application had to find the data. The end of the file contained an integer that indicated where the data block started.
2. I had to design it in a flexible/expandable way without wasting space.

Also, you can usually edit string data in executable files (and resource files) with no issues, as long as you keep the length the same. If you have a string you want to edit, you can make it easy to find, and just do a search/replace without worrying about the resource format much (since the metadata supporting the string will stay the same).

Yet, as mentioned my previous posters, either editing or appending the file will both change the check-sum, and thus break code-signing. You would need to have the code-signing tool be re-run as a part of the customization process.

Thank you,
Noah Silva

2012/8/30 Jonas Maebe

Show quoted text 20 lines
Krzysztof wrote on Thu, 30 Aug 2012: Hmm sounds good. So I can normally open another exec in for example > TFileStream and write something at the end and this exec run without > error? > Yes. Do keep in mind that the original exe has to be able to find the length of the data you appended to it. So it's easiest if you add a 4 byte length or so after the appended data, which the original exe then can read to find the start of that data. Jonas ______________________________**_________________ fpc-pascal maillist - http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>

Reply by email