home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / alt / hackers / 1676 < prev    next >
Encoding:
Internet Message Format  |  1992-11-13  |  1.9 KB

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