'CHECK.BAS
'This uses QuickBASIC 4.5 compiled with the /O option for a
'stand alone program.  Linked with EVCHK3.OBJ BCOM45.LIB.
'BC CHECK /o;
'
'LINK CHECK + EVCHK3.obj,,,bcom45 /e;
'
'Last Updated 28/May/96 SSS
'
'  Define the SB block in the included SB.BAS file
'  $INCLUDE: 'SB.BAS'
'
   DIM SB AS SecureBlock  
'
'  Declare the EVCHK3 function 
'
   DECLARE FUNCTION EVCHK3% (SEG SB AS SecureBlock)
'
'  Initialize the required fields and call EVCHK3
'
   GOSUB CHECK

   IF rcode = 0 THEN        ' If the return code is 0 EVCHK3 ran
      IF SB.STAT1 = 0 THEN  ' If the structure Status Return is 0 then valid
         GOSUB OUTP         ' Output fields of the SB Structure
      ELSE                  ' Otherwise Status Return reports an Error
         PRINT "ERROR This program is not authorized" ' Print Error Message
         PRINT HEX$(SB.STAT1); "-"; HEX$(SB.STAT2); "-"; HEX$(SB.STAT3)
      END IF
   ELSE                     ' Otherwise EVCHK3 did not run successfully
      PRINT "EVCHK3 Authorization Error = "; HEX$(rcode) ' Print Error Message
   END IF

'
  END

CHECK:
'
'Initialize fields for EVCHK3 call.
'
   SB.ID = "AZSB"                ' ID field is AZSB
   SB.STAT1 = &H7240             ' Initialize to EVCHK3 failed return code.
   SB.FUNC = 1                   ' Function 0, 1, 2 or 3.
   SB.SNP = 0                    ' Verify product serial number, should be 0
                                 '   if not to be checked.
   SB.SOURCE = "A:\PCHECK.EXE"   ' Check specific drive, path and program
   SB.PIN = &H6B87B188           ' Verify with PIN
'
   rcode = EVCHK3%(SB)           ' Call EVCHK3 function
'
   RETURN

OUTP:
'
   PRINT "          Return Code: "; HEX$(SB.STAT1); "-"; HEX$(SB.STAT2); "-"; HEX$(SB.STAT3)
   PRINT "        Function Code: "; SB.FUNC
   PRINT "             Drive ID: "; SB.DRV
   PRINT "      Protection Type: "; SB.PTYPE
   PRINT "              Product: "; SB.PROD
   PRINT "      Product Serial#: "; SB.SNP
   PRINT "     Net-Users Handle: "; SB.HNUC
   PRINT "Authorization Version: "; SB.AVERS
   IF SB.ECL = &HFFFF THEN
      PRINT "     Exec-Count Limit: UNLIMITED"
   ELSE
      PRINT "   Current Exec-Count: "; SB.ECL
   END IF
   IF SB.EDL = &HFFFF THEN
      PRINT "    Expire-Days Limit: UNLIMITED"
   ELSE
      PRINT "    Current Days Left: "; SB.EDL
      PRINT "          Expire Date: "; SB.ED
   END IF
   IF SB.NUL = &HFFFF THEN
      PRINT "      Net-Users Limit: UNLIMITED"
   ELSE
      PRINT "      Net-Users Count: "; SB.NUC
      PRINT "      Net-Users Limit: "; SB.NUL
   END IF
   IF SB.PTYPE = "P" THEN
      PRINT "        Install Count: "; SB.ICR
   END IF

'  Print User-Data
   PRINT "            User Data: ";
   FOR i = 1 TO 8
      PRINT HEX$(ASC(MID$(SB.USRDAT, i, 1))); " ";
   NEXT i

'  Print list of Access Flags
   FLG$ = ""
   k = 0
   PRINT "     Access Flags Set: ";
   FOR i = 0 TO 7
      FLG$ = MID$(SB.ACCFLG, i + 1, 1)
      FOR j = 1 TO 8
         IF j = 1 THEN
            IF ASC(FLG$) AND 1 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 2 THEN
            IF ASC(FLG$) AND 2 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 3 THEN
            IF ASC(FLG$) AND 4 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 4 THEN
            IF ASC(FLG$) AND 8 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 5 THEN
            IF ASC(FLG$) AND 16 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 6 THEN
            IF ASC(FLG$) AND 32 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 7 THEN
            IF ASC(FLG$) AND 64 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
         IF j = 8 THEN
            IF ASC(FLG$) AND 128 THEN
               PRINT ((i * 8) + j); " ";
               k = k + 1
            END IF
         END IF
      NEXT j
   NEXT i
   IF k = 0 THEN
      PRINT "NONE"
   END IF

'  Print Registration Info
   IF SB.RTYPE = "N" THEN
      PRINT "   Registered to Name: "; SB.RNAME
      PRINT "Registered to Company: "; SB.RCOMP
      PRINT "  Registered Location: "; SB.RLOC
      PRINT "      Date Registered: "; SB.RDATE
   END IF

'  Print Current Date
   PRINT "         Current Date: "; SB.CDATE

'  Print Secure String
   PRINT "        Secure String: "
   PRINT SB.SECSTR
   RETURN

