$IFNDEF CALL_ASM_PROC_X
$DEFINE CALL_ASM_PROC_X
DECLARE FUNCTION CallAsmProc LIB "user32" ALIAS "CallWindowProcA" _
(Proc AS LONG, A1 AS LONG, A2 AS LONG, A3 AS LONG, A4 AS LONG) AS LONG
$ENDIF
DEFBYTE RC4BinStrArray (0 TO 310) = _
{ _
&HC8, &H00, &H00, &H00, &H81, &HEC, &H2C, &H01, &H00, &H00, _
&H89, &HE8, &H2D, &H2C, &H01, &H00, &H00, &H89, &H45, &HD8, _
&H53, &H51, &H52, &H56, &H57, &H8B, &H75, &H08, &H81, &HEE, _
&H04, &H00, &H00, &H00, &H8B, &H06, &H89, &H45, &HDC, &H8B, _
&H75, &H0C, &H81, &HEE, &H04, &H00, &H00, &H00, &H8B, &H06, _
&H89, &H45, &HE0, &H81, &H7D, &H0C, &H00, &H00, &H00, &H00, _
&H75, &H0A, &HB8, &H01, &H00, &H00, &H00, &HE9, &HE6, &H00, _
&H00, &H00, &H81, &H7D, &HE0, &H00, &H00, &H00, &H00, &H75, _
&H0A, &HB8, &H02, &H00, &H00, &H00, &HE9, &HD3, &H00, &H00, _
&H00, &H81, &H7D, &H08, &H00, &H00, &H00, &H00, &H75, &H0A, _
&HB8, &H03, &H00, &H00, &H00, &HE9, &HC0, &H00, &H00, &H00, _
&H81, &H7D, &HDC, &H00, &H00, &H00, &H00, &H75, &H0A, &HB8, _
&H04, &H00, &H00, &H00, &HE9, &HAD, &H00, &H00, &H00, &HE8, _
&H6A, &H00, &H00, &H00, &HB8, &H00, &H00, &H00, &H00, &HBB, _
&H00, &H00, &H00, &H00, &H8B, &H75, &HD8, &H8B, &H7D, &H08, _
&HB9, &H00, &H00, &H00, &H00, &HBA, &H00, &H00, &H00, &H00, _
&HFE, &HC3, &H02, &H04, &H33, &H8A, &H14, &H33, &H86, &H14, _
&H30, &H86, &H14, &H33, &H8A, &H14, &H33, &H02, &H14, &H30, _
&H50, &HB8, &H00, &H00, &H00, &H00, &H25, &HFF, &H00, &H00, _
&H00, &H8A, &H04, &H32, &H30, &H04, &H39, &H58, &H41, &H3B, _
&H4D, &HDC, &H75, &HD4, &HB8, &H00, &H00, &H00, &H00, &HE9, _
&H58, &H00, &H00, &H00, &HB8, &H00, &H00, &H00, &H00, &H8B, _
&H7D, &HD8, &H88, &H07, &H47, &HFE, &HC0, &H75, &HF9, &HB8, _
&H00, &H00, &H00, &H00, &HB8, &H00, &H00, &H00, &H00, &HC3, _
&HE8, &HE1, &HFF, &HFF, &HFF, &HB8, &H00, &H00, &H00, &H00, _
&HBB, &H00, &H00, &H00, &H00, &HB9, &H00, &H00, &H00, &H00, _
&H8B, &H75, &HD8, &H8B, &H7D, &H0C, &HBA, &H00, &H00, &H00, _
&H00, &H02, &H04, &H1E, &H39, &H4D, &HE0, &H75, &H05, &HB9, _
&H00, &H00, &H00, &H00, &H02, &H04, &H0F, &H8A, &H14, &H30, _
&H86, &H14, &H33, &H86, &H14, &H30, &H41, &HFE, &HC3, &H75, _
&HE2, &HC3, &H5F, &H5E, &H5A, &H59, &H5B, &HC9, &HC2, &H10, _
&H00 _
}
DEFINT ptrRC4BinStr
ptrRC4BinStr = VARPTR (RC4BinStrArray(0))
FUNCTION RC4BinStr (sDatas AS STRING, sKEY AS STRING) AS LONG
DEFSTR ssDatas = sDatas
DEFSTR ssKEY = sKEY
Result = CallAsmProc (ptrRC4BinStr, VARPTR(ssDatas), VARPTR(ssKEY), 0, 0)
END FUNCTION
DEFBYTE RC4InitArray (0 TO 187) = _
{ _
&HC8, &H00, &H00, &H00, &H81, &HEC, &H28, &H00, &H00, &H00, _
&H53, &H51, &H52, &H56, &H57, &H8B, &H75, &H0C, &H81, &HEE, _
&H04, &H00, &H00, &H00, &H8B, &H06, &H89, &H45, &HD8, &H81, _
&H7D, &H08, &H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H05, _
&H00, &H00, &H00, &HE9, &H83, &H00, &H00, &H00, &H81, &H7D, _
&H0C, &H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H01, &H00, _
&H00, &H00, &HE9, &H70, &H00, &H00, &H00, &H81, &H7D, &HD8, _
&H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H02, &H00, &H00, _
&H00, &HE9, &H5D, &H00, &H00, &H00, &HB8, &H00, &H00, &H00, _
&H00, &H8B, &H7D, &H08, &H88, &H07, &H47, &HFE, &HC0, &H75, _
&HF9, &HB8, &H00, &H00, &H00, &H00, &HBB, &H00, &H00, &H00, _
&H00, &HB9, &H00, &H00, &H00, &H00, &H8B, &H75, &H08, &H8B, _
&H7D, &H0C, &HBA, &H00, &H00, &H00, &H00, &H02, &H04, &H1E, _
&H39, &H4D, &HD8, &H75, &H05, &HB9, &H00, &H00, &H00, &H00, _
&H02, &H04, &H0F, &H8A, &H14, &H30, &H86, &H14, &H33, &H86, _
&H14, &H30, &H41, &HFE, &HC3, &H75, &HE2, &H8B, &H7D, &H08, _
&HC6, &H87, &H00, &H01, &H00, &H00, &H00, &HC6, &H87, &H01, _
&H01, &H00, &H00, &H00, &HB8, &H00, &H00, &H00, &H00, &H5F, _
&H5E, &H5A, &H59, &H5B, &HC9, &HC2, &H10, &H00 _
}
DEFINT ptrRC4Init
ptrRC4Init = VARPTR (RC4InitArray(0))
FUNCTION RC4Init (sTable AS STRING, sKEY AS STRING) AS LONG
DEFSTR ssTable = sTable
DEFSTR ssKEY = sKEY
Result = CallAsmProc (ptrRC4Init, VARPTR(ssTable), VARPTR(ssKEY), 0, 0)
END FUNCTION
DEFBYTE RC4PipeArray (0 TO 195) = _
{ _
&HC8, &H00, &H00, &H00, &H81, &HEC, &H28, &H00, &H00, &H00, _
&H53, &H51, &H52, &H56, &H57, &H8B, &H75, &H0C, &H81, &HEE, _
&H04, &H00, &H00, &H00, &H8B, &H06, &H89, &H45, &HD8, &H81, _
&H7D, &H0C, &H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H03, _
&H00, &H00, &H00, &HE9, &H8B, &H00, &H00, &H00, &H81, &H7D, _
&HD8, &H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H04, &H00, _
&H00, &H00, &HE9, &H78, &H00, &H00, &H00, &H81, &H7D, &H08, _
&H00, &H00, &H00, &H00, &H75, &H0A, &HB8, &H05, &H00, &H00, _
&H00, &HE9, &H65, &H00, &H00, &H00, &H8B, &H75, &H08, &H8A, _
&H9E, &H00, &H01, &H00, &H00, &H81, &HE3, &HFF, &H00, &H00, _
&H00, &H8A, &H86, &H01, &H01, &H00, &H00, &H25, &HFF, &H00, _
&H00, &H00, &H8B, &H7D, &H0C, &HB9, &H00, &H00, &H00, &H00, _
&HBA, &H00, &H00, &H00, &H00, &HFE, &HC3, &H02, &H04, &H33, _
&H8A, &H14, &H33, &H86, &H14, &H30, &H86, &H14, &H33, &H8A, _
&H14, &H33, &H02, &H14, &H30, &H50, &HB8, &H00, &H00, &H00, _
&H00, &H81, &HE2, &HFF, &H00, &H00, &H00, &H8A, &H04, &H32, _
&H30, &H04, &H39, &H58, &H41, &H3B, &H4D, &HD8, &H75, &HD3, _
&H88, &H9E, &H00, &H01, &H00, &H00, &H88, &H86, &H01, &H01, _
&H00, &H00, &HB8, &H00, &H00, &H00, &H00, &H5F, &H5E, &H5A, _
&H59, &H5B, &HC9, &HC2, &H10, &H00 _
}
DEFINT ptrRC4Pipe
ptrRC4Pipe = VARPTR (RC4PipeArray(0))
FUNCTION RC4Pipe (sTable AS STRING, sDatas AS STRING) AS LONG
DEFSTR ssTable = sTable
DEFSTR ssDatas = sDatas
Result = CallAsmProc (ptrRC4Pipe, VARPTR(ssTable), VARPTR(ssDatas), 0, 0)
END FUNCTION
$TYPECHECK ON
CONST RC4ASM_FINISHED_OK = 0
CONST RC4ASM_ERROR_PTR_KEY = 1
CONST RC4ASM_ERROR_LEN_KEY = 2
CONST RC4ASM_ERROR_PTR_DATAS = 3
CONST RC4ASM_ERROR_LEN_DATAS = 4
CONST RC4ASM_ERROR_PTR_STABLE = 5
CONST RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED = 6
CONST RC4ASM_ERROR_CANT_CREATE_FILE_OUT = 7
CONST RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE = 8
CONST RC4ASM_ERROR_UNEXPECTED = 255
FUNCTION GetRC4AsmErrorByName (iError AS LONG) AS STRING
SELECT CASE iError
CASE RC4ASM_FINISHED_OK
Result = " *** RC4ASM FINISHED_OK *** "
CASE RC4ASM_ERROR_PTR_KEY
Result = " *** RC4ASM ERROR_PTR_KEY *** "
CASE RC4ASM_ERROR_LEN_KEY
Result = " *** RC4ASM ERROR_LEN_KEY *** "
CASE RC4ASM_ERROR_PTR_DATAS
Result = " *** RC4ASM ERROR_PTR_DATAS *** "
CASE RC4ASM_ERROR_LEN_DATAS
Result = " *** RC4ASM ERROR_LEN_DATAS *** "
CASE RC4ASM_ERROR_PTR_STABLE
Result = " *** RC4ASM ERROR_PTR_STABLE *** "
CASE RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED
Result = " *** RC4ASM ERROR FILE IN CANT BE OPENED ***"
CASE RC4ASM_ERROR_CANT_CREATE_FILE_OUT
Result = " *** RC4ASM ERROR CANT CREATE FILE OUT ***"
CASE RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE
Result = " *** RC4ASM ERROR IBITSIZE_IN_RC4FILE_PIPE ***"
CASE ELSE
Result = " *** RC4ASM ERRONEOUS ERROR NUMBER :) " & STR$(iError) & " ***"
END SELECT
END FUNCTION
FUNCTION RC4File (PathFileNameIn AS STRING, PathFileNameOut AS STRING, Key AS STRING, iBitsSize AS LONG) AS LONG
DEFSTR sPathFileNameIn = PathFileNameIn, sPathFileNameOut = PathFileNameOut
DIM file2Rc4 AS QFILESTREAM
DIM fileRC4Out AS QFILESTREAM
DIM sTable AS STRING * 258
DEFINT iReturn
DEFINT iFileLengthLeft
DEFSTR sBits, sTmp
DEFSTR sKey = KEY
IF iBitsSize < 1 THEN Result = RC4ASM_ERROR_IBITSIZE_IN_RC4FILE_PIPE:EXIT FUNCTION
IF file2RC4.OPEN (sPathFileNameIn, 0) <> 0 THEN
IF fileRC4Out.OPEN (sPathFileNameOut, 65535) <> 0 THEN
iFileLengthLeft = file2RC4.Size
file2RC4.Position = 0
iReturn = RC4Init (sTable, sKey)
DO
IF iReturn = 0 THEN
IF iFileLengthLeft >= iBitsSize THEN
sBits = file2RC4.ReadBinStr (iBitsSize)
iReturn = RC4Pipe (sTable, sBits)
IF iReturn <> 0 THEN Result = iReturn:EXIT DO
fileRC4Out.WriteBinStr (sBits, iBitsSize)
iFileLengthLeft = iFileLengthLeft - iBitsSize
ELSE
sBits = file2RC4.ReadBinStr (iFileLengthLeft)
iReturn = RC4Pipe (sTable, sBits)
IF iReturn <> 0 THEN Result = iReturn:EXIT DO
fileRC4Out.WriteBinStr (sBits, iFileLengthLeft)
iFileLengthLeft = 0
END IF
ELSE
Result = iReturn
EXIT DO
END IF
LOOP UNTIL iFileLengthLeft = 0
fileRC4Out.CLOSE
ELSE
Result = RC4ASM_ERROR_CANT_CREATE_FILE_OUT
END IF
file2RC4.CLOSE
ELSE
Result = RC4ASM_ERROR_FILE_IN_CANT_BE_OPENED
EXIT FUNCTION
END IF
IF iFileLengthLeft <= 0 THEN Result = 0
END FUNCTION
$TYPECHECK OFF
|
|