[comp.lang.pascal] Auto Installation

NORM%IONAACAD.BITNET@cunyvm.cuny.edu ( Norman Walsh) (06/12/90)

A better way to do this sort of thing (especially with multiple-segment
programs like TP) is to open the file and search for some string, like
the following:

type
   InstallRecord = Record
                     IdString : String(.10.);
                     OtherJunk: String(.10.); { or whatever }
                   end;
const
   InstallInfo   : InstallRecord = ('!FOUND IT!','');

Procedure Install(Junk: String);
var
  ExeFile : File;
  Buffer  : Array(.1..512.) of Byte;
  Actual  : Word;


begin
  Assign(ExeFile,'whatever your program name is -- ExecSpec in Dos3.0+?');
  Reset(ExeFile,1);
  BlockRead(ExeFile,Buffer,SizeOf(Buffer),Actual);
  While (Actual > 0) do
    begin
      {look for '!FOUND IT!' string and then you know where your
       install record is.  Remember to handle buffer boundry
       conditions!  Sorry I got lasy and didn't finish this code,
       if anyone really wants to see it done, let me know...
      }
    end
  {now you know where your record is, load it, change it and write
   it back to the ExeFile}
end;

                                                 ndw

dmurdoch@watstat.uwaterloo.ca (Duncan Murdoch) (06/12/90)

In article <23617@adm.BRL.MIL> NORM%IONAACAD.BITNET@cunyvm.cuny.edu ( Norman Walsh) writes:
>A better way to do this sort of thing (especially with multiple-segment
>programs like TP) is to open the file and search for some string, like
>the following:

I don't see why the "search for key string" algorithm is better than the
"work out the offset" algorithm of the original posting (For new readers:
the discussion is about how to allow a program
to patch itself.  The original messages were in comp.lang.pascal, but I've
moved followups to comp.sys.ibm.pc.programmer, which seems more appropriate.)
The search is certainly slower, and runs the risk of finding a false key:
maybe the spot in your help screen where you say how to make manual patches,
or someone's password which just happens to be the same as your search key.

On the other hand, the format of the .EXE file is documented, as
is the loading algorithm, and the only way I can see that it would go
wrong is if Turbo Pascal chose to move data around in memory after it was
loaded.  I can't see any reason for that; can you?  (Perhaps your method
would work with overlays?  But TP doesn't overlay data, does it?)

Duncan Murdoch

taylorj@yvax.byu.edu (06/15/90)

In article <1990Jun12.152857.5272@maytag.waterloo.edu>,
dmurdoch@watstat.uwaterloo.ca (Duncan Murdoch) writes:

>I don't see why the "search for key string" algorithm is better than the
>"work out the offset" algorithm of the original posting

I much prefer the "search for key string" technique to a "hard-coded" address
in the .EXE file for a number of reasons.  You don't have to find the new
address and re-enter it every time you make a change to your program.  You
don't have to go through the bother of finding the address in the first place.
You can use EXE packers and any other utilities that modify the EXE file.

It's true that this method is slower, but patching a file is generally not a
frequent activity, so this isn't really a problem.  There is no risk at all of
finding a "false key" if the key is carefully chosen.


(P.S. Yes, I know the followups were directed to comp.sys.ibm.programmer, but
my news reader doesn't do followups.)

Jim Taylor
Microcomputer Support for Curriculum   |
Brigham Young University               |   Bitnet: taylorj@byuvax.bitnet
101 HRCB, Provo, UT  84602             |   Internet: taylorj@yvax.byu.edu