home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!watson.ibm.com
- From: chess@watson.ibm.com (David M. Chess)
- Message-ID: <19921113.43280.7776.chess@watson.ibm.com>
- Date: 13 Nov 1992 12:01:20 EST
- Newsgroups: alt.hackers
- Approved: Right-thinking people everywhere
- Subject: self-generating hack
- Lines: 33
-
- I wanted a small assembler program to be able to check itself at
- runtime to make sure it hadn't been changed / damaged / hacked-
- by-an-amateur. The first and obvious solution was to have it
- read a checksum from some set place in the file (like the very
- end), and read itself from disk and check against that checksum
- at runtime. The checksum value itself would be calculated and
- patched in by a second program as part of the MAKE process. But
- that's a boring solution, and it would mean having another
- program to maintain, and having two different implementations
- of the same algorithm (because the primary program is in
- assembler, and the checksum-patcher-in would most likely be
- in C).
-
- So instead I changed the source to the primary program so that
- when run it would jump to the very end of itself, where there is
- a routine that calls the checksum-calculation subroutine on the
- main part of the program, patches itself in memory to include
- the calculated value, patches out the initial jump-to-end,
- and then writes a copy of the patched in-memory image (just enough
- to include the main program and the checksum, and not itself)
- back to disk under a name passed in as an argument. So now
- the MAKE process first assembles FOO, and then FOO is run to
- create BAR, which is the self-testing end product. More of
- a kludge than a hack, I suppose... *8)
-
- UlteriorMotiveHack: an XEDIT macro that automatically makes
- my maunderings into something the gateways and such will
- make into a news posting. So here I am testing it.
-
- - -- -
- David M. Chess \ Come home to your wife and family,
- High Integrity Computing Lab \ Come home to the fireside bright.
- IBM Watson Research \
-