Advertisement
Guest User

unsecure.bas

a guest
Oct 29th, 2017
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' UNSECURE.BAS: Unsecures RMB and compatible PROG format files.
  2.  
  3. ' Copyright (C) 1997 Oswego Software, Inc. All rights reserved.
  4. ' Written by Shawn Fessenden. No part of this program may be reproduced or
  5. ' transmitted by any means, electronic or otherwise, without the express
  6. ' written permission of Oswego Software, Inc.
  7.  
  8. ' THIS PROGRAM IS FOR OSWEGO SOFTWARE, INC. INTERNAL USE ONLY!
  9.  
  10. ' To use for BASIC/WS, copy prog source with HPCOPY in RAW mode.
  11. ' Run this program, then copy back with HPCOPY in RAW mode, set NEW HP
  12. ' FILE TYPE to -5808 (BASIC/WS PROG file type).
  13.  
  14. OPTION BASE 1
  15.  
  16. ' Frequently used constants.
  17.  
  18.   ' Boolean True & False.
  19.   CONST False = 0           'Common definition of FALSE.
  20.   CONST True = (NOT False)  'Common definition of TRUE.
  21.  
  22.   ' Access constants for crack data (i.e. enum {CRACK_UNUSED,CRACK_EOL...}).
  23.   CONST CRACK.UNUSED = 0    'Not used.
  24.   CONST CRACK.EOL = 1       'End of line token.
  25.   CONST CRACK.SEC = 2       'Secure flag.
  26.   CONST CRACK.UNSEC = 3     'Unsecure flag.
  27.   CONST CRACK.PTRWORD = 4   'Offset to ptr to first possible secure flag.
  28.   CONST CRACK.BIGENDIAN = 5 'True if machine type is big endian.
  29.   CONST CRACK.CHECKLAG = 6  'Number of bytes to continue checking for EOL after first EOL is found.
  30.  
  31. ' Variable declaration.
  32.  
  33.   ' Boolean.
  34.   DIM bCheck AS INTEGER         'True = start checking for secure flag.
  35.  
  36.   ' Integers.
  37.   DIM nThisByte AS INTEGER      'Current byte in in/out files.
  38.   DIM nLastByte AS INTEGER      'Last byte in in/out files.
  39.   DIM nSourceType AS INTEGER    'Select input file type.
  40.   DIM nCrack(3, 6) AS INTEGER   'Crack constants.
  41.  
  42.   ' Pointers.
  43.   DIM pInFile AS INTEGER        'Input file number.
  44.   DIM pOutFile AS INTEGER       'Output file number.
  45.   DIM pPtrWord AS INTEGER       'Ptr to ptr word in input file.
  46.   'i.e. PWORD *pwPtrWord. Note double-indirection.
  47.   'Yes, this *is* supposed to be obscure.
  48.  
  49.   ' Single precision.
  50.   DIM fVarEnd AS SINGLE         'End of var table as defined by pointer word.
  51.   DIM fBytePos AS SINGLE        'Current byte position in in/out files.
  52.   DIM fLastEol AS SINGLE        'Byte positon of last Eol tag.
  53.   DIM fFoundTags AS SINGLE      'Number of secure tags found.
  54.  
  55.   ' Strings.
  56.   DIM sInFile AS STRING         'Input file.
  57.   DIM sOutFile AS STRING        'Output file.
  58.   DIM sByte AS STRING * 1       'Byte at current offset in in/out files.
  59.   DIM sVarTbl AS STRING         'Message buffer, just to make everything look pretty.
  60.   DIM sSpin(4) AS STRING * 1    'Progress spinner characters.
  61.   DIM sPtrWord(4) AS STRING * 1 'Temporary holding bin for pointer bytes.
  62.   DIM sVarTblStart AS STRING    'Var tbl start copy time.
  63.   DIM sVarTblStop  AS STRING    'Var tbl stop copy time.
  64.   DIM sCrackStart AS STRING     'Crack start time.
  65.   DIM sCrackStop AS STRING      'Crack stop time.
  66.   DIM sMenu(3) AS STRING        'Main menu data.
  67.  
  68. ' QUIT BITCHING! THIS IS SUPPOSED TO BE OBSCURE DAMNIT.
  69.  
  70. ' Menu setup.
  71. MenuData:
  72. DATA 3
  73. DATA "HP BASIC/WS source."
  74. DATA "TransEra HT Basic for Windows source."
  75. DATA "Hewlett Packard HP Basic for Windows source."
  76.  
  77. RESTORE MenuData
  78. READ i
  79. FOR j = 1 TO i
  80.   READ sMenu(j)
  81. NEXT j
  82.  
  83. ' Crack data setup.
  84. ' DATA EOL, SEC, UNSEC, PTRWORD, ENDIAN, CHECKLAG
  85. CrackData:
  86. DATA 3
  87. DATA 179,72,64,39,1,2
  88. DATA 201,1,0,267,0,2
  89. DATA 201,1,0,267,0,2
  90.  
  91. RESTORE CrackData
  92. READ i
  93. FOR j = 1 TO i
  94.   FOR k = 1 TO 6
  95.     READ nCrack(j, k)
  96.   NEXT k
  97. NEXT j
  98.  
  99. ' Spinner setup.
  100. SpinnerData:
  101. DATA \,|,/,-
  102.  
  103. RESTORE SpinnerData
  104. FOR i = 1 TO 4
  105.   READ sSpin(i)
  106. NEXT i
  107.  
  108. ' Begin Main.
  109. CLS
  110.  
  111. ' Intro & choose source type.
  112. PRINT "Source file must be in PROG format, not ASCII."
  113. PRINT
  114. PRINT "Choose source type:"
  115. PRINT
  116. RESTORE MenuData
  117. READ i
  118. FOR j = 1 TO i
  119.   PRINT TAB(5); LTRIM$(STR$(j)); ") "; sMenu(j)
  120. NEXT j
  121. PRINT
  122. PRINT "Enter 1 to "; LTRIM$(STR$(i));
  123. INPUT nSourceType
  124. IF nSourceType < 1 OR nSourceType > i THEN SYSTEM
  125. PRINT : PRINT
  126.  
  127. ' Get file names.
  128. LINE INPUT "Input file :"; sInFile
  129. LINE INPUT "Output file:"; sOutFile
  130. PRINT
  131.  
  132. ' Get file pointers.
  133. pInFile = FREEFILE
  134. pOutFile = pInFile + 1
  135.  
  136. ' Open files.
  137. OPEN sInFile FOR BINARY AS #pInFile LEN = 1
  138. OPEN sOutFile FOR BINARY AS #pOutFile LEN = 1
  139.  
  140. ' Get PtrWord. (offset to first possible secure flag).
  141. pPtrWord = nCrack(nSourceType, CRACK.PTRWORD)
  142. FOR i = 0 TO 3
  143.   GET #pInFile, pPtrWord + i, sPtrWord(1 + i)
  144. NEXT i
  145.  
  146. ' Convert pointer bytes to a file offset.
  147. IF nCrack(nSourceType, CRACK.BIGENDIAN) THEN
  148.   ' Big Endian for HP BASIC/WS.
  149.   fVarEnd = ((ASC(sPtrWord(1)) * 256 + ASC(sPtrWord(2))) * 65536) + ((ASC(sPtrWord(3)) * 256 + ASC(sPtrWord(4)))) + 12
  150. ELSE
  151.   ' Little Endian for Basic for Windows.
  152.   fVarEnd = ((ASC(sPtrWord(2)) * 256 + ASC(sPtrWord(1))) * 65536) + ((ASC(sPtrWord(4)) * 256 + ASC(sPtrWord(3)))) + 256
  153. END IF
  154.  
  155. ' All bytes from the first to fVarEnd are the variable table (basically).
  156. sVarTbl = RIGHT$("000000" + HEX$(fVarEnd), 6) + " " + "VarTbl.....  "
  157. PRINT sVarTbl;
  158. sVarTblStart = TIME$
  159. FOR fBytePos = 1 TO fVarEnd
  160.   GET #pInFile, fBytePos, sByte
  161.   PUT #pOutFile, fBytePos, sByte
  162.   LOCATE CSRLIN, POS(0) - 1
  163.   PRINT sSpin(fBytePos MOD 4 + 1);
  164. NEXT fBytePos
  165. sVarTblStop = TIME$
  166.  
  167. ' Next byte may be a secure flag; make it an unsecure flag.
  168. GET #pInFile, fBytePos, sByte
  169. IF ASC(sByte) = nCrack(nSourceType, CRACK.SEC) THEN
  170.   sByte = CHR$(nCrack(nSourceType, CRACK.UNSEC))
  171.   fFoundTags = fFoundTags + 1
  172. END IF
  173. PUT #pOutFile, fBytePos, sByte
  174. fBytePos = fBytePos + 1
  175.  
  176. ' Start looking for EOL markers.
  177. PRINT : PRINT TAB(8); "Cracking...  ";
  178. sCrackStart = TIME$
  179. bCheck = False
  180. GET #pInFile, fBytePos, sByte
  181. fLastEol = fBytePos
  182. nThisByte = ASC(sByte)
  183.  
  184. WHILE NOT EOF(pInFile)
  185. ' You're not supposed to be seeing this so shut up.
  186.  
  187.   ' Check to see if the current byte is a secure flag.
  188.   IF bCheck AND nThisByte = nCrack(nSourceType, CRACK.SEC) THEN sByte = CHR$(nCrack(nSourceType, CRACK.UNSEC))
  189.  
  190.   ' Turn off secure checking CRACK.CHECKLAG bytes after last Eol.
  191.   IF fBytePos >= fLastEol + nCrack(nSourceType, CRACK.CHECKLAG) THEN bCheck = False
  192.  
  193.   ' Write current byte.
  194.   PUT #pOutFile, fBytePos, sByte
  195.  
  196.   ' Check to see if the current byte is an eol tag.
  197.   IF nThisByte = nCrack(nSourceType, CRACK.EOL) THEN
  198.     bCheck = True         'Start looking for secure flags.
  199.     fLastEol = fBytePos   'Record position of this Eol.
  200.   END IF
  201.  
  202.   ' Show progress.
  203.   LOCATE CSRLIN, POS(0) - 1
  204.   PRINT sSpin(fBytePos MOD 4 + 1);
  205.  
  206.   ' Bump pointer & get next byte.
  207.   fBytePos = fBytePos + 1
  208.   GET #pInFile, fBytePos, sByte
  209.   nThisByte = ASC(sByte)
  210. WEND
  211. sCrackStop = TIME$
  212.  
  213. CLOSE
  214. PRINT : PRINT
  215.  
  216. PRINT "Var table copy start time: "; sVarTblStart
  217. PRINT "Var table copy end time  : "; sVarTblStop
  218. PRINT
  219. PRINT "Crack start time         : "; sCrackStart
  220. PRINT "Crack end time           : "; sCrackStop
  221. PRINT : PRINT : PRINT : PRINT
  222.  
  223. PRINT "Done."
  224. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement