This topic thread was originally posted in the xplorer² Professional forum. Moved here 9-September-2013 =fg=
============================================================
Updated March 4, 2014 - Version 1.4.1
No changes. Dropbox deleted my shared links for some reason. Restored.
Updated August 25, 2013 - Version 1.4.1
No changes. Updated post to make download links less confusing.
Updated August 12, 2013 - Version 1.4.1
* Reinsert back method of checking OS Bits before launching the correct executable. Sorry I have not thought about the possibility of problems that can occur if I use the previous method.
Updated August 12, 2013 - Version 1.4
* Many optimizations and tweaks.
* Remove OSBit check and used a simpler more efficient check. It simply runs xplorer2_64.exe if found and otherwise, will just use xplorer2_UC.exe *REMOVED IN 1.4.1
* Integrates UPX compressed 7za.exe. It will now automatically unpack 7za.exe and deletes it when it's done. To prevent false positives with AV software, I no longer compressed my executable. I only compressed the 7za.exe. I might still provide a version that does not package 7za.exe if it still cause a lot of problems for users.
* Added encrypted files integrity check. It will now make sure that the encrypted file is in working order before it wipes the original license key.
* Better way of checking if xplorer2 is actually running.
Updated August 05, 2013 - Version 1.3
* Realized that I did not compile the binary as Unicode. It should not support Unicode which means Unicode command-line arguments can be passed to it. Tools have also been recompiled to Unicode. No changes in source.
Updated August 05, 2013 - Version 1.3
* Can now be used with both 32Bit and 64Bit versions of xplorer2
* Can pass command-line arguments that are given to xp2KeyCrypt directly to xplorer2. All command-line arguments for xplorer2 are usable!
* A lot of code have been rewritten to work as expected. Optimized and streamlined.
* Not a new feature but executable and 7za.exe have been compressed with Free UPX by Pazera-Software to make it even smaller (especiallya 7za).
http://www.pazera-software.com/products/free-upx/
A lot of thanks is given to Kilmatead. Thank you very much for all your time, help, suggestions, and testing!
Updated August 02, 2013 - Version 1.2
* Change wipe algorithm to something simple (3 pass vs 7 pass) but is standardized. Should also reduce wearing of flash drives.
* Added some extra password checks and input dialogs.
* Optimize code. Should perform a bit better.
* Added an extra 250 ms wait for a total of 1 second wait after XYplorer supposed quit to make sure XYploer really did quit (instead of restarting) before attempting to re-encrypt XYplorer.ini and then wiping the file.
Updated August 02, 2013 - Version 1.1
* Small bug fix.
Updated August 02, 2013 - Version 1.0
* Initial Release
What this program does is it encrypts the X2.LIC file on your flash drive so that you won't have to worry even if someone gets ahold of your flash drive. Once it is fully set up, it will automatically decrypt the license file, start xplorer2, wait for xplorer2 to end, and then re-encrypt the license file. All you have to do is simply run xp2KeyCrypt.exe.
This is specifically for the Ultimate Version of xplorer2. I actually don't have the Ultimate version but since even the Professional License have the X2.LIC file in the root directory of the program, I have tested it and it works and technically should work with the Ultimate version which it is intended for. Do note that I tested it by copying the root directory to somewhere else where even a non-admin can write to it.
This program is actually originally written for XYPlorer and all I did was make it work with xplorer2 Ultimate (since I do own the Professional version which has the same method of using the X2.LIC file). It was was written more out of a whim since I remember seeing someone here in this forum talked about a little wrapper that protects X2.LIC and since I was playing around with PureBasic, I thought I should try using it to write this program. Anyway, I most likely won't work on this any further but you're free to have the source code and work on it more if you know PureBasic.
Also, the program uses 7-Zip (7za.exe) to handle the encryption since it's open source and it's already something well known so I don't need to mess around with implementing AES256 and make sure that it's secure enough. Although the encrypted file is named X2.DAT, it's actually a X2.7z file but I just changed it to DAT as to hide it. Obviously anyone with some bit of knowledge can easily figure out the original file extension but I did it anyway to keep the honest people out. Another thing is the wipe function. I implemented a very basic 3 pass wipe (1st wipe with all 0s, then 1s, and then random). It's not meant to be super secure but it should be sufficient enough and should not cause too much wear on the drive (only 3 passes). I DO NOT TAKE RESPONSIBILITY IF SOMEONE WAS ABLE TO RECOVER THE X2.LIC FILE WHICH SHOULD BE A GIVEN SINCE YOU DECIDED TO CARRY IT WITH YOU IN THE FIRST PLACE.
Finally, since I'm a new member here, I'm not really sure if this is the correct thread where to post this or is it supposed to be in x2 / 2X General thread. Anyways, enjoy!
Download
xp2KeyCrypt 1.4.1
https://www.dropbox.com/s/rum2be9ngvf7n ... yCrypt.zip
Non-Integrated 7za.exe xp2KeyCrypt 1.4.1 with Source (7za.exe remain as a separate executable)
https://www.dropbox.com/s/1odlx8iz6d9z6 ... zaless.zip
Dropbox Root Folder:
https://www.dropbox.com/sh/b52w1i6aa8pqnl7/PjgoG6RhOZ
Features
☆ Encrypt X2.LIC - Protects License Key
☆ Automatic Decryption & Re-Encryption - Can automatically decrypt X2.LIC and start xplorer2. Will automatically re-encrypt X2.LIC when it verifies that xplorer2 is running.
☆ Use 7-Zip's Built-In AES256 Encryption
☆ Does Not Require Admin Access - Unlike Full Disk Encryption which requires Admin access due to loading drivers, this is a file type encryption method so no need for admin access. Can be used anywhere!
☆ Works with Both 32Bit & 64Bit xplorer2
☆ xplorer2 Command-Line Arguments Can All Be Used - Simply pass the xplorer2 command-line arguments you want to use to xp2KeyCrypt and it launch xplorer2 with those arguments. No loss of command-line arguments functions!
☆ Fully Unicode
Setup
Remember to backup your files. I don't guarantee anything.
Copy xp2KeyCrypt.exe and 7za.exe to the root of xplorer2 (together with xplorer2_UC.exe or xplorer2_64 for 64Bit). Now from now on, always run xp2KeyCrypt.exe.
Code: Select all
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;xp2KeyCrypt - Allows the Automatical Encryption and Decryption of X2.LIC to Protect License Key.
;Use 7-Zip Built-In AES256 Encryption
;1. Encrypt X2.LIC to X2.DAT
;2. Automatically Decrypt X2.LIC and Start xplorer2_UC.exe
;3. Automatically Re-Encrypt X2.LIC After xplorer2 Ends
;
;Icon Source: Icon Source: https://www.iconfinder.com/icondetails/12578/48/key_lock_password_icon
;7za.exe (7-Zip) Igor Pavlov. http://www.7-zip.org/
;http://www.pazera-software.com/products/free-upx/ UPX GUI - Used to Compress Executable and 7za.exe
;http://forums.purebasic.com/english/viewtopic.php?p=36475
;http://forum.purebasic.com/english/viewtopic.php?p=179733
;http://forum.purebasic.com/english/viewtopic.php?t=55806 - Major Thanks to JHPJHP
;
;Instructions: Extract 7za.exe and xp2KeyCrypt.exe in Root Directory of xplorer2
;
;Thread at xplorer2 Support Forum: http://forum.zabkat.com/viewtopic.php?f=18&t=10212
;Major Thanks to Kilmatead for all the help, suggestions, testing, and time.
;Thread at XYPlorer Support Forum: http://www.xyplorer.com/xyfc/viewtopic.php?t=10039
;
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
DataSection
SevenZipExe:
IncludeBinary "7za.exe"
SevenZipExe_E:
EndDataSection
RunFile.s = GetCurrentDirectory()+"\7za.exe"
CreateDirectory(GetPathPart(RunFile))
File.l = CreateFile(#PB_Any, RunFile)
WriteData(File, ?SevenZipExe, ?SevenZipExe_E-?SevenZipExe)
CloseFile(#PB_Any)
;http://forums.purebasic.com/english/viewtopic.php?p=129817
Procedure.s InputBox(txtw, txth, title$, prompt$, def$="", flags=0)
; A version of InputRequester() by BackupUser
; Modified by AKJ 18-Oct-06
; Downloaded: www.purebasic.fr/english/viewtopic.php?t=2412
; textw and txth are the outer dimensions of the prompt text gadget
; Available flags are:
; #PB_String_{BorderLess LowerCase Numeric Password ReadOnly Uppercase}
Protected winBox, txtPrompt, strInput, butOK, butCancel ; Gadgets
Protected box, ev, id, ret, esc, a, thread1, thread2, text$=""
If txtw<128 : txtw=128 : EndIf ; To show buttons correctly
If txth<20 : txth = 20 : EndIf ; Height of a normal text line
winBox=OpenWindow(#PB_Any,0,0,txtw+13,txth+20+23+8*4,title$,#PB_Window_ScreenCentered)
box=WindowID(winBox)
If winBox And UseGadgetList(box)
txtPrompt=TextGadget(#PB_Any,6,8,txtw,txth,prompt$)
If flags&#PB_String_Password=0 : flags|#ES_MULTILINE : EndIf
strInput=StringGadget(#PB_Any,6,txth+8*2,txtw,20,def$,flags|#ES_AUTOVSCROLL)
butOK=ButtonGadget(#PB_Any,6,txth+20+8*3,60,23,"OK") ; Set x=txtw-122 for button to be on the right
butCancel=ButtonGadget(#PB_Any,txtw-54,txth+20+8*3,60,23,"Cancel")
SendMessage_(GadgetID(strInput),#EM_SETSEL,0,Len(def$))
GetAsyncKeyState_(#VK_RETURN) : GetAsyncKeyState_(#VK_ESCAPE)
StickyWindow(winBox,#True) : SetForegroundWindow_(box) : SetActiveGadget(strInput) : MessageBeep_(#MB_ICONQUESTION)
Repeat
ev=WaitWindowEvent(1) : id=EventGadget() : ret=GetAsyncKeyState_(#VK_RETURN) : esc=GetAsyncKeyState_(#VK_ESCAPE)
a=GetForegroundWindow_()
If a<>box
thread1=GetWindowThreadProcessId_(@a,0) : thread2=GetWindowThreadProcessId_(@box,0)
If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#True) : EndIf
If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf
SetActiveGadget(strInput)
EndIf
Until (ev=#PB_Event_Gadget And (id=butOK Or id=butCancel)) Or ret<>0 Or esc<>0 Or ev=#PB_Event_CloseWindow
If id=butOK Or ret<>0 : text$=GetGadgetText(strInput) : Else : text$=def$ : EndIf
CloseWindow(winBox)
EndIf
ProcedureReturn text$
EndProcedure
;http://www.purebasic.fr/english/viewtopic.php?f=3&t=50075
Procedure OSBits()
Protected si.SYSTEM_INFO, result = 32
Protected DLL = OpenLibrary(#PB_Any, "Kernel32.dll")
If DLL
If GetFunction(DLL,"GetNativeSystemInfo")
CallFunction(DLL, "GetNativeSystemInfo", @si)
If si\wProcessorArchitecture
result = 64
EndIf
EndIf
CloseLibrary(DLL)
EndIf
ProcedureReturn result
EndProcedure
;Personal Code
;http://forums.purebasic.com/english/viewtopic.php?p=296219
;http://en.wikipedia.org/wiki/Data_erasure
;Not meant to be super secure. Simple wipe.
; More Secure
; For i = 1 To 2
; FileSeek(0,0)
; For j=1 To Lof(0)
; RNum = Random(999)
; WriteByte(0,RNum)
; Next
; FlushFileBuffers(0)
; Next
Procedure Wipe(File$)
;SetFileAttributes(File$,#PB_FileSystem_Normal) Required To Remove Read-Only Attributes
SetFileAttributes(File$,#PB_FileSystem_Normal)
If OpenFile(0,File$)
FileSeek(0,0)
For j=1 To Lof(0)
WriteByte(0,0)
Next
FlushFileBuffers(0)
FileSeek(0,0)
For j=1 To Lof(0)
WriteByte(0,1)
Next
FlushFileBuffers(0)
FileSeek(0,0)
For j=1 To Lof(0)
RNum = Random(999)
WriteByte(0,RNum)
Next
FlushFileBuffers(0)
CloseFile(#PB_All)
DeleteFile(File$)
EndIf
EndProcedure
Procedure EndCleanup()
DeleteFile("7za.exe")
End
EndProcedure
;If FileSize("7za.exe") = -1
; MessageRequester("xp2KeyCrypt","7za.exe Missing. Cannot Continue.",#MB_ICONSTOP)
; EndCleanup()
;EndIf
;If FileSize("xplorer2_UC.exe") = -1 And FileSize("xplorer2_64.exe") = -1
; MessageRequester("xp2KeyCrypt","xplorer2 Executable Missing. Cannot Continue.",#MB_ICONSTOP)
; EndCleanup()
;ElseIf FileSize("xplorer2_64.exe") <> -1
; xplorer2$ = "xplorer2_64.exe"
;Else
; xplorer2$ = "xplorer2_UC"
;EndIf
Bits = OSBits()
If Bits = 32
xplorer2$ = "xplorer2_UC.exe"
ElseIf Bits = 64
xplorer2$ = "xplorer2_64.exe"
EndIf
If FileSize(xplorer2$) = -1
MessageRequester("xp2KeyCrypt",xplorer2$+" Missing. Cannot Continue.",#MB_ICONSTOP)
EndCleanup()
EndIf
;Get Program Parameters
For p = 1 To CountProgramParameters()
CParam$ = CParam$ + " " + Chr(34) + ProgramParameter() + Chr(34)
Next
If FileSize("X2.DAT") = -1
If FileSize("X2.LIC") <> -1
MessageRequester("xp2KeyCrypt","X2.DAT Not Found. Proceeding to Setup.",#MB_ICONINFORMATION)
While KeySame = 0
Delay(250)
Pass$ = InputBox(300,20,"xp2KeyCrypt","Encryption Key for X2.LIC:","",#PB_String_Password)
If Pass$ = "" : EndCleanup() : EndIf
Delay(250)
PassCheck$ = InputBox(300,20,"xp2KeyCrypt","Please Enter the Encryption Key Again:","",#PB_String_Password)
If PassCheck$ = ""
EndCleanup()
ElseIf PassCheck$ = Pass$
KeySame = 1
Else
MessageRequester("xp2KeyCrypt","Encryption Key Does Not Match.",#MB_ICONSTOP)
EndIf
Wend
RunProgram("7za.exe","a -mhe=on -mmt=on -p"+Pass$+" X2.DAT X2.LIC","",#PB_Program_Wait|#PB_Program_Hide)
Integrity7z = RunProgram("7za.exe","t -p"+Pass$+" X2.DAT","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Error)
While ProgramRunning(Integrity7z) : : Wend
ExitCode = ProgramExitCode(Integrity7z)
If ExitCode = 2
MessageRequester("xp2KeyCrypt Error "+StrD(ExitCode),"Error Occured During Encryption of X2.LIC. Check Read/Write Access to the Current Folder. Cannot Continue.",#MB_ICONSTOP)
EndCleanup()
EndIf
Wipe("X2.LIC")
Delay(750)
MessageRequester("xp2KeyCrypt","Configuration Complete.",#MB_ICONINFORMATION)
ExeName$ = GetFilePart(ProgramFilename())
RunProgram(ExeName$,CParam$,"")
Else
MessageRequester("xp2KeyCrypt","X2.DAT and X2.LIC Not Found. Cannot Continue.",#MB_ICONSTOP)
EndIf
Else
If FileSize("X2.LIC") <> -1 : EndCleanup() : EndIf
Delay(250)
Pass$ = InputBox(300,20,"xp2KeyCrypt","Decryption Key for X2.LIC:","",#PB_String_Password)
If Pass$ = "" : EndCleanup() : EndIf
Integrity7z = RunProgram("7za.exe","t -p"+Pass$+" X2.DAT","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Error)
While ProgramRunning(Integrity7z) : : Wend
ExitCode = ProgramExitCode(Integrity7z)
If ExitCode = 2
MessageRequester("xp2KeyCrypt Error "+StrD(ExitCode),"X2.DAT Corrupted. Cannot Continue.",#MB_ICONSTOP)
EndCleanup()
EndIf
RunProgram("7za.exe","e -p"+Pass$+" X2.DAT","",#PB_Program_Wait|#PB_Program_Hide)
If FileSize("X2.LIC") <> -1
xplorer2 = RunProgram(xplorer2$,CParam$,"")
xp2Run = 0
xp2RunE = 0
While xp2Run < 5
If xp2RunE = 20
MessageRequester("xp2KeyCrypt","xplorer2 Not Starting Correctly. Cannot Continue.",#MB_ICONSTOP)
Break 1
ElseIf FindWindow_("ATL:ExplorerFrame",0)
xp2Run = xp2Run+1
Delay(500)
Else
xp2RunE = xp2RunE+1
Delay(500)
EndIf
Wend
Integrity7z = RunProgram("7za.exe","t -p"+Pass$+" X2.DAT","",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Error)
Delay(200)
While ProgramRunning(Integrity7z) : : Wend
If ExitCode = 2
MessageRequester("xp2KeyCrypt Error "+StrD(ExitCode),"X2.DAT Corrupted. Cannot Continue Wipe of X2.LIC.",#MB_ICONSTOP)
EndCleanup()
EndIf
Wipe("X2.LIC")
EndIf
EndIf
DeleteFile("7za.exe")
; IDE Options = PureBasic 5.11 (Windows - x86)
; EnableUnicode
; EnableThread
; EnableXP
; UseIcon = 1375436159_12578.ICO
; Executable = xp2KeyCrypt.exe
; CPU = 1
; DisableDebugger
; CompileSourceDirectory
; IncludeVersionInfo
; VersionField0 = 1.4.1
; VersionField3 = xp2KeyCrypt
; VersionField6 = xplorer2 License Crypter
; VersionField8 = xp2KeyCrypt
; VersionField14 = http://www.zabkat.com/
; VersionField18 = xplorer2 User
; VersionField21 = Enternal