├── src ├── VBCodeGenerator │ ├── frmCodeGen.frx │ └── frmCodeGen.frm ├── FrmMain.frm ├── FrmMain.frx ├── ID_DOC1.ico ├── lib │ ├── Stack.cls │ ├── Helper.bas │ ├── Replace.bas │ ├── ApiHelper.bas │ ├── clsStrCat.cls │ ├── ClsFilename.cls │ ├── RegExp.bas │ ├── Commandline.cls │ ├── clsConsole.cls │ └── StringReader.cls ├── base64 │ ├── Base64.bas │ ├── Base64.vbp │ └── Base64.frm ├── FrmDecodeLicenseFile.frx ├── Blowfish │ ├── basTestBlowfish.bas │ ├── Out │ │ └── Cryptography Software Code in Visual Basic and C.URL │ ├── BlowfishEx.vbw │ ├── basAPITimer.bas │ ├── Blowfish.vbp │ ├── BlowfishEx.vbp │ ├── basUnsignedWord.bas │ ├── basTestRadix64.bas │ ├── basBlowfish.bas │ ├── BlowfishReadMe.txt │ ├── basConvert.bas │ ├── frmBlowfish.frm │ ├── basBlowfishByteFns.bas │ ├── basRadix64.bas │ └── BlowfishEx.frm ├── z_unused │ ├── MersenneTwister2.bas │ ├── Pe_info.bas │ └── PE_info.cls ├── SRC RanRot_MT.dll - Mersenne Twister & RanRot │ └── RanRot │ │ ├── Main.cpp │ │ ├── RanRot_MT.def │ │ ├── randomC.H │ │ ├── RANROTB.CPP │ │ ├── url │ │ └── UnifRamdomranrotb.cpp Source File.URL │ │ ├── RanRot.sln │ │ ├── RanRot.vcproj │ │ └── mt19937ar.c ├── SHA256 │ ├── SHATest.vbp │ └── FSHATest.frm ├── IC_Decompile_Helper.bas ├── IC_Decompile_Const.bas └── MersenneTwister.bas ├── ZlibTool.ocx ├── Ironcube_Decoder.exe ├── data ├── make_license.exe ├── ByteCodeNames_list.dat └── php_functions_list.dat ├── install_ZlibTool_ocx.cmd ├── history.txt ├── README.md └── Ioncube_Decoder.vbp /src/VBCodeGenerator/frmCodeGen.frx: -------------------------------------------------------------------------------- 1 | lt -------------------------------------------------------------------------------- /ZlibTool.ocx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/ZlibTool.ocx -------------------------------------------------------------------------------- /src/FrmMain.frm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/FrmMain.frm -------------------------------------------------------------------------------- /src/FrmMain.frx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/FrmMain.frx -------------------------------------------------------------------------------- /src/ID_DOC1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/ID_DOC1.ico -------------------------------------------------------------------------------- /src/lib/Stack.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/lib/Stack.cls -------------------------------------------------------------------------------- /Ironcube_Decoder.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/Ironcube_Decoder.exe -------------------------------------------------------------------------------- /src/lib/Helper.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/lib/Helper.bas -------------------------------------------------------------------------------- /src/lib/Replace.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/lib/Replace.bas -------------------------------------------------------------------------------- /data/make_license.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/data/make_license.exe -------------------------------------------------------------------------------- /src/base64/Base64.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/base64/Base64.bas -------------------------------------------------------------------------------- /src/lib/ApiHelper.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/lib/ApiHelper.bas -------------------------------------------------------------------------------- /src/lib/clsStrCat.cls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/lib/clsStrCat.cls -------------------------------------------------------------------------------- /src/FrmDecodeLicenseFile.frx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/FrmDecodeLicenseFile.frx -------------------------------------------------------------------------------- /src/Blowfish/basTestBlowfish.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/Blowfish/basTestBlowfish.bas -------------------------------------------------------------------------------- /src/z_unused/MersenneTwister2.bas: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/z_unused/MersenneTwister2.bas -------------------------------------------------------------------------------- /src/Blowfish/Out/Cryptography Software Code in Visual Basic and C.URL: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=http://www.di-mgt.com.au/crypto.html#BlowfishVB 3 | -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/Main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/Main.cpp -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/RanRot_MT.def: -------------------------------------------------------------------------------- 1 | LIBRARY mt 2 | EXPORTS 3 | MT_GetI8 = genrand_int31 4 | MT_Init = init_genrand 5 | RanRot_Init 6 | RanRot_GetI8 -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/randomC.H: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/randomC.H -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/RANROTB.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/80000v/IonCube_Decoder/HEAD/src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/RANROTB.CPP -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/url/UnifRamdomranrotb.cpp Source File.URL: -------------------------------------------------------------------------------- 1 | [InternetShortcut] 2 | URL=http://www.chasanc.com/source_code_doc_haydwt/ranrotb_8cpp-source.html 3 | -------------------------------------------------------------------------------- /src/Blowfish/BlowfishEx.vbw: -------------------------------------------------------------------------------- 1 | frmBlowfishEx = 22, 22, 629, 359, , 0, 0, 0, 0, C 2 | basBlfArrays = 0, 0, 0, 0, C 3 | basBlowfish = 0, 0, 0, 0, C 4 | basConvert = 0, 0, 0, 0, C 5 | basRadix64 = 44, 44, 525, 381, 6 | basUnsignedWord = 0, 0, 0, 0, C 7 | basBlowfishByteFns = 66, 66, 547, 403, 8 | -------------------------------------------------------------------------------- /install_ZlibTool_ocx.cmd: -------------------------------------------------------------------------------- 1 | @prompt -$G 2 | regsvr32 /u /s ZlibTool.ocx 3 | 4 | @echo Uninstall succeed-DownFeed.net. 5 | @echo Press any key to install or ctrl+c to cancel-DownFeed.net. 6 | @pause >nul 7 | 8 | regsvr32 ZlibTool.ocx 9 | 10 | @if errorlevel==1 ( 11 | 12 | @echo Regsvr32 returns Error: %errorlevel% ! Calling rundll32 that may show more details about the problem: 13 | rundll32 ZlibTool.ocx,DllRegisterServer 14 | 15 | @pause >nul 16 | ) 17 | -------------------------------------------------------------------------------- /src/Blowfish/basAPITimer.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basAPITimer" 2 | Option Explicit 3 | 4 | ' Module: basAPITimer 5 | ' API Timer Functions - from Litwin, Getz, Gilbert 6 | 7 | Declare Function wu_GetTime Lib "winmm.dll" Alias _ 8 | "timeGetTime" () As Long 9 | Private mlStartTime As Long 10 | 11 | Public Sub ap_StartTimer() 12 | mlStartTime = wu_GetTime() 13 | End Sub 14 | 15 | Public Function ap_EndTimer() As Long 16 | ap_EndTimer = wu_GetTime() - mlStartTime 17 | End Function 18 | 19 | -------------------------------------------------------------------------------- /history.txt: -------------------------------------------------------------------------------- 1 | 11.02.20010 2 | Made decoder independent from licensefile 3 | 4 | 07.02.20010 5 | Added 'Decode License File' form 6 | 7 | 15.01.2010 8 | Recompiled ZlibTool.ocx and make it to use MFC42.dll msvcrt.dll(instead of MFC71.dll msvcr71.dll) that are included within the windows installation - thus are present on every system. 9 | Removed InitCommonControls() VB6 workaround and integrate the bugfix into ZlibTool.ocx 10 | 11 | 4.12.2009 12 | added *.Txt dumper 13 | improved bytecode log output 14 | add stack error detecting & correction function 15 | 16 | 2.12.2009 17 | fixed ZlibTool.ocx bug to came up on compiled exe 18 | 19 | 1.12.2009 20 | Started with decompiler part 21 | 22 | 15.11.2009 23 | fixed bug in HandleServerRestrictions 24 | started with php5 support -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IonCube_Decoder 2 | IonCube_Decoder--------IonCube decryption tool 3 | 4 | 5 | ChangeLog 6 | 7 | 11.02.20010 8 | Made decoder independent from licensefile 9 | 10 | 07.02.20010 11 | Added 'Decode License File' form 12 | 13 | 15.01.2010 14 | Recompiled ZlibTool.ocx and make it to use MFC42.dll msvcrt.dll(instead of MFC71.dll msvcr71.dll) that are included within the windows installation - thus are present on every system. 15 | Removed InitCommonControls() VB6 workaround and integrate the bugfix into ZlibTool.ocx 16 | 17 | 4.12.2009 18 | added *.Txt dumper 19 | improved bytecode log output 20 | add stack error detecting & correction function 21 | 22 | 2.12.2009 23 | fixed ZlibTool.ocx bug to came up on compiled exe 24 | 25 | 1.12.2009 26 | Started with decompiler part 27 | 28 | 15.11.2009 29 | fixed bug in HandleServerRestrictions 30 | started with php5 support 31 | -------------------------------------------------------------------------------- /src/base64/Base64.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=Base64.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation 4 | Module=modBase64; Base64.bas 5 | IconForm="frmBase64" 6 | Startup="frmBase64" 7 | HelpFile="" 8 | Title="Project1" 9 | ExeName32="Project1.exe" 10 | Path32="..\..\..\.." 11 | Command32="" 12 | Name="Base64" 13 | HelpContextID="0" 14 | CompatibleMode="0" 15 | MajorVer=1 16 | MinorVer=0 17 | RevisionVer=0 18 | AutoIncrementVer=0 19 | ServerSupportFiles=0 20 | VersionCompanyName="ggrz" 21 | CompilationType=0 22 | OptimizationType=0 23 | FavorPentiumPro(tm)=0 24 | CodeViewDebugInfo=0 25 | NoAliasing=-1 26 | BoundsCheck=-1 27 | OverflowCheck=-1 28 | FlPointCheck=-1 29 | FDIVCheck=-1 30 | UnroundedFP=-1 31 | StartMode=0 32 | Unattended=0 33 | Retained=0 34 | ThreadPerObject=0 35 | MaxNumberOfThreads=1 36 | 37 | [MS Transaction Server] 38 | AutoRefresh=1 39 | -------------------------------------------------------------------------------- /src/SHA256/SHATest.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=FSHATest.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation 4 | Class=CSHA256; CSHA256.cls 5 | IconForm="FSHATest" 6 | Startup="FSHATest" 7 | HelpFile="" 8 | Title="SHATest" 9 | ExeName32="SHATest.exe" 10 | Command32="" 11 | Name="SHATest" 12 | HelpContextID="0" 13 | CompatibleMode="0" 14 | MajorVer=1 15 | MinorVer=0 16 | RevisionVer=0 17 | AutoIncrementVer=0 18 | ServerSupportFiles=0 19 | VersionCompanyName="Frez Systems Limited" 20 | VersionLegalCopyright="Copyright 2001 Frez Systems Limited" 21 | CompilationType=0 22 | OptimizationType=0 23 | FavorPentiumPro(tm)=0 24 | CodeViewDebugInfo=0 25 | NoAliasing=0 26 | BoundsCheck=0 27 | OverflowCheck=0 28 | FlPointCheck=0 29 | FDIVCheck=0 30 | UnroundedFP=0 31 | StartMode=0 32 | Unattended=0 33 | Retained=0 34 | ThreadPerObject=0 35 | MaxNumberOfThreads=1 36 | 37 | [MS Transaction Server] 38 | AutoRefresh=1 39 | -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/RanRot.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 8.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RanRot", "RanRot.vcproj", "{EB75293C-0935-4DD4-8F8A-4F16B60F559D}" 3 | ProjectSection(ProjectDependencies) = postProject 4 | EndProjectSection 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfiguration) = preSolution 8 | Debug = Debug 9 | Release = Release 10 | EndGlobalSection 11 | GlobalSection(ProjectConfiguration) = postSolution 12 | {EB75293C-0935-4DD4-8F8A-4F16B60F559D}.Debug.ActiveCfg = Release|Win32 13 | {EB75293C-0935-4DD4-8F8A-4F16B60F559D}.Debug.Build.0 = Release|Win32 14 | {EB75293C-0935-4DD4-8F8A-4F16B60F559D}.Release.ActiveCfg = Release|Win32 15 | {EB75293C-0935-4DD4-8F8A-4F16B60F559D}.Release.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(ExtensibilityGlobals) = postSolution 18 | EndGlobalSection 19 | GlobalSection(ExtensibilityAddIns) = postSolution 20 | EndGlobalSection 21 | EndGlobal 22 | -------------------------------------------------------------------------------- /src/Blowfish/Blowfish.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=frmBlowfish.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation 4 | Module=basBlfArrays; basBlfArrays.bas 5 | Module=basBlowfish; basBlowfish.bas 6 | Module=basConvert; basConvert.bas 7 | Module=basRadix64; basRadix64.bas 8 | Module=basUnsignedWord; basUnsignedWord.bas 9 | Module=basBlowfishByteFns; basBlowfishByteFns.bas 10 | IconForm="frmBlowfish" 11 | Startup="frmBlowfish" 12 | HelpFile="" 13 | Title="Blowfish" 14 | ExeName32="Blowfish.exe" 15 | Command32="" 16 | Name="Blowfish" 17 | HelpContextID="0" 18 | CompatibleMode="0" 19 | MajorVer=1 20 | MinorVer=6 21 | RevisionVer=1 22 | AutoIncrementVer=1 23 | ServerSupportFiles=0 24 | VersionComments="Use at your own risk." 25 | VersionCompanyName="DI Management Services P/L" 26 | VersionLegalCopyright="Copyright (C) 2000-3 DI Management Services Pty Ltd. All rights reserved." 27 | VersionProductName="Blowfish Demo" 28 | CompilationType=0 29 | OptimizationType=0 30 | FavorPentiumPro(tm)=0 31 | CodeViewDebugInfo=0 32 | NoAliasing=0 33 | BoundsCheck=0 34 | OverflowCheck=0 35 | FlPointCheck=0 36 | FDIVCheck=0 37 | UnroundedFP=0 38 | StartMode=0 39 | Unattended=0 40 | Retained=0 41 | ThreadPerObject=0 42 | MaxNumberOfThreads=1 43 | 44 | [MS Transaction Server] 45 | AutoRefresh=1 46 | -------------------------------------------------------------------------------- /src/Blowfish/BlowfishEx.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=BlowfishEx.frm 3 | Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation 4 | Module=basBlfArrays; basBlfArrays.bas 5 | Module=basBlowfish; basBlowfish.bas 6 | Module=basConvert; basConvert.bas 7 | Module=basRadix64; basRadix64.bas 8 | Module=basUnsignedWord; basUnsignedWord.bas 9 | Module=basBlowfishByteFns; basBlowfishByteFns.bas 10 | IconForm="frmBlowfishEx" 11 | Startup="frmBlowfishEx" 12 | HelpFile="" 13 | Title="BlowfishEx" 14 | ExeName32="BlowfishEx.exe" 15 | Command32="" 16 | Name="BlowfishEx" 17 | HelpContextID="0" 18 | CompatibleMode="0" 19 | MajorVer=1 20 | MinorVer=6 21 | RevisionVer=1 22 | AutoIncrementVer=1 23 | ServerSupportFiles=0 24 | VersionComments="Use at your own risk." 25 | VersionCompanyName="DI Management Services P/L" 26 | VersionLegalCopyright="Copyright (C) 2000-3 DI Management Services Pty Ltd. All rights reserved." 27 | VersionProductName="Blowfish Extended Demo" 28 | CompilationType=0 29 | OptimizationType=0 30 | FavorPentiumPro(tm)=0 31 | CodeViewDebugInfo=0 32 | NoAliasing=0 33 | BoundsCheck=0 34 | OverflowCheck=0 35 | FlPointCheck=0 36 | FDIVCheck=0 37 | UnroundedFP=0 38 | StartMode=0 39 | Unattended=0 40 | Retained=0 41 | ThreadPerObject=0 42 | MaxNumberOfThreads=1 43 | 44 | [MS Transaction Server] 45 | AutoRefresh=1 46 | -------------------------------------------------------------------------------- /Ioncube_Decoder.vbp: -------------------------------------------------------------------------------- 1 | Type=Exe 2 | Form=src\FrmMain.frm 3 | Module=ApiHelper; src\lib\ApiHelper.bas 4 | Class=ClsFilename; src\lib\ClsFilename.cls 5 | Class=clsStrCat; src\lib\clsStrCat.cls 6 | Class=Commandline; src\lib\Commandline.cls 7 | Class=FileStream; src\lib\FileStream.cls 8 | Module=Helper; src\lib\Helper.bas 9 | Module=mod_Replace; src\lib\Replace.bas 10 | Class=StringReader; src\lib\StringReader.cls 11 | Module=modBase64; src\base64\Base64.bas 12 | Module=MersenneTwister; src\MersenneTwister.bas 13 | Module=IC_Decoder; src\IC_Decoder.bas 14 | Class=Stack; src\lib\Stack.cls 15 | Object={E88121A0-9FA9-11CF-9D9F-00AA003A3AA3}#1.0#0; ZlibTool.ocx 16 | Form=src\VBCodeGenerator\frmCodeGen.frm 17 | Module=IC_Decompile_Helper; src\IC_Decompile_Helper.bas 18 | Module=IC_Decompile_ByteCodeConst; src\IC_Decompile_Const.bas 19 | Form=src\FrmDecodeLicenseFile.frm 20 | Class=Console; src\lib\clsConsole.cls 21 | Class=CSHA256; src\SHA256\CSHA256.cls 22 | Form=src\SHA256\FSHATest.frm 23 | Module=basBlowfishByteFns; src\Blowfish\basBlowfishByteFns.bas 24 | Module=basBlfArrays; src\Blowfish\basBlfArrays.bas 25 | Module=basUnsignedWord; src\Blowfish\basUnsignedWord.bas 26 | Module=basBlowfish; src\Blowfish\basBlowfish.bas 27 | Module=basConvert; src\Blowfish\basConvert.bas 28 | Module=IC_Decompile; src\IC_Decompile.bas 29 | IconForm="FrmMain" 30 | Startup="FrmMain" 31 | HelpFile="" 32 | Title="Ioncube_Decoder" 33 | ExeName32="Ironcube_Decoder.exe" 34 | Command32=":\Programmierung\Projekte\Ioncube_Decoder\Test\TestOut\test1.php" 35 | Name="Ioncube_Decoder" 36 | HelpContextID="0" 37 | CompatibleMode="0" 38 | MajorVer=1 39 | MinorVer=1 40 | RevisionVer=41 41 | AutoIncrementVer=1 42 | ServerSupportFiles=0 43 | VersionComments="Data striptease for Ion cube PHP-Encoded files" 44 | CondComp="isDebug = 1" 45 | CompilationType=-1 46 | OptimizationType=0 47 | FavorPentiumPro(tm)=0 48 | CodeViewDebugInfo=0 49 | NoAliasing=0 50 | BoundsCheck=0 51 | OverflowCheck=0 52 | FlPointCheck=0 53 | FDIVCheck=0 54 | UnroundedFP=0 55 | StartMode=0 56 | Unattended=0 57 | Retained=0 58 | ThreadPerObject=0 59 | MaxNumberOfThreads=1 60 | DebugStartupOption=0 61 | 62 | [MS Transaction Server] 63 | AutoRefresh=1 64 | -------------------------------------------------------------------------------- /data/ByteCodeNames_list.dat: -------------------------------------------------------------------------------- 1 | ZEND_NOP 2 | ZEND_ADD 3 | ZEND_SUB 4 | ZEND_MUL 5 | ZEND_DIV 6 | ZEND_MOD 7 | ZEND_SL 8 | ZEND_SR 9 | ZEND_CONCAT 10 | ZEND_BW_OR 11 | ZEND_BW_AND 12 | ZEND_BW_XOR 13 | ZEND_BW_NOT 14 | ZEND_BOOL_NOT 15 | ZEND_BOOL_XOR 16 | ZEND_IS_IDENTICAL 17 | ZEND_IS_NOT_IDENTICAL 18 | ZEND_IS_EQUAL 19 | ZEND_IS_NOT_EQUAL 20 | ZEND_IS_SMALLER 21 | ZEND_IS_SMALLER_OR_EQUAL 22 | ZEND_CAST 23 | ZEND_QM_ASSIGN 24 | ZEND_ASSIGN_ADD 25 | ZEND_ASSIGN_SUB 26 | ZEND_ASSIGN_MUL 27 | ZEND_ASSIGN_DIV 28 | ZEND_ASSIGN_MOD 29 | ZEND_ASSIGN_SL 30 | ZEND_ASSIGN_SR 31 | ZEND_ASSIGN_CONCAT 32 | ZEND_ASSIGN_BW_OR 33 | ZEND_ASSIGN_BW_AND 34 | ZEND_ASSIGN_BW_XOR 35 | ZEND_PRE_INC 36 | ZEND_PRE_DEC 37 | ZEND_POST_INC 38 | ZEND_POST_DEC 39 | ZEND_ASSIGN 40 | ZEND_ASSIGN_REF 41 | ZEND_ECHO 42 | ZEND_PRINT 43 | ZEND_JMP 44 | ZEND_JMPZ 45 | ZEND_JMPNZ 46 | ZEND_JMPZNZ 47 | ZEND_JMPZ_EX 48 | ZEND_JMPNZ_EX 49 | ZEND_CASE 50 | ZEND_SWITCH_FREE 51 | ZEND_BRK 52 | ZEND_CONT 53 | ZEND_BOOL 54 | ZEND_INIT_STRING 55 | ZEND_ADD_CHAR 56 | ZEND_ADD_STRING 57 | ZEND_ADD_VAR 58 | ZEND_BEGIN_SILENCE 59 | ZEND_END_SILENCE 60 | ZEND_INIT_FCALL_BY_NAME 61 | ZEND_DO_FCALL 62 | ZEND_DO_FCALL_BY_NAME 63 | ZEND_RETURN 64 | ZEND_RECV 65 | ZEND_RECV_INIT 66 | ZEND_SEND_VAL 67 | ZEND_SEND_VAR 68 | ZEND_SEND_REF 69 | ZEND_NEW 70 | ZEND_JMP_NO_CTOR 71 | ZEND_FREE 72 | ZEND_INIT_ARRAY 73 | ZEND_ADD_ARRAY_ELEMENT 74 | ZEND_INCLUDE_OR_EVAL 75 | ZEND_UNSET_VAR 76 | ZEND_UNSET_DIM 77 | ZEND_UNSET_OBJ 78 | ZEND_FE_RESET 79 | ZEND_FE_FETCH 80 | ZEND_EXIT 81 | ZEND_FETCH_R 82 | ZEND_FETCH_DIM_R 83 | ZEND_FETCH_OBJ_R 84 | ZEND_FETCH_W 85 | ZEND_FETCH_DIM_W 86 | ZEND_FETCH_OBJ_W 87 | ZEND_FETCH_RW 88 | ZEND_FETCH_DIM_RW 89 | ZEND_FETCH_OBJ_RW 90 | ZEND_FETCH_IS 91 | ZEND_FETCH_DIM_IS 92 | ZEND_FETCH_OBJ_IS 93 | ZEND_FETCH_FUNC_ARG 94 | ZEND_FETCH_DIM_FUNC_ARG 95 | ZEND_FETCH_OBJ_FUNC_ARG 96 | ZEND_FETCH_UNSET 97 | ZEND_FETCH_DIM_UNSET 98 | ZEND_FETCH_OBJ_UNSET 99 | ZEND_FETCH_DIM_TMP_VAR 100 | ZEND_FETCH_CONSTANT 101 | ZEND_DECLARE_FUNCTION_OR_CLASS 102 | ZEND_EXT_STMT 103 | ZEND_EXT_FCALL_BEGIN 104 | ZEND_EXT_FCALL_END 105 | ZEND_EXT_NOP 106 | ZEND_TICKS 107 | ZEND_SEND_VAR_NO_REF 108 | ZEND_CATCH 109 | ZEND_THROW 110 | ZEND_FETCH_CLASS 111 | ZEND_CLONE 112 | ZEND_INIT_CTOR_CALL 113 | ZEND_INIT_METHOD_CALL 114 | ZEND_INIT_STATIC_METHOD_CALL 115 | ZEND_ISSET_ISEMPTY_VAR 116 | ZEND_ISSET_ISEMPTY_DIM_OBJ 117 | ZEND_IMPORT_FUNCTION 118 | ZEND_IMPORT_CLASS 119 | ZEND_IMPORT_CONST 120 | ZEND_OP_119 121 | ZEND_OP_120 122 | ZEND_ASSIGN_ADD_OBJ 123 | ZEND_ASSIGN_SUB_OBJ 124 | ZEND_ASSIGN_MUL_OBJ 125 | ZEND_ASSIGN_DIV_OBJ 126 | ZEND_ASSIGN_MOD_OBJ 127 | ZEND_ASSIGN_SL_OBJ 128 | ZEND_ASSIGN_SR_OBJ 129 | ZEND_ASSIGN_CONCAT_OBJ 130 | ZEND_ASSIGN_BW_OR_OBJ 131 | ZEND_ASSIGN_BW_AND_OBJ 132 | ZEND_ASSIGN_BW_XOR_OBJ 133 | ZEND_PRE_INC_OBJ 134 | ZEND_PRE_DEC_OBJ 135 | ZEND_POST_INC_OBJ 136 | ZEND_POST_DEC_OBJ 137 | ZEND_ASSIGN_OBJ 138 | ZEND_OP_DATA 139 | ZEND_INSTANCEOF 140 | ZEND_DECLARE_CLASS 141 | ZEND_DECLARE_INHERITED_CLASS 142 | ZEND_DECLARE_FUNCTION 143 | ZEND_RAISE_ABSTRACT_ERROR 144 | ZEND_START_NAMESPACE 145 | ZEND_ADD_INTERFACE 146 | ZEND_VERIFY_INSTANCEOF 147 | ZEND_VERIFY_ABSTRACT_CLASS 148 | ZEND_ASSIGN_DIM 149 | ZEND_ISSET_ISEMPTY_PROP_OBJ 150 | ZEND_HANDLE_EXCEPTION 151 | ZEND_USER_OPCODE 152 | ZEND_U_NORMALIZE 153 | ZEND_JMP_SET 154 | ZEND_DECLARE_LAMBDA_FUNCTION -------------------------------------------------------------------------------- /src/lib/ClsFilename.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "ClsFilename" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = False 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" 15 | Attribute VB_Ext_KEY = "Top_Level" ,"Yes" 16 | Option Explicit 17 | 'Private 18 | Public mvarFileName$ 19 | 20 | 21 | Public Property Get FileName() As String 22 | Attribute FileName.VB_UserMemId = 0 23 | FileName = mvarFileName 24 | End Property 25 | 26 | Public Property Let FileName(ByVal vNewValue As String) 27 | mvarFileName = vNewValue 28 | End Property 29 | 30 | ' FileName.WholeName = .lpstrFile 31 | ' FileName.Path = Left(.lpstrFile, .nFileOffset) 32 | ' FileName.FileName = Mid(.lpstrFile, .nFileOffset, .nFileExtension - .nFileOffset) 33 | ' FileName.Ext = Mid(.lpstrFile, .nFileExtension, -1) 34 | 35 | Public Property Get Dir() As String 36 | On Error Resume Next 37 | Dim tmp 38 | tmp = Split(mvarFileName, "\") 39 | Dir = tmp(UBound(tmp) - 1) & "\" 40 | End Property 41 | 42 | 43 | Public Property Get Path() As String 44 | Path = Left(mvarFileName, InStrRev(mvarFileName, "\")) 45 | End Property 46 | 47 | Public Property Let Path(ByVal vNewValue As String) 48 | If Right(vNewValue, 1) = "\" Then 49 | mvarFileName = vNewValue & Name & Ext 50 | Else 51 | mvarFileName = vNewValue & "\" & Name & Ext 52 | End If 53 | End Property 54 | 55 | 56 | Public Property Get Name() As String 57 | On Error Resume Next 58 | Name = Split(Mid$(mvarFileName, Len(Path) + 1), ".")(0) 59 | End Property 60 | 61 | Public Property Let Name(ByVal vNewValue As String) 62 | mvarFileName = Path & vNewValue & Ext 63 | End Property 64 | 65 | 66 | Public Property Get Ext() As String 67 | On Error Resume Next 68 | Ext = Mid$(mvarFileName, InStrRev(mvarFileName, ".")) 69 | End Property 70 | 71 | Public Property Let Ext(ByVal vNewValue As String) 72 | 73 | mvarFileName = Path & Name & IIf(Left(vNewValue, 1) = ".", "", ".") & vNewValue 74 | End Property 75 | 76 | Public Property Get NameWithExt() As String 77 | On Error Resume Next 78 | NameWithExt = Mid$(mvarFileName, Len(Path) + 1) 79 | End Property 80 | 81 | Public Property Let NameWithExt(ByVal vNewValue As String) 82 | mvarFileName = Replace(Path & vNewValue, "\\", "\") 83 | ' mvarFileName = Path & vNewValue 84 | End Property 85 | 86 | Public Sub MakePath() 87 | ' create Dir and stop on all error other than 'dir already exists' 88 | 89 | Dim NewDir, NewPath$ 90 | NewPath = "" 91 | For Each NewDir In Split(Path, "\") 92 | 93 | 'Extent path Dir by Dir Create 94 | NewPath = NewPath & NewDir & "\" 95 | 96 | On Error Resume Next 97 | MkDir NewPath 98 | 99 | If (Err <> 75) And (Err <> 0) Then 'And (Err <> 76) 100 | Dim tmpstr$ 101 | tmpstr = Err.Description & " [" & Err.Number & "] when creating dir: " & Path 102 | On Error GoTo 0 103 | Err.Raise vbObjectError, , tmpstr 104 | End If 105 | 106 | Next 107 | 108 | End Sub 109 | 110 | -------------------------------------------------------------------------------- /src/lib/RegExp.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "RegExp" 2 | Option Explicit 3 | 4 | Dim myRegExp As New RegExp 5 | 6 | Public Const RE_Anchor_LineBegin$ = "^" 7 | Public Const RE_Anchor_LineEnd$ = "$" 8 | 9 | Public Const RE_Anchor_WordBoarder$ = "\b" 10 | Public Const RE_Anchor_NoWordBoarder$ = "\B" 11 | 12 | Public Const RE_AnyChar$ = "." 13 | Public Const RE_AnyChars$ = ".*" 14 | 15 | Public Const RE_AnyCharNL$ = "[\S\s]" 16 | Public Const RE_AnyCharsNL$ = "[\S\s]*?" 17 | 18 | Public Const RE_NewLine$ = "\r?\n" 19 | 20 | 21 | Public Function RE_WSpace(ParamArray Elements()) As String 22 | Dim WS$ ' WhiteSpace 23 | WS = "\s*" 24 | 25 | RE_WSpace = Join(Elements, WS) 26 | End Function 27 | 28 | 29 | 30 | Public Function RE_LookHead_positive(ExpressionThatShouldBeFound$) As String 31 | RE_LookHead_positive = "(?=" & ExpressionThatShouldBeFound & ")" 32 | End Function 33 | 34 | Public Function RE_LookHead_negative(ExpressionThatShouldNOTBeFound$) As String 35 | RE_LookHead_negative = "(?!" & ExpressionThatShouldNOTBeFound & ")" 36 | End Function 37 | 38 | Public Function RE_Repeat(Optional MinRepeat& = 0, Optional MaxRepeat = "") As String 39 | If (MinRepeat = MaxRepeat) Then 40 | RE_Repeat = "{" & MinRepeat & "}" 41 | Else 42 | RE_Repeat = "{" & MinRepeat & "," & MaxRepeat & "}" 43 | End If 44 | 45 | End Function 46 | 47 | 48 | Public Function RE_AnyCharRepeat(Optional MinRepeat& = 0, Optional MaxRepeat = "") As String 49 | RE_AnyCharRepeat = "." & RE_Repeat(MinRepeat, MaxRepeat) 50 | End Function 51 | 52 | Public Function RE_Group(RegExpForTheGroup$) As String 53 | RE_Group = "(" & RegExpForTheGroup & ")" 54 | End Function 55 | 56 | Public Function RE_Group_NonCaptured(RegExpForTheNonCapturedGroup$) As String 57 | RE_Group_NonCaptured = "(?:" & RegExpForTheNonCapturedGroup & ")" 58 | End Function 59 | 60 | Public Function RE_Literal(TextWithLiterals) As String 61 | 'Mask metachars 62 | RE_Literal = RE_Mask(TextWithLiterals, "][{}()*+?.\\^$|") 63 | 64 | End Function 65 | 66 | 67 | Public Function RE_Replace_Literal(TextWithLiterals) As String 68 | 'Mask Replace metachars 69 | ' $0-9 Back reference 70 | ' $+ Last reference 71 | 72 | ' $& MatchText 73 | 74 | ' $` Text left from subject 75 | ' $' Text right from subject 76 | ' $_ Whole subject 77 | 78 | RE_Replace_Literal = RE_Mask(TextWithLiterals, "0-9+`'_", "\$", "$$") 79 | 80 | 81 | End Function 82 | Private Sub RE_Mask_Whitespace(Text) 83 | ReplaceDo Text, vbCr, "\r" 84 | ReplaceDo Text, vbLf, "\n" 85 | ReplaceDo Text, vbTab, "\t" 86 | End Sub 87 | 88 | Private Function RE_Mask(Text, CharsToMask$, _ 89 | Optional CharMaskSearch$ = "", _ 90 | Optional CharMaskReplace$ = "\") As String 91 | With myRegExp 92 | .Global = True 93 | 94 | ' Mask MetaChars like with a preciding '\' 95 | .Pattern = CharMaskSearch & "[" & CharsToMask & "]" 96 | 97 | 'Attention Text is passed byref - so don use Text =...! 98 | RE_Mask = .Replace(Text, CharMaskReplace & "$&") 99 | 100 | 101 | End With 102 | 103 | ' RE_Mask_Whitespace Text 104 | 105 | ' RE_Mask = Text 106 | 107 | End Function 108 | 109 | Public Function RE_CharCls(Chars$) As String 110 | ' mask ']' and '-' 111 | RE_CharCls = "[" & RE_Mask(Chars, "]\\-") & "]" 112 | End Function 113 | 114 | Public Function RE_CharCls_Excluded(Chars$) As String 115 | ' mask ']' and '-' 116 | RE_CharCls_Excluded = "[^" & RE_Mask(Chars, "]\\-") & "]" 117 | 118 | End Function 119 | 120 | -------------------------------------------------------------------------------- /src/IC_Decompile_Helper.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "IC_Decompile_Helper" 2 | Option Explicit 3 | 4 | Const DeCompiledSource_CodeIndentation& = 3 5 | 6 | Public Function MakeStr$(Text) 7 | MakeStr = StrQuote(Replace(Text, vbLf, "\n")) 8 | End Function 9 | Private Function GetObjData(c As IC_CmdAttrib, _ 10 | Optional isCommand As Boolean, _ 11 | Optional isVar As Boolean) As Variant 12 | 13 | Select Case c.a_op_type 14 | 15 | 16 | Case IS_CONST__1 17 | 18 | 'Stack=0 19 | Select Case c.e_Obj_Type 20 | Case IS_LONG__1, IS_DOUBLE__2 21 | If isCommand Then 22 | Err.Raise vbObjectError, , "Logic Error keyword expected - a literal(Number) found." 23 | myStop 24 | Else 25 | GetObjData = c.c_Object 26 | End If 27 | 28 | Case IS_STRING__3 29 | If isCommand Then 30 | GetObjData = c.c_Object 31 | 32 | ElseIf isVar Then 33 | GetObjData = "$" & c.c_Object 34 | Else 35 | GetObjData = MakeStr(c.c_Object) 36 | End If 37 | 38 | Case IS_NULL__0 39 | GetObjData = Null 40 | 41 | 42 | Case IS_CONSTANT__8 43 | ' myStop 44 | GetObjData = c.c_Object 45 | 46 | Case IS_CONSTANT_ARRAY__9 47 | ' myStop 48 | GetObjData = c.c_Object 49 | 50 | Case Else 51 | myStop 52 | 53 | 54 | End Select 55 | 56 | 57 | 58 | Case IS_TMP_VAR__2 59 | 'concat TmpData according to type 60 | Select Case tmp_valueType 61 | 62 | 'Dirty Quick Hack1 - Till theres a better solution 63 | 'Makes TMP_VAR->Out to behave like IS_CONST 64 | Case 0 65 | GoTo IS_VAR_TmpHack 66 | 67 | Case IS_ARRAY__4 68 | GetObjData = "array(" & joinCol(tmp_values(c.c_Object), ", ") & ")" 69 | tmp_valueType = 0 'Dirty Quick Hack1 70 | 71 | Case IS_STRING__3 72 | GetObjData = MakeStr(joinCol(tmp_values(c.c_Object), "")) 73 | tmp_valueType = 0 'Dirty Quick Hack1 74 | 75 | Case Else 76 | myStop 77 | End Select 78 | 79 | Case IS_VAR__4 80 | IS_VAR_TmpHack: 'Dirty Quick Hack1 81 | 82 | 'Stack=1 83 | GetObjData = Stack.pop(c.c_Object) 84 | 85 | Case IS_UNUSED__8 86 | GetObjData = c.c_Object 87 | 88 | ' GetObjData = "" 89 | 90 | 91 | Case Else 92 | myStop 93 | 94 | End Select 95 | End Function 96 | 97 | 98 | Public Function Var(c As IC_CmdAttrib) 99 | Var = GetObjData(c, False, True) 100 | End Function 101 | 102 | Public Function Key(c As IC_CmdAttrib) 103 | Key = GetObjData(c, True) 104 | End Function 105 | 106 | Public Function Str(c As IC_CmdAttrib) 107 | Str = GetObjData(c) 108 | End Function 109 | 110 | Public Function Num(c As IC_CmdAttrib) 111 | Num = GetObjData(c) 112 | End Function 113 | 114 | 115 | Public Sub DecompiledOutPut(TextLine$, Optional IndentLevel = 0) 116 | Dim CodeIndent$ 117 | CodeIndent = String(IndentLevel * DeCompiledSource_CodeIndentation, " ") 118 | 119 | log_decompiled CodeIndent & TextLine 120 | 121 | End Sub 122 | 123 | Private Sub log_decompiled(Text$) 124 | FrmMain.List_Source.AddItem Text 125 | End Sub 126 | -------------------------------------------------------------------------------- /src/lib/Commandline.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "Commandline" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" 15 | Attribute VB_Ext_KEY = "Member0" ,"CommandLine" 16 | Attribute VB_Ext_KEY = "Top_Level" ,"Yes" 17 | Option Explicit 18 | 19 | Private Declare Function GetCommandLineRaw Lib "kernel32" Alias "GetCommandLineA" () As String 20 | Private argsWithQuotes$() 21 | Private Args$() 22 | Private EmptyArray$() 23 | 24 | Public NumberOfCommandLineArgs 25 | Public commandline As String 26 | 27 | 28 | '/////////////////////////////////////////////////// 29 | '// getArgs - Get CommandLineArguments with Quotes 30 | Public Function getArgs() As String() 31 | getArgs = Args 32 | End Function 33 | 34 | Public Function getArgsWithQuotes() 35 | getArgsWithQuotes = argsWithQuotes 36 | End Function 37 | 38 | 39 | '////////////////////////////////////////////////////////////////////////// 40 | '// Constructor - Sets args, args and NumberOfCommandLineArgs 41 | Private Sub Class_Initialize() 42 | 43 | GetCommandLine 44 | 45 | If commandline = Empty Then Exit Sub 46 | Call commandLineSplitRek(commandline) 47 | 48 | End Sub 49 | 50 | 51 | '//////////////////////////////////////////////////////////////////////////////////////////////// 52 | '// commandLineSplitRek - Split the commandLine and store chunks in args() and argsWithQuotes() 53 | '// should only used by the Constructor 54 | Private Sub commandLineSplitRek(lCommandLine As String, Optional oldpos% = 1, Optional levelCounter = 0) 55 | 'On Error GoTo commandLineSplitRek_err 56 | 57 | Dim endPos% ' Endposition for cut (...e.exe"<-) 58 | Dim startPos% ' Startposition for "new" commandline (->"C:\p...") 59 | Dim bIsQuoted As Boolean 60 | Dim bEndLine As Boolean 61 | Dim bNoQuotedAtEnd As Boolean 62 | 63 | 'Filter Leading Space 64 | For startPos = 1 To Len(lCommandLine) 65 | If Mid(lCommandLine, startPos, 1) > " " Then Exit For 66 | Next 67 | 68 | 'Trivial case - we are already at the end 69 | If (startPos >= Len(lCommandLine)) Then 70 | 71 | ' create array for saving commandline arguments 72 | NumberOfCommandLineArgs = levelCounter 73 | If NumberOfCommandLineArgs > 0 Then 74 | ReDim argsWithQuotes(NumberOfCommandLineArgs - 1) 75 | ReDim Args(NumberOfCommandLineArgs - 1) 76 | Else 77 | 'Clear Arrays 78 | argsWithQuotes = EmptyArray 79 | Args = EmptyArray 80 | End If 81 | 82 | 83 | 84 | 'Recusion case - Look for next element 85 | Else 86 | 87 | ' does Commandline starts with "C:\P... 88 | bIsQuoted = Mid(lCommandLine, startPos, 1) = """" 89 | If bIsQuoted Then 90 | ' find next "(DoubleQuote) 91 | endPos = InStr(startPos + 1, lCommandLine, """") + 1 92 | bEndLine = (endPos <= 1) 93 | Else 94 | ' find next ' '(Space) 95 | endPos = InStr(startPos, lCommandLine, " ") 96 | bEndLine = (endPos <= 0) 97 | End If 98 | 99 | If bEndLine Then 100 | endPos = Len(lCommandLine) 101 | End If 102 | 103 | ' Call commandLineSplitRek recursiv with "new" commandline 6 increase levelCounter 104 | commandLineSplitRek Mid(lCommandLine, endPos), startPos, levelCounter + 1 105 | 106 | 107 | ' bNoQuotedAtEnd = bIsQuoted And bEndLine And (endPos = 0) 108 | 109 | Dim length& 110 | length = endPos - startPos 111 | 112 | 'Save Data in Array 113 | argsWithQuotes(levelCounter) = Mid(lCommandLine, startPos, length + 1) 114 | If bIsQuoted Then 115 | Args(levelCounter) = Mid(argsWithQuotes(levelCounter), 2, length - 2) 116 | 117 | Else 118 | Args(levelCounter) = argsWithQuotes(levelCounter) 119 | 120 | End If 121 | 122 | End If 123 | 124 | 'commandLineSplitRek_err: 125 | End Sub 126 | Private Function GetCommandLine() As String 127 | 128 | commandline = Command 129 | 130 | 131 | End Function 132 | 133 | -------------------------------------------------------------------------------- /src/SHA256/FSHATest.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form FSHATest 3 | Caption = "SHA Test" 4 | ClientHeight = 6540 5 | ClientLeft = 60 6 | ClientTop = 345 7 | ClientWidth = 9300 8 | BeginProperty Font 9 | Name = "Courier New" 10 | Size = 8.25 11 | Charset = 0 12 | Weight = 400 13 | Underline = 0 'False 14 | Italic = 0 'False 15 | Strikethrough = 0 'False 16 | EndProperty 17 | LinkTopic = "Form1" 18 | ScaleHeight = 6540 19 | ScaleWidth = 9300 20 | StartUpPosition = 3 'Windows-Standard 21 | Begin VB.CommandButton cmdTest256 22 | Caption = "Test SHA-256" 23 | BeginProperty Font 24 | Name = "MS Sans Serif" 25 | Size = 8.25 26 | Charset = 0 27 | Weight = 400 28 | Underline = 0 'False 29 | Italic = 0 'False 30 | Strikethrough = 0 'False 31 | EndProperty 32 | Height = 495 33 | Left = 60 34 | TabIndex = 0 35 | Top = 60 36 | Width = 1215 37 | End 38 | End 39 | Attribute VB_Name = "FSHATest" 40 | Attribute VB_GlobalNameSpace = False 41 | Attribute VB_Creatable = False 42 | Attribute VB_PredeclaredId = True 43 | Attribute VB_Exposed = False 44 | '******************************************************************************* 45 | ' MODULE: FSHATest 46 | ' FILENAME: FSHATest.frm 47 | ' AUTHOR: Phil Fresle 48 | ' CREATED: 10-Apr-2001 49 | ' COPYRIGHT: Copyright 2001 Phil Fresle. All Rights Reserved. 50 | ' 51 | ' DESCRIPTION: 52 | ' This form tests the CSHA256 class for generating a SHA-256 digest of a string 53 | ' message. See the class module for further details 54 | ' 55 | ' This is 'free' software with the following restrictions: 56 | ' 57 | ' You may not redistribute this code as a 'sample' or 'demo'. However, you are free 58 | ' to use the source code in your own code, but you may not claim that you created 59 | ' the sample code. It is expressly forbidden to sell or profit from this source code 60 | ' other than by the knowledge gained or the enhanced value added by your own code. 61 | ' 62 | ' Use of this software is also done so at your own risk. The code is supplied as 63 | ' is without warranty or guarantee of any kind. 64 | ' 65 | ' Should you wish to commission some derivative work based on this code provided 66 | ' here, or any consultancy work, please do not hesitate to contact me. 67 | ' 68 | ' Web Site: http://www.frez.co.uk 69 | ' E-mail: sales@frez.co.uk 70 | ' 71 | ' MODIFICATION HISTORY: 72 | ' 10-Apr-2001 Phil Fresle Initial Version 73 | '******************************************************************************* 74 | Option Explicit 75 | 76 | '******************************************************************************* 77 | ' cmdTest256_Click (SUB) 78 | ' 79 | ' DESCRIPTION: 80 | ' Runs the test 81 | '******************************************************************************* 82 | Private Sub cmdTest256_Click() 83 | Dim oSHA256 As CSHA256 84 | 85 | Set oSHA256 = New CSHA256 86 | 87 | Me.Cls 88 | Me.Print "" 89 | Me.Print "" 90 | 91 | 92 | 93 | Dim abc$, i 94 | abc = "" 95 | For i = &H20 To &HFF& 96 | abc = abc & Chr(i) 97 | Next 98 | 99 | ' Clipboard.Clear 100 | ' Clipboard.SetText abc, ClipBoardConstants.vbCFText 101 | Me.Print "" 102 | Me.Print abc '"SHA256(""[0xfa]"")" 103 | Me.Print "Expected: aea90164ab8e0638099106b39bffc56598aac72a0b127732fb0ecca857434153" 104 | Me.Print "Actual: " & oSHA256.SHA256(abc) '"thomas ist unser kundenschreck") 105 | 106 | Me.Print "" 107 | Me.Print "SHA256(""abc"")" 108 | Me.Print "Expected: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" 109 | Me.Print "Actual: " & oSHA256.SHA256("abc") 110 | 111 | Me.Print "" 112 | Me.Print "SHA256(""abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"")" 113 | Me.Print "Expected: 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" 114 | Me.Print "Actual: " & oSHA256.SHA256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") 115 | 116 | 117 | Set oSHA256 = Nothing 118 | 119 | End Sub 120 | -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/RanRot.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 12 | 13 | 14 | 20 | 31 | 33 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 65 | 72 | 85 | 87 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 114 | 116 | 118 | 120 | 121 | 122 | 123 | 124 | 125 | 129 | 131 | 132 | 134 | 135 | 137 | 138 | 140 | 141 | 142 | 146 | 148 | 149 | 150 | 154 | 155 | 156 | 157 | 158 | 159 | -------------------------------------------------------------------------------- /src/z_unused/Pe_info.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "Pe_info_bas" 2 | Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long 3 | Public Type JOBOBJECT_BASIC_LIMIT_INFORMATION 4 | PerProcessUserTimeLimit As Long 5 | PerJobUserTimeLimit As Long 6 | LimitFlags As Long 7 | MinimumWorkingSetSize As Long 8 | MaximumWorkingSetSize As Long 9 | ActiveProcessLimit As Long 10 | Affinity As Long 11 | PriorityClass As Long 12 | SchedulingClass As Long 13 | End Type 14 | 15 | 16 | Public Type PE_Section 17 | SectionName As String * 8 18 | VirtualSize As Long 19 | RVAOffset As Long 20 | RawDataSize As Long 21 | PointertoRawData As Long 22 | PointertoRelocs As Long 23 | PointertoLineNumbers As Long 24 | NumberofRelocs As Integer 25 | NumberofLineNumbers As Integer 26 | SectionFlags As Long 27 | End Type 28 | 29 | Public Type PE_Header 30 | PESignature As Long 31 | Machine As Integer 32 | NumberofSections As Integer 33 | TimeDateStamp As Long 34 | PointertoSymbolTable As Long 35 | NumberofSymbols As Long 36 | OptionalHeaderSize As Integer 37 | Characteristics As Integer 38 | Magic As Integer 39 | MajorVersionNumber As Byte 40 | MinorVersionNumber As Byte 41 | SizeofCodeSection As Long 42 | InitializedDataSize As Long 43 | UninitializedDataSize As Long 44 | EntryPointRVA As Long 45 | BaseofCode As Long 46 | BaseofData As Long 47 | 48 | ' extra NT stuff 49 | ImageBase As Long 50 | SectionAlignment As Long 51 | FileAlignment As Long 52 | OSMajorVersion As Integer 53 | OSMinorVersion As Integer 54 | UserMajorVersion As Integer 55 | UserMinorVersion As Integer 56 | SubSysMajorVersion As Integer 57 | SubSysMinorVersion As Integer 58 | RESERVED As Long 59 | ImageSize As Long 60 | HeaderSize As Long 61 | FileChecksum As Long 62 | SubSystem As Integer 63 | DLLFlags As Integer 64 | StackReservedSize As Long 65 | StackCommitSize As Long 66 | HeapReserveSize As Long 67 | HeapCommitSize As Long 68 | LoaderFlags As Long 69 | NumberofDataDirectories As Long 70 | 'end of NTOPT Header 71 | ExportTableAddress As Long 72 | ExportTableAddressSize As Long 73 | ImportTableAddress As Long 74 | ImportTableAddressSize As Long 75 | ResourceTableAddress As Long 76 | ResourceTableAddressSize As Long 77 | ExceptionTableAddress As Long 78 | ExceptionTableAddressSize As Long 79 | SecurityTableAddress As Long 80 | SecurityTableAddressSize As Long 81 | BaseRelocationTableAddress As Long 82 | BaseRelocationTableAddressSize As Long 83 | DebugDataAddress As Long 84 | DebugDataAddressSize As Long 85 | CopyrightDataAddress As Long 86 | CopyrightDataAddressSize As Long 87 | GlobalPtr As Long 88 | GlobalPtrSize As Long 89 | TLSTableAddress As Long 90 | TLSTableAddressSize As Long 91 | LoadConfigTableAddress As Long 92 | LoadConfigTableAddressSize As Long 93 | 94 | BoundImportsAddress As Long 95 | BoundImportsAddressSize As Long 96 | IATAddress As Long 97 | IATAddressSize As Long 98 | 99 | DelayImportAddress As Long 100 | DelayImportAddressSize As Long 101 | COMDescriptorAddress As Long 102 | COMDescriptorAddressSize As Long 103 | 104 | ReservedAddress As Long 105 | ReservedAddressSize As Long 106 | 107 | ' Gap As String * &H28& 108 | Sections(64) As PE_Section 109 | End Type 110 | 111 | 112 | 'assumption the .text Sections ist the first and .data Section the second in pe_header 113 | Public Const TEXT_SECTION& = 0 114 | Public Const DATA_SECTION& = 1 115 | 116 | Public PE_info As New PE_info 117 | Public PE_Header As PE_Header 118 | Public File As New FileStream 119 | Public file_readonly As New FileStream 120 | Public FileName As New ClsFilename 121 | Public PE_SectionData As Collection 122 | -------------------------------------------------------------------------------- /src/Blowfish/basUnsignedWord.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basUnsignedWord" 2 | Option Explicit 3 | 4 | ' basUnsignedWord: Utilities for unsigned word arithmetic 5 | 6 | ' Version 6.1. June 2008. Fixed overflow problem in uw_WordAdd 7 | ' Version 6. November 2003. Unchanged from Version 5. 8 | ' Version 5. January 2002. Replaced uw_WordSplit and uw_WordJoin 9 | ' with more efficient uwSplit and uwJoin. 10 | ' Version 4. 12 May 2001. Mods to speed up. 11 | ' Thanks to Doug J Ward and Ernie Gibbs for advice and suggestions. 12 | '************************* COPYRIGHT NOTICE************************* 13 | ' This code was originally written in Visual Basic by David Ireland 14 | ' and is copyright (c) 2000-8 D.I. Management Services Pty Limited, 15 | ' all rights reserved. 16 | 17 | ' You are free to use this code as part of your own applications 18 | ' provided you keep this copyright notice intact and acknowledge 19 | ' its authorship with the words: 20 | 21 | ' "Contains cryptography software by David Ireland of 22 | ' DI Management Services Pty Ltd ." 23 | 24 | ' If you use it as part of a web site, please include a link 25 | ' to our site in the form 26 | ' Cryptography 27 | ' Software Code 28 | 29 | ' This code may only be used as part of an application. It may 30 | ' not be reproduced or distributed separately by any means without 31 | ' the express written permission of the author. 32 | 33 | ' David Ireland and DI Management Services Pty Limited make no 34 | ' representations concerning either the merchantability of this 35 | ' software or the suitability of this software for any particular 36 | ' purpose. It is provided "as is" without express or implied 37 | ' warranty of any kind. 38 | 39 | ' Please forward comments or bug reports to . 40 | ' The latest version of this source code can be downloaded from 41 | ' www.di-mgt.com.au/crypto.html. 42 | '****************** END OF COPYRIGHT NOTICE************************* 43 | 44 | Private Const OFFSET_4 = 4294967296# 45 | Private Const MAXINT_4 = 2147483647 46 | 47 | Public Function uwJoin(a As Byte, b As Byte, C As Byte, d As Byte) As Long 48 | ' Added Version 5: replacement for uw_WordJoin 49 | ' Join 4 x 8-bit bytes into one 32-bit word a.b.c.d 50 | uwJoin = ((a And &H7F) * &H1000000) Or (b * &H10000) Or (CLng(C) * &H100) Or d 51 | If a And &H80 Then 52 | uwJoin = uwJoin Or &H80000000 53 | End If 54 | End Function 55 | 56 | Public Sub uwSplit(ByVal w As Long, a As Byte, b As Byte, C As Byte, d As Byte) 57 | ' Added Version 5: replacement for uw_WordSplit 58 | ' Split 32-bit word w into 4 x 8-bit bytes 59 | a = CByte(((w And &HFF000000) \ &H1000000) And &HFF) 60 | b = CByte(((w And &HFF0000) \ &H10000) And &HFF) 61 | C = CByte(((w And &HFF00) \ &H100) And &HFF) 62 | d = CByte((w And &HFF) And &HFF) 63 | End Sub 64 | 65 | ' Function re-written 11 May 2001. 66 | Public Function uw_ShiftLeftBy8(wordX As Long) As Long 67 | ' Shift 32-bit long value to left by 8 bits 68 | ' i.e. VB equivalent of "wordX << 8" in C 69 | ' Avoiding problem with sign bit 70 | uw_ShiftLeftBy8 = (wordX And &H7FFFFF) * &H100 71 | If (wordX And &H800000) <> 0 Then 72 | uw_ShiftLeftBy8 = uw_ShiftLeftBy8 Or &H80000000 73 | End If 74 | End Function 75 | 76 | Public Function uw_WordAdd(wordA As Long, wordB As Long) As Long 77 | ' Adds words A and B avoiding overflow 78 | Dim myUnsigned As Double 79 | 80 | myUnsigned = LongToUnsigned(wordA) + LongToUnsigned(wordB) 81 | ' Cope with overflow 82 | ' [2008-06-25] Changed "> OFFSET_4" to ">= OFFSET_4' 83 | ' -- thanks to Ernie Gibbs for this. 84 | If myUnsigned >= OFFSET_4 Then 85 | myUnsigned = myUnsigned - OFFSET_4 86 | End If 87 | uw_WordAdd = UnsignedToLong(myUnsigned) 88 | 89 | End Function 90 | 91 | Public Function uw_WordSub(wordA As Long, wordB As Long) As Long 92 | ' Subtract words A and B avoiding underflow 93 | Dim myUnsigned As Double 94 | 95 | myUnsigned = LongToUnsigned(wordA) - LongToUnsigned(wordB) 96 | ' Cope with underflow 97 | If myUnsigned < 0 Then 98 | myUnsigned = myUnsigned + OFFSET_4 99 | End If 100 | uw_WordSub = UnsignedToLong(myUnsigned) 101 | End Function 102 | 103 | '**************************************************** 104 | ' These two functions from Microsoft Article Q189323 105 | ' "HOWTO: convert between Signed and Unsigned Numbers" 106 | 107 | Function UnsignedToLong(value As Double) As Long 108 | If value < 0 Or value >= OFFSET_4 Then Error 6 ' Overflow 109 | If value <= MAXINT_4 Then 110 | UnsignedToLong = value 111 | Else 112 | UnsignedToLong = value - OFFSET_4 113 | End If 114 | End Function 115 | 116 | Public Function LongToUnsigned(value As Long) As Double 117 | If value < 0 Then 118 | LongToUnsigned = value + OFFSET_4 119 | Else 120 | LongToUnsigned = value 121 | End If 122 | End Function 123 | 124 | ' End of Microsoft-article functions 125 | '**************************************************** 126 | 127 | -------------------------------------------------------------------------------- /src/Blowfish/basTestRadix64.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basTestRadix64" 2 | Option Explicit 3 | Option Base 0 4 | 5 | ' basTestRadix64: Tests for Radix 64 en/decoding functions 6 | ' Version 4a: Updated November 2003. 7 | ' Version 4. Updated 17 August 2002 to do comparisons with older versions. 8 | ' Version 2. Updated 16 January 2002. 9 | ' Version 1. Published 28 December 2000 10 | '************************* COPYRIGHT NOTICE************************* 11 | ' This code was originally written in Visual Basic by David Ireland 12 | ' and is copyright (c) 2000-2 D.I. Management Services Pty Limited, 13 | ' all rights reserved. 14 | 15 | ' You are free to use this code as part of your own applications 16 | ' provided you keep this copyright notice intact and acknowledge 17 | ' its authorship with the words: 18 | 19 | ' "Contains cryptography software by David Ireland of 20 | ' DI Management Services Pty Ltd ." 21 | 22 | ' This code may only be used as part of an application. It may 23 | ' not be reproduced or distributed separately by any means without 24 | ' the express written permission of the author. 25 | 26 | ' David Ireland and DI Management Services Pty Limited make no 27 | ' representations concerning either the merchantability of this 28 | ' software or the suitability of this software for any particular 29 | ' purpose. It is provided "as is" without express or implied 30 | ' warranty of any kind. 31 | 32 | ' Please forward comments or bug reports to . 33 | ' The latest version of this source code can be downloaded from 34 | ' www.di-mgt.com.au/crypto.html. 35 | '****************** END OF COPYRIGHT NOTICE************************* 36 | '-------------------------------------------------------------- 37 | ' Timer Functions - from Litwin, Getz, Gilbert 38 | '-------------------------------------------------------------- 39 | Declare Function wu_GetTime Lib "winmm.dll" Alias _ 40 | "timeGetTime" () As Long 41 | Private mlStartTime As Long 42 | Private Sub ap_StartTimer() 43 | mlStartTime = wu_GetTime() 44 | End Sub 45 | Private Function ap_EndTimer() As Long 46 | ap_EndTimer = wu_GetTime() - mlStartTime 47 | End Function 48 | '-------------------------------------------------------------- 49 | 50 | ' NOTE: The function cv_HexFromBytes() 51 | ' is in module basConvert.txt 52 | 53 | Public Function TestBytesEnc64Rand() 54 | Dim nLen As Integer, i As Integer 55 | Dim abBytes() As Byte 56 | Dim sBase64 As String 57 | Dim abDecoded() As Byte 58 | ' Fill array with a random no of random binary values 59 | Randomize 60 | nLen = Int(32 * Rnd) + 1 61 | ReDim abBytes(nLen - 1) 62 | For i = 0 To nLen - 1 63 | abBytes(i) = CByte((Rnd * 256) And &HFF) 64 | Next 65 | 66 | ' Print hex values, encode it, then decode it again 67 | Debug.Print "Input:", cv_HexFromBytes(abBytes) 68 | sBase64 = EncodeBytes64(abBytes) 69 | Debug.Print "Encoded:", sBase64 70 | abDecoded = DecodeBytes64(sBase64) 71 | Debug.Print "Decoded:", cv_HexFromBytes(abDecoded) 72 | ' Compare byte arrays using hex conversion 73 | If cv_HexFromBytes(abBytes) <> cv_HexFromBytes(abDecoded) Then 74 | MsgBox "Radix64 Error" 75 | End If 76 | 77 | End Function 78 | 79 | Public Function TestEnc64Time() 80 | Dim nLen As Long, i As Long 81 | Dim lTime As Long 82 | Dim abBytes() As Byte 83 | Dim sBase64 As String 84 | Dim abDecoded() As Byte 85 | Dim sInput As String, sDecoded As String 86 | 87 | ' Fill a string with a lot of random binary values 88 | Randomize 89 | nLen = 100000 + Rnd() * 5 90 | ReDim abBytes(nLen - 1) 91 | For i = 0 To nLen - 1 92 | abBytes(i) = CByte((Rnd * 256) And &HFF) 93 | Next 94 | 95 | ' 1. Use latest version 96 | ' Encode it, then decode it again 97 | Call ap_StartTimer 98 | sBase64 = EncodeBytes64(abBytes) 99 | lTime = ap_EndTimer() 100 | Debug.Print "Encode with Bytes: " & nLen & " chars took " & lTime & " milliseconds" 101 | Call ap_StartTimer 102 | abDecoded = DecodeBytes64(sBase64) 103 | lTime = ap_EndTimer() 104 | Debug.Print "Decode with Bytes: " & nLen & " chars took " & lTime & " milliseconds" 105 | ' Check result equals the input 106 | If cv_HexFromBytes(abBytes) <> cv_HexFromBytes(abDecoded) Then 107 | MsgBox "Radix64 Error" 108 | End If 109 | 110 | ' 2. Compare times using deprecated String version 111 | ' Encode it, then decode it again 112 | sInput = StrConv(abBytes, vbUnicode) 113 | Call ap_StartTimer 114 | sBase64 = EncodeStr64(sInput) 115 | lTime = ap_EndTimer() 116 | Debug.Print "Encode with String: " & nLen & " chars took " & lTime & " milliseconds" 117 | Call ap_StartTimer 118 | sDecoded = DecodeStr64(sBase64) 119 | lTime = ap_EndTimer() 120 | Debug.Print "Decode with String: " & nLen & " chars took " & lTime & " milliseconds" 121 | ' Check result equals the input 122 | If sInput <> sDecoded Then 123 | MsgBox "Radix64 Error" 124 | End If 125 | 126 | 127 | End Function 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /src/base64/Base64.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form frmBase64 3 | AutoRedraw = -1 'True 4 | BorderStyle = 1 'Fixed Single 5 | Caption = "VB-Tec / Base64 - Jost Schwider, Soest" 6 | ClientHeight = 6150 7 | ClientLeft = 45 8 | ClientTop = 330 9 | ClientWidth = 8850 10 | LinkTopic = "Form1" 11 | MaxButton = 0 'False 12 | MinButton = 0 'False 13 | ScaleHeight = 6150 14 | ScaleWidth = 8850 15 | StartUpPosition = 1 'CenterOwner 16 | Begin VB.CommandButton cmdTrimWS 17 | Caption = "Trim WhiteSpaces" 18 | Height = 315 19 | Left = 3420 20 | TabIndex = 7 21 | Top = 60 22 | Width = 1575 23 | End 24 | Begin VB.FileListBox lstFile 25 | Height = 2430 26 | Left = 60 27 | TabIndex = 2 28 | Top = 3660 29 | Width = 1995 30 | End 31 | Begin VB.DirListBox lstDir 32 | Height = 2790 33 | Left = 60 34 | TabIndex = 1 35 | Top = 840 36 | Width = 1995 37 | End 38 | Begin VB.DriveListBox lstDrive 39 | Height = 315 40 | Left = 60 41 | TabIndex = 0 42 | Top = 480 43 | Width = 1995 44 | End 45 | Begin VB.CommandButton cmdFromBase64 46 | Caption = "From Base64" 47 | Height = 315 48 | Left = 5040 49 | TabIndex = 8 50 | Top = 60 51 | Width = 1215 52 | End 53 | Begin VB.CommandButton cmdToBase64 54 | Caption = "To Base64" 55 | Height = 315 56 | Left = 2160 57 | TabIndex = 6 58 | Top = 60 59 | Width = 1155 60 | End 61 | Begin VB.CommandButton cmdSave 62 | Caption = "Save" 63 | Height = 315 64 | Left = 1080 65 | TabIndex = 5 66 | Top = 60 67 | Width = 975 68 | End 69 | Begin VB.CommandButton cmdLoad 70 | Caption = "Load" 71 | Height = 315 72 | Left = 60 73 | TabIndex = 4 74 | Top = 60 75 | Width = 975 76 | End 77 | Begin VB.TextBox txt 78 | Height = 5595 79 | Left = 2160 80 | MultiLine = -1 'True 81 | ScrollBars = 2 'Vertical 82 | TabIndex = 3 83 | Top = 480 84 | Width = 6615 85 | End 86 | End 87 | Attribute VB_Name = "frmBase64" 88 | Attribute VB_GlobalNameSpace = False 89 | Attribute VB_Creatable = False 90 | Attribute VB_PredeclaredId = True 91 | Attribute VB_Exposed = False 92 | Option Explicit 93 | 94 | Private Sub cmdFromBase64_Click() 95 | MousePointer = vbHourglass 96 | txt.Text = Base64DecodeUnicode(txt.Text) 97 | MousePointer = vbDefault 98 | End Sub 99 | 100 | Private Sub cmdLoad_Click() 101 | Dim s As String 102 | 103 | s = ReadFile(lstFile.Path & "\" & lstFile.FileName) 104 | txt.Text = s 105 | DoEvents 106 | txt.Tag = s 107 | End Sub 108 | 109 | Private Sub cmdSave_Click() 110 | Dim FileName As String 111 | 112 | FileName = lstFile.Path & "\" & lstFile.FileName 113 | FileName = InputBox("Datei speichern unter...", , FileName) 114 | If Len(FileName) Then WriteFile FileName, txt.Text 115 | End Sub 116 | 117 | Private Sub cmdToBase64_Click() 118 | MousePointer = vbHourglass 119 | txt.Text = Base64EncodeUnicode(txt.Tag) 120 | MousePointer = vbDefault 121 | End Sub 122 | 123 | Private Sub cmdTrimWS_Click() 124 | txt.Tag = TrimWS2(txt.Tag) 125 | txt.Text = txt.Tag 126 | End Sub 127 | 128 | Private Sub lstDir_Change() 129 | lstFile.Path = lstDir.Path 130 | End Sub 131 | 132 | Private Sub lstDrive_Change() 133 | lstDir.Path = lstDrive.Drive 134 | End Sub 135 | 136 | Private Sub lstFile_DblClick() 137 | cmdLoad_Click 138 | End Sub 139 | 140 | 141 | Private Function TrimWS2(ByVal s As String) As String 142 | Dim i As Long 143 | Dim j As Long 144 | 145 | For i = 1 To Len(s) 146 | If Asc(Mid$(s, i, 1)) > 32 Then 147 | j = j + 1 148 | Mid$(s, j) = Mid$(s, i, 1) 149 | End If 150 | Next i 151 | TrimWS2 = Left$(s, j) 152 | End Function 153 | 154 | Private Function ReadFile(ByRef Path As String) As String 155 | Dim f As Integer 156 | 157 | f = FreeFile 158 | Open Path For Binary As #f 159 | ReadFile = Space$(LOF(f)) 160 | Get #f, , ReadFile 161 | Close #f 162 | End Function 163 | 164 | Private Sub WriteFile(ByRef Path As String, ByRef Text As String) 165 | Dim FileNr As Long 166 | 167 | FileNr = FreeFile 168 | Open Path For Output As #FileNr 169 | Print #FileNr, Text; 170 | Close #FileNr 171 | End Sub 172 | 173 | Private Sub txt_Change() 174 | txt.Tag = txt.Text 175 | End Sub 176 | -------------------------------------------------------------------------------- /src/z_unused/PE_info.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "PE_info" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" 15 | Attribute VB_Ext_KEY = "Top_Level" ,"Yes" 16 | Option Explicit 17 | Private PEStart& 18 | 'Private Const CHECKSUM_OPEN_FAILURE As Long = 1 19 | 'Private Const CHECKSUM_MAP_FAILURE As Long = 2 20 | 'Private Const CHECKSUM_MAPVIEW_FAILURE As Long = 3 21 | 'Private Const CHECKSUM_UNICODE_FAILURE As Long = 4 22 | Private Declare Function MapFileAndCheckSum Lib "E:\Programmierung\Projekte\vir_clean\Imagehlp.dll" Alias "MapFileAndCheckSumA" (ByVal FileName As String, ByRef HeaderSum As Long, ByRef CheckSum As Long) As Long 23 | 24 | Public Sub Create() 25 | ' '--- find PE-signature --- 26 | ' 'Get First 0x400 Bytes 27 | ' Dim tmpstr$ 28 | ' file.Position = 0 29 | ' tmpstr = file.FixedString(&H400) 30 | ' 31 | ' 'Locate start of PE-header 32 | ' PEStart = InStr(1, tmpstr, "PE" & vbNullChar & vbNullChar, vbBinaryCompare) 33 | ' If PEStart = 0 Then err.Raise vbObjectError + 1, , "No PE-Header Found" 34 | 35 | '--- find PE-signature --- 36 | 'Check DOS Header 37 | Dim tmpstr$ 38 | file.Position = 0 39 | 40 | 'MZ DOS-Header->e_magic 41 | If file.intValue <> &H5A4D Then Err.Raise vbObjectError + 1, , "No ExeFile DOS-Header.e_magic<>""MZ""" 42 | 43 | 44 | 'Locate & Validate PE-header 45 | file.Position = &H3C ' DOS-Header->e_lfanew 46 | PEStart = file.longValue 47 | file.Position = PEStart 48 | PEStart = PEStart + 1 49 | 50 | If file.longValue <> &H4550 Then Err.Raise vbObjectError + 2, , "No ExeFile 'PE-Header.Signature<>""PE""" 51 | 52 | ' --- get PE_Header --- 53 | Dim hFile& 54 | hFile = FreeFile 55 | Open file.FileName For Binary Access Read As #hFile 56 | Get hFile, PEStart, PE_Header 57 | Close hFile 58 | 59 | 60 | ' Validate Machine Type 61 | If PE_Header.Machine <> &H14C Then 62 | If PE_Header.Machine = &H8664 Then 63 | Err.Raise vbObjectError + 4, , "PE-Header.Signature=HDR64_MAGIC!" 64 | Else 65 | Err.Raise vbObjectError + 3, , "Unsupported PE-Header.Signature<>I386(0x14C)." 66 | End If 67 | End If 68 | 69 | ' ' Validate Optionaldata Type 70 | ' If PE_Header.Magic <> &H10B Then 71 | ' err.Raise vbObjectError + 5, , "PE_Header.Magic <> PE32!" 72 | ' End If 73 | 74 | If PE_Header.OptionalHeaderSize <> &HE0 Then 75 | Err.Raise vbObjectError + 5, , "PE_Header.OptionalHeaderSize = E0 expected" 76 | End If 77 | 78 | 79 | 80 | ' If PE_Header.NumberofDataDirectories > &HE Then 81 | ' err.Raise vbObjectError + 5, , "PE_Header.NumberofDataDirectories must be greater than 14" 82 | ' End If 83 | 'imagever 3..5 <-winXP / 6 vista 84 | 85 | End Sub 86 | 87 | Public Sub WriteHeader() 88 | If PEStart = 0 Then Err.Raise vbObjectError, , "You must call PE_info::Create first!" 89 | 90 | Dim tmpstr$ 91 | tmpstr = Space(Len(PE_Header) - (UBound(PE_Header.Sections) - PE_Header.NumberofSections) * &H28) 92 | ' Stop 93 | MemCopyAnyToStr tmpstr, PE_Header, Len(tmpstr) 94 | file.Position = PEStart - 1 95 | file.FixedString(-1) = tmpstr 96 | 97 | ' ' --- get PE_Header --- 98 | ' Dim hFile& 99 | ' hFile = FreeFile 100 | ' Open file.FileName For Binary Access Write As #hFile 101 | ' Put hFile, PEStart, PE_Header 102 | ' Close hFile 103 | 104 | End Sub 105 | 106 | Public Function UpdateChecksum&() '(Optional ByRef Output_ChecksumCurrent&, Optional ByRef Output_ChecksumNew&) 107 | If PEStart = 0 Then Err.Raise vbObjectError, , "You must call PE_info::Create first!" 108 | UpdateChecksum = MapFileAndCheckSum(file.FileName, 0, PE_Header.FileChecksum) 109 | WriteHeader 110 | End Function 111 | 112 | 113 | Public Function GetChecksum&() '(Optional ByRef Output_ChecksumCurrent&, Optional ByRef Output_ChecksumNew&) 114 | If PEStart = 0 Then Err.Raise vbObjectError, , "You must call PE_info::Create first!" 115 | Dim tmp&, RetVal& 116 | RetVal = MapFileAndCheckSum(file.FileName, 0, tmp) 117 | GetChecksum = tmp 118 | End Function 119 | 120 | Public Function ComputeSizeOfHeader&() 121 | ComputeSizeOfHeader = PEStart + &H18 + PE_Header.OptionalHeaderSize + PE_Header.NumberofSections * &H28 122 | End Function 123 | 124 | 125 | Public Sub PE_GetSectionData() 126 | 'ReDim PE_SectionData(PE_Header.NumberofSections - 1) 127 | 128 | Set PE_SectionData = New Collection 129 | 130 | Dim i&, filedata As StringReader 131 | For i = 0 To PE_Header.NumberofSections - 1 132 | With PE_Header.Sections(i) 133 | 134 | Set filedata = New StringReader 135 | 136 | file.Position = .PointertoRawData 137 | filedata = file.FixedString(.RawDataSize) 138 | PE_SectionData.Add filedata 139 | End With 140 | Next 141 | 142 | End Sub 143 | 144 | Public Sub PE_SetSectionData() 145 | Dim i& 146 | For i = 0 To PE_Header.NumberofSections - 1 147 | With PE_Header.Sections(i) 148 | file.Position = .PointertoRawData 149 | file.FixedString(.RawDataSize) = PE_SectionData(i) 150 | End With 151 | Next 152 | ' ReDim PE_SectionData(0) 153 | End Sub 154 | 155 | -------------------------------------------------------------------------------- /src/VBCodeGenerator/frmCodeGen.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form frmCodeGen 3 | Caption = "Form1" 4 | ClientHeight = 7905 5 | ClientLeft = 60 6 | ClientTop = 345 7 | ClientWidth = 10365 8 | Icon = "frmCodeGen.frx":0000 9 | LinkTopic = "Form1" 10 | ScaleHeight = 7905 11 | ScaleWidth = 10365 12 | StartUpPosition = 3 'Windows-Standard 13 | Begin VB.TextBox Txt_data 14 | BeginProperty Font 15 | Name = "Courier New" 16 | Size = 9.75 17 | Charset = 0 18 | Weight = 400 19 | Underline = 0 'False 20 | Italic = 0 'False 21 | Strikethrough = 0 'False 22 | EndProperty 23 | Height = 6855 24 | Left = 0 25 | MultiLine = -1 'True 26 | TabIndex = 0 27 | Top = 0 28 | Width = 9855 29 | End 30 | End 31 | Attribute VB_Name = "frmCodeGen" 32 | Attribute VB_GlobalNameSpace = False 33 | Attribute VB_Creatable = False 34 | Attribute VB_PredeclaredId = True 35 | Attribute VB_Exposed = False 36 | Option Explicit 37 | 38 | Const IndentCount& = 3 39 | Private Sub Form_Load() 40 | 41 | Dim Operators 42 | Operators = Array("+", "-", "*", "/", "%", "<<", ">>", ".", "|", "%", "%", "!", "!!", "^", "===", "!==", "==", "!=", "<", "<=", "?CAST?", ":", "+=", "-=", "*=", "\=", "%=", "<<=", ">>=", ".=", "|=", "%=", "^=", "++", "--", "++") 43 | 44 | 45 | Dim LineMaxLength& 46 | LineMaxLength = 0 47 | 48 | 49 | Dim NameMaxLength& 50 | NameMaxLength = 0 51 | 52 | Dim output 53 | ArrayAdd output, "Attribute VB_Name = ""IC_DecompileConsts""" 54 | ArrayAdd output, "Option Explicit" 55 | 56 | Dim ConstStartLine& 57 | ConstStartLine = UBound(output) + 1 58 | 59 | Dim lineNr& 60 | For lineNr = LBound(icByteCodeNames) To UBound(icByteCodeNames) 61 | Dim Text$ 62 | Text = icByteCodeNames(lineNr) 63 | 64 | 65 | Dim Operator 66 | Operator = "" 67 | On Error Resume Next 68 | Operator = Operators(lineNr - 1) 69 | 70 | Dim outputLine$ 71 | outputLine = Join(Array( _ 72 | "Public Const ", Text, " as Long = &h", H8(lineNr) _ 73 | ), "") 74 | 75 | MaxProc LineMaxLength, Len(outputLine) 76 | MaxProc NameMaxLength, Len(Text) 77 | 78 | ArrayAdd output, outputLine 79 | Next 80 | 81 | Inc LineMaxLength, 2 82 | Inc NameMaxLength, 2 83 | 84 | For lineNr = ConstStartLine To UBound(output) 85 | output(lineNr) = BlockAlign_r(output(lineNr), LineMaxLength) & " ' " & lineNr - ConstStartLine & " " & Operator 86 | Next 87 | Txt_data = Join(output, vbCrLf) 88 | FileSave App.Path & "\IC_Decompile_Const.bas", Txt_data 89 | 90 | ReDim output(0) 91 | ArrayAdd output, "Attribute VB_Name = ""IC_DecompileFuncs""" 92 | ArrayAdd output, "Option Explicit" 93 | 94 | 95 | '-------Select case ------------- 96 | 97 | ArrayAdd output, "" 98 | ArrayAdd output, "" 99 | 100 | ArrayAdd output, Indent(0) & "sub ic_interpret(cmd&)" 101 | ArrayAdd output, Indent(1) & "" 102 | ArrayAdd output, Indent(1) & "Dim Prefix$, InFix$, PostFix$" 103 | ArrayAdd output, Indent(1) & "" 104 | ArrayAdd output, Indent(1) & "select case cmd" 105 | 106 | ArrayAdd output, "" 107 | 108 | Dim Functions 109 | ArrayAdd Functions, Indent(0) & "'" 110 | ArrayAdd Functions, Indent(0) & "'" 111 | ArrayAdd Functions, Indent(0) & "'" 112 | ArrayAdd Functions, Indent(0) & "'" & String(70, "=") 113 | ArrayAdd Functions, Indent(0) & "" 114 | ArrayAdd Functions, Indent(0) & "' F U N C T I O N S " & String(70, "=") 115 | ArrayAdd Functions, Indent(0) & "" 116 | ArrayAdd Functions, Indent(0) & "'" & String(70, "=") 117 | 118 | For lineNr = LBound(icByteCodeNames) To UBound(icByteCodeNames) 119 | Text = icByteCodeNames(lineNr) 120 | 121 | Operator = "" 122 | On Error Resume Next 123 | Operator = Operators(lineNr - 1) 124 | 125 | outputLine = Join(Array( _ 126 | Indent(2) & "case ", BlockAlign_r(Text, NameMaxLength), _ 127 | " ' &h", H8(lineNr), " ", lineNr _ 128 | ), "") 129 | 130 | ArrayAdd output, outputLine 131 | 132 | Dim FuncName$ 133 | FuncName = "Do" & Text 134 | 135 | ArrayAdd Functions, Indent(0) & "'" & String(70, "/") 136 | ArrayAdd Functions, Indent(0) & "'// " & FuncName 137 | ArrayAdd Functions, Indent(0) & "'// " 138 | ArrayAdd Functions, Indent(0) & "Private Sub " & FuncName & "()" 139 | ArrayAdd Functions, Indent(1) & "On error goto " & FuncName & "_err" 140 | ArrayAdd Functions, Indent(0) & "" 141 | ArrayAdd Functions, Indent(2) & "PreFix= """" : InFix = """": PostFix = """"" 142 | ArrayAdd Functions, Indent(2) & "" 143 | ArrayAdd Functions, Indent(2) & "" 144 | ArrayAdd Functions, Indent(2) & "" 145 | ArrayAdd Functions, Indent(0) & Text & "_err:" 146 | ArrayAdd Functions, Indent(0) & "Select case err" 147 | ArrayAdd Functions, Indent(1) & "Case 0" 148 | ArrayAdd Functions, Indent(2) & "" 149 | ArrayAdd Functions, Indent(1) & "Case else" 150 | ArrayAdd Functions, Indent(2) & "Err.raise vbobjecterror , , ""Error in Decomile!" & FuncName & """ - """"" 151 | ArrayAdd Functions, Indent(1) & "end select" 152 | ArrayAdd Functions, Indent(0) & "End Sub" 153 | ArrayAdd Functions, Indent(0) & "" 154 | ArrayAdd Functions, Indent(0) & "" 155 | ' ArrayAdd Functions, Indent(0) & "'" & String(70, "_") 156 | ArrayAdd Functions, Indent(0) & "" 157 | ArrayAdd Functions, Indent(0) & "" 158 | 159 | 160 | ' ArrayAdd output, Indent(3) & FuncName 161 | ArrayAdd output, Indent(3) & "PreFix= """" : InFix = """ & Operator & """: PostFix = """"" 162 | ArrayAdd output, Indent(3) & "myStop" 163 | ArrayAdd output, "" 164 | Next 165 | 166 | 167 | ArrayAdd output, Indent(1) & "end select" 168 | ArrayAdd output, Indent(0) & "end sub" 169 | 170 | Txt_data = Join(output, vbCrLf) ' & _ 171 | Join(Functions, vbCrLf) 172 | 173 | FileSave App.Path & "\IC_Decompile.bas", Txt_data 174 | MsgBox "Saved to :" & App.Path 175 | End Sub 176 | 177 | Function Indent$(Level) 178 | Indent = String(Level * IndentCount, " ") 179 | End Function 180 | 181 | -------------------------------------------------------------------------------- /src/SRC RanRot_MT.dll - Mersenne Twister & RanRot/RanRot/mt19937ar.c: -------------------------------------------------------------------------------- 1 | /* 2 | A C-program for MT19937, with initialization improved 2002/1/26. 3 | Coded by Takuji Nishimura and Makoto Matsumoto. 4 | 5 | Before using, initialize the state by using init_genrand(seed) 6 | or init_by_array(init_key, key_length). 7 | 8 | Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions 13 | are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | 3. The names of its contributors may not be used to endorse or promote 23 | products derived from this software without specific prior written 24 | permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | Any feedback is very welcome. 40 | http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html 41 | email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) 42 | */ 43 | 44 | //#include 45 | 46 | /* Period parameters */ 47 | #define N 624 48 | #define M 397 49 | #define MATRIX_A 0x9908b0dfUL /* constant vector a */ 50 | #define UPPER_MASK 0x80000000UL /* most significant w-r bits */ 51 | #define LOWER_MASK 0x7fffffffUL /* least significant r bits */ 52 | 53 | static unsigned long mt[N]; /* the array for the state vector */ 54 | static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */ 55 | 56 | /* initializes mt[N] with a seed */ 57 | void _stdcall init_genrand(unsigned long s) 58 | { 59 | mt[0]= s & 0xffffffffUL; 60 | for (mti=1; mti> 30)) + mti); 63 | /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ 64 | /* In the previous versions, MSBs of the seed affect */ 65 | /* only MSBs of the array mt[]. */ 66 | /* 2002/01/09 modified by Makoto Matsumoto */ 67 | mt[mti] &= 0xffffffffUL; 68 | /* for >32 bit machines */ 69 | } 70 | } 71 | 72 | /* initialize by an array with array-length */ 73 | /* init_key is the array for initializing keys */ 74 | /* key_length is its length */ 75 | /* slight change for C++, 2004/2/26 */ 76 | void init_by_array(unsigned long init_key[], int key_length) 77 | { 78 | int i, j, k; 79 | init_genrand(19650218UL); 80 | i=1; j=0; 81 | k = (N>key_length ? N : key_length); 82 | for (; k; k--) { 83 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) 84 | + init_key[j] + j; /* non linear */ 85 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 86 | i++; j++; 87 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 88 | if (j>=key_length) j=0; 89 | } 90 | for (k=N-1; k; k--) { 91 | mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) 92 | - i; /* non linear */ 93 | mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ 94 | i++; 95 | if (i>=N) { mt[0] = mt[N-1]; i=1; } 96 | } 97 | 98 | mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ 99 | } 100 | 101 | /* generates a random number on [0,0xffffffff]-interval */ 102 | unsigned long genrand_int32(void) 103 | { 104 | unsigned long y; 105 | static unsigned long mag01[2]={0x0UL, MATRIX_A}; 106 | /* mag01[x] = x * MATRIX_A for x=0,1 */ 107 | 108 | if (mti >= N) { /* generate N words at one time */ 109 | int kk; 110 | 111 | if (mti == N+1) /* if init_genrand() has not been called, */ 112 | init_genrand(5489UL); /* a default initial seed is used */ 113 | 114 | for (kk=0;kk> 1) ^ mag01[y & 0x1UL]; 117 | } 118 | for (;kk> 1) ^ mag01[y & 0x1UL]; 121 | } 122 | y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); 123 | mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; 124 | 125 | mti = 0; 126 | } 127 | 128 | y = mt[mti++]; 129 | 130 | /* Tempering */ 131 | y ^= (y >> 11); 132 | y ^= (y << 7) & 0x9d2c5680UL; 133 | y ^= (y << 15) & 0xefc60000UL; 134 | y ^= (y >> 18); 135 | 136 | return y; 137 | } 138 | 139 | 140 | /* generates a random number on [0,0x7fffffff]-interval */ 141 | long _stdcall genrand_int31(void) 142 | { 143 | return (long)(genrand_int32()>>1); 144 | } 145 | 146 | /* generates a random number on [0,1]-real-interval */ 147 | double genrand_real1(void) 148 | { 149 | return genrand_int32()*(1.0/4294967295.0); 150 | /* divided by 2^32-1 */ 151 | } 152 | 153 | /* generates a random number on [0,1)-real-interval */ 154 | double genrand_real2(void) 155 | { 156 | return genrand_int32()*(1.0/4294967296.0); 157 | /* divided by 2^32 */ 158 | } 159 | 160 | /* generates a random number on (0,1)-real-interval */ 161 | double genrand_real3(void) 162 | { 163 | return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); 164 | /* divided by 2^32 */ 165 | } 166 | 167 | /* generates a random number on [0,1) with 53-bit resolution*/ 168 | double genrand_res53(void) 169 | { 170 | unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; 171 | return(a*67108864.0+b)*(1.0/9007199254740992.0); 172 | } 173 | /* These real versions are due to Isaku Wada, 2002/01/09 added */ 174 | 175 | 176 | //int main2(void) 177 | //{ 178 | // int i; 179 | //// unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4; 180 | //// init_by_array(init, length); 181 | // 182 | // init_genrand(0x16FA); 183 | // printf("1000 outputs of genrand_int32()\n"); 184 | // for (i=0; i<10; i++) { 185 | // printf("%x ", genrand_int31()); 186 | // if (i%5==4) printf("\n"); 187 | // } 188 | // //printf("\n1000 outputs of genrand_real2()\n"); 189 | // //for (i=0; i<1000; i++) { 190 | // // printf("%10.8f ", genrand_real2()); 191 | // // if (i%5==4) printf("\n"); 192 | // //} 193 | // return 0; 194 | //} 195 | -------------------------------------------------------------------------------- /src/Blowfish/basBlowfish.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basBlowfish" 2 | Option Explicit 3 | Option Base 0 4 | 5 | ' basBlowfish: Bruce Schneier's Blowfish algorithm in VB 6 | ' Core routines. 7 | 8 | ' Version 6. November 2003. Removed redundant functions blf_Enc() 9 | ' and blf_Dec(). 10 | ' Version 5: January 2002. Speed improvements. 11 | ' Version 4: 12 May 2001. Fixed maxkeylen size from bits to bytes. 12 | ' First published October 2000. 13 | '************************* COPYRIGHT NOTICE************************* 14 | ' This code was originally written in Visual Basic by David Ireland 15 | ' and is copyright (c) 2000-2 D.I. Management Services Pty Limited, 16 | ' all rights reserved. 17 | 18 | ' You are free to use this code as part of your own applications 19 | ' provided you keep this copyright notice intact and acknowledge 20 | ' its authorship with the words: 21 | 22 | ' "Contains cryptography software by David Ireland of 23 | ' DI Management Services Pty Ltd ." 24 | 25 | ' If you use it as part of a web site, please include a link 26 | ' to our site in the form 27 | ' Cryptography 28 | ' Software Code 29 | 30 | ' This code may only be used as part of an application. It may 31 | ' not be reproduced or distributed separately by any means without 32 | ' the express written permission of the author. 33 | 34 | ' David Ireland and DI Management Services Pty Limited make no 35 | ' representations concerning either the merchantability of this 36 | ' software or the suitability of this software for any particular 37 | ' purpose. It is provided "as is" without express or implied 38 | ' warranty of any kind. 39 | 40 | ' Please forward comments or bug reports to . 41 | ' The latest version of this source code can be downloaded from 42 | ' www.di-mgt.com.au/crypto.html. 43 | '****************** END OF COPYRIGHT NOTICE************************* 44 | 45 | ' Public Functions in this module: 46 | ' blf_EncipherBlock: Encrypts two words 47 | ' blf_DecipherBlock: Decrypts two words 48 | ' blf_Initialise: Initialise P & S arrays using key 49 | ' blf_KeyInit: Initialise using byte-array key 50 | ' blf_EncryptBytes: Encrypts an block of 8 bytes 51 | ' blf_DecryptBytes: Decrypts an block of 8 bytes 52 | ' 53 | ' Superseded functions: 54 | ' blf_Key: Initialise using byte-array and its length 55 | ' blf_Enc: Encrypts an array of words 56 | ' blf_Dec: Decrypts an array of words 57 | 58 | Private Const ncROUNDS As Integer = 16 59 | Private Const ncMAXKEYLEN As Integer = 56 60 | ' Version 4: ncMAXKEYLEN was previously incorrectly set as 448 61 | ' (bits vs bytes) 62 | ' Thanks to Robert Garofalo for pointing this out. 63 | 64 | Private Function blf_F(x As Long) As Long 65 | Dim a As Byte, b As Byte, C As Byte, d As Byte 66 | Dim y As Long 67 | 68 | Call uwSplit(x, a, b, C, d) 69 | 70 | y = uw_WordAdd(blf_S(0, a), blf_S(1, b)) 71 | y = y Xor blf_S(2, C) 72 | y = uw_WordAdd(y, blf_S(3, d)) 73 | blf_F = y 74 | 75 | End Function 76 | 77 | Public Function blf_EncipherBlock(xL As Long, xR As Long) 78 | Dim i As Integer 79 | Dim temp As Long 80 | 81 | 'Reverse Xl and XR 82 | 83 | For i = 0 To ncROUNDS - 1 84 | xL = xL Xor blf_P(i) 85 | xR = blf_F(xL) Xor xR 86 | 87 | ' Swap xL and xR 88 | temp = xL 89 | xL = xR 90 | xR = temp 91 | 92 | Next 93 | 94 | ' Swap xL and xR 95 | temp = xL 96 | xL = xR 97 | xR = temp 98 | 99 | xR = xR Xor blf_P(ncROUNDS) 100 | xL = xL Xor blf_P(ncROUNDS + 1) 101 | 102 | End Function 103 | 104 | Public Function blf_DecipherBlock(xL As Long, xR As Long) 105 | Dim i As Integer 106 | Dim temp As Long 107 | 108 | 'Difference to Encrypt (Indexes) 109 | For i = ncROUNDS + 1 To 2 Step -1 110 | xL = xL Xor blf_P(i) 111 | xR = blf_F(xL) Xor xR 112 | temp = xL 113 | xL = xR 114 | xR = temp 115 | Next 116 | 117 | temp = xL 118 | xL = xR 119 | xR = temp 120 | 121 | xR = xR Xor blf_P(1) 122 | xL = xL Xor blf_P(0) 123 | 124 | End Function 125 | 126 | Public Function blf_Initialise(aKey() As Byte, nKeyBytes As Integer) 127 | Dim i As Integer, j As Integer, K As Integer 128 | Dim wData As Long, wDataL As Long, wDataR As Long 129 | 130 | Call blf_LoadArrays ' Initialise P and S arrays 131 | 132 | ' Init P-Box with key 133 | j = 0 134 | For i = 0 To (ncROUNDS + 2 - 1) 135 | wData = &H0 136 | For K = 0 To 3 137 | wData = uw_ShiftLeftBy8(wData) Or aKey(j) 138 | j = j + 1 139 | If j >= nKeyBytes Then j = 0 140 | Next K 141 | blf_P(i) = blf_P(i) Xor wData 142 | ' Debug.Print "P-Box: " i, H32(blf_P(i)) 143 | Next i 144 | 145 | 146 | 'Stop 147 | ' Init for P-Box 148 | wDataL = &H0 149 | wDataR = &H0 150 | For i = 0 To (ncROUNDS + 2 - 1) Step 2 151 | Call blf_EncipherBlock(wDataL, wDataR) 152 | 153 | blf_P(i) = wDataL 154 | blf_P(i + 1) = wDataR 155 | Next i 156 | 157 | ' Init S-Box 158 | For i = 0 To 3 159 | For j = 0 To 255 Step 2 160 | Call blf_EncipherBlock(wDataL, wDataR) 161 | 162 | blf_S(i, j) = wDataL 163 | blf_S(i, j + 1) = wDataR 164 | Next j 165 | Next i 166 | 167 | End Function 168 | 169 | Public Function blf_Key(aKey() As Byte, nKeyLen As Integer) As Boolean 170 | blf_Key = False 171 | If nKeyLen < 0 Or nKeyLen > ncMAXKEYLEN Then 172 | Exit Function 173 | End If 174 | 175 | Call blf_Initialise(aKey, nKeyLen) 176 | 177 | blf_Key = True 178 | End Function 179 | 180 | Public Function blf_KeyInit(aKey() As Byte) As Boolean 181 | ' Added Version 5: Replacement for blf_Key to avoid specifying keylen 182 | ' Version 6: Added error checking for input 183 | Dim nKeyLen As Integer 184 | 185 | blf_KeyInit = False 186 | 187 | 'Set up error handler to catch empty array 188 | On Error GoTo ArrayIsEmpty 189 | 190 | nKeyLen = UBound(aKey) - LBound(aKey) + 1 191 | If nKeyLen < 0 Or nKeyLen > ncMAXKEYLEN Then 192 | Exit Function 193 | End If 194 | 195 | Call blf_Initialise(aKey, nKeyLen) 196 | 197 | 198 | blf_KeyInit = True 199 | 200 | ArrayIsEmpty: 201 | 202 | End Function 203 | 204 | Public Function blf_EncryptBytes(aBytes() As Byte) 205 | ' aBytes() must be 8 bytes long 206 | ' Revised Version 5: January 2002. To use faster uwJoin and uwSplit fns. 207 | Dim wordL As Long, wordR As Long 208 | 209 | ' Convert to 2 x words 210 | wordL = uwJoin(aBytes(0), aBytes(1), aBytes(2), aBytes(3)) 211 | wordR = uwJoin(aBytes(4), aBytes(5), aBytes(6), aBytes(7)) 212 | ' Encrypt it 213 | Call blf_EncipherBlock(wordL, wordR) 214 | ' Put back into bytes 215 | Call uwSplit(wordL, aBytes(0), aBytes(1), aBytes(2), aBytes(3)) 216 | Call uwSplit(wordR, aBytes(4), aBytes(5), aBytes(6), aBytes(7)) 217 | 218 | End Function 219 | 220 | Public Function blf_DecryptBytes(aBytes() As Byte) 221 | ' aBytes() must be 8 bytes long 222 | ' Revised Version 5:: January 2002. To use faster uwJoin and uwSplit fns. 223 | Dim wordL As Long, wordR As Long 224 | 225 | ' Convert to 2 x words 226 | wordL = uwJoin(aBytes(0), aBytes(1), aBytes(2), aBytes(3)) 227 | wordR = uwJoin(aBytes(4), aBytes(5), aBytes(6), aBytes(7)) 228 | 229 | ' Decrypt it 230 | Call blf_DecipherBlock(wordL, wordR) 231 | 232 | ' Put back into bytes 233 | Call uwSplit(wordL, aBytes(0), aBytes(1), aBytes(2), aBytes(3)) 234 | Call uwSplit(wordR, aBytes(4), aBytes(5), aBytes(6), aBytes(7)) 235 | 236 | End Function 237 | 238 | -------------------------------------------------------------------------------- /src/Blowfish/BlowfishReadMe.txt: -------------------------------------------------------------------------------- 1 | The README file for Visual Basic Blowfish functions 2 | 3 | This is a Visual Basic version of Bruce Schneier's Blowfish algorithm 4 | as detailed in "Applied Cryptography", 2nd edition, 1996 5 | 6 | It has been tested in VB6 and Access VBA. Use at your own risk. 7 | 8 | Version 6. Published 20 November 2003. History at end. 9 | '************************* COPYRIGHT NOTICE************************* 10 | ' This code was originally written in Visual Basic by David Ireland 11 | ' and is copyright (c) 2000-8 D.I. Management Services Pty Limited, 12 | ' all rights reserved. 13 | 14 | ' You are free to use this code as part of your own applications 15 | ' provided you keep this copyright notice intact and acknowledge 16 | ' its authorship with the words: 17 | 18 | ' "Contains cryptography software by David Ireland of 19 | ' DI Management Services Pty Ltd ." 20 | 21 | ' If you use it as part of a web site, please include a link 22 | ' to our site in the form 23 | ' Cryptography 24 | ' Software Code 25 | 26 | ' This code may only be used as part of an application. It may 27 | ' not be reproduced or distributed separately by any means without 28 | ' the express written permission of the author. 29 | 30 | ' David Ireland and DI Management Services Pty Limited make no 31 | ' representations concerning either the merchantability of this 32 | ' software or the suitability of this software for any particular 33 | ' purpose. It is provided "as is" without express or implied 34 | ' warranty of any kind. 35 | 36 | ' Please forward comments or bug reports to . 37 | ' The latest version of this source code can be downloaded from 38 | ' . 39 | '****************** END OF COPYRIGHT NOTICE************************* 40 | 41 | 42 | There are 11 VB modules and two VB projects. 43 | 44 | The main modules are: 45 | 46 | 1. basBlowfishByteFns: the (new) main wrapper fns you will call in your programs 47 | 2. basBlowfishFileFns: wrapper functions for file encryption 48 | 3. basBlowfish: the actual Blowfish algorithm in Visual Basic 49 | 4. basBlfArrays: the blowfish S and P arrays 50 | 5. basUnsignedWord: utilities for unsigned word operations 51 | 6. basConvert: conversion utilities for byte-strings-hex-word 52 | 7. basFileAPI: wrapper fns to read and write files using Windows API 53 | functions (these work better than VB's standard Open and Put fns). 54 | 8. basRadix64: functions to encode binary strings to base64 format 55 | and vice versa (aka radix64, Transfer Encoding, Printable Encoding). 56 | 57 | These modules that contain test functions: 58 | 9. basTestBlowfish: examples of Blowfish use and a test suite 59 | 10. basTestRadix64: examples of base64/radix64 encoding and decoding 60 | 11. basAPITimer: Timer functions by Litwin, Getz, Gilbert. 61 | 62 | Two VB Projects: 63 | Blowfish.vbp: Demo of simple Blowfish encryption 64 | BlowfishEx.vbp: Extended demo showing ECB and CBC modes 65 | 66 | Plus three text files to use in testing the file encryption functions: 67 | hello.txt, nowis.txt, sonnets.txt. 68 | 69 | To use: 70 | 71 | Add the files to your VB project or import them into modules in Access. 72 | 73 | Main ECB functions for variable length data 74 | ------------------------------------------- 75 | blf_BytesEnc(abData): Enciphers byte array abData with current key and padding 76 | blf_BytesDec(abData): Deciphers byte array abData with current key and padding 77 | blf_BytesRaw(abData, bEncrypt): En/Deciphers abData without padding 78 | blf_FileEnc(sFileIn, sFileOut): Enciphers file with name sFileIn 79 | with current key and writes output to new file sFileOut 80 | blf_FileDec(sFileIn, sFileOut): Deciphers file with name sFileIn 81 | with current key and writes output to new file sFileOut 82 | 83 | To set the current key, call blf_KeyInit(aKey()) 84 | where aKey() is the key as an array of Bytes. 85 | 86 | CBC Functions 87 | ------------- 88 | blf_BytesEncCBC 89 | blf_BytesDecCBC 90 | blf_BytesEncRawCBC 91 | blf_BytesDecRawCBC 92 | blf_FileEncCBC 93 | blf_FileDecCBC 94 | 95 | Note that the FilexCBC functions require the Initialisation Vector 96 | as a hex string, but the BytesxCBC functions require it as a byte array. 97 | This is for historical reasons. 98 | 99 | Padding 100 | ------- 101 | The padding technique is as described in PKCS#5/RFC2630/RFC3370. 102 | If you don't want padding, use the 'Raw' versions. 103 | PadBytes(abData): Returns padded byte array. 104 | UnpadBytes(abData): Returns unpadded byte array. 105 | 106 | Basic functions in basBlowfish 107 | ------------------------------------ 108 | blf_KeyInit(abKey): Sets current key with contents of abKey 109 | blf_Key: [redundant] 110 | blf_Initialise(aKey, nKeyBytes): Sets current key of nKeyBytes length. 111 | blf_EncryptBytes(aBytes): Encrypts 8-byte block with current key. 112 | blf_DecryptBytes(aBytes): Decrypts 8-byte block with current key. 113 | 114 | Class Modules: It is a trivial exercise to convert these functions 115 | to class modules. Please feel free to do so, but please keep the 116 | copyright notice intact if you do. 117 | 118 | Modification history 119 | -------------------- 120 | 20 October 2000: Version 1 first published. 121 | ============================================= 122 | 16 November 2000: Version 2: 123 | Added new module basBlowfishCBC with CBC variants 124 | of main wrapper functions. 125 | Changed En(De)CryptBytes fns from private to public 126 | Changed name of bu_Str2Bytes to bu_HexStr2Bytes 127 | Ditto bu_Str2Words to bu_HexStr2Words 128 | Added new byte utility fns: 129 | bu_XorBytes 130 | bu_CopyBytes 131 | bu_Bytes2String 132 | bu_String2Bytes 133 | Added CBC tests to basTestBlowfish 134 | ============================================= 135 | 28 December 2000: Version 3: 136 | Added Radix64 functions and 137 | improved functionality of demo form. 138 | Improved (!) legalise in copyright notice. 139 | New base64/radix64 functions are: 140 | EncodeStr64 - encodes string of binary chars to radix 64 format. 141 | - does not add CRLFs or any other formatting. 142 | DecodeStr64 - decodes radix64 chars back to binary string. 143 | - ignores any non-radix64 characters. 144 | ============================================= 145 | 20 January 2001: Version 3a: 146 | Minor bug fix to demo project form frmBlowfish.frm. 147 | If ciphertext ends with an acsii zero and is then stored directly 148 | in a VB text box, the text box truncates the trailing zeroes. 149 | Changed code behind form to store ciphertext in a string instead. 150 | Thanks to Jim McCusker of epotec.com for this fix. 151 | ============================================== 152 | 12 May 2001: Version 4: 153 | Various minor improvements. 154 | Thanks to Doug J Ward for his suggestions and advice on improving 155 | the speed of some of the byte operations and for much improved 156 | ShiftLeft and ShiftRight functions used in basRadix64. 157 | Thanks also to Robert Garofalo for pointing out an error in 158 | the max length of the blowfish key and a fix in error handling. 159 | ============================================== 160 | 27 January 2002: Version 5: 161 | Major re-write. 162 | Improved internal Blowfish word manipulation functions. 163 | Major speed improvements to string encryption functions 164 | (with many thanks to Robert Garofalo for suggestions 165 | incorporated here). 166 | Replaced old-style byte conversion routines in basByteUtils 167 | with dynamic array versions in basConvert 168 | ============================================== 169 | 20 November 2003: Version 6: 170 | Replaced deprecated 'String' functions with 'Byte' versions. 171 | Added 'Byte' functions and error handling to basRadix64. 172 | Updated basConvert with error handling. 173 | ============================================== 174 | 175 | 176 | -------------------------------------------------------------------------------- /src/Blowfish/basConvert.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basConvert" 2 | Option Explicit 3 | Option Base 0 4 | 5 | ' basConvert: Utilities to convert between byte arrays, hex strings, 6 | ' strings containing binary values, and 32-bit word arrays. 7 | 8 | ' NB: On 32-bit Unicode/CJK systems you may need to do a global 9 | ' replace of Asc() and Chr() with AscW() and ChrW() respectively. 10 | 11 | ' Version 2. November 2003: removed cv_BytesFromString which can be 12 | ' done with abBytes = StrConv(strInput, vbFromUnicode). 13 | ' - Added error handling to catch empty arrays. 14 | ' - Made HexFromByte public. 15 | ' Version 1. First published January 2002 16 | '************************* COPYRIGHT NOTICE************************* 17 | ' This code was originally written in Visual Basic by David Ireland 18 | ' and is copyright (c) 2000-2 D.I. Management Services Pty Limited, 19 | ' all rights reserved. 20 | 21 | ' You are free to use this code as part of your own applications 22 | ' provided you keep this copyright notice intact. 23 | 24 | ' This code may only be used as part of an application. It may 25 | ' not be reproduced or distributed separately by any means without 26 | ' the express written permission of the author. 27 | 28 | ' David Ireland and DI Management Services Pty Limited make no 29 | ' representations concerning either the merchantability of this 30 | ' software or the suitability of this software for any particular 31 | ' purpose. It is provided "as is" without express or implied 32 | ' warranty of any kind. 33 | 34 | ' Please forward comments or bug reports to . 35 | ' The latest version of this source code can be downloaded from 36 | ' www.di-mgt.com.au/crypto.html. 37 | '****************** END OF COPYRIGHT NOTICE************************* 38 | 39 | ' The Public Functions in this module are: 40 | ' cv_BytesFromHex(sInputHex): Returns array of bytes 41 | ' cv_WordsFromHex(sHex): Returns array of words (Longs) 42 | ' cv_HexFromWords(aWords): Returns hex string 43 | ' cv_HexFromBytes(aBytes()): Returns hex string 44 | ' cv_HexFromString(str): Returns hex string 45 | ' cv_StringFromHex(strHex): Returns string of ascii characters 46 | ' cv_GetHexByte(sInputHex, iIndex): Extracts iIndex'th byte from hex string 47 | ' RandHexByte(): Returns random byte as a 2-digit hex string 48 | ' HexFromByte(x): Returns 2-digit hex string representing byte x 49 | 50 | Public Function cv_BytesFromHex(ByVal sInputHex As String) As Variant 51 | ' Returns array of bytes from hex string in big-endian order 52 | ' E.g. sHex="FEDC80" will return array {&HFE, &HDC, &H80} 53 | Dim i As Long 54 | Dim M As Long 55 | Dim aBytes() As Byte 56 | If Len(sInputHex) Mod 2 <> 0 Then 57 | sInputHex = "0" & sInputHex 58 | End If 59 | 60 | M = Len(sInputHex) \ 2 61 | If M <= 0 Then 62 | ' Version 2: Returns empty array 63 | cv_BytesFromHex = aBytes 64 | Exit Function 65 | End If 66 | 67 | ReDim aBytes(M - 1) 68 | 69 | For i = 0 To M - 1 70 | aBytes(i) = Val("&H" & Mid$(sInputHex, i * 2 + 1, 2)) 71 | Next 72 | 73 | cv_BytesFromHex = aBytes 74 | 75 | End Function 76 | 77 | Public Function cv_WordsFromHex(ByVal sHex As String) As Variant 78 | ' Converts string with hex values into array of words (long ints) 79 | ' E.g. "fedcba9876543210" will be converted into {&HFEDCBA98, &H76543210} 80 | Const ncLEN As Integer = 8 81 | Dim i As Long 82 | Dim nWords As Long 83 | Dim aWords() As Long 84 | 85 | nWords = Len(sHex) \ ncLEN 86 | If nWords <= 0 Then 87 | ' Version 2: Returns empty array 88 | cv_WordsFromHex = aWords 89 | Exit Function 90 | End If 91 | 92 | ReDim aWords(nWords - 1) 93 | For i = 0 To nWords - 1 94 | aWords(i) = Val("&H" & Mid(sHex, i * ncLEN + 1, ncLEN)) 95 | Next 96 | 97 | cv_WordsFromHex = aWords 98 | 99 | End Function 100 | 101 | Public Function cv_HexFromWords(aWords) As String 102 | ' Converts array of words (Longs) into a hex string 103 | ' E.g. {&HFEDCBA98, &H76543210} will be converted to "FEDCBA9876543210" 104 | Const ncLEN As Integer = 8 105 | Dim i As Long 106 | Dim nWords As Long 107 | Dim sHex As String * ncLEN 108 | Dim iIndex As Long 109 | 110 | 'Set up error handler to catch empty array 111 | On Error GoTo ArrayIsEmpty 112 | If Not IsArray(aWords) Then 113 | Exit Function 114 | End If 115 | 116 | nWords = UBound(aWords) - LBound(aWords) + 1 117 | cv_HexFromWords = String(nWords * ncLEN, " ") 118 | iIndex = 0 119 | For i = 0 To nWords - 1 120 | sHex = Hex(aWords(i)) 121 | sHex = String(ncLEN - Len(sHex), "0") & sHex 122 | Mid$(cv_HexFromWords, iIndex + 1, ncLEN) = sHex 123 | iIndex = iIndex + ncLEN 124 | Next 125 | 126 | ArrayIsEmpty: 127 | 128 | End Function 129 | 130 | Public Function cv_HexFromBytes(aBytes() As Byte) As String 131 | ' Returns hex string from array of bytes 132 | ' E.g. aBytes() = {&HFE, &HDC, &H80} will return "FEDC80" 133 | Dim i As Long 134 | Dim iIndex As Long 135 | Dim nLen As Long 136 | 137 | 'Set up error handler to catch empty array 138 | On Error GoTo ArrayIsEmpty 139 | 140 | nLen = UBound(aBytes) - LBound(aBytes) + 1 141 | 142 | cv_HexFromBytes = String(nLen * 2, " ") 143 | iIndex = 0 144 | For i = LBound(aBytes) To UBound(aBytes) 145 | Mid$(cv_HexFromBytes, iIndex + 1, 2) = HexFromByte(aBytes(i)) 146 | iIndex = iIndex + 2 147 | Next 148 | 149 | ArrayIsEmpty: 150 | 151 | End Function 152 | 153 | Public Function cv_HexFromString(str As String) As String 154 | ' Converts string of ascii chars to string in hex format 155 | ' str may contain chars of any value between 0 and 255. 156 | ' E.g. "abc." will be converted to "6162632E" 157 | Dim byt As Byte 158 | Dim i As Long 159 | Dim n As Long 160 | Dim iIndex As Long 161 | Dim sHex As String 162 | 163 | n = Len(str) 164 | sHex = String(n * 2, " ") 165 | iIndex = 0 166 | For i = 1 To n 167 | byt = CByte(Asc(Mid$(str, i, 1)) And &HFF) 168 | Mid$(sHex, iIndex + 1, 2) = HexFromByte(byt) 169 | iIndex = iIndex + 2 170 | Next 171 | cv_HexFromString = sHex 172 | 173 | End Function 174 | 175 | Public Function cv_StringFromHex(strHex As String) As String 176 | ' Converts string in hex format to string of ascii chars 177 | ' with value between 0 and 255. 178 | ' E.g. "6162632E" will be converted to "abc." 179 | Dim i As Integer 180 | Dim nBytes As Integer 181 | 182 | nBytes = Len(strHex) \ 2 183 | cv_StringFromHex = String(nBytes, " ") 184 | For i = 0 To nBytes - 1 185 | Mid$(cv_StringFromHex, i + 1, 1) = Chr$(Val("&H" & Mid$(strHex, i * 2 + 1, 2))) 186 | Next 187 | 188 | End Function 189 | 190 | Public Function cv_GetHexByte(ByVal sInputHex As String, iIndex As Long) As Byte 191 | ' Extracts iIndex'th byte from hex string (starting at 1) 192 | ' E.g. cv_GetHexByte("fecdba98", 3) will return &HBA 193 | Dim i As Long 194 | i = 2 * iIndex 195 | If i > Len(sInputHex) Or i <= 0 Then 196 | cv_GetHexByte = 0 197 | Else 198 | cv_GetHexByte = Val("&H" & Mid$(sInputHex, i - 1, 2)) 199 | End If 200 | 201 | End Function 202 | 203 | Public Function RandHexByte() As String 204 | ' Returns a random byte as a 2-digit hex string 205 | Static stbInit As Boolean 206 | If Not stbInit Then 207 | Randomize 208 | stbInit = True 209 | End If 210 | 211 | RandHexByte = HexFromByte(CByte((Rnd * 256) And &HFF)) 212 | End Function 213 | 214 | Public Function HexFromByte(ByVal x) As String 215 | ' Returns a 2-digit hex string for byte x 216 | x = x And &HFF 217 | If x < 16 Then 218 | HexFromByte = "0" & Hex(x) 219 | Else 220 | HexFromByte = Hex(x) 221 | End If 222 | End Function 223 | 224 | 225 | Public Function testWordsHex() 226 | Dim aWords 227 | 228 | aWords = cv_WordsFromHex("FEDCBA9876543210") 229 | Debug.Print cv_HexFromWords(aWords) 230 | 231 | End Function 232 | 233 | 234 | 235 | -------------------------------------------------------------------------------- /src/lib/clsConsole.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "Console" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Option Explicit 15 | '_____________________ Console ________________________________ 16 | Private Declare Function CreatePipe Lib "kernel32" (phReadPipe _ 17 | As Long, phWritePipe As Long, lpPipeAttributes As Any, _ 18 | ByVal nSize As Long) As Long 19 | 20 | Private Declare Function ReadFile Lib "kernel32" (ByVal hFile _ 21 | As Long, ByVal lpBuffer As String, ByVal _ 22 | nNumberOfBytesToRead As Long, lpNumberOfBytesRead As _ 23 | Long, ByVal lpOverlapped As Any) As Long 24 | 25 | Private Declare Function CreateProcessA Lib "kernel32" (ByVal _ 26 | lpApplicationName As Long, ByVal lpCommandLine As _ 27 | String, lpProcessAttributes As Any, lpThreadAttributes _ 28 | As Any, ByVal bInheritHandles As Long, ByVal _ 29 | dwCreationFlags As Long, ByVal lpEnvironment As Long, _ 30 | ByVal lpCurrentDirectory As Long, lpSTARTUPINFOupInfo As Any, _ 31 | lpProcessInformation As Any) As Long 32 | 33 | Private Declare Function CloseHandle Lib "kernel32" (ByVal _ 34 | hObject As Long) As Long 35 | 36 | Private Declare Function PeekNamedPipe Lib "kernel32" (ByVal _ 37 | hNamedPipe As Long, lpBuffer As Any, ByVal nBufferSize _ 38 | As Long, lpBytesRead As Long, lpTotalBytesAvail As Long, _ 39 | lpBytesLeftThisMessage As Long) As Long 40 | 41 | Private Declare Function WaitForSingleObject Lib "kernel32" ( _ 42 | ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long 43 | 44 | Private Declare Function GetExitCodeProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByRef lpExitCode As Long) As Long 45 | 46 | Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long 47 | 48 | 49 | 50 | Private Const STATUS_PENDING As Long = &H103 51 | Private Const STILL_ACTIVE As Long = STATUS_PENDING 52 | 53 | 54 | Private Type SECURITY_ATTRIBUTES 55 | nLength As Long 56 | lpSecurityDescriptor As Long 57 | bInheritHandle As Long 58 | End Type 59 | 60 | Private Type STARTUPINFO 61 | cb As Long 62 | lpReserved As Long 63 | lpDesktop As Long 64 | lpTitle As Long 65 | dwX As Long 66 | dwY As Long 67 | dwXSize As Long 68 | dwYSize As Long 69 | dwXCountChars As Long 70 | dwYCountChars As Long 71 | dwFillAttribute As Long 72 | dwFlags As Long 73 | wShowWindow As Integer 74 | cbReserved2 As Integer 75 | lpReserved2 As Long 76 | hStdInput As Long 77 | hStdOutput As Long 78 | hStdError As Long 79 | End Type 80 | 81 | Private Type PROCESS_INFORMATION 82 | hProcess As Long 83 | hThread As Long 84 | dwProcessID As Long 85 | dwThreadID As Long 86 | End Type 87 | 88 | Const NORMAL_PRIORITY_CLASS& = &H20& 89 | Const STARTUPINFOF_USESTDHANDLES& = &H100& 90 | Const STARTF_USESHOWWINDOW& = 1 91 | 92 | 93 | Public Event OnOutput(TextLine$, ProgramName$) 94 | 95 | Public Function ShellExConsole(FileName$, Params$, Optional ByRef ExitCode&, Optional WinStyle As VbAppWinStyle = vbHide) As String 96 | On Error GoTo ShellExConsole_err 97 | 98 | ' GUI_SkipEnable 99 | 100 | 101 | Dim tmp As New ClsFilename 102 | tmp = FileName 103 | 104 | Dim ProgramName$ 105 | ProgramName = tmp.Name 106 | 107 | 108 | ' Create CommandLine 109 | Dim ShellCommand$ 110 | ShellCommand = """" & FileName & """" & " " & Params 111 | 112 | ' Open Pipe 113 | Dim sa As SECURITY_ATTRIBUTES 114 | sa.nLength = Len(sa) 115 | sa.bInheritHandle = 1& 116 | sa.lpSecurityDescriptor = 0& 117 | 118 | 119 | 120 | ' Create hWritePipe for CreateProcess!STARTUPINFO 121 | ' -> creates a console we'll read the output from 122 | Dim Retval As Long 123 | Dim hReadPipe As Long, hWritePipe As Long 124 | Retval = CreatePipe(hReadPipe, hWritePipe, sa, 0) 125 | If Retval = 0 Then 126 | Err.Raise 5, , "CreatePipe failed! RetVal: 0x" & H32(Retval) 127 | End If 128 | 129 | ' Prepare STARTUPINFO for CreateProcess 130 | ' make it use our handle for ConsoleOutput instead of the standard one 131 | Dim STARTUPINFO As STARTUPINFO 132 | With STARTUPINFO 133 | .cb = Len(STARTUPINFO) 134 | .dwFlags = STARTUPINFOF_USESTDHANDLES 135 | If WinStyle = vbHide Then 136 | .dwFlags = .dwFlags Or STARTF_USESHOWWINDOW 137 | ' .wShowWindow = 0 138 | 139 | End If 140 | .hStdOutput = hWritePipe 141 | End With 142 | 143 | ' Call CreateProcess 144 | Dim proc As PROCESS_INFORMATION 145 | Retval = CreateProcessA(0&, ShellCommand$, sa, sa, 1&, _ 146 | NORMAL_PRIORITY_CLASS, 0&, 0&, STARTUPINFO, proc) 147 | 148 | If Retval <> 0 Then 149 | 150 | Do 151 | Dim lPeekData As Long 152 | PeekNamedPipe hReadPipe, ByVal 0&, 0&, ByVal 0&, _ 153 | lPeekData, ByVal 0& 154 | 155 | If lPeekData > 0 Then 156 | 157 | ' Read and append console output data via ReadFile 158 | Dim L As Long 159 | Dim Buffer As String 160 | Buffer = Space$(lPeekData) 161 | Retval = ReadFile(hReadPipe, Buffer, Len(Buffer), L, 0&) 162 | If Retval = 1 Then 163 | 164 | Buffer = Left(Buffer, L) 165 | 166 | ' Send line / raise OnOutputLine Event 167 | RaiseEvent OnOutput(Buffer, ProgramName) 168 | 169 | 170 | Dim retText As String 171 | retText = retText & Buffer 172 | 173 | 174 | Else 175 | Err.Raise 5, , "ReadFile failed! RetVal: 0x" & H32(Retval) 176 | End If 177 | 178 | Else 179 | ' Wait until procress finishes and get its ExitCode 180 | Dim GetExitCode_RetVal& 181 | GetExitCode_RetVal = GetExitCodeProcess(proc.hProcess, ExitCode) 182 | 183 | End If 184 | 185 | myDoEvents 186 | Loop While GetExitCode_RetVal And (ExitCode = STILL_ACTIVE) 187 | 188 | Else 189 | Err.Raise 5, , "CreateProcessA failed! RetVal: 0x" & H32(Retval) 190 | End If 191 | 192 | CloseHandle hReadPipe 193 | CloseHandle hWritePipe 194 | 195 | ShellExConsole = retText 196 | 197 | Err.Clear 198 | ShellExConsole_err: 199 | 200 | 'GUI_SkipDisable 201 | 202 | Select Case Err 203 | Case 0 204 | Case 5, 53 205 | Err.Raise vbObjectError Or Err.Number, "ShellExConsole()", "Shell(" & ShellCommand & ") [@ApiHelper.bas] FAILED! Error: " & Err.description 206 | 207 | Case ERR_CANCEL_ALL 208 | Retval = TerminateProcess(proc.hProcess, ExitCode) 209 | If Retval Then 210 | Err.Raise ERR_CANCEL_ALL, , "User canceled process " & ProgramName & " terminated." 211 | Else 212 | Err.Raise ERR_CANCEL_ALL, , "User canceled process " & ProgramName & " terminated. FAILED! - ErrCode: " & H32(Err.LastDllError) 213 | End If 214 | 215 | Case ERR_SKIP 216 | Retval = TerminateProcess(proc.hProcess, ExitCode) 217 | If Retval Then 218 | log "User skipped/canceled process " & ProgramName & " terminated." 219 | Else 220 | log "User skipped/canceled process " & ProgramName & " terminated. FAILED! - ErrCode: " & H32(Err.LastDllError) 221 | End If 222 | 223 | 224 | Case Else 225 | Err.Raise vbObjectError Or Err.Number, "ShellExConsole()", Err.description 226 | End Select 227 | 228 | 229 | 230 | End Function 231 | 232 | 233 | -------------------------------------------------------------------------------- /src/lib/StringReader.cls: -------------------------------------------------------------------------------- 1 | VERSION 1.0 CLASS 2 | BEGIN 3 | MultiUse = -1 'True 4 | Persistable = 0 'NotPersistable 5 | DataBindingBehavior = 0 'vbNone 6 | DataSourceBehavior = 0 'vbNone 7 | MTSTransactionMode = 0 'NotAnMTSObject 8 | END 9 | Attribute VB_Name = "StringReader" 10 | Attribute VB_GlobalNameSpace = False 11 | Attribute VB_Creatable = True 12 | Attribute VB_PredeclaredId = False 13 | Attribute VB_Exposed = False 14 | Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes" 15 | Attribute VB_Ext_KEY = "Top_Level" ,"Yes" 16 | 'Important ref to clean up the Chr, ChrB, ChrW Hassle 17 | 'http://support.microsoft.com/kb/145745/ 18 | 19 | 20 | 21 | Option Explicit 22 | Private Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, src As Any, ByVal Length&) 23 | 24 | Private Declare Sub MemCopyStrToCur Lib "kernel32" Alias "RtlMoveMemory" (dest As Currency, ByVal src As String, ByVal Length&) 25 | 26 | Private Declare Sub MemCopyStrToDbl Lib "kernel32" Alias "RtlMoveMemory" (dest As Double, ByVal src As String, ByVal Length&) 27 | 28 | 29 | Private Declare Sub MemCopyStrToLng Lib "kernel32" Alias "RtlMoveMemory" (dest As Long, ByVal src As String, ByVal Length&) 30 | Private Declare Sub MemCopyLngToStr Lib "kernel32" Alias "RtlMoveMemory" (ByVal dest As String, src As Long, ByVal Length&) 31 | Private Declare Sub MemCopyLngToInt Lib "kernel32" Alias "RtlMoveMemory" (dest As Long, ByVal src As Integer, ByVal Length&) 32 | 33 | Public bSearchBackward As Boolean 34 | 'lokale Variable(n) zum Zuweisen der Eigenschaft(en) 35 | Private mvarPosition As Long 'lokale Kopie 36 | Public mvardata As String 'lokale Kopie 37 | 'Public Position As Long 'lokale Kopie 38 | Public mStorePos As Long 39 | Public DisableAutoMove As Boolean 40 | Public DisableAutoMoveOnRead As Boolean 41 | 42 | Public Sub Truncate() 43 | Data = Left(Data, Position) 44 | End Sub 45 | 46 | 47 | Public Property Get Stream(Length As Long) As StringReader 48 | Set Stream = New StringReader 49 | Stream.Data = FixedString(Length) 50 | End Property 51 | 52 | 53 | 54 | 55 | 56 | Public Property Let zeroString(ByVal vData As String) 57 | myStop 58 | End Property 59 | 60 | 61 | Public Property Get zeroString() As String 62 | Dim EndOfZeroString As Long 63 | EndOfZeroString = InStr(mvarPosition, mvardata, vbNullChar) 64 | zeroString = FixedString(EndOfZeroString - mvarPosition) 65 | ' Skip over zerobyte at the end of the ZeroTerminatedString 66 | mvarPosition = mvarPosition + 1 67 | 68 | End Property 69 | 70 | 71 | 72 | 73 | 74 | 75 | Public Property Let Length(ByVal vData As Long) 76 | myStop 'not implemented 77 | End Property 78 | 79 | 80 | Public Property Get Length() As Long 81 | Length = Len(mvardata) 82 | End Property 83 | 84 | 85 | 86 | 87 | Public Sub RestorePos() 88 | Position = mStorePos 89 | End Sub 90 | 91 | Public Sub StorePos() 92 | mStorePos = Position 93 | End Sub 94 | 95 | 96 | Public Property Let ToMove(ByVal vData As Long) 97 | If DisableAutoMove Then Exit Property 98 | Move (vData) 99 | End Property 100 | 101 | 102 | Public Property Let Position(vData As Long) 103 | mvarPosition = limit(vData, Len(mvardata), 0) + 1 104 | End Property 105 | 106 | 107 | Public Property Get Position() As Long 108 | Position = mvarPosition - 1 109 | End Property 110 | 111 | 112 | Private Function StrtoULng(ByVal value$) As Currency 113 | MemCopyStrToCur StrtoULng, value, 4 114 | StrtoULng = StrtoULng * 10000 115 | 116 | End Function 117 | 118 | 119 | Private Function StrtoLng(ByVal value$) As Long 120 | MemCopyStrToLng StrtoLng, value, 4 121 | End Function 122 | ' 123 | Private Function LngtoStr(ByVal value&) As String 124 | Dim tmp$ 125 | tmp = Space(4) 126 | MemCopyLngToStr tmp, value, 4 127 | LngtoStr = tmp 128 | End Function 129 | 130 | '///////////////////////////////////////////////////////// 131 | '// set_EOS - Returns True if Position is at the End Of String 132 | Public Property Let EOS(ByVal vData As Boolean) 133 | Position = Len(mvardata) And vData 134 | End Property 135 | '// get_EOS - Forward to End Of String 136 | Public Property Get EOS() As Boolean 137 | ' EOS = Position >= Len(mvardata) 138 | 'optimised 139 | ' EOS = (mvarPosition - 1) >= Len(mvardata) 140 | EOS = mvarPosition > Len(mvardata) 141 | End Property 142 | 143 | 144 | Public Sub Move(chars&) 145 | Position = Position + chars 146 | ' Debug.Print "Move: ", Chars 147 | End Sub 148 | 149 | Public Function FindByte(ByVal LongValue_To_Find$, Optional Range) As Long 150 | FindByte = FindString(Left(LngtoStr(LongValue_To_Find), 1)) 151 | End Function 152 | 153 | Public Function FindInt(ByVal LongValue_To_Find$, Optional Range) As Long 154 | FindInt = FindString(Left(LngtoStr(LongValue_To_Find), 2)) 155 | End Function 156 | 157 | Public Function FindLong(ByVal LongValue_To_Find$, Optional Range) As Long 158 | FindLong = FindString(LngtoStr(LongValue_To_Find)) 159 | End Function 160 | 161 | Public Function FindString(String_To_Find$, Optional Range) ', Optional Alternativ_String_To_Find) As Long 162 | If IsMissing(Range) Then Range = Len(mvardata) 163 | 164 | ' Findstring = InStr(1, mid$(mvarData, mvarPosition, Range), String_To_Find) 165 | If bSearchBackward Then 166 | FindString = InStrRev(mvardata, String_To_Find, mvarPosition) 167 | 168 | Else 169 | FindString = InStr(mvarPosition, mvardata, String_To_Find) 170 | 171 | End If 172 | 173 | 'Test if out of range 174 | If Abs(mvarPosition - FindString - 1) > Range Then 175 | FindString = 0 176 | End If 177 | 178 | 179 | ' If IsMissing(Alternativ_String_To_Find = False) And (Findstring = 0) Then 180 | ' Findstring = InStr(1, mid$(mvarData, Position, Range), String_To_Find) 181 | 182 | 183 | ' If string was found 184 | If FindString Then 185 | 186 | 'Return start of String 187 | ' Findstring = (Findstring - 1) + Position 188 | FindString = (FindString - 1) 189 | 190 | 191 | 'seek at the end of found String 192 | ToMove = (FindString - Position) + Len(String_To_Find) 193 | 194 | 195 | End If 196 | End Function 197 | 198 | Public Property Let FixedString(Optional ByVal Length& = -1, vData As String) 199 | If Length <= 0 Then Length = Len(vData) 200 | If Length <= 0 Then Exit Property 201 | 202 | 'Enlarge Buffer if necessary 203 | Dim enlarge& 204 | enlarge = (Length + mvarPosition - 1) - Len(mvardata) 205 | If enlarge >= 1 Then mvardata = mvardata & Space(enlarge) 206 | 207 | Mid$(mvardata, mvarPosition, Length) = vData 208 | ToMove = Length 209 | End Property 210 | 211 | 212 | Public Property Get FixedString(Optional ByVal Length& = -1) As String 213 | If Length <= -1 Then Length = Len(mvardata) 214 | FixedString = Mid$(mvardata, mvarPosition, Length) 215 | 216 | If DisableAutoMoveOnRead = False Then ToMove = Length 217 | End Property 218 | 219 | Public Property Get FixedBytes(Optional ByVal Length& = -1) As Byte() 220 | 'FixedBytes = FixedString(Length) 221 | FixedBytes = StrConv(FixedString(Length), vbFromUnicode) 222 | End Property 223 | 224 | Public Property Let FixedBytes(Optional ByVal Length& = -1, vData() As Byte) 225 | FixedString(Length) = StrConv(vData, vbUnicode) 226 | End Property 227 | 228 | 229 | Public Property Let int32(vData As Long) 230 | FixedString = LngtoStr(vData) 231 | End Property 232 | 233 | 234 | Public Property Get int32() As Long 235 | int32 = StrtoLng(FixedString(4)) 236 | End Property 237 | 238 | Public Property Get UInt32() As Currency 239 | UInt32 = StrtoULng(FixedString(4)) 240 | End Property 241 | 242 | 243 | 244 | 245 | Public Property Let int16(vData As Long) 246 | FixedString(2) = LngtoStr(vData) 247 | End Property 248 | 249 | 250 | Public Property Get int16() As Long 251 | int16 = StrtoLng(FixedString(2)) 252 | End Property 253 | 254 | 'Public Property Let int16Sig(vData As Integer) 255 | ' FixedString(2) = LngtoStr(vData) 256 | 'End Property 257 | 258 | 259 | Public Property Get int16Sig() As Integer 260 | Dim value& 261 | value = StrtoLng(FixedString(2)) 262 | int16Sig = value Or -(value And &H8000) '-32768 '&H8000 263 | End Property 264 | 265 | 266 | Public Property Get GetFloat64() As Double 267 | 268 | Dim tmp As Double 269 | ' tmp = Space(8) 270 | 271 | MemCopyStrToDbl tmp, FixedString(8), 8 272 | GetFloat64 = tmp 273 | 274 | 275 | End Property 276 | 277 | 278 | Public Property Let int8(vData As Long) 279 | FixedString(1) = LngtoStr(vData) 280 | ' FixedString(1) = ChrB(vData) & ChrB(0) 281 | ' FixedString(-1) = ChrW$(vData) ' & ChrB(0) 282 | End Property 283 | 284 | 285 | 286 | Public Property Get int8() As Long 287 | ' int8 = StrtoLng(FixedString(1)) 288 | ' int8 = Asc(FixedString(1)) 289 | ' Debug.Assert AscB(Mid(mvardata, mvarPosition, 1)) = Asc(Mid(mvardata, mvarPosition, 1)) 290 | int8 = Asc(Mid$(mvardata, mvarPosition, 1)) 291 | ' int8 = AscB(MidB(StrConv(mvardata, vbFromUnicode), mvarPosition, 1)) 292 | 293 | If DisableAutoMoveOnRead = False Then ToMove = 1 294 | 295 | 296 | 297 | End Property 298 | 299 | 'Public Property Let int8Sig(vData As Long) 300 | ' FixedString(1) = LngtoStr(vData) 301 | 'End Property 302 | 303 | 304 | Public Property Get int8Sig() As Long 305 | 306 | int8Sig = StrtoLng(FixedString(1)) 307 | int8Sig = int8Sig Or -(int8Sig And &H80) 308 | 309 | End Property 310 | 311 | 312 | Public Property Let Data(vData As String) 313 | mvardata = vData 314 | Position = 0 315 | End Property 316 | 317 | 318 | Public Property Get Data() As String 319 | Attribute Data.VB_UserMemId = 0 320 | Data = mvardata 321 | End Property 322 | 323 | Public Sub CopyData(src&, dest&, Optional Size = -1) 324 | Dim tmpstr$ 325 | Position = src 326 | tmpstr = FixedString(Size) 327 | 328 | Position = dest 329 | FixedString(Size) = tmpstr 330 | 331 | 332 | End Sub 333 | 334 | Private Sub Class_Initialize() 335 | mvarPosition = 1 336 | End Sub 337 | 338 | -------------------------------------------------------------------------------- /data/php_functions_list.dat: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | _GET 10 | _POST 11 | _SERVER 12 | _SESSION 13 | _GLOBALS 14 | this 15 | key 16 | count 17 | substr 18 | abs 19 | acos 20 | addcslashes 21 | addslashes 22 | array_count_values 23 | array_diff 24 | array_filter 25 | array_flip 26 | array_intersect 27 | array_keys 28 | array_map 29 | array_merge 30 | array_merge_recursive 31 | array_multisort 32 | array_pad 33 | array_pop 34 | array_push 35 | array_rand 36 | array_reduce 37 | array_reverse 38 | array_search 39 | array_shift 40 | array_slice 41 | array_splice 42 | array_sum 43 | array_unique 44 | array_unshift 45 | array_values 46 | array_walk 47 | arsort 48 | asin 49 | asort 50 | assert 51 | assert_options 52 | atan2 53 | atan 54 | base64_decode 55 | base64_encode 56 | base_convert 57 | basename 58 | bin2hex 59 | bindec 60 | bindtextdomain 61 | call_user_func 62 | call_user_func_array 63 | call_user_method 64 | call_user_method_array 65 | ceil 66 | chdir 67 | checkdate 68 | checkdnsrr 69 | chgrp 70 | chmod 71 | chop 72 | chown 73 | chr 74 | chroot 75 | chunk_split 76 | class_exists 77 | clearstatcache 78 | closedir 79 | closelog 80 | compact 81 | connection_aborted 82 | connection_status 83 | constant 84 | convert_cyr_string 85 | copy 86 | cos 87 | count_chars 88 | crc32 89 | create_function 90 | crypt 91 | current 92 | date 93 | dcgettext 94 | decbin 95 | dechex 96 | decoct 97 | define 98 | define_syslog_variables 99 | defined 100 | deg2rad 101 | dgettext 102 | dir 103 | dirname 104 | diskfreespace 105 | dl 106 | doubleval 107 | each 108 | end 109 | ereg 110 | ereg_replace 111 | eregi 112 | eregi_replace 113 | error_log 114 | error_reporting 115 | escapeshellarg 116 | escapeshellcmd 117 | exec 118 | exp 119 | explode 120 | extension_loaded 121 | extract 122 | ezmlm_hash 123 | fclose 124 | feof 125 | fflush 126 | fgetc 127 | fgetcsv 128 | fgets 129 | fgetss 130 | file 131 | file_exists 132 | fileatime 133 | filectime 134 | filegroup 135 | fileinode 136 | filemtime 137 | fileowner 138 | fileperms 139 | filesize 140 | filetype 141 | flock 142 | floor 143 | flush 144 | fopen 145 | fopenstream 146 | fpassthru 147 | fputs 148 | fread 149 | fscanf 150 | fseek 151 | fsockopen 152 | fstat 153 | ftell 154 | ftruncate 155 | func_get_arg 156 | func_get_args 157 | func_num_args 158 | function_exists 159 | fwrite 160 | get_browser 161 | get_cfg_var 162 | get_class 163 | get_class_methods 164 | get_class_vars 165 | get_current_user 166 | get_declared_classes 167 | get_defined_functions 168 | get_defined_vars 169 | get_extension_funcs 170 | get_html_translation_table 171 | get_included_files 172 | get_loaded_extensions 173 | get_magic_quotes_gpc 174 | get_magic_quotes_runtime 175 | get_meta_tags 176 | get_object_vars 177 | get_parent_class 178 | get_required_files 179 | get_resource_type 180 | getcwd 181 | getdate 182 | getenv 183 | gethostbyaddr 184 | gethostbyname 185 | gethostbynamel 186 | getimagesize 187 | getlastmod 188 | getmxrr 189 | getmyinode 190 | getmypid 191 | getmyuid 192 | getprotobyname 193 | getprotobynumber 194 | getrandmax 195 | getrusage 196 | getservbyname 197 | getservbyport 198 | gettext 199 | gettimeofday 200 | gettype 201 | gmdate 202 | gmmktime 203 | gmstrftime 204 | gzclose 205 | gzcompress 206 | gzdeflate 207 | gzencode 208 | gzeof 209 | gzfile 210 | gzgetc 211 | gzgets 212 | gzgetss 213 | gzinflate 214 | gzopen 215 | gzpassthru 216 | gzputs 217 | gzread 218 | gzrewind 219 | gzseek 220 | gztell 221 | gzuncompress 222 | gzwrite 223 | header 224 | headers_sent 225 | hebrev 226 | hebrevc 227 | hexdec 228 | highlight_file 229 | highlight_string 230 | htmlentities 231 | htmlspecialchars 232 | HTTP_GET_VARS 233 | HTTP_POST_VARS 234 | HTTP_SERVER_VARS 235 | ignore_user_abort 236 | implode 237 | i 238 | in_array 239 | ini_alter 240 | ini_get 241 | ini_restore 242 | ini_set 243 | intval 244 | ip2long 245 | iptcembed 246 | iptcparse 247 | is_array 248 | is_bool 249 | is_callable 250 | is_dir 251 | is_double 252 | is_executable 253 | is_file 254 | is_float 255 | is_int 256 | is_integer 257 | is_link 258 | is_long 259 | is_null 260 | is_numeric 261 | is_object 262 | is_readable 263 | is_real 264 | is_resource 265 | is_scalar 266 | is_string 267 | is_subclass_of 268 | is_uploaded_file 269 | is_writable 270 | is_writeable 271 | j 272 | join 273 | k 274 | key_exists 275 | krsort 276 | ksort 277 | lcg_value 278 | leak 279 | levenshtein 280 | link 281 | linkinfo 282 | localeconv 283 | localtime 284 | log10 285 | log 286 | long2ip 287 | lstat 288 | ltrim 289 | m 290 | magic_quotes_runtime 291 | mail 292 | max 293 | md5 294 | metaphone 295 | method_exists 296 | microtime 297 | min 298 | mkdir 299 | mktime 300 | move_uploaded_file 301 | mt_getrandmax 302 | mt_rand 303 | mt_srand 304 | mysql 305 | mysql_affected_rows 306 | mysql_close 307 | mysql_connect 308 | mysql_create_db 309 | mysql_createdb 310 | mysql_data_seek 311 | mysql_db_name 312 | mysql_db_query 313 | mysql_dbname 314 | mysql_drop_db 315 | mysql_dropdb 316 | mysql_errno 317 | mysql_error 318 | mysql_escape_string 319 | mysql_fetch_array 320 | mysql_fetch_assoc 321 | mysql_fetch_field 322 | mysql_fetch_lengths 323 | mysql_fetch_object 324 | mysql_fetch_row 325 | mysql_field_flags 326 | mysql_field_len 327 | mysql_field_name 328 | mysql_field_seek 329 | mysql_field_table 330 | mysql_field_type 331 | mysql_fieldflags 332 | mysql_fieldlen 333 | mysql_fieldname 334 | mysql_fieldtable 335 | mysql_fieldtype 336 | mysql_free_result 337 | mysql_freeresult 338 | mysql_get_client_info 339 | mysql_get_host_info 340 | mysql_get_proto_info 341 | mysql_get_server_info 342 | mysql_insert_id 343 | mysql_list_dbs 344 | mysql_list_fields 345 | mysql_list_tables 346 | mysql_listdbs 347 | mysql_listfields 348 | mysql_listtables 349 | mysql_num_fields 350 | mysql_num_rows 351 | mysql_numfields 352 | mysql_numrows 353 | mysql_pconnect 354 | mysql_query 355 | mysql_result 356 | mysql_select_db 357 | mysql_selectdb 358 | mysql_tablename 359 | mysql_unbuffered_query 360 | n 361 | natcasesort 362 | natsort 363 | next 364 | nl2br 365 | number_format 366 | ob_end_clean 367 | ob_end_flush 368 | ob_get_contents 369 | ob_get_length 370 | ob_gzhandler 371 | ob_implicit_flush 372 | ob_start 373 | octdec 374 | opendir 375 | openlog 376 | ord 377 | pack 378 | parent 379 | parse_ini_file 380 | parse_str 381 | parse_url 382 | passthru 383 | pathinfo 384 | pclose 385 | pfsockopen 386 | php_logo_guid 387 | php_sapi_name 388 | php_uname 389 | phpcredits 390 | phpinfo 391 | phpversion 392 | pi 393 | popen 394 | pos 395 | posix_ctermid 396 | posix_getcwd 397 | posix_getegid 398 | posix_geteuid 399 | posix_getgid 400 | posix_getgrgid 401 | posix_getgrnam 402 | posix_getgroups 403 | posix_getlogin 404 | posix_getpgid 405 | posix_getpgrp 406 | posix_getpid 407 | posix_getppid 408 | posix_getpwnam 409 | posix_getpwuid 410 | posix_getrlimit 411 | posix_getsid 412 | posix_getuid 413 | posix_isatty 414 | posix_kill 415 | posix_mkfifo 416 | posix_setegid 417 | posix_seteuid 418 | posix_setgid 419 | posix_setpgid 420 | posix_setsid 421 | posix_setuid 422 | posix_times 423 | posix_ttyname 424 | posix_uname 425 | pow 426 | preg_grep 427 | preg_match 428 | preg_match_all 429 | preg_quote 430 | preg_replace 431 | preg_replace_callback 432 | preg_split 433 | prev 434 | print_r 435 | printf 436 | putenv 437 | quoted_printable_decode 438 | quotemeta 439 | rad2deg 440 | rand 441 | range 442 | rawurldecode 443 | rawurlencode 444 | readdir 445 | readfile 446 | readgzfile 447 | readlink 448 | realpath 449 | register_shutdown_function 450 | register_tick_function 451 | rename 452 | reset 453 | restore_error_handler 454 | rewind 455 | rewinddir 456 | rmdir 457 | round 458 | rsort 459 | rtrim 460 | sem_acquire 461 | sem_get 462 | sem_release 463 | serialize 464 | session_cache_limiter 465 | session_decode 466 | session_destroy 467 | session_encode 468 | session_get_cookie_params 469 | session_id 470 | session_is_registered 471 | session_module_name 472 | session_name 473 | session_register 474 | session_save_path 475 | session_set_cookie_params 476 | session_set_save_handler 477 | session_start 478 | session_unregister 479 | session_unset 480 | session_write_close 481 | set_error_handler 482 | set_file_buffer 483 | set_magic_quotes_runtime 484 | set_socket_blocking 485 | set_time_limit 486 | setcookie 487 | setlocale 488 | settype 489 | shell_exec 490 | shm_attach 491 | shm_detach 492 | shm_get_var 493 | shm_put_var 494 | shm_remove 495 | shm_remove_var 496 | show_source 497 | shuffle 498 | similar_text 499 | sin 500 | sizeof 501 | sleep 502 | socket_get_status 503 | socket_set_blocking 504 | socket_set_timeout 505 | sort 506 | soundex 507 | split 508 | spliti 509 | sprintf 510 | sql_regcase 511 | sqrt 512 | srand 513 | sscanf 514 | stat 515 | str_pad 516 | str_repeat 517 | str_replace 518 | strcasecmp 519 | strchr 520 | strcmp 521 | strcoll 522 | strcspn 523 | strftime 524 | strip_tags 525 | stripcslashes 526 | stripslashes 527 | stristr 528 | strlen 529 | strnatcasecmp 530 | strnatcmp 531 | strncasecmp 532 | strncmp 533 | strpos 534 | strrchr 535 | strrev 536 | strrpos 537 | strspn 538 | strstr 539 | strtok 540 | strtolower 541 | strtotime 542 | strtoupper 543 | strtr 544 | strval 545 | substr_count 546 | substr_replace 547 | symlink 548 | syslog 549 | system 550 | tan 551 | tempnam 552 | textdomain 553 | time 554 | tmpfile 555 | touch 556 | trigger_error 557 | trim 558 | uasort 559 | ucfirst 560 | ucwords 561 | uksort 562 | umask 563 | uniqid 564 | unlink 565 | unpack 566 | unregister_tick_function 567 | unserialize 568 | urldecode 569 | urlencode 570 | user_error 571 | usleep 572 | usort 573 | utf8_decode 574 | utf8_encode 575 | var_dump 576 | wordwrap 577 | x 578 | xml_error_string 579 | xml_get_current_byte_index 580 | xml_get_current_column_number 581 | xml_get_current_line_number 582 | xml_get_error_code 583 | xml_parse 584 | xml_parse_into_struct 585 | xml_parser_create 586 | xml_parser_free 587 | xml_parser_get_option 588 | xml_parser_set_option 589 | xml_set_character_data_handler 590 | xml_set_default_handler 591 | xml_set_element_handler 592 | xml_set_external_entity_ref_handler 593 | xml_set_notation_decl_handler 594 | xml_set_object 595 | xml_set_processing_instruction_handler 596 | xml_set_unparsed_entity_decl_handler 597 | y 598 | z 599 | zend_logo_guid -------------------------------------------------------------------------------- /src/Blowfish/frmBlowfish.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form frmBlowfish 3 | Caption = "Blowfish Testbed Demo Version 6" 4 | ClientHeight = 7110 5 | ClientLeft = 60 6 | ClientTop = 345 7 | ClientWidth = 6240 8 | LinkTopic = "Form1" 9 | MaxButton = 0 'False 10 | ScaleHeight = 7110 11 | ScaleWidth = 6240 12 | StartUpPosition = 3 'Windows-Standard 13 | Begin VB.TextBox txtCipher64 14 | BackColor = &H80000004& 15 | Height = 375 16 | Left = 1200 17 | Locked = -1 'True 18 | TabIndex = 19 19 | Top = 4680 20 | Width = 4695 21 | End 22 | Begin VB.Frame grpKeyForm 23 | Caption = "Key form:" 24 | Height = 615 25 | Left = 1200 26 | TabIndex = 16 27 | Top = 600 28 | Width = 3855 29 | Begin VB.OptionButton optAlphaKey 30 | Caption = "Alpha" 31 | Height = 255 32 | Left = 2040 33 | TabIndex = 18 34 | Top = 240 35 | Width = 1335 36 | End 37 | Begin VB.OptionButton optHexKey 38 | Caption = "Hex string" 39 | Height = 255 40 | Left = 480 41 | TabIndex = 17 42 | Top = 240 43 | Value = -1 'True 44 | Width = 1215 45 | End 46 | End 47 | Begin VB.TextBox txtCipherHex 48 | BackColor = &H80000004& 49 | Height = 375 50 | Left = 1200 51 | Locked = -1 'True 52 | TabIndex = 15 53 | Top = 4200 54 | Width = 4695 55 | End 56 | Begin VB.TextBox txtCipher 57 | BackColor = &H80000004& 58 | Height = 405 59 | Left = 1200 60 | TabIndex = 14 61 | Top = 3720 62 | Width = 4695 63 | End 64 | Begin VB.TextBox txtDecrypt 65 | BackColor = &H80000004& 66 | Height = 375 67 | Left = 1200 68 | Locked = -1 'True 69 | TabIndex = 10 70 | Top = 5880 71 | Width = 4695 72 | End 73 | Begin VB.CommandButton cmdDecrypt 74 | Caption = "&Decrypt It" 75 | Enabled = 0 'False 76 | Height = 495 77 | Left = 2160 78 | TabIndex = 9 79 | Top = 5160 80 | Width = 1695 81 | End 82 | Begin VB.TextBox txtKeyAsString 83 | BackColor = &H80000004& 84 | Height = 375 85 | Left = 1200 86 | Locked = -1 'True 87 | TabIndex = 7 88 | Top = 1920 89 | Width = 4695 90 | End 91 | Begin VB.CommandButton cmdSetKey 92 | Caption = "&Set Key" 93 | Height = 495 94 | Left = 2160 95 | TabIndex = 6 96 | Top = 1320 97 | Width = 1815 98 | End 99 | Begin VB.CommandButton cmdEncrypt 100 | Caption = "&Encrypt It" 101 | Enabled = 0 'False 102 | Height = 495 103 | Left = 2160 104 | TabIndex = 5 105 | Top = 3120 106 | Width = 1695 107 | End 108 | Begin VB.TextBox txtKey 109 | Height = 375 110 | Left = 1080 111 | TabIndex = 0 112 | Text = "fedcba9876543210" 113 | Top = 120 114 | Width = 4815 115 | End 116 | Begin VB.TextBox txtPlain 117 | Height = 375 118 | Left = 1200 119 | TabIndex = 1 120 | Top = 2520 121 | Width = 4695 122 | End 123 | Begin VB.Label Label7 124 | Caption = "(Radix64):" 125 | Height = 375 126 | Left = 240 127 | TabIndex = 20 128 | Top = 4680 129 | Width = 855 130 | End 131 | Begin VB.Label Label6 132 | Alignment = 2 'Zentriert 133 | Caption = "Copyright (C) 2000-3 DI Management Services Pty Ltd " 134 | Height = 495 135 | Left = 1350 136 | TabIndex = 13 137 | Top = 6525 138 | Width = 3855 139 | End 140 | Begin VB.Label Label2 141 | Caption = "(In hex):" 142 | Height = 255 143 | Index = 1 144 | Left = 240 145 | TabIndex = 12 146 | Top = 4200 147 | Width = 975 148 | End 149 | Begin VB.Label Label5 150 | Caption = "Deciphered" 151 | Height = 255 152 | Left = 240 153 | TabIndex = 11 154 | Top = 5880 155 | Width = 975 156 | End 157 | Begin VB.Label Label4 158 | Caption = "Active key:" 159 | Height = 255 160 | Left = 240 161 | TabIndex = 8 162 | Top = 1920 163 | Width = 855 164 | End 165 | Begin VB.Label Label3 166 | Caption = "Key:" 167 | Height = 255 168 | Left = 360 169 | TabIndex = 4 170 | Top = 120 171 | Width = 855 172 | End 173 | Begin VB.Label Label2 174 | Caption = "Cipher text:" 175 | Height = 255 176 | Index = 0 177 | Left = 240 178 | TabIndex = 3 179 | Top = 3840 180 | Width = 975 181 | End 182 | Begin VB.Label Label1 183 | Caption = "Plain text:" 184 | Height = 255 185 | Left = 240 186 | TabIndex = 2 187 | Top = 2520 188 | Width = 975 189 | End 190 | End 191 | Attribute VB_Name = "frmBlowfish" 192 | Attribute VB_GlobalNameSpace = False 193 | Attribute VB_Creatable = False 194 | Attribute VB_PredeclaredId = True 195 | Attribute VB_Exposed = False 196 | Option Explicit 197 | Option Base 0 198 | 199 | ' frmBlowfish.frm 200 | 201 | ' Examples of how to use the basic Blowfish functions 202 | ' to set the key, encrypt and decrypt using Blowfish 203 | ' and some of the byte-handling utilities. 204 | 205 | ' This is just a test-bed demo. It is not meant to be 206 | ' represesentative of good security code practices. 207 | 208 | ' Version 6. Published November 2003. Replaced deprecated 209 | ' String functions with Byte versions. 210 | ' Version 5. Published January 2002. Speed improvements 211 | ' and revised byte and word conversion functions. 212 | ' Replaced basByteUtils with basConvert. 213 | ' Thanks to Robert Garofalo and Doug Ward for advice 214 | ' and speed fixes incorporated here. 215 | ' Version 3. Published 20 January 2001. Fixed minor bug - 216 | ' stored ciphertext in a string instead of text box to 217 | ' avoid stripping trailing ascii zeroes. 218 | ' Thanks to Jim McCusker of epotec.com for this bug fix. 219 | ' Version 2. Published 28 December 2000. Added Radix64 fns and 220 | ' option to have alpha or hex key input. 221 | ' Version 1. Published 28 November 2000. 222 | '************************* COPYRIGHT NOTICE************************* 223 | ' This code was originally written in Visual Basic by David Ireland 224 | ' and is copyright (c) 2000-3 D.I. Management Services Pty Limited, 225 | ' all rights reserved. 226 | 227 | ' You are free to use this code as part of your own applications 228 | ' provided you keep this copyright notice intact and acknowledge 229 | ' its authorship with the words: 230 | 231 | ' "Contains cryptography software by David Ireland of 232 | ' DI Management Services Pty Ltd ." 233 | 234 | ' If you use it as part of a web site, please include a link 235 | ' to our site in the form 236 | ' Cryptography 237 | ' Software Code 238 | 239 | ' This code may only be used as part of an application. It may 240 | ' not be reproduced or distributed separately by any means without 241 | ' the express written permission of the author. 242 | 243 | ' David Ireland and DI Management Services Pty Limited make no 244 | ' representations concerning either the merchantability of this 245 | ' software or the suitability of this software for any particular 246 | ' purpose. It is provided "as is" without express or implied 247 | ' warranty of any kind. 248 | 249 | ' Please forward comments or bug reports to . 250 | ' The latest version of this source code can be downloaded from 251 | ' www.di-mgt.com.au/crypto.html. 252 | '****************** END OF COPYRIGHT NOTICE************************* 253 | 254 | 255 | Dim aKey() As Byte 256 | Dim abCipher() As Byte ' Used to store ciphertext 257 | 258 | Private Sub cmdEncrypt_Click() 259 | Dim abPlain() As Byte 260 | abPlain = StrConv(Me.txtPlain, vbFromUnicode) 261 | 262 | abCipher = blf_BytesEnc(abPlain) 263 | 264 | Me.txtCipher = StrConv(abCipher, vbUnicode) 265 | Me.txtCipherHex = cv_HexFromBytes(abCipher) 266 | Me.txtCipher64 = EncodeBytes64(abCipher) 267 | 268 | Me.cmdDecrypt.Enabled = True 269 | End Sub 270 | 271 | Private Sub cmdDecrypt_Click() 272 | Dim abPlain() As Byte 273 | abPlain = blf_BytesDec(abCipher) 274 | Me.txtDecrypt = StrConv(abPlain, vbUnicode) 275 | End Sub 276 | 277 | Private Sub cmdSetKey_Click() 278 | ' Get key bytes from user's string 279 | 280 | ' What format is it in 281 | If Me.optHexKey Then 282 | ' In hex format 283 | aKey() = cv_BytesFromHex(Me.txtKey) 284 | Else 285 | ' User has provided a plain alpha string 286 | aKey() = StrConv(Me.txtKey, vbFromUnicode) 287 | End If 288 | 289 | ' Show key 290 | Me.txtKeyAsString = cv_HexFromBytes(aKey()) 291 | 292 | 'Initialise key 293 | Call blf_KeyInit(aKey) 294 | 295 | ' Allow encrypt 296 | Me.cmdEncrypt.Enabled = True 297 | 298 | ' Put user in plaintext box 299 | Me.txtPlain.SetFocus 300 | 301 | End Sub 302 | 303 | -------------------------------------------------------------------------------- /src/IC_Decompile_Const.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "IC_Decompile_ByteCodeConst" 2 | Option Explicit 3 | Public Const ZEND_NOP as Long = &h00 ' 0 4 | Public Const ZEND_ADD as Long = &h01 ' 1 5 | Public Const ZEND_SUB as Long = &h02 ' 2 6 | Public Const ZEND_MUL as Long = &h03 ' 3 7 | Public Const ZEND_DIV as Long = &h04 ' 4 8 | Public Const ZEND_MOD as Long = &h05 ' 5 9 | Public Const ZEND_SL as Long = &h06 ' 6 10 | Public Const ZEND_SR as Long = &h07 ' 7 11 | Public Const ZEND_CONCAT as Long = &h08 ' 8 12 | Public Const ZEND_BW_OR as Long = &h09 ' 9 13 | Public Const ZEND_BW_AND as Long = &h0A ' 10 14 | Public Const ZEND_BW_XOR as Long = &h0B ' 11 15 | Public Const ZEND_BW_NOT as Long = &h0C ' 12 16 | Public Const ZEND_BOOL_NOT as Long = &h0D ' 13 17 | Public Const ZEND_BOOL_XOR as Long = &h0E ' 14 18 | Public Const ZEND_IS_IDENTICAL as Long = &h0F ' 15 19 | Public Const ZEND_IS_NOT_IDENTICAL as Long = &h10 ' 16 20 | Public Const ZEND_IS_EQUAL as Long = &h11 ' 17 21 | Public Const ZEND_IS_NOT_EQUAL as Long = &h12 ' 18 22 | Public Const ZEND_IS_SMALLER as Long = &h13 ' 19 23 | Public Const ZEND_IS_SMALLER_OR_EQUAL as Long = &h14 ' 20 24 | Public Const ZEND_CAST as Long = &h15 ' 21 25 | Public Const ZEND_QM_ASSIGN as Long = &h16 ' 22 26 | Public Const ZEND_ASSIGN_ADD as Long = &h17 ' 23 27 | Public Const ZEND_ASSIGN_SUB as Long = &h18 ' 24 28 | Public Const ZEND_ASSIGN_MUL as Long = &h19 ' 25 29 | Public Const ZEND_ASSIGN_DIV as Long = &h1A ' 26 30 | Public Const ZEND_ASSIGN_MOD as Long = &h1B ' 27 31 | Public Const ZEND_ASSIGN_SL as Long = &h1C ' 28 32 | Public Const ZEND_ASSIGN_SR as Long = &h1D ' 29 33 | Public Const ZEND_ASSIGN_CONCAT as Long = &h1E ' 30 34 | Public Const ZEND_ASSIGN_BW_OR as Long = &h1F ' 31 35 | Public Const ZEND_ASSIGN_BW_AND as Long = &h20 ' 32 36 | Public Const ZEND_ASSIGN_BW_XOR as Long = &h21 ' 33 37 | Public Const ZEND_PRE_INC as Long = &h22 ' 34 38 | Public Const ZEND_PRE_DEC as Long = &h23 ' 35 39 | Public Const ZEND_POST_INC as Long = &h24 ' 36 40 | Public Const ZEND_POST_DEC as Long = &h25 ' 37 41 | Public Const ZEND_ASSIGN as Long = &h26 ' 38 42 | Public Const ZEND_ASSIGN_REF as Long = &h27 ' 39 43 | Public Const ZEND_ECHO as Long = &h28 ' 40 44 | Public Const ZEND_PRINT as Long = &h29 ' 41 45 | Public Const ZEND_JMP as Long = &h2A ' 42 46 | Public Const ZEND_JMPZ as Long = &h2B ' 43 47 | Public Const ZEND_JMPNZ as Long = &h2C ' 44 48 | Public Const ZEND_JMPZNZ as Long = &h2D ' 45 49 | Public Const ZEND_JMPZ_EX as Long = &h2E ' 46 50 | Public Const ZEND_JMPNZ_EX as Long = &h2F ' 47 51 | Public Const ZEND_CASE as Long = &h30 ' 48 52 | Public Const ZEND_SWITCH_FREE as Long = &h31 ' 49 53 | Public Const ZEND_BRK as Long = &h32 ' 50 54 | Public Const ZEND_CONT as Long = &h33 ' 51 55 | Public Const ZEND_BOOL as Long = &h34 ' 52 56 | Public Const ZEND_INIT_STRING as Long = &h35 ' 53 57 | Public Const ZEND_ADD_CHAR as Long = &h36 ' 54 58 | Public Const ZEND_ADD_STRING as Long = &h37 ' 55 59 | Public Const ZEND_ADD_VAR as Long = &h38 ' 56 60 | Public Const ZEND_BEGIN_SILENCE as Long = &h39 ' 57 61 | Public Const ZEND_END_SILENCE as Long = &h3A ' 58 62 | Public Const ZEND_INIT_FCALL_BY_NAME as Long = &h3B ' 59 63 | Public Const ZEND_DO_FCALL as Long = &h3C ' 60 64 | Public Const ZEND_DO_FCALL_BY_NAME as Long = &h3D ' 61 65 | Public Const ZEND_RETURN as Long = &h3E ' 62 66 | Public Const ZEND_RECV as Long = &h3F ' 63 67 | Public Const ZEND_RECV_INIT as Long = &h40 ' 64 68 | Public Const ZEND_SEND_VAL as Long = &h41 ' 65 69 | Public Const ZEND_SEND_VAR as Long = &h42 ' 66 70 | Public Const ZEND_SEND_REF as Long = &h43 ' 67 71 | Public Const ZEND_NEW as Long = &h44 ' 68 72 | Public Const ZEND_JMP_NO_CTOR as Long = &h45 ' 69 73 | Public Const ZEND_FREE as Long = &h46 ' 70 74 | Public Const ZEND_INIT_ARRAY as Long = &h47 ' 71 75 | Public Const ZEND_ADD_ARRAY_ELEMENT as Long = &h48 ' 72 76 | Public Const ZEND_INCLUDE_OR_EVAL as Long = &h49 ' 73 77 | Public Const ZEND_UNSET_VAR as Long = &h4A ' 74 78 | Public Const ZEND_UNSET_DIM as Long = &h4B ' 75 79 | Public Const ZEND_UNSET_OBJ as Long = &h4C ' 76 80 | Public Const ZEND_FE_RESET as Long = &h4D ' 77 81 | Public Const ZEND_FE_FETCH as Long = &h4E ' 78 82 | Public Const ZEND_EXIT as Long = &h4F ' 79 83 | Public Const ZEND_FETCH_R as Long = &h50 ' 80 84 | Public Const ZEND_FETCH_DIM_R as Long = &h51 ' 81 85 | Public Const ZEND_FETCH_OBJ_R as Long = &h52 ' 82 86 | Public Const ZEND_FETCH_W as Long = &h53 ' 83 87 | Public Const ZEND_FETCH_DIM_W as Long = &h54 ' 84 88 | Public Const ZEND_FETCH_OBJ_W as Long = &h55 ' 85 89 | Public Const ZEND_FETCH_RW as Long = &h56 ' 86 90 | Public Const ZEND_FETCH_DIM_RW as Long = &h57 ' 87 91 | Public Const ZEND_FETCH_OBJ_RW as Long = &h58 ' 88 92 | Public Const ZEND_FETCH_IS as Long = &h59 ' 89 93 | Public Const ZEND_FETCH_DIM_IS as Long = &h5A ' 90 94 | Public Const ZEND_FETCH_OBJ_IS as Long = &h5B ' 91 95 | Public Const ZEND_FETCH_FUNC_ARG as Long = &h5C ' 92 96 | Public Const ZEND_FETCH_DIM_FUNC_ARG as Long = &h5D ' 93 97 | Public Const ZEND_FETCH_OBJ_FUNC_ARG as Long = &h5E ' 94 98 | Public Const ZEND_FETCH_UNSET as Long = &h5F ' 95 99 | Public Const ZEND_FETCH_DIM_UNSET as Long = &h60 ' 96 100 | Public Const ZEND_FETCH_OBJ_UNSET as Long = &h61 ' 97 101 | Public Const ZEND_FETCH_DIM_TMP_VAR as Long = &h62 ' 98 102 | Public Const ZEND_FETCH_CONSTANT as Long = &h63 ' 99 103 | Public Const ZEND_DECLARE_FUNCTION_OR_CLASS as Long = &h64 ' 100 104 | Public Const ZEND_EXT_STMT as Long = &h65 ' 101 105 | Public Const ZEND_EXT_FCALL_BEGIN as Long = &h66 ' 102 106 | Public Const ZEND_EXT_FCALL_END as Long = &h67 ' 103 107 | Public Const ZEND_EXT_NOP as Long = &h68 ' 104 108 | Public Const ZEND_TICKS as Long = &h69 ' 105 109 | Public Const ZEND_SEND_VAR_NO_REF as Long = &h6A ' 106 110 | Public Const ZEND_CATCH as Long = &h6B ' 107 111 | Public Const ZEND_THROW as Long = &h6C ' 108 112 | Public Const ZEND_FETCH_CLASS as Long = &h6D ' 109 113 | Public Const ZEND_CLONE as Long = &h6E ' 110 114 | Public Const ZEND_INIT_CTOR_CALL as Long = &h6F ' 111 115 | Public Const ZEND_INIT_METHOD_CALL as Long = &h70 ' 112 116 | Public Const ZEND_INIT_STATIC_METHOD_CALL as Long = &h71 ' 113 117 | Public Const ZEND_ISSET_ISEMPTY_VAR as Long = &h72 ' 114 118 | Public Const ZEND_ISSET_ISEMPTY_DIM_OBJ as Long = &h73 ' 115 119 | Public Const ZEND_IMPORT_FUNCTION as Long = &h74 ' 116 120 | Public Const ZEND_IMPORT_CLASS as Long = &h75 ' 117 121 | Public Const ZEND_IMPORT_CONST as Long = &h76 ' 118 122 | Public Const ZEND_OP_119 as Long = &h77 ' 119 123 | Public Const ZEND_OP_120 as Long = &h78 ' 120 124 | Public Const ZEND_ASSIGN_ADD_OBJ as Long = &h79 ' 121 125 | Public Const ZEND_ASSIGN_SUB_OBJ as Long = &h7A ' 122 126 | Public Const ZEND_ASSIGN_MUL_OBJ as Long = &h7B ' 123 127 | Public Const ZEND_ASSIGN_DIV_OBJ as Long = &h7C ' 124 128 | Public Const ZEND_ASSIGN_MOD_OBJ as Long = &h7D ' 125 129 | Public Const ZEND_ASSIGN_SL_OBJ as Long = &h7E ' 126 130 | Public Const ZEND_ASSIGN_SR_OBJ as Long = &h7F ' 127 131 | Public Const ZEND_ASSIGN_CONCAT_OBJ as Long = &h80 ' 128 132 | Public Const ZEND_ASSIGN_BW_OR_OBJ as Long = &h81 ' 129 133 | Public Const ZEND_ASSIGN_BW_AND_OBJ as Long = &h82 ' 130 134 | Public Const ZEND_ASSIGN_BW_XOR_OBJ as Long = &h83 ' 131 135 | Public Const ZEND_PRE_INC_OBJ as Long = &h84 ' 132 136 | Public Const ZEND_PRE_DEC_OBJ as Long = &h85 ' 133 137 | Public Const ZEND_POST_INC_OBJ as Long = &h86 ' 134 138 | Public Const ZEND_POST_DEC_OBJ as Long = &h87 ' 135 139 | Public Const ZEND_ASSIGN_OBJ as Long = &h88 ' 136 140 | Public Const ZEND_OP_DATA as Long = &h89 ' 137 141 | Public Const ZEND_INSTANCEOF as Long = &h8A ' 138 142 | Public Const ZEND_DECLARE_CLASS as Long = &h8B ' 139 143 | Public Const ZEND_DECLARE_INHERITED_CLASS as Long = &h8C ' 140 144 | Public Const ZEND_DECLARE_FUNCTION as Long = &h8D ' 141 145 | Public Const ZEND_RAISE_ABSTRACT_ERROR as Long = &h8E ' 142 146 | Public Const ZEND_START_NAMESPACE as Long = &h8F ' 143 147 | Public Const ZEND_ADD_INTERFACE as Long = &h90 ' 144 148 | Public Const ZEND_VERIFY_INSTANCEOF as Long = &h91 ' 145 149 | Public Const ZEND_VERIFY_ABSTRACT_CLASS as Long = &h92 ' 146 150 | Public Const ZEND_ASSIGN_DIM as Long = &h93 ' 147 151 | Public Const ZEND_ISSET_ISEMPTY_PROP_OBJ as Long = &h94 ' 148 152 | Public Const ZEND_HANDLE_EXCEPTION as Long = &h95 ' 149 153 | Public Const ZEND_USER_OPCODE as Long = &h96 ' 150 154 | Public Const ZEND_U_NORMALIZE as Long = &h97 ' 151 155 | Public Const ZEND_JMP_SET as Long = &h98 ' 152 156 | Public Const ZEND_DECLARE_LAMBDA_FUNCTION as Long = &h99 ' 153 157 | 158 | -------------------------------------------------------------------------------- /src/MersenneTwister.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "MersenneTwister" 2 | 'http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/BASIC/visualbasicMT.txt 3 | ' 4 | ' Visual Basic Mersenne-Twister 5 | ' Author: Carmine Arturo Sangiovanni 6 | ' carmine @ daygo.com.br 7 | ' 8 | ' Aug 13,2004 9 | ' 10 | ' based on C++ code 11 | ' 12 | 13 | 14 | 15 | Option Explicit 16 | 17 | Const N = 624 18 | Const M = 397 19 | 20 | Global mt(0 To N) As Currency 21 | Global mti As Currency 22 | 23 | Dim MATRIX_A As Currency 24 | Dim UPPER_MASK As Currency 25 | Dim LOWER_MASK As Currency 26 | Dim FULL_MASK As Currency 27 | Dim TEMPERING_MASK_B As Currency 28 | Dim TEMPERING_MASK_C As Currency 29 | 30 | Function tempering_shift_u(ty As Currency) 31 | '>> 11' => 2^11 => 2048 32 | tempering_shift_u = f_and(Int(ty / 2048@), FULL_MASK) 33 | End Function 34 | 35 | Function tempering_shift_s(ty As Currency) 36 | '<< 7 => 2^7 => 128 37 | tempering_shift_s = and_ffffffff(ty * 128@) 38 | End Function 39 | 40 | Function tempering_shift_t(ty As Currency) 41 | '<< 15 => 2^15 => 32768 42 | tempering_shift_t = and_ffffffff(ty * 32768@) 43 | End Function 44 | 45 | Function tempering_shift_l(ty As Currency) 46 | '>> 18' => 2^18 =>262144 47 | tempering_shift_l = f_and(Int(ty / 262144@), FULL_MASK) 48 | End Function 49 | 50 | Function f_and(p1 As Currency, p2 As Currency) 51 | Dim v As Currency 52 | Dim i As Integer 53 | 54 | 55 | If (p1 < UPPER_MASK) Then 56 | 57 | If (p2 < UPPER_MASK) Then 58 | f_and = p1 And p2 59 | Else 60 | f_and = p1 And (p2 - UPPER_MASK) 61 | End If 62 | 63 | Else 64 | 65 | If (p2 < UPPER_MASK) Then 66 | f_and = (p1 - UPPER_MASK) And p2 67 | Else 68 | f_and = (p1 - UPPER_MASK) And (p2 - UPPER_MASK) 69 | f_and = f_and + UPPER_MASK 70 | End If 71 | End If 72 | End Function 73 | 74 | Function f_or(p1 As Currency, p2 As Currency) 75 | Dim v As Currency 76 | Dim i As Integer 77 | Dim f As Boolean 78 | 79 | 80 | If (p1 < UPPER_MASK) Then 81 | 82 | If (p2 < UPPER_MASK) Then 83 | f_or = p1 Or p2 84 | Else 85 | f_or = p1 Or (p2 - UPPER_MASK) 86 | f_or = f_or + UPPER_MASK 87 | End If 88 | 89 | Else 90 | 91 | If (p2 < UPPER_MASK) Then 92 | f_or = (p1 - UPPER_MASK) Or p2 93 | f_or = f_or + UPPER_MASK 94 | Else 95 | f_or = (p1 - UPPER_MASK) Or (p2 - UPPER_MASK) 96 | f_or = f_or + UPPER_MASK 97 | 98 | End If 99 | 100 | End If 101 | End Function 102 | 103 | Function LongUnSignedToCurrency(value As Currency) As Currency 104 | If value < 0 Then 105 | Const Val_0x100000000 = 4294967296# 106 | LongUnSignedToCurrency = value + Val_0x100000000 107 | End If 108 | End Function 109 | 110 | 111 | Function f_xor(p1 As Currency, p2 As Currency) 112 | Dim v As Currency 113 | Dim i As Integer 114 | 115 | If (p1 < UPPER_MASK) Then 116 | 117 | If (p2 < UPPER_MASK) Then 118 | f_xor = p1 Xor p2 119 | Else 120 | f_xor = p1 Xor (p2 - UPPER_MASK) 121 | f_xor = f_xor + UPPER_MASK 122 | End If 123 | 124 | Else 125 | 126 | If (p2 < UPPER_MASK) Then 127 | f_xor = (p1 - UPPER_MASK) Xor p2 128 | f_xor = f_xor + UPPER_MASK 129 | Else 130 | f_xor = (p1 - UPPER_MASK) Xor (p2 - UPPER_MASK) 131 | End If 132 | 133 | End If 134 | 135 | 136 | End Function 137 | 138 | 'Bug 3: ByVal required to avoid unwanted sideeffects 139 | Function f_lower(ByVal p1 As Currency) 140 | Do 141 | If p1 < UPPER_MASK Then 142 | f_lower = p1 143 | Exit Do 144 | Else 145 | p1 = p1 - UPPER_MASK 146 | End If 147 | Loop 148 | End Function 149 | 150 | Function f_upper(p1 As Currency) 151 | If p1 > LOWER_MASK Then 152 | f_upper = UPPER_MASK 153 | Else 154 | f_upper = 0 155 | End If 156 | End Function 157 | 158 | Function f_xor3(p1 As Currency, p2 As Currency, p3 As Currency) As Currency 159 | Dim v As Currency 160 | Dim tmp As Currency 161 | Dim i As Integer 162 | Dim f As Integer 163 | 164 | 165 | 166 | If (p1 < UPPER_MASK) Then 167 | 168 | If (p2 < UPPER_MASK) Then 169 | tmp = p1 Xor p2 170 | Else 171 | tmp = p1 Xor (p2 - UPPER_MASK) 172 | tmp = tmp + UPPER_MASK 173 | End If 174 | 175 | Else 176 | 177 | If (p2 < UPPER_MASK) Then 178 | tmp = (p1 - UPPER_MASK) Xor p2 179 | tmp = tmp + UPPER_MASK 180 | Else 181 | tmp = (p1 - UPPER_MASK) Xor (p2 - UPPER_MASK) 182 | End If 183 | 184 | End If 185 | 186 | 187 | 188 | 189 | If (tmp < UPPER_MASK) And (p3 < UPPER_MASK) Then 190 | f_xor3 = tmp Xor p3 191 | End If 192 | If (tmp < UPPER_MASK) And (p3 >= UPPER_MASK) Then 193 | f_xor3 = tmp Xor (p3 - UPPER_MASK) 194 | f_xor3 = f_xor3 + UPPER_MASK 195 | End If 196 | If (tmp >= UPPER_MASK) And (p3 < UPPER_MASK) Then 197 | f_xor3 = (tmp - UPPER_MASK) Xor p3 198 | f_xor3 = f_xor3 + UPPER_MASK 199 | End If 200 | If (tmp >= UPPER_MASK) And (p3 >= UPPER_MASK) Then 201 | f_xor3 = (tmp - UPPER_MASK) Xor (p3 - UPPER_MASK) 202 | End If 203 | 204 | End Function 205 | 206 | Function and_ffffffff(c As Currency) 207 | Dim e As Currency 208 | Dim i As Integer 209 | 'Delete each bit before 32Bit (=>2^15) 210 | i = 32 211 | Do 212 | e = 2 ^ (i + 16) 213 | Do While c >= e 214 | c = c - e 215 | Loop 216 | i = i - 1 217 | Loop While i > 15 218 | 219 | and_ffffffff = c 220 | End Function 221 | 222 | 'Sub random_init(key As Long) 223 | ' Dim seed As Currency 224 | ' If key < 0 Then 225 | ' seed = key + 4294967296# '0x100000000 226 | ' Else 227 | ' seed = key 228 | ' End If 229 | ' 230 | ' 231 | ' mt(0) = and_ffffffff(seed) 232 | ' For mti = 1 To N - 1 233 | ' mt(mti) = and_ffffffff(69069 * mt(mti - 1)) 234 | ' Next mti 235 | 'End Sub 236 | Sub random_init(seed As Long) 237 | 238 | 'int with 16Bit Values 239 | Dim tmp As New StringReader 240 | With tmp 241 | .Data = Space(&H9C0) 242 | 243 | Dim newKey& 244 | newKey = seed 245 | .EOS = False 246 | Do Until .EOS 247 | 248 | ' Dim i 249 | 250 | 'Store HighPart 251 | Dim Key32Bit_HighPart& 252 | Key32Bit_HighPart = shr16(newKey, &H10) 253 | 254 | 'Debug.Print H32(Key32Bit_HighPart), i, H16(i * 2) 255 | 'Debug.Assert i <> 470 * 2 256 | .int16 = Key32Bit_HighPart 257 | 258 | 259 | newKey = MulInt32(newKey, 69069) + 1 260 | 261 | ' Inc i 262 | 263 | Loop 264 | 265 | 266 | 'Write 32Bit Values 267 | .EOS = False 268 | For mti = 0 To N - 1 269 | 270 | Dim L@, h@ 271 | h = .int16 272 | L = .int16 273 | mt(mti) = h * CCur(&H10000) + L 274 | Next mti 275 | 276 | End With 277 | 278 | 279 | 280 | End Sub 281 | 282 | 283 | Function Mersenne_twister_random(Optional BitMask As Long = &HFFFFFFFF, Optional XorKey As Currency = &H0) As Long 284 | 285 | ' XorKey = LongUnSignedToCurrency(XorKey) 286 | 287 | 'f_Xor will not come along with negative values 288 | If XorKey < 0 Then 289 | Static alreadyShow As Boolean 290 | If alreadyShow = False Then 291 | log "-> WARNING: Stupid Bug - Mersenne_twister_random() does not come along with a XorKey negative values! Decryption will fail!" 292 | alreadyShow = True 293 | End If 294 | 295 | ' Exit Function 296 | 297 | End If 298 | 299 | Dim kk As Integer 300 | 301 | Dim ty1 As Currency 302 | Dim ty2 As Currency 303 | Dim y As Currency 304 | 305 | Dim mag01(0 To 1) As Currency 306 | 307 | MATRIX_A = 2567483615@ '&H9908b0df 308 | UPPER_MASK = 2147483648@ '&H80000000 309 | LOWER_MASK = 2147483647@ '&H7fffffff 310 | FULL_MASK = LOWER_MASK + UPPER_MASK '&Hffffffff 311 | TEMPERING_MASK_B = 2636928640@ '&H9D2C5680 (<= &HFF3A58AD << 0x7 ) 312 | TEMPERING_MASK_C = 4022730752@ '&HEFC60000 (<= &HFFFFDF8C << 0xF ) 313 | 314 | 315 | mag01(0) = 0@ 316 | mag01(1) = MATRIX_A 317 | 318 | If mti >= N Then 319 | 'Init already called? 320 | If mti = N + 1 Then 321 | random_init 4537 322 | End If 323 | 324 | ' 009F1D80 2616263785 1485109129 1222459022 1470865537 325 | ' 009F1D90 2221574427 34070531 2495128680 3752208502 326 | ' 009F1DA0 3221593492 3182452335 2992174400 1056224458 327 | ' 009F1DB0 736937993 2469744774 1683846344 2704511074 328 | ' 009F1DC0 1318321291 2944046138 2842695760 1475108897 329 | ' 009F1DD0 2302328966 1376761661 3318325827 1612024421 330 | ' 331 | 332 | For kk = 0 To (N - M) - 1 333 | ' Debug.Assert kk <> 73 334 | y = f_or(f_upper(mt(kk)), f_lower(mt(kk + 1))) 335 | '3632592777=D884F789 336 | 337 | mt(kk) = f_xor3(mt(kk + M), Int(y / 2@), mag01(f_and(y, 1))) 338 | 'mt(3)? 473F343F 1195324479 bad 339 | ' 73F343F 121582655 good 340 | 'mt(74)? 1373583696 Good 341 | ' 1372600656 Bad 342 | 343 | 344 | Next kk 345 | 346 | For kk = kk To (N - 1) - 1 347 | y = f_or(f_upper(mt(kk)), f_lower(mt(kk + 1))) 348 | 349 | mt(kk) = f_xor3(mt(kk + (M - N)), Int(y / 2@), mag01(f_and(y, 1))) 350 | Next kk 351 | 352 | y = f_or(f_upper(mt(N - 1)), f_lower(mt(0))) 353 | 354 | mt(N - 1) = f_xor3(mt(M - 1), Int(y / 2@), mag01(f_and(y, 1))) 355 | mti = 0 356 | End If 357 | 358 | '--------------------------------------------------- 359 | y = mt(mti): mti = mti + 1 360 | 361 | '--------------------------------------------------- 362 | ' 363 | ' IONCUBE Specific added line! 364 | y = f_xor(y, XorKey) 365 | 'y 8B3D956F -1958898321 366 | 'XorKey 3555331 367 | '-1834523451 368 | 369 | 370 | y = f_xor(y, tempering_shift_u(y)) 371 | 372 | ty1 = f_and(tempering_shift_s(y), TEMPERING_MASK_B) 373 | y = f_xor(y, ty1) 374 | 375 | ty1 = f_and(tempering_shift_t(y), TEMPERING_MASK_C) 376 | y = f_xor(y, ty1) 377 | 378 | y = f_xor(y, tempering_shift_l(y)) 379 | 380 | '--------------------------------------------------- 381 | 382 | 'Convert to long 383 | If y >= UPPER_MASK Then 384 | Mersenne_twister_random = -(4294967296@ - y) '(2 * UPPER_MASK) - y 385 | Else 386 | Mersenne_twister_random = y 387 | End If 388 | 389 | 'Apply Bitmask 390 | Mersenne_twister_random = Mersenne_twister_random And BitMask 391 | 392 | End Function 393 | 394 | -------------------------------------------------------------------------------- /src/Blowfish/basBlowfishByteFns.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basBlowfishByteFns" 2 | Option Explicit 3 | Option Base 0 4 | 5 | ' basBlowfishByteFns: Wrapper functions to call Blowfish algorithms 6 | 7 | ' Version 6. November 2003. Added this module with new Byte functions 8 | ' Blowfish in Visual Basic first published October 2000. 9 | '************************* COPYRIGHT NOTICE************************* 10 | ' This code was originally written in Visual Basic by David Ireland 11 | ' and is copyright (c) 2000-3 D.I. Management Services Pty Limited, 12 | ' all rights reserved. 13 | 14 | ' You are free to use this code as part of your own applications 15 | ' provided you keep this copyright notice intact and acknowledge 16 | ' its authorship with the words: 17 | 18 | ' "Contains cryptography software by David Ireland of 19 | ' DI Management Services Pty Ltd ." 20 | 21 | ' If you use it as part of a web site, please include a link 22 | ' to our site in the form 23 | ' Cryptography 24 | ' Software Code 25 | 26 | ' This code may only be used as part of an application. It may 27 | ' not be reproduced or distributed separately by any means without 28 | ' the express written permission of the author. 29 | 30 | ' David Ireland and DI Management Services Pty Limited make no 31 | ' representations concerning either the merchantability of this 32 | ' software or the suitability of this software for any particular 33 | ' purpose. It is provided "as is" without express or implied 34 | ' warranty of any kind. 35 | 36 | ' Please forward comments or bug reports to . 37 | ' The latest version of this source code can be downloaded from 38 | ' www.di-mgt.com.au/crypto.html. 39 | '****************** END OF COPYRIGHT NOTICE************************* 40 | 41 | ' The functions in this module are: 42 | ' blf_BytesRaw(abData, bEncrypt): En/Deciphers bytes abData without padding 43 | ' blf_BytesEnc(abData): Pads and enciphers byte array abData with current key 44 | ' blf_BytesDec(abData): Deciphers byte array abData with current key and unpads 45 | ' PadBytes(abData): Pads byte array to next multiple of 8 bytes 46 | ' UnpadBytes(abData): Removes padding after decryption 47 | ' blf_BytesEncRawCBC(abData, abInitV): Encrypts abData in CBC mode 48 | ' blf_BytesEncCBC(abData, abInitV): Pads and encrypts abData in CBC mode 49 | ' blf_BytesDecRawCBC(abData, abInitV): Decrypts abData in CBC mode 50 | ' blf_BytesDecCBC(abData, abInitV): Decrypts abData in CBC mode and unpads 51 | 52 | ' To set current key, call blf_KeyInit(aKey()) 53 | ' where aKey() is the key as an array of Bytes 54 | 55 | ' NB The functions in this module deal with data of any length, but 56 | ' if you only want to deal with an 8-byte block, use 57 | ' blf_EncryptBytes() and blf_DecryptBytes() in module basBlowfish 58 | 59 | ' Use faster API call to copy bytes 60 | Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ 61 | (ByVal lpDestination As Any, ByVal lpSource As Any, ByVal Length As Long) 62 | 63 | Public Function blf_BytesRaw(abData() As Byte, bEncrypt As Boolean) As Variant 64 | ' New function added version 6. 65 | ' Encrypts or decrypts byte array abData without padding using to current key. 66 | ' Similar to blf_BytesEnc and blf_BytesDec, but does not add padding 67 | ' and ignores trailing odd bytes. 68 | ' ECB mode - each block is en/decrypted independently 69 | Dim nLen As Long 70 | Dim nBlocks As Long 71 | Dim iBlock As Long 72 | Dim j As Long 73 | Dim abOutput() As Byte 74 | Dim abBlock(7) As Byte 75 | Dim iIndex As Long 76 | 77 | ' Calc number of 8-byte blocks (ignore odd trailing bytes) 78 | nLen = UBound(abData) - LBound(abData) + 1 79 | nBlocks = nLen \ 8 80 | 81 | ReDim abOutput(nBlocks * 8 - 1) 82 | 83 | ' Work through in blocks of 8 bytes 84 | iIndex = 0 85 | For iBlock = 1 To nBlocks 86 | ' Get the next block of 8 bytes 87 | CopyMemory VarPtr(abBlock(0)), VarPtr(abData(iIndex)), 8& 88 | 89 | ' En/Decrypt the block according to flag 90 | If bEncrypt Then 91 | Call blf_EncryptBytes(abBlock()) 92 | Else 93 | Call blf_DecryptBytes(abBlock()) 94 | End If 95 | 96 | ' Copy to output string 97 | CopyMemory VarPtr(abOutput(iIndex)), VarPtr(abBlock(0)), 8& 98 | 99 | iIndex = iIndex + 8 100 | Next 101 | 102 | blf_BytesRaw = abOutput 103 | 104 | End Function 105 | 106 | Public Function blf_BytesEnc(abData() As Byte) As Variant 107 | ' Encrypts byte array abData after adding PKCS#5/RFC2630/RFC3370 padding 108 | ' NB always adds padding - use blf_BytesRaw() if you don't want padding 109 | ' ECB mode 110 | ' Returns encrypted byte array as a variant. 111 | ' Requires key and boxes to be already set up. 112 | ' New in Version 6. 113 | 114 | Dim abOutput() As Byte 115 | 116 | abOutput = PadBytes(abData) 117 | abOutput = blf_BytesRaw(abOutput, True) 118 | 119 | blf_BytesEnc = abOutput 120 | End Function 121 | 122 | Public Function blf_BytesDec(abData() As Byte) As Variant 123 | ' Decrypts byte array abData assuming PKCS#5/RFC2630/RFC3370 padding and ECB mode 124 | ' NB always removes valid padding - use blf_BytesRaw() if you don't want padding 125 | ' Returns encrypted byte array as a variant. 126 | ' Requires key and boxes to be already set up. 127 | ' New in Version 6. 128 | 129 | Dim abOutput() As Byte 130 | 131 | abOutput = blf_BytesRaw(abData, False) 132 | abOutput = UnpadBytes(abOutput) 133 | 134 | blf_BytesDec = abOutput 135 | End Function 136 | 137 | Public Function PadBytes(abData() As Byte) As Variant 138 | ' Pad data bytes to next multiple of 8 bytes as per PKCS#5/RFC2630/RFC3370 139 | Dim nLen As Long 140 | Dim nPad As Integer 141 | Dim abPadded() As Byte 142 | Dim i As Long 143 | 144 | 'Set up error handler for empty array 145 | On Error GoTo ArrayIsEmpty 146 | 147 | nLen = UBound(abData) - LBound(abData) + 1 148 | nPad = ((nLen \ 8) + 1) * 8 - nLen 149 | 150 | ReDim abPadded(nLen + nPad - 1) ' Pad with # of pads (1-8) 151 | If nLen > 0 Then 152 | CopyMemory VarPtr(abPadded(0)), VarPtr(abData(0)), nLen 153 | End If 154 | For i = nLen To nLen + nPad - 1 155 | abPadded(i) = CByte(nPad) 156 | Next 157 | 158 | ArrayIsEmpty: 159 | PadBytes = abPadded 160 | 161 | End Function 162 | 163 | Public Function UnpadBytes(abData() As Byte) As Variant 164 | ' Strip PKCS#5/RFC2630/RFC3370-style padding 165 | Dim nLen As Long 166 | Dim nPad As Long 167 | Dim abUnpadded() As Byte 168 | Dim i As Long 169 | 170 | 'Set up error handler for empty array 171 | On Error GoTo ArrayIsEmpty 172 | 173 | nLen = UBound(abData) - LBound(abData) + 1 174 | If nLen = 0 Then GoTo ArrayIsEmpty 175 | ' Get # of padding bytes from last char 176 | nPad = abData(nLen - 1) 177 | If nPad > 8 Then nPad = 0 ' In case invalid 178 | If nLen - nPad > 0 Then 179 | ReDim abUnpadded(nLen - nPad - 1) 180 | CopyMemory VarPtr(abUnpadded(0)), VarPtr(abData(0)), nLen - nPad 181 | End If 182 | 183 | ArrayIsEmpty: 184 | UnpadBytes = abUnpadded 185 | 186 | End Function 187 | 188 | Public Function TestPadBytes() 189 | Dim abData() As Byte 190 | 191 | abData = StrConv("abc", vbFromUnicode) 192 | abData = PadBytes(abData) 193 | Stop 194 | abData = UnpadBytes(abData) 195 | Stop 196 | 197 | End Function 198 | 199 | Private Sub bXorBytes(aByt1() As Byte, aByt2() As Byte, nBytes As Long) 200 | ' XOR's bytes in array aByt1 with array aByt2 201 | ' Returns results in aByt1 202 | ' i.e. aByt1() = aByt1() XOR aByt2() 203 | Dim i As Long 204 | For i = 0 To nBytes - 1 205 | aByt1(i) = aByt1(i) Xor aByt2(i) 206 | Next 207 | End Sub 208 | 209 | Public Function blf_BytesEncRawCBC(abData() As Byte, abInitV() As Byte) As Variant 210 | ' Encrypts byte array in CBC mode 211 | ' using byte array as initialisation vector. 212 | ' Returns ciphertext as variant array of bytes. 213 | ' Requires key and boxes to be already set up. 214 | ' New in Version 6. 215 | Dim nLen As Long 216 | Dim nBlocks As Long 217 | Dim iBlock As Long 218 | Dim abBlock(7) As Byte 219 | Dim iIndex As Long 220 | Dim abReg(7) As Byte ' Feedback register 221 | Dim abOutput() As Byte 222 | 223 | ' Initialisation vector should be a 8-byte array 224 | ' so ReDim just to make sure 225 | ' This will add zero bytes if too short or chop off any extra 226 | ReDim Preserve abInitV(7) 227 | 228 | ' Calc number of 8-byte blocks 229 | nLen = UBound(abData) - LBound(abData) + 1 230 | nBlocks = nLen \ 8 231 | 232 | ' Dimension output 233 | ReDim abOutput(nBlocks * 8 - 1) 234 | 235 | ' C_0 = IV 236 | CopyMemory VarPtr(abReg(0)), VarPtr(abInitV(0)), 8& 237 | 238 | ' Work through string in blocks of 8 bytes 239 | iIndex = 0 240 | For iBlock = 1 To nBlocks 241 | ' Fetch next block from input 242 | CopyMemory VarPtr(abBlock(0)), VarPtr(abData(iIndex)), 8& 243 | 244 | 245 | ' XOR with feedback register = Pi XOR C_i-1 246 | Call bXorBytes(abBlock, abReg, 8) 247 | 248 | ' Encrypt the block Ci = Ek(Pi XOR C_i-1) 249 | Call blf_EncryptBytes(abBlock()) 250 | 251 | 252 | ' Store in feedback register Reg = Ci 253 | CopyMemory VarPtr(abReg(0)), VarPtr(abBlock(0)), 8& 254 | 255 | ' Copy to output string 256 | CopyMemory VarPtr(abOutput(iIndex)), VarPtr(abBlock(0)), 8& 257 | 258 | iIndex = iIndex + 8 259 | Next 260 | 261 | blf_BytesEncRawCBC = abOutput 262 | 263 | End Function 264 | 265 | Public Function blf_BytesDecRawCBC(abData() As Byte, abInitV() As Byte) As Variant 266 | ' Decrypts byte array in CBC mode 267 | ' using byte array as initialisation vector. 268 | ' Returns plaintext as variant array of bytes. 269 | ' Requires key and boxes to be already set up. 270 | ' New in Version 6. 271 | ' Dim strIn As String 272 | ' Dim strOut As String 273 | 274 | Dim nLen As Long 275 | Dim nBlocks As Long 276 | Dim iBlock As Long 277 | Dim abBlock(7) As Byte 278 | Dim iIndex As Long 279 | Dim abReg(7) As Byte ' Feedback register 280 | Dim abStore(7) As Byte 281 | Dim abOutput() As Byte 282 | 283 | ' Initialisation vector should be a 8-byte array 284 | ' so ReDim just to make sure 285 | ' This will add zero bytes if too short or chop off any extra 286 | ReDim Preserve abInitV(7) 287 | 288 | ' Calc number of 8-byte blocks 289 | nLen = UBound(abData) - LBound(abData) + 1 290 | nBlocks = nLen \ 8 291 | 292 | ' Dimension output 293 | ReDim abOutput(nBlocks * 8 - 1) 294 | 295 | ' C_0 = IV 296 | CopyMemory VarPtr(abReg(0)), VarPtr(abInitV(0)), 8& 297 | 298 | ' Work through string in blocks of 8 bytes 299 | iIndex = 0 300 | For iBlock = 1 To nBlocks 301 | ' Fetch next block from input 302 | CopyMemory VarPtr(abBlock(0)), VarPtr(abData(iIndex)), 8& 303 | 304 | 305 | ' Save C_i-1 306 | CopyMemory VarPtr(abStore(0)), VarPtr(abBlock(0)), 8& 307 | 308 | ' Decrypt the block Dk(Ci) 309 | Call blf_DecryptBytes(abBlock()) 310 | 311 | ' XOR with feedback register = C_i-1 XOR Dk(Ci) 312 | Call bXorBytes(abBlock, abReg, 8) 313 | 314 | 315 | ' Store in feedback register Reg = C_i-1 316 | CopyMemory VarPtr(abReg(0)), VarPtr(abStore(0)), 8& 317 | 318 | ' Copy to output string 319 | CopyMemory VarPtr(abOutput(iIndex)), VarPtr(abBlock(0)), 8& 320 | 321 | iIndex = iIndex + 8 322 | Next 323 | 324 | blf_BytesDecRawCBC = abOutput 325 | 326 | End Function 327 | 328 | Public Function blf_BytesEncCBC(abData() As Byte, abInitV() As Byte) As Variant 329 | ' Encrypts byte array abData after adding PKCS#5/RFC2630/RFC3370 padding 330 | ' NB always adds padding - use blf_BytesEncRawCBC() if you don't want padding 331 | ' CBC mode 332 | ' Returns encrypted byte array as a variant. 333 | ' Requires key and boxes to be already set up. 334 | ' New in Version 6. 335 | 336 | Dim abOutput() As Byte 337 | 338 | abOutput = PadBytes(abData) 339 | abOutput = blf_BytesEncRawCBC(abOutput, abInitV) 340 | 341 | blf_BytesEncCBC = abOutput 342 | End Function 343 | 344 | Public Function blf_BytesDecCBC(abData() As Byte, abInitV() As Byte) As Variant 345 | ' Decrypts byte array abData assuming PKCS#5/RFC2630/RFC3370 padding and CBC mode 346 | ' NB always removes valid padding - use blf_BytesDecRawCBC() if you don't want padding 347 | ' Returns encrypted byte array as a variant. 348 | ' Requires key and boxes to be already set up. 349 | ' New in Version 6. 350 | 351 | Dim abOutput() As Byte 352 | 353 | abOutput = blf_BytesDecRawCBC(abData, abInitV) 354 | abOutput = UnpadBytes(abOutput) 355 | 356 | blf_BytesDecCBC = abOutput 357 | End Function 358 | 359 | 360 | 361 | -------------------------------------------------------------------------------- /src/Blowfish/basRadix64.bas: -------------------------------------------------------------------------------- 1 | Attribute VB_Name = "basRadix64" 2 | Option Explicit 3 | Option Base 0 4 | 5 | ' basRadix64: Radix 64 en/decoding functions 6 | ' Version 6. 20 November 2003. Added error handling for empty arrays. 7 | ' Version 5. 10 August 2003. Added EncodeBytes64() and DecodeBytes64() 8 | ' functions that "do it properly" using a Byte array for 9 | ' binary data and a String for textual data. 10 | ' Version 4. 17 August 2002 re-write even faster using Byte arrays 11 | ' and StrConv function. Thanks to Chris Thompson for this 12 | ' and for other much appreciated advice incorporated here. 13 | ' Version 3.1: 13 August 2002 mod to DecodeStr64 function 14 | ' to cope with invalid characters. 15 | ' Thanks to Seth Perelman for this. 16 | ' Version 3. Published January 2002 with even faster SHR/SHL functions 17 | ' and using Mid$ function instead of appending to strings. 18 | ' Version 2. Published 12 May 2001 19 | ' Version 1. Published 28 December 2000 20 | '************************* COPYRIGHT NOTICE************************* 21 | ' This code was originally written in Visual Basic by David Ireland 22 | ' and is copyright (c) 2000-3 D.I. Management Services Pty Limited, 23 | ' all rights reserved. 24 | 25 | ' You are free to use this code as part of your own applications 26 | ' provided you keep this copyright notice intact and acknowledge 27 | ' its authorship with the words: 28 | 29 | ' "Contains cryptography software by David Ireland of 30 | ' DI Management Services Pty Ltd ." 31 | 32 | ' This code may only be used as part of an application. It may 33 | ' not be reproduced or distributed separately by any means without 34 | ' the express written permission of the author. 35 | 36 | ' David Ireland and DI Management Services Pty Limited make no 37 | ' representations concerning either the merchantability of this 38 | ' software or the suitability of this software for any particular 39 | ' purpose. It is provided "as is" without express or implied 40 | ' warranty of any kind. 41 | 42 | ' Please forward comments or bug reports to . 43 | ' The latest version of this source code can be downloaded from 44 | ' www.di-mgt.com.au/crypto.html. 45 | 46 | ' Credit where credit is due: 47 | ' Some parts of this VB code are based on original C code 48 | ' by Carl M. Ellison. See "cod64.c" published 1995. 49 | '****************** END OF COPYRIGHT NOTICE************************* 50 | 51 | Private aDecTab(255) As Integer 52 | Private aEncTab(63) As Byte 53 | 54 | Public Function EncodeBytes64(abBytes() As Byte) As String 55 | ' Return base64 encoding of Byte array. 56 | ' Does not insert CRLFs. Just returns one long string, 57 | ' so it's up to the user to add line breaks or other formatting. 58 | Dim sOutput As String 59 | Dim abOutput() As Byte 60 | Dim sLast As String 61 | Dim b(3) As Byte 62 | Dim j As Integer 63 | Dim i As Long, nLen As Long, nQuants As Long 64 | Dim iIndex As Long 65 | 66 | 'Set up error handler to catch empty array 67 | On Error GoTo ArrayIsEmpty 68 | nLen = UBound(abBytes) - LBound(abBytes) + 1 69 | nQuants = nLen \ 3 70 | iIndex = 0 71 | Call MakeEncTab 72 | If (nQuants > 0) Then 73 | ReDim abOutput(nQuants * 4 - 1) 74 | ' Now start reading in 3 bytes at a time 75 | For i = 0 To nQuants - 1 76 | For j = 0 To 2 77 | b(j) = abBytes((i * 3) + j) 78 | Next 79 | Call EncodeQuantumB(b) 80 | abOutput(iIndex) = b(0) 81 | abOutput(iIndex + 1) = b(1) 82 | abOutput(iIndex + 2) = b(2) 83 | abOutput(iIndex + 3) = b(3) 84 | iIndex = iIndex + 4 85 | Next 86 | sOutput = StrConv(abOutput, vbUnicode) 87 | End If 88 | 89 | ' Cope with odd bytes 90 | ' (no real performance hit by using strings here) 91 | Select Case nLen Mod 3 92 | Case 0 93 | sLast = "" 94 | Case 1 95 | b(0) = abBytes(nLen - 1) 96 | b(1) = 0 97 | b(2) = 0 98 | Call EncodeQuantumB(b) 99 | sLast = StrConv(b(), vbUnicode) 100 | ' Replace last 2 with = 101 | sLast = Left(sLast, 2) & "==" 102 | Case 2 103 | b(0) = abBytes(nLen - 2) 104 | b(1) = abBytes(nLen - 1) 105 | b(2) = 0 106 | Call EncodeQuantumB(b) 107 | sLast = StrConv(b(), vbUnicode) 108 | ' Replace last with = 109 | sLast = Left(sLast, 3) & "=" 110 | End Select 111 | 112 | EncodeBytes64 = sOutput & sLast 113 | 114 | ArrayIsEmpty: 115 | 116 | End Function 117 | 118 | Public Function DecodeBytes64(sEncoded As String) As Variant 119 | ' Return Byte array of decoded binary values given base64 string 120 | ' Ignores any chars not in the 64-char subset 121 | Dim abDecoded() As Byte 122 | Dim d(3) As Byte 123 | Dim C As Integer ' NB Integer to catch -1 value 124 | Dim di As Integer 125 | Dim i As Long 126 | Dim nLen As Long 127 | Dim iIndex As Long 128 | 129 | nLen = Len(sEncoded) 130 | If nLen < 4 Then 131 | ' Return an empty array 132 | DecodeBytes64 = abDecoded 133 | Exit Function 134 | End If 135 | ReDim abDecoded(((nLen \ 4) * 3) - 1) 136 | 137 | iIndex = 0 138 | di = 0 139 | Call MakeDecTab 140 | ' Read in each char in turn 141 | For i = 1 To Len(sEncoded) 142 | C = CByte(Asc(Mid(sEncoded, i, 1))) 143 | C = aDecTab(C) 144 | If C >= 0 Then 145 | d(di) = CByte(C) 146 | di = di + 1 147 | If di = 4 Then 148 | abDecoded(iIndex) = SHL2(d(0)) Or (SHR4(d(1)) And &H3) 149 | iIndex = iIndex + 1 150 | abDecoded(iIndex) = SHL4(d(1) And &HF) Or (SHR2(d(2)) And &HF) 151 | iIndex = iIndex + 1 152 | abDecoded(iIndex) = SHL6(d(2) And &H3) Or d(3) 153 | iIndex = iIndex + 1 154 | If d(3) = 64 Then 155 | iIndex = iIndex - 1 156 | abDecoded(iIndex) = 0 157 | End If 158 | If d(2) = 64 Then 159 | iIndex = iIndex - 1 160 | abDecoded(iIndex) = 0 161 | End If 162 | di = 0 163 | End If 164 | End If 165 | Next i 166 | ' Trim to correct length 167 | ReDim Preserve abDecoded(iIndex - 1) 168 | DecodeBytes64 = abDecoded 169 | End Function 170 | 171 | Public Function EncodeStr64(sInput As String) As String 172 | ' Return radix64 encoding of string of binary values 173 | ' Does not insert CRLFs. Just returns one long string, 174 | ' so it's up to the user to add line breaks or other formatting. 175 | ' Version 4: Use Byte array and StrConv - much faster 176 | Dim abOutput() As Byte ' Version 4: now a Byte array 177 | Dim sLast As String 178 | Dim b(3) As Byte ' Version 4: Now 3 not 2 179 | Dim j As Integer 180 | Dim i As Long, nLen As Long, nQuants As Long 181 | Dim iIndex As Long 182 | 183 | EncodeStr64 = "" 184 | nLen = Len(sInput) 185 | nQuants = nLen \ 3 186 | iIndex = 0 187 | Call MakeEncTab 188 | If (nQuants > 0) Then 189 | ReDim abOutput(nQuants * 4 - 1) 190 | ' Now start reading in 3 bytes at a time 191 | For i = 0 To nQuants - 1 192 | For j = 0 To 2 193 | b(j) = Asc(Mid(sInput, (i * 3) + j + 1, 1)) 194 | Next 195 | Call EncodeQuantumB(b) 196 | abOutput(iIndex) = b(0) 197 | abOutput(iIndex + 1) = b(1) 198 | abOutput(iIndex + 2) = b(2) 199 | abOutput(iIndex + 3) = b(3) 200 | iIndex = iIndex + 4 201 | Next 202 | EncodeStr64 = StrConv(abOutput, vbUnicode) 203 | End If 204 | 205 | ' Cope with odd bytes 206 | ' (no real performance hit by using strings here) 207 | Select Case nLen Mod 3 208 | Case 0 209 | sLast = "" 210 | Case 1 211 | b(0) = Asc(Mid(sInput, nLen, 1)) 212 | b(1) = 0 213 | b(2) = 0 214 | Call EncodeQuantumB(b) 215 | sLast = StrConv(b(), vbUnicode) 216 | ' Replace last 2 with = 217 | sLast = Left(sLast, 2) & "==" 218 | Case 2 219 | b(0) = Asc(Mid(sInput, nLen - 1, 1)) 220 | b(1) = Asc(Mid(sInput, nLen, 1)) 221 | b(2) = 0 222 | Call EncodeQuantumB(b) 223 | sLast = StrConv(b(), vbUnicode) 224 | ' Replace last with = 225 | sLast = Left(sLast, 3) & "=" 226 | End Select 227 | 228 | EncodeStr64 = EncodeStr64 & sLast 229 | End Function 230 | 231 | Public Function DecodeStr64(sEncoded As String) As String 232 | ' Return string of decoded binary values given radix64 string 233 | ' Ignores any chars not in the 64-char subset 234 | ' Version 4: Use Byte array and StrConv - much faster 235 | Dim abDecoded() As Byte 'Version 4: Now a Byte array 236 | Dim d(3) As Byte 237 | Dim C As Integer ' NB Integer to catch -1 value 238 | Dim di As Integer 239 | Dim i As Long 240 | Dim nLen As Long 241 | Dim iIndex As Long 242 | 243 | nLen = Len(sEncoded) 244 | If nLen < 4 Then 245 | Exit Function 246 | End If 247 | ReDim abDecoded(((nLen \ 4) * 3) - 1) 'Version 4: Now base zero 248 | 249 | iIndex = 0 ' Version 4: Changed to base 0 250 | di = 0 251 | Call MakeDecTab 252 | ' Read in each char in turn 253 | For i = 1 To Len(sEncoded) 254 | C = CByte(Asc(Mid(sEncoded, i, 1))) 255 | C = aDecTab(C) 256 | If C >= 0 Then 257 | d(di) = CByte(C) ' Version 3.1: add CByte() 258 | di = di + 1 259 | If di = 4 Then 260 | abDecoded(iIndex) = SHL2(d(0)) Or (SHR4(d(1)) And &H3) 261 | iIndex = iIndex + 1 262 | abDecoded(iIndex) = SHL4(d(1) And &HF) Or (SHR2(d(2)) And &HF) 263 | iIndex = iIndex + 1 264 | abDecoded(iIndex) = SHL6(d(2) And &H3) Or d(3) 265 | iIndex = iIndex + 1 266 | If d(3) = 64 Then 267 | iIndex = iIndex - 1 268 | abDecoded(iIndex) = 0 269 | End If 270 | If d(2) = 64 Then 271 | iIndex = iIndex - 1 272 | abDecoded(iIndex) = 0 273 | End If 274 | di = 0 275 | End If 276 | End If 277 | Next i 278 | ' Convert to a string 279 | DecodeStr64 = StrConv(abDecoded(), vbUnicode) 280 | ' Remove any unwanted trailing chars 281 | DecodeStr64 = Left(DecodeStr64, iIndex) 282 | End Function 283 | 284 | Private Sub EncodeQuantumB(b() As Byte) 285 | ' Expects at least 4 bytes in b, i.e. Dim b(3) As Byte 286 | 287 | Dim b0 As Byte, b1 As Byte, b2 As Byte, b3 As Byte 288 | 289 | b0 = SHR2(b(0)) And &H3F 290 | b1 = SHL4(b(0) And &H3) Or (SHR4(b(1)) And &HF) 291 | b2 = SHL2(b(1) And &HF) Or (SHR6(b(2)) And &H3) 292 | b3 = b(2) And &H3F 293 | 294 | b(0) = aEncTab(b0) 295 | b(1) = aEncTab(b1) 296 | b(2) = aEncTab(b2) 297 | b(3) = aEncTab(b3) 298 | 299 | End Sub 300 | 301 | 302 | Private Function MakeDecTab() 303 | ' Set up Radix 64 decoding table 304 | Dim t As Integer 305 | Dim C As Integer 306 | 307 | For C = 0 To 255 308 | aDecTab(C) = -1 309 | Next 310 | 311 | t = 0 312 | For C = Asc("A") To Asc("Z") 313 | aDecTab(C) = t 314 | t = t + 1 315 | Next 316 | 317 | For C = Asc("a") To Asc("z") 318 | aDecTab(C) = t 319 | t = t + 1 320 | Next 321 | 322 | For C = Asc("0") To Asc("9") 323 | aDecTab(C) = t 324 | t = t + 1 325 | Next 326 | 327 | C = Asc("+") 328 | aDecTab(C) = t 329 | t = t + 1 330 | 331 | C = Asc("/") 332 | aDecTab(C) = t 333 | t = t + 1 334 | 335 | C = Asc("=") ' flag for the byte-deleting char 336 | aDecTab(C) = t ' should be 64 337 | 338 | End Function 339 | 340 | Private Function MakeEncTab() 341 | ' Set up Radix 64 encoding table in bytes 342 | Dim i As Integer 343 | Dim C As Integer 344 | 345 | i = 0 346 | For C = Asc("A") To Asc("Z") 347 | aEncTab(i) = C 348 | i = i + 1 349 | Next 350 | 351 | For C = Asc("a") To Asc("z") 352 | aEncTab(i) = C 353 | i = i + 1 354 | Next 355 | 356 | For C = Asc("0") To Asc("9") 357 | aEncTab(i) = C 358 | i = i + 1 359 | Next 360 | 361 | C = Asc("+") 362 | aEncTab(i) = C 363 | i = i + 1 364 | 365 | C = Asc("/") 366 | aEncTab(i) = C 367 | i = i + 1 368 | 369 | End Function 370 | 371 | ' Version 3: ShiftLeft and ShiftRight functions improved. 372 | Private Function SHL2(ByVal bytValue As Byte) As Byte 373 | ' Shift 8-bit value to left by 2 bits 374 | ' i.e. VB equivalent of "bytValue << 2" in C 375 | SHL2 = (bytValue * &H4) And &HFF 376 | End Function 377 | 378 | Private Function SHL4(ByVal bytValue As Byte) As Byte 379 | ' Shift 8-bit value to left by 4 bits 380 | ' i.e. VB equivalent of "bytValue << 4" in C 381 | SHL4 = (bytValue * &H10) And &HFF 382 | End Function 383 | 384 | Private Function SHL6(ByVal bytValue As Byte) As Byte 385 | ' Shift 8-bit value to left by 6 bits 386 | ' i.e. VB equivalent of "bytValue << 6" in C 387 | SHL6 = (bytValue * &H40) And &HFF 388 | End Function 389 | 390 | Private Function SHR2(ByVal bytValue As Byte) As Byte 391 | ' Shift 8-bit value to right by 2 bits 392 | ' i.e. VB equivalent of "bytValue >> 2" in C 393 | SHR2 = bytValue \ &H4 394 | End Function 395 | 396 | Private Function SHR4(ByVal bytValue As Byte) As Byte 397 | ' Shift 8-bit value to right by 4 bits 398 | ' i.e. VB equivalent of "bytValue >> 4" in C 399 | SHR4 = bytValue \ &H10 400 | End Function 401 | 402 | Private Function SHR6(ByVal bytValue As Byte) As Byte 403 | ' Shift 8-bit value to right by 6 bits 404 | ' i.e. VB equivalent of "bytValue >> 6" in C 405 | SHR6 = bytValue \ &H40 406 | End Function 407 | 408 | 409 | -------------------------------------------------------------------------------- /src/Blowfish/BlowfishEx.frm: -------------------------------------------------------------------------------- 1 | VERSION 5.00 2 | Begin VB.Form frmBlowfishEx 3 | Caption = "BlowfishEx Testbed Demo" 4 | ClientHeight = 7110 5 | ClientLeft = 60 6 | ClientTop = 345 7 | ClientWidth = 8550 8 | LinkTopic = "Form1" 9 | MaxButton = 0 'False 10 | ScaleHeight = 7110 11 | ScaleWidth = 8550 12 | StartUpPosition = 2 'CenterScreen 13 | Begin VB.TextBox txtDecrypt 14 | Appearance = 0 'Flat 15 | BackColor = &H80000004& 16 | Height = 315 17 | Left = 1125 18 | TabIndex = 38 19 | Top = 6075 20 | Width = 7320 21 | End 22 | Begin VB.TextBox txtPlainAsHex 23 | Appearance = 0 'Flat 24 | BackColor = &H80000004& 25 | Height = 315 26 | Left = 1125 27 | TabIndex = 36 28 | Top = 4200 29 | Width = 7320 30 | End 31 | Begin VB.TextBox txtDecryptHex 32 | Appearance = 0 'Flat 33 | BackColor = &H80000004& 34 | Height = 300 35 | Left = 1125 36 | TabIndex = 35 37 | Top = 6450 38 | Width = 7320 39 | End 40 | Begin VB.Frame Frame4 41 | Caption = "Plain text format" 42 | Height = 540 43 | Left = 3075 44 | TabIndex = 31 45 | Top = 3600 46 | Width = 2640 47 | Begin VB.OptionButton optPTHex 48 | Caption = "Hex" 49 | Height = 240 50 | Left = 1200 51 | TabIndex = 33 52 | Top = 225 53 | Width = 1365 54 | End 55 | Begin VB.OptionButton optPTAlpha 56 | Caption = "Alpha" 57 | Height = 240 58 | Left = 150 59 | TabIndex = 32 60 | Top = 225 61 | Value = -1 'True 62 | Width = 840 63 | End 64 | End 65 | Begin VB.TextBox txtIVAsString 66 | Appearance = 0 'Flat 67 | BackColor = &H80000004& 68 | Height = 285 69 | Left = 1125 70 | TabIndex = 28 71 | Top = 2925 72 | Width = 7320 73 | End 74 | Begin VB.TextBox txtIV 75 | Height = 300 76 | Left = 855 77 | TabIndex = 3 78 | Top = 1725 79 | Width = 6120 80 | End 81 | Begin VB.Frame Frame3 82 | Caption = "Paddin&g" 83 | Height = 1065 84 | Left = 3600 85 | TabIndex = 25 86 | Top = 150 87 | Width = 1365 88 | Begin VB.OptionButton optNoPad 89 | Caption = "None" 90 | Height = 240 91 | Left = 150 92 | TabIndex = 27 93 | Top = 600 94 | Width = 915 95 | End 96 | Begin VB.OptionButton optPad 97 | Caption = "PKCS#5" 98 | Height = 240 99 | Left = 150 100 | TabIndex = 26 101 | Top = 300 102 | Value = -1 'True 103 | Width = 1065 104 | End 105 | End 106 | Begin VB.Frame grpMode 107 | Caption = "&Mode" 108 | Height = 1065 109 | Left = 2250 110 | TabIndex = 22 111 | Top = 150 112 | Width = 990 113 | Begin VB.OptionButton optModeCBC 114 | Caption = "CBC" 115 | Height = 195 116 | Left = 150 117 | TabIndex = 24 118 | Top = 600 119 | Width = 765 120 | End 121 | Begin VB.OptionButton optModeECB 122 | Caption = "ECB" 123 | Height = 240 124 | Left = 150 125 | TabIndex = 23 126 | Top = 300 127 | Value = -1 'True 128 | Width = 765 129 | End 130 | End 131 | Begin VB.TextBox txtCipher64 132 | Appearance = 0 'Flat 133 | BackColor = &H80000004& 134 | Height = 300 135 | Left = 1125 136 | Locked = -1 'True 137 | TabIndex = 20 138 | Top = 5325 139 | Width = 7320 140 | End 141 | Begin VB.Frame grpKeyForm 142 | Caption = "Key &format:" 143 | Height = 840 144 | Left = 7125 145 | TabIndex = 17 146 | Top = 1200 147 | Width = 1305 148 | Begin VB.OptionButton optAlphaKey 149 | Caption = "Alpha" 150 | Height = 255 151 | Left = 150 152 | TabIndex = 19 153 | Top = 525 154 | Width = 960 155 | End 156 | Begin VB.OptionButton optHexKey 157 | Caption = "Hex string" 158 | Height = 255 159 | Left = 150 160 | TabIndex = 18 161 | Top = 225 162 | Value = -1 'True 163 | Width = 1065 164 | End 165 | End 166 | Begin VB.TextBox txtCipherHex 167 | Appearance = 0 'Flat 168 | BackColor = &H80000004& 169 | Height = 300 170 | Left = 1125 171 | Locked = -1 'True 172 | TabIndex = 16 173 | Top = 4950 174 | Width = 7320 175 | End 176 | Begin VB.TextBox txtCipher 177 | Appearance = 0 'Flat 178 | BackColor = &H80000004& 179 | Height = 300 180 | Left = 1125 181 | TabIndex = 7 182 | Top = 4575 183 | Width = 7320 184 | End 185 | Begin VB.CommandButton cmdDecrypt 186 | Caption = "&Decrypt cipher text" 187 | Enabled = 0 'False 188 | Height = 345 189 | Left = 1125 190 | TabIndex = 12 191 | Top = 5700 192 | Width = 1695 193 | End 194 | Begin VB.TextBox txtKeyAsString 195 | Appearance = 0 'Flat 196 | BackColor = &H80000004& 197 | Height = 300 198 | Left = 1125 199 | Locked = -1 'True 200 | TabIndex = 10 201 | Top = 2550 202 | Width = 7320 203 | End 204 | Begin VB.CommandButton cmdSetKey 205 | Caption = "&Set Key" 206 | Height = 390 207 | Left = 900 208 | TabIndex = 9 209 | Top = 2100 210 | Width = 990 211 | End 212 | Begin VB.CommandButton cmdEncrypt 213 | Caption = "&Encrypt plain text" 214 | Enabled = 0 'False 215 | Height = 450 216 | Left = 1125 217 | TabIndex = 8 218 | Top = 3675 219 | Width = 1695 220 | End 221 | Begin VB.TextBox txtKey 222 | Height = 300 223 | Left = 855 224 | TabIndex = 1 225 | Text = "fedcba9876543210" 226 | Top = 1320 227 | Width = 6120 228 | End 229 | Begin VB.TextBox txtPlain 230 | Height = 300 231 | Left = 1125 232 | TabIndex = 5 233 | Top = 3300 234 | Width = 7320 235 | End 236 | Begin VB.Label Label12 237 | Caption = "PT input:" 238 | Height = 240 239 | Left = 150 240 | TabIndex = 37 241 | Top = 4275 242 | Width = 840 243 | End 244 | Begin VB.Label Label11 245 | Caption = "Demonstration of Blowfish VB functions." 246 | BeginProperty Font 247 | Name = "MS Sans Serif" 248 | Size = 8.25 249 | Charset = 0 250 | Weight = 700 251 | Underline = 0 'False 252 | Italic = 0 'False 253 | Strikethrough = 0 'False 254 | EndProperty 255 | ForeColor = &H00800000& 256 | Height = 915 257 | Left = 75 258 | TabIndex = 34 259 | Top = 150 260 | Width = 1665 261 | End 262 | Begin VB.Label Label10 263 | Caption = "(In hex):" 264 | Height = 240 265 | Left = 150 266 | TabIndex = 30 267 | Top = 6450 268 | Width = 840 269 | End 270 | Begin VB.Label Label9 271 | Caption = "Active IV:" 272 | Height = 165 273 | Left = 150 274 | TabIndex = 29 275 | Top = 2925 276 | Width = 915 277 | End 278 | Begin VB.Label Label8 279 | Caption = "I&V (hex):" 280 | Height = 315 281 | Left = 150 282 | TabIndex = 2 283 | Top = 1725 284 | Width = 615 285 | End 286 | Begin VB.Label Label7 287 | Caption = "(Radix64):" 288 | Height = 375 289 | Left = 165 290 | TabIndex = 21 291 | Top = 5280 292 | Width = 855 293 | End 294 | Begin VB.Label Label6 295 | Alignment = 2 'Center 296 | Caption = "Copyright (C) 2001-3 DI Management Services Pty Ltd . All rights reserved." 297 | ForeColor = &H00800000& 298 | Height = 225 299 | Left = 225 300 | TabIndex = 15 301 | Top = 6825 302 | Width = 7380 303 | End 304 | Begin VB.Label Label2 305 | Caption = "(In hex):" 306 | Height = 255 307 | Index = 1 308 | Left = 165 309 | TabIndex = 14 310 | Top = 4950 311 | Width = 975 312 | End 313 | Begin VB.Label Label5 314 | Caption = "Deciphered:" 315 | Height = 255 316 | Left = 150 317 | TabIndex = 13 318 | Top = 6105 319 | Width = 975 320 | End 321 | Begin VB.Label Label4 322 | Caption = "Active key:" 323 | Height = 255 324 | Left = 150 325 | TabIndex = 11 326 | Top = 2550 327 | Width = 855 328 | End 329 | Begin VB.Label Label3 330 | Caption = "&Key:" 331 | Height = 255 332 | Left = 135 333 | TabIndex = 0 334 | Top = 1320 335 | Width = 855 336 | End 337 | Begin VB.Label Label2 338 | Caption = "&Cipher text:" 339 | Height = 255 340 | Index = 0 341 | Left = 165 342 | TabIndex = 6 343 | Top = 4575 344 | Width = 975 345 | End 346 | Begin VB.Label Label1 347 | Caption = "&Plain text:" 348 | Height = 255 349 | Left = 165 350 | TabIndex = 4 351 | Top = 3270 352 | Width = 975 353 | End 354 | End 355 | Attribute VB_Name = "frmBlowfishEx" 356 | Attribute VB_GlobalNameSpace = False 357 | Attribute VB_Creatable = False 358 | Attribute VB_PredeclaredId = True 359 | Attribute VB_Exposed = False 360 | Option Explicit 361 | Option Base 0 362 | 363 | ' frmBlowfishEx.frm 364 | ' A multi-function example to demonstrate some 365 | ' of the extended Blowfish functions. 366 | 367 | ' This is just a test-bed demo. It is not meant to be 368 | ' represesentative of good security code practices. 369 | ' There are no error handling facilities, either. 370 | 371 | ' Version 2. Released November 2003 using Byte versions of functions. 372 | ' Version 1. Published January 2002. 373 | '************************* COPYRIGHT NOTICE************************* 374 | ' This code was originally written in Visual Basic by David Ireland 375 | ' and is copyright (c) 2000-3 D.I. Management Services Pty Limited, 376 | ' all rights reserved. 377 | 378 | ' You are free to use this code as part of your own applications 379 | ' provided you keep this copyright notice intact and acknowledge 380 | ' its authorship with the words: 381 | 382 | ' "Contains cryptography software by David Ireland of 383 | ' DI Management Services Pty Ltd ." 384 | 385 | ' If you use it as part of a web site, please include a link 386 | ' to our site in the form 387 | ' Cryptography 388 | ' Software Code 389 | 390 | ' This code may only be used as part of an application. It may 391 | ' not be reproduced or distributed separately by any means without 392 | ' the express written permission of the author. 393 | 394 | ' David Ireland and DI Management Services Pty Limited make no 395 | ' representations concerning either the merchantability of this 396 | ' software or the suitability of this software for any particular 397 | ' purpose. It is provided "as is" without express or implied 398 | ' warranty of any kind. 399 | 400 | ' Please forward comments or bug reports to . 401 | ' The latest version of this source code can be downloaded from 402 | ' www.di-mgt.com.au/crypto.html. 403 | '****************** END OF COPYRIGHT NOTICE************************* 404 | 405 | ' The byte values in these arrays are used directly 406 | Dim abPlain() As Byte 407 | Dim abCipher() As Byte 408 | Dim abDecrypt() As Byte 409 | ' The key and IV stored as an array of bytes 410 | Dim aKey() As Byte 411 | Dim abInitV() As Byte 412 | 413 | Private Sub cmdSetKey_Click() 414 | Call SetKey 415 | Call SetIV 416 | End Sub 417 | 418 | Private Sub SetKey() 419 | ' Get key bytes from user's string 420 | 421 | ' What format is it in 422 | If Me.optHexKey Then 423 | ' In hex format 424 | aKey() = cv_BytesFromHex(Me.txtKey) 425 | Else 426 | ' User has provided a plain alpha string 427 | aKey() = StrConv(Me.txtKey, vbFromUnicode) 428 | End If 429 | 430 | ' Show key 431 | Me.txtKeyAsString = cv_HexFromBytes(aKey()) 432 | 433 | 'Initialise key 434 | Call blf_KeyInit(aKey) 435 | 436 | ' Allow encrypt 437 | Me.cmdEncrypt.Enabled = True 438 | ' Put user in plaintext box 439 | Me.txtPlain.SetFocus 440 | 441 | Done: 442 | 443 | End Sub 444 | 445 | Private Sub SetIV() 446 | ' Set IV 447 | Dim strIV As String 448 | Dim nBlkLen As Long 449 | Dim nPad As Long 450 | 451 | ' Check mode 452 | If Me.optModeECB Then 453 | Me.txtIVAsString = "" 454 | Exit Sub 455 | End If 456 | 457 | ' Convert to array of bytes 458 | strIV = Me.txtIV & "00" 459 | abInitV = cv_BytesFromHex(strIV) 460 | 461 | ' And make sure it is exactly 8 bytes long 462 | ReDim Preserve abInitV(7) 463 | 464 | ' Show iv 465 | Me.txtIVAsString = cv_HexFromBytes(abInitV) 466 | 467 | 468 | End Sub 469 | 470 | Private Sub cmdEncrypt_Click() 471 | ' Encrypt the plain text as required using hex strings 472 | Dim nBlkLen As Long 473 | Dim lngRet As Long 474 | Dim sMode As String 475 | 476 | ' Make sure key and IV are set 477 | Call SetKey 478 | Call SetIV 479 | 480 | ' Store plain text in byte array 481 | If Me.optPTAlpha Then 482 | abPlain = StrConv(Me.txtPlain, vbFromUnicode) 483 | Else 484 | abPlain = cv_BytesFromHex(Me.txtPlain) 485 | End If 486 | 487 | ' Then pad input if required 488 | If Me.optPad Then 489 | abPlain = PadBytes(abPlain) 490 | ElseIf UBound(abPlain) - LBound(abPlain) + 1 < 8 Then 491 | MsgBox "Plain text is too short to encrypt without padding" 492 | Exit Sub 493 | End If 494 | 495 | ' Show input data as hex 496 | Me.txtPlainAsHex = cv_HexFromBytes(abPlain) 497 | 498 | ' Now encrypt as per mode 499 | If Me.optModeCBC Then 500 | abCipher = blf_BytesEncRawCBC(abPlain, abInitV) 501 | Else 502 | abCipher = blf_BytesRaw(abPlain, bEncrypt:=True) 503 | End If 504 | 505 | ' Display results 506 | Me.txtCipher = StrConv(abCipher, vbUnicode) 507 | Me.txtCipherHex = cv_HexFromBytes(abCipher) 508 | Me.txtCipher64 = EncodeBytes64(abCipher) 509 | Me.cmdDecrypt.Enabled = True 510 | 511 | End Sub 512 | 513 | Private Sub cmdDecrypt_Click() 514 | Dim lngRet As Long 515 | Dim sMode As String 516 | 517 | 518 | ' Now decrypt as per mode 519 | If Me.optModeCBC Then 520 | abDecrypt = blf_BytesDecRawCBC(abCipher, abInitV) 521 | Else 522 | abDecrypt = blf_BytesRaw(abCipher, bEncrypt:=False) 523 | End If 524 | 525 | ' Strip padding if nec 526 | If Me.optPad Then 527 | abDecrypt = UnpadBytes(abDecrypt) 528 | End If 529 | 530 | ' Display output 531 | Me.txtDecryptHex = cv_HexFromBytes(abDecrypt) 532 | Me.txtDecrypt = StrConv(abDecrypt, vbUnicode) 533 | 534 | End Sub 535 | 536 | 537 | --------------------------------------------------------------------------------