home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / VIRUS / CVIRPROT.ZIP / PATCH.DOC < prev    next >
Encoding:
Text File  |  1989-09-30  |  5.1 KB  |  117 lines

  1.  
  2.  
  3.         PATCH - A program to include anitivirus code
  4.                       into programs
  5.                           
  6.                           
  7.   PATCH consists of two programs, one of which gets included in your
  8. source code (acheck.c) and  a second program (patch.exe) which is run 
  9. on a newly compiled program and patches that program to provide
  10. the antivirus code with information it needs to determine if the
  11. file has been altered.
  12.  
  13. How patch works:
  14.     PATCH works by calculating CRCs (or checksums) for variable
  15. length blocks of the executable file.  These CRCs are very
  16. sensitive to changes in the file, and changing just one bit will
  17. change the CRC, alerting you that a virus may have changed the
  18. file.  The CRC values calculated by PATCH are embedded in a
  19. structure (static struct avirus) so that every time the file is
  20. executed, CHECK (the patch function you include in your code)
  21. can recalculate the CRCs and compare them to the ones originally
  22. calculated by PATCH.
  23.  
  24.     The structure avirus is the key to the operation of PATCH.
  25. The first variable in the structure is an 8 character string
  26. which must be initialized to a string that does not occurr
  27. elsewhere in your file.  The only purpose of this string is to
  28. provide a key so that PATCH can find the avirus structure in
  29. your executable file.  Once PATCH has located the structure, it
  30. calculates the CRCs and writes them into the executable file.
  31. Later, when CHECK is called from you program, it recalculates
  32. the CRCs, comparing them to the ones patched into the file by
  33. PATCH.  When it reaches the avirus structure, however, it must
  34. insert 0's instead of the CRC values PATCH placed in the code
  35. (since PATCH saw only zero's before it patched the code).
  36.   
  37.     Patch will not keep a virus from infecting your program, but
  38. it will tell you when one has invaded.
  39.  
  40. How to use patch:
  41.     To use patch, you must include the file ACHECK.C in your
  42. source file.  Early in the program (first?), you should call the
  43. function check(argc, argv).  Check will return an integer code,
  44. which have the following meanings:
  45.  
  46.   /* Return codes */
  47.   /* 0 - File checked out OK               */
  48.   /* 1 - File never patched, no protection */
  49.   /* 2 - User turned off protection        */ 
  50.   /* 3 - File has been changed since patch */
  51.  
  52.     See test.c for an example on how to use check.  I have
  53. included a command line option to turn off virus checking.  If
  54. the token /a appears on the command line, CHECK will not check
  55. the file.  This allows for more rapid file loading if the user
  56. is sure that no virus has attacked since last checking the file.
  57.  An alternative would be to make the default no checking, and
  58. only check the file when the user requested it.
  59.     
  60.     Once your program has been compiled, your should run
  61. PATCH.EXE on it.  PATCH will give you an option on how big you
  62. want your block size.  Larger blocks will run faster, but always
  63. designate a block size less than the actual file size.  This
  64. makes it more difficult for viruses to defeat the protection.
  65. PATCH will then display the values it is inserting into the
  66. file, after which your executable file is patched and virus
  67. resistant.
  68.  
  69. A question of speed:
  70.     While CRC values are very sensitive to alterations in the
  71. code, they also take quite awhile to calculate.  On large files,
  72. the wait can be frustrating.  As an alternative, I have also
  73. included code to use checksum values.  These are less secure,
  74. but very quick to calculate. To change to checksums, comment out
  75. the line "#define CRC_METHOD" in both ACHECK.C and PATCH.C.
  76.  
  77. Et Cetera:
  78.     This program is a revision of code originally submitted to
  79. PC Magazine, and which appeared in the August issure
  80. (Vol.6,#14).  That code unfortunately had a bug in PATCH which
  81. did  not allow it to work on large files.  FOr those who might
  82. have tpyed it in, the correction is:
  83.   anitvir.lowcrc = (sector-1) * 512 + offset;
  84. should read:
  85.   anitvir.lowcrc = (sector-1) * 512L + offset; 
  86.  
  87.     I woud like to thank the anonynous  programmer who provided
  88. the CRC code used in this program.  The code came from an
  89. archive called CRCFAST, with no mention of the author's name.
  90.  
  91. Caveat:
  92.     #1: This program will only work if the linker you are using
  93. stores the structure avirus complete with the uninitialized
  94. zeroes in avirus.crcs.  If your linker optimizes and removes
  95. these zeroes in the file written to disk, then you may have to
  96. initialize the structure to 1s f.ex.  If you do this, remember
  97. that check should then insert 1s and not zeroes when going over
  98. the structure.  Specifically, use of the Microsoft overlay
  99. linker with the /e option will require some changes in the code.
  100.  
  101.     #2: Be aware of combining object code from different
  102. compilers.  ANSI C does not specify how structures should be
  103. aligned internally, only that the addresses of members be
  104. increasing in order of declaration.  Using one compiler for
  105. PATCH and another for CHECK could result in incompatabilities
  106. from different alignments.  
  107.  
  108.  
  109. Author:
  110.     Mike Caprio, Graduate Student in Entomology (thats insects!)
  111. at the University of Hawaii, Manoa.  He can be reached via
  112. bitnet at :  caprio@uhccux.
  113. Address:  Dept. of Entomology
  114.           3050 Maile Way, Gilmore 310
  115.           Honolulu, HI  96822
  116.           (808) 948-8261
  117.