home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / PBCLON20.ZIP / PATCHER.BAS < prev    next >
BASIC Source File  |  1991-11-18  |  2KB  |  51 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        PBClone  Copyright (c) 1990-1991  Thomas G. Hanlin III        |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7.    DECLARE SUB FindPatch (FileName$, SearchSt$, ErrCode%)
  8.    DECLARE SUB SetPatch (St$)
  9.    DECLARE SUB PatchDone ()
  10.  
  11.    DEFINT A-Z
  12.  
  13.    ' --- We read SearchSt$ to avoid duplicating it in an assignment statement.
  14.    ' --- The ConfigSt$ is the value we patched in last time.
  15.    READ SearchSt$, ConfigSt$
  16.  
  17.    ' --- Get the value to patch in this time.
  18.    St$ = LTRIM$(RTRIM$(COMMAND$))
  19.  
  20.    ' --- Make it the right length (this is important)!
  21.    IF LEN(St$) < LEN(ConfigSt$) THEN
  22.       St$ = St$ + SPACE$(LEN(ConfigSt$) - LEN(St$))
  23.    ELSE
  24.       St$ = LEFT$(St$, LEN(ConfigSt$))
  25.    END IF
  26.  
  27.    ' --- Tell 'em what's up.
  28.    PRINT "This is a demo of the PBClone routines which allow a program to patch itself."
  29.    PRINT "It patches itself with whatever you enter on the command line."
  30.    PRINT
  31.    PRINT "The last entry was: "; CHR$(34); RTRIM$(ConfigSt$); CHR$(34)
  32.    PRINT "Next time it'll be: "; CHR$(34); RTRIM$(St$); CHR$(34)
  33.  
  34.    ' --- Here we do the actual patching.
  35.    ' --- Note that the ".EXE" extension is optional.
  36.    FindPatch "PATCHER", SearchSt$, ErrCode
  37.    IF ErrCode THEN
  38.       PRINT "Unable to patch PATCHER.EXE-- error code: "; ErrCode
  39.       END
  40.    END IF
  41.    SetPatch St$
  42.    PatchDone
  43.  
  44.    ' --- Here's the data: one quoted string per statement, with the first
  45.    ' --- statement containing a unique string.  The first statement won't be
  46.    ' --- patched, since we may need it again another time.  The second data
  47.    ' --- statement will be the first patched.  There is no limit to the
  48.    ' --- number of data statements which may be patched.
  49.    DATA "UniqueString"
  50.    DATA "This space intentionally left blank!                             "
  51.