Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Modify Tlabel.caption of another delphi program

Posted on 2006-07-01
22
Medium Priority
?
640 Views
Last Modified: 2010-04-05
Hi there,

I have two delphi programs

A.exe
B.exe

Delphi program A opens program B and modifys the resource for Tlabel.caption
then when I run program B it's Tlabel.caption is changed to what I set it in program A.

I understand this can be done with modifying the resource...

any ideas?
 
0
Comment
Question by:wildzero
  • 13
  • 8
22 Comments
 
LVL 10

Author Comment

by:wildzero
ID: 17025565
don't want any external files

program A must modify program B
0
 
LVL 10

Author Comment

by:wildzero
ID: 17025566
and program A shouldn't have to be running at the same time as when program B is.
0
 

Expert Comment

by:SergiuAdrian
ID: 17025765
the best way to do it is using windows messages
here you can find a very good example how to send data between applications
http://delphi.about.com/od/windowsshellapi/a/wm_copydata.htm
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Author Comment

by:wildzero
ID: 17025964
and program A shouldn't have to be running at the same time as when program B is.

Any other ideas?
0
 
LVL 28

Expert Comment

by:2266180
ID: 17026250
hm... that is pretty close to reverse engineering.

why do you want to do that modification in the first place? maybe there are other solutions. are you trying to make some branded software? if so, this can be done at compile time. modifying directly the binary is not that hard but requires some certain knowledge one might not have.
onw way to go is using a patch program:
- compile B, save output
- modify from source the caption
- compile B, save output
- run patch, see where it finds the differences. try to make out which one is the caption.

now you will have several pretty big issues here:
1) if the original caption is smaller that the one you want to assign, you will need to shift the contents of teh executable which is a pretty bad thing to do since you need to make sure you don't mess up code
2) if the original caption is smaller, issues are not that big, just in case you have a problem with displaying white spaces in teh caption.

so better tell us why you want to do that and we might think of a better approach to your problem
0
 
LVL 10

Author Comment

by:wildzero
ID: 17027500
Hmmm now that could be an idea.

First could leave the caption blank then run
then fill the caption to it's max 255 chars then run

that way we can insert anything and just fill with blanks up to 255.

I got a program I have written which I want people to be able to insert there hyperlink into, so I guess it would be branding. Then they can distribute my program. But don't want to have to worry about any other files - just want to deal with the exe file, no tag along ini/dat files.


- run patch, see where it finds the differences. try to make out which one is the caption.

Where do I get this from :)
0
 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 17027614
hm.. that you get from any patch program out there (personally I never used one :) ) you can also do it with a diff like program (I use araxis merge for that)

on teh otehr hand, you don't need that :)

whT I have done to solve a similar problem was this:
- have the program open itself in readonly mode (otherwise you get an error), seek to it's end (this one is trickier, i'll tell you leter) and read up the count and the list of strings (this is highly customziable. I had a lot of data types after the exe :) )
- have anotehr program that modifies the above one by modifying the count and the list of strings.

now, the setup would look something like this:

size.pas:
  var mysize:integer = 0;// this is expressed in bytes

unit1.pas of porgram A (modifier)
....
{$L size.pas} // this includes the aove small file
...
open program b exe file, seek to mysize, do the dirty work
...

unit1.pas of program B (actual app)
...
{$L size.pas} // this includes the aove small file
...
open program b exe file, seek to mysize, do the dirty work (read up the data
...

at compile time:
compile B
modify size.pas if needed// you can write a small utility app that opens B, see it's size and recreate size.pas with only that one line :)
if modified size.pas then compile B
compile A

for this you will need a comile.bat file in order to do this from the command line. you will of course use dcc32 to compile the project.

for a pretty nice example on how to do this see this demo I made: http://www.ciuly.com/delphi/multimedia/dspackStreamPlayer/index.html

now the demo will append a video file to the player exe and the player exe will read it. in you case, you will make another program (A) to modify the contents after the program B as you need and not use the video of course :P
the idea you need to catch from that example is how to do that dirty work with size and command line compilation ;)
0
 
LVL 10

Author Comment

by:wildzero
ID: 17028918
Thanks for that, it's an excellent post.

Just  2 things
 1 - If I gave someone program A to make there own 'version' of progrma B (perhaps with a different video of there own for exmaple) then they would need delphi to compile the program?

 2 - Have you ever had any problems saving data to the end of a file? I done this a few times and once ran into an invalid .exe application error on one perticular XP Pro machine. They had the file fully downloaded and everything, it just didn't like it....  (worked fine on a bunch of other machines)

I will check out your link now.
Thanks
0
 
LVL 10

Author Comment

by:wildzero
ID: 17028934
Page don't seem to wanna load :-/
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 2000 total points
ID: 17029845
1) no. since you already compiled it, A knows the size of B. BUT if you modify B and the size of B modifies, then you must provide a new version of A

2) no problems. I have been using this tehnique in a commercial application for almost 2 years now and there were no such problems reported (and it was also run on some win9x machines). But I guess that maybe som badly written antivirus like program might interfere in the process in trial of stopping self modifying programs or alike might of course block the app and hence throw such errors. just a thought.

sorry. my isp died on me a few hours ago but it has been up and running for more than 3 hours now.

let me know if there are any other problems
0
 
LVL 10

Author Comment

by:wildzero
ID: 17029928
Yea I bet that is what it was
some antivirus/antispyware program thought it was bad.

Hmm ok.
Now I don't quite understand your example.

Are you able to whip up a quick demo?
Program A with an edit box and Button -> Program B with a label
whatever is written in program A then shows up when Program B runs (as it pulls it from it's self).

I don't mind opening another question.

Much appreaciated
Nick
0
 
LVL 28

Expert Comment

by:2266180
ID: 17030819
I am at work right now and can't seem to find enough "spare" time to do this. I'll put up an example for you in about 3-4 hours when I get home.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17032742
I made a qucik demo for you. I didn't spent time to integrate teh automatic build process as I already gave you a working demo for that :)
download project files from http://www.ciuly.com/delphi/ModifyExeString.zip
compile B. then write the size manuallt in size.pas then compile B again.
after you make it work manually, you can adapt the build process to your needs. maybe test it first with this deme ;)

cheers
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033225
Great
i'll check this out in a tick! thanks!
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033717
Nice that worked quite well.
And you have used this for years with no problems?
0
 
LVL 28

Assisted Solution

by:2266180
2266180 earned 2000 total points
ID: 17033754
2 years actually, yes. :) or at least I haven't been reported any such or similar problems.
of course, if the user woulc use an outdated version of A to modify B, will result in a corupted B, but that is human error from the user part. that is why my software carries validation for the data appended. one such validation is version number. before the program modifies the otehr, it check to make sure it's a compatible version. and only after that modifies it. and since an A will only modify a compatible B, there is no place for human error. and since A works fine for the compatible B, there is no error on PC side either. But for this you must make sure that indeed you are using correct and reversible methods to store the data

for example, if you write a string like:
word char char ... char
and read it like
integer char char .. char

you will obviously get errors ;) but that is a bug in your code and not in teh tehnique itself. Of course, I haven't tested this on win2003 and above :) but works quite fine for most if not all windowses below. (check the video demo for a pretty complete way of doing it that should work fine on all windowses below 2003
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033783
The best way to handle that is to include version B as a resource of A, then you just extract B from A and add the text to B.
That way the user will only use the latest B.

:D
Good stuff.
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033795
0
 
LVL 28

Expert Comment

by:2266180
ID: 17033809
hm.. the user must alway use the latest A AND B. there can be a an A that works with multiple versions of B (I had that quite a few times) so the idea is not that ok. that is why I said that A must work with compatible B's. that can mean a range of versions. in my case, what I have done is to keep track of 2 versions:
1 - the program version
2- the resource version ;)
now whenever some mechanism in the resource changes, A and B gets a new version and A will only work with the version it knows no matter what B's version is (of course the B's resource version will have to be the same with the one from A's resource version)

it can be confusing to use 2 versioning but it helped me keep everything clean.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17033820
>please post in there so I can accept you to please.

sorry but EE does not accept "points for..." questions :) these are the rules, we must comply.

You can delete that question yourself to save the page editor from doing it (unless someone posts in it)

anyway, thanks for the thought :)
peace
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033831
Yea that is why I thought.
If you make it the latest B gets put into a resource file and included with A
Then A is ran the B resouce gets extracted to Progject1 and then A does the dirty work
So the only way a user can put in an old B is if he copies and old Project1 to the folder before the software has time to include the text in the one it extracted - which would be near impossible......
0
 
LVL 10

Author Comment

by:wildzero
ID: 17033835
I thought they did...
ive done it before...

hmm
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question