xp2KeyCrypt 1.4.1 Final - August 12, 2013

A collection of especially useful xplorer² topics and ideas. New users may find it helpful to look here before searching the other forums for information. >>>>>> Please post new material in the relevant forum. (New stuff posted here will be removed.) Thanks. -fg-

Moderators: fgagnon, nikos

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

xp2KeyCrypt 1.4.1 Final - August 12, 2013

Post by Enternal » 2013 Aug 03, 06:00

For encrypting the licence key X2.LIC file, when xplorer² is run from a flash drive.
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! :D
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
Last edited by Enternal on 2014 Mar 05, 04:02, edited 13 times in total.

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 03, 09:51

Nice idea - though I imagine anyone using x2 portable in anger would use a proper auto-encrypted USB method, this is as effective a way as any. :D

That said, as you're using it as a launch/wrapper, a few suggestions...

- x64 versions of x2 are not named xplorer2_UC, they use xplorer2_64.exe as the binary, so hardcoding the executable is impractical.

- Most users launch x2 with at least one or two command-line arguments (either '/'-options, or startup hard-folders), and so these should be passed on via the RunProgram("xplorer2_UC.exe","","") call.

- By erroring-out when both LIC and DAT exist, you're banjaxing multiple-instancing with x2, which seems unneccesary (unless I'm missing something). I assume this was implemented as your original thought was the preservation of the xyplorer .INI file - this is superfluous to x2.

- As a thought, and barring any extended experiments, as far as I know, x2 references the .LIC file upon process-startup, and then may not require it anymore, which means one could probably just delete the .LIC after the process has been verified, and save the overhead of this process remaining a parent, since only the .DAT is actually required for launch, there's no need to wait for x2 to terminate before killing it. :shrug: (This might also solve any lingering questions over exactly what happens when an x64 process has a permanent x86 parent, and any subsequent permission inheritance requests therefrom. :wink:)

Or that that what you meant by "I most likely won't work on this any further but you're free to have the source code and work on it more..."? :D

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 03, 11:28

Kilmatead wrote:Nice idea - though I imagine anyone using x2 portable in anger would use a proper auto-encrypted USB method, this is as effective a way as any. :D

That said, as you're using it as a launch/wrapper, a few suggestions...

- x64 versions of x2 are not named xplorer2_UC, they use xplorer2_64.exe as the binary, so hardcoding the executable is impractical.

- Most users launch x2 with at least one or two command-line arguments (either '/'-options, or startup hard-folders), and so these should be passed on via the RunProgram("xplorer2_UC.exe","","") call.

- By erroring-out when both LIC and DAT exist, you're banjaxing multiple-instancing with x2, which seems unneccesary (unless I'm missing something). I assume this was implemented as your original thought was the preservation of the xyplorer .INI file - this is superfluous to x2.

- As a thought, and barring any extended experiments, as far as I know, x2 references the .LIC file upon process-startup, and then may not require it anymore, which means one could probably just delete the .LIC after the process has been verified, and save the overhead of this process remaining a parent, since only the .DAT is actually required for launch, there's no need to wait for x2 to terminate before killing it. :shrug: (This might also solve any lingering questions over exactly what happens when an x64 process has a permanent x86 parent, and any subsequent permission inheritance requests therefrom. :wink:)

Or that that what you meant by "I most likely won't work on this any further but you're free to have the source code and work on it more..."? :D
Wow that's a lot of suggestions! Haha and yes I did plan on not working on this any further but... was a little free so I attempted to address all those suggestions and I think I got them all. I haven't fully test them all yet but I will tomorrow but the code now is posted below. Also I have updated my Dropbox sharing link with the new source code and the newly compiled executable. Once I finish testing, I probably will not work on it any further lol (unless I end up feeling like it again like I did in the last couple hours). Anyway thank you very much for your suggestions!
https://www.dropbox.com/sh/qh0wx571kdyqtjp/aIKAIKNa2M

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
;
;Note: SetFileAttributes(File$,#PB_FileSystem_Normal) Required To Remove Read-Only Attributes
;
;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://forums.purebasic.com/english/viewtopic.php?p=36475
;http://forum.purebasic.com/english/viewtopic.php?f=13&t=51825
;
;Instructions: Extract 7za.exe and xp2KeyCrypt.exe in Root Directory of xplorer2
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;http://forums.purebasic.com/english/viewtopic.php?f=13&t=39891 GetPIDByName
#PROCESS_ALL_ACCESS_VISTA_WIN7 = $1FFFFF
Prototype.i PFNCreateToolhelp32Snapshot(dwFlags.i, th32ProcessID.i) ;
Prototype.b PFNProcess32First(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Prototype.b PFNProcess32Next(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Procedure GetPidByName(p_name$)
	Protected hDLL.i, process_name$
	Protected PEntry.PROCESSENTRY32, hTool32.i
	Protected pCreateToolhelp32Snapshot.PFNCreateToolhelp32Snapshot
	Protected pProcess32First.PFNProcess32First
	Protected pProcess32Next.PFNProcess32Next
	Protected pid.i
	hDLL = OpenLibrary(#PB_Any,"kernel32.dll")
	If hDLL
		pCreateToolhelp32Snapshot = GetFunction(hDLL,"CreateToolhelp32Snapshot")
		pProcess32First = GetFunction(hDLL,"Process32First")
		pProcess32Next = GetFunction(hDLL,"Process32Next")
	Else
		ProcedureReturn 0
	EndIf
	PEntry\dwSize = SizeOf(PROCESSENTRY32)
	hTool32 = pCreateToolhelp32Snapshot(#TH32CS_SNAPPROCESS, 0)
	pProcess32First(hTool32, @PEntry)
	process_name$ = Space(#MAX_PATH)
	CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
	If UCase(process_name$) = UCase(p_name$)
		ProcedureReturn PEntry\th32ProcessID
	EndIf
	While pProcess32Next(hTool32, @PEntry) > 0
		process_name$ = Space(#MAX_PATH)
		CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
		If UCase(process_name$) = UCase(p_name$)
			ProcedureReturn PEntry\th32ProcessID
		EndIf
	Wend
	CloseLibrary(hDLL)
	ProcedureReturn 0
EndProcedure

;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}
; Features:
; (1) Modal (locks the calling window until done)
; (2) Prompt area is larger
; (3) Prompt area supports multi-line text with Chr(13)
; (4) Cancel button in addition to OK button
; (5) Returns the default string (def$) if the Cancel button is pressed
; (6) Returns "" if an error occurs
; (7) Standard Windows look-And-feel
; (8) Plays the "question" prompt sound
; (9) Works with or without a calling window
;(10) Emulates the Visual Basic InputBox() command
;(11) Supports all #PB_String_xxx flags
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)
	;If winBox And CreateGadgetList <- Original Code. Now Deprecated.
	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
			SetForegroundWindow_(box) : Sleep_(1)
			If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf
			SetActiveGadget(strInput); !!! : MessageBeep_(#MB_ICONQUESTION)
		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

;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$)
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(0)
	DeleteFile(File$)
EndIf
EndProcedure

If ReadFile(0,"7za.exe") = 0
	MessageRequester("xp2KeyCrypt","7za.exe Missing. Cannot Continue.",#MB_ICONSTOP)
	End
EndIf

;Get Executable's Name.
ExeName$ = GetFilePart(ProgramFilename())
;Get Command Line
;http://forums.purebasic.com/english/viewtopic.php?f=13&t=43459
*s.String = GetCommandLine_()
CmdRaw$ = PeekS(*s)
Cmd$ = RemoveString(CmdRaw$,ExeName$+" ")

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

If ReadFile(0,"X2.DAT") = 0
	CloseFile(0)
	If ReadFile(0,"X2.LIC")
		SetFileAttributes("X2.LIC",#PB_FileSystem_Normal)
		CloseFile(0)
		MessageRequester("xp2KeyCrypt","X2.DAT Not Found. Proceeding to Setup.",#MB_ICONINFORMATION)
		While KeySame = 0
			Delay(250)
			;Pass$ = InputRequester("xp2KeyCrypt", "Encryption Key for X2.LIC:","",#PB_InputRequester_Password)
			Pass$ = InputBox(300,20,"xp2KeyCrypt","Encryption Key For X2.LIC:","",#PB_String_Password)
			If Pass$ = ""
				End
			EndIf
			PassCheck$ = InputBox(300,20,"xp2KeyCrypt","Please Enter the Encryption Key Again:","",#PB_String_Password)
			If PassCheck$ = ""
				End
			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)
		MessageRequester("xp2KeyCrypt","Configuration Complete. Please Rerun xp2KeyCrypt.",#MB_ICONINFORMATION)
		Wipe("X2.LIC")
	Else
		MessageRequester("xp2KeyCrypt","X2.DAT and X2.LIC Not Found. Cannot Continue.",#MB_ICONSTOP)
	EndIf
Else
	;Pass$ = InputRequester("xp2KeyCrypt", "Dncryption Key for X2.LIC:","",#PB_InputRequester_Password)
	Pass$ = InputBox(300,20,"xp2KeyCrypt","Decryption Key for X2.LIC:","",#PB_String_Password)
	If Pass$ = ""
		End
	EndIf
	RunProgram("7za.exe","e -p"+Pass$+" X2.DAT","",#PB_Program_Wait|#PB_Program_Hide)
	Delay(100)
	If ReadFile(0,"X2.LIC")
		SetFileAttributes("X2.LIC",#PB_FileSystem_Normal)
		CloseFile(0)
		OSBits = OSBits()
		If OSBits = 64
			xplorer2$ = "xplorer2_64.exe"
		Else
			xplorer2$ = "xplorer2_UC.exe"
		EndIf
		RunProgram(xplorer2$,Cmd$,"")
		Delay(100)
		RunProgram("7za.exe","u -mhe -p"+Pass$+" X2.DAT X2.LIC","",#PB_Program_Wait|#PB_Program_Hide)
		Wipe("X2.LIC")
	ElseIf ReadFile(0,"X2.LIC") = 0
		MessageRequester("xp2KeyCrypt","Wrong Decryption Key. Try Again.",#MB_ICONSTOP)
	EndIf
EndIf

; IDE Options = PureBasic 5.11 (Windows - x86)
; EnableThread
; UseIcon = 1375436159_12578.ICO
; Executable = xp2KeyCrypt.exe
; CPU = 1
; DisableDebugger
; IncludeVersionInfo
; VersionField0 = 1.2.0.0
; VersionField3 = xp2KeyCrypt
; VersionField6 = xplorer2 License Crypter
; VersionField8 = xp2KeyCrypt
; VersionField14 = http://www.zabkat.com/
; VersionField18 = xplorer2 User
; VersionField21 = Enternal

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 03, 12:11

Er, not quite there yet. This one doesn't seem to be extracting the LIC for some reason (and yet, weirdly, executes the x2 binary anyway). :? And I'm not certain multiple (or indeed any) argument parameters are being passed properly.

Edit: Or, rather, a delay of 100ms is not sufficient for x2 to grasp its LIC existence before you nuke it. Once the process is launched, it wouldn't hurt anything to linger a few seconds before the wipe. And why are you repacking the DAT before termination?

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 03, 20:04

Kilmatead wrote:Er, not quite there yet. This one doesn't seem to be extracting the LIC for some reason (and yet, weirdly, executes the x2 binary anyway). :? And I'm not certain multiple (or indeed any) argument parameters are being passed properly.

Edit: Or, rather, a delay of 100ms is not sufficient for x2 to grasp its LIC existence before you nuke it. Once the process is launched, it wouldn't hurt anything to linger a few seconds before the wipe. And why are you repacking the DAT before termination?
I went to sleep before fully testing it. It's my bad idea to upload that executable before it's finished. Anyway, I will give it a larger time delay to see if it works. Also, do you have any recommendations on what type of parameter I should pass to make sure some of the basic parameters that are usually passed works? I also removed the repacking the DAT. That's actually from XYplorer.ini and I forgot that for xplorer2, X2.LIC is ONLY the license unlike XYplorer which also stores the settings.

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 03, 20:44

Enternal wrote:...do you have any recommendations on what type of parameter I should pass to make sure some of the basic parameters that are usually passed works?
The specific argument types are not that important - as long as x2 receives them in the same order and format as your binary does - for example, paths with spaces are usually the main bugbear in this situation... passing "C:\Nikos Has Spaces In His Brain" should not be splintered into 6 separate parameters, so (depending on how PureBasic's RunCommand() actually handles arguments) you'll probably have to double-quote each enumeration individually to rebuild the raw command-line string itself:

Quote$ + Arg[1] + Quote$ + Space$ + Quote$ + Arg[2] + Quote$ + Space$ + Quote$ + Arg[3] + Quote$ ...

...or Chr(32/34)... you get the idea.

I usually set up a shortcut passing two paths with spaces in them for the panes to default to, say "M:\Secret Porn Stash" (or something with spaces) and "C:\Users" and an extra argument like "/R:C:\Users" so you can't browse to the root of C:. That way you know pretty much immediately if it all works first time.

Isn't it amusing how little projects you figure you can whip up in half-an-hour have a bad habit of ballooning into the better part of a nebulous Saturday evening... :D

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 03, 21:54

Kilmatead wrote:
Enternal wrote:...do you have any recommendations on what type of parameter I should pass to make sure some of the basic parameters that are usually passed works?
The specific argument types are not that important - as long as x2 receives them in the same order and format as your binary does - for example, paths with spaces are usually the main bugbear in this situation... passing "C:\Nikos Has Spaces In His Brain" should not be splintered into 6 separate parameters, so (depending on how PureBasic's RunCommand() actually handles arguments) you'll probably have to double-quote each enumeration individually to rebuild the raw command-line string itself:

Quote$ + Arg[1] + Quote$ + Space$ + Quote$ + Arg[2] + Quote$ + Space$ + Quote$ + Arg[3] + Quote$ ...

...or Chr(32/34)... you get the idea.

I usually set up a shortcut passing two paths with spaces in them for the panes to default to, say "M:\Secret Porn Stash" (or something with spaces) and "C:\Users" and an extra argument like "/R:C:\Users" so you can't browse to the root of C:. That way you know pretty much immediately if it all works first time.

Isn't it amusing how little projects you figure you can whip up in half-an-hour have a bad habit of ballooning into the better part of a nebulous Saturday evening... :D
Ok I updated a new executable and it's located in the Beta folder now. I also restored the source code and executable in the root folder to the very first version that I uploaded here. Until this new program fully finish, it will stay in the Beta folder. Anyways, it was somewhat painful trying to make the passing parameter work and even now, I feel that the way I did it was kind of ugly but it seems to work. The problem I had was mainly starting the program from the shell ended up sending extra parameters that are not needed unlike starting the program from the command line. So I had to do extra work to make sure it does not pass any parameter when starting from the shell and only pass parameters when an intended parameter is passed. I have took your example of parameters and also used my own and they all seem to work perfectly. Of course there will probably always be some odd problem I think. Anyways, I also uploaded two tools that I used. OSBits.exe just tell you what Bit your system currently is which allows xp2KeyCrypt to switch from xplorer2_UC to xplorer2_64. The PassParameterTest.exe is used to tell me what the parameters were. I changed it to xplorer_UC.exe and ran xp2KeyCrypt which then display exactly what the parameters that were passed to it from xp2KeyCrypt.

But yes... *sigh. This was simply a play program that should have been done in a couple hours at most ended up sucking almost two days out of me. The XYplorer version also was a handful and this was pretty much the same lol :shock:. Now I'm even more confident that my decision not to become a programmer is clear :D. This is definitely not my thing. Anyway, I hope it works better now and will see what else can be done. Thank you!

https://www.dropbox.com/sh/qh0wx571kdyqtjp/aIKAIKNa2M
The tools and the beta code and exe are in their respective folders.
New Code:

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
;
;Note: SetFileAttributes(File$,#PB_FileSystem_Normal) Required To Remove Read-Only Attributes
;
;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://forums.purebasic.com/english/viewtopic.php?p=36475
;http://forum.purebasic.com/english/viewtopic.php?f=13&t=51825
;
;Instructions: Extract 7za.exe and xp2KeyCrypt.exe in Root Directory of xplorer2
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;http://forums.purebasic.com/english/viewtopic.php?f=13&t=39891 GetPIDByName
#PROCESS_ALL_ACCESS_VISTA_WIN7 = $1FFFFF
Prototype.i PFNCreateToolhelp32Snapshot(dwFlags.i, th32ProcessID.i) ;
Prototype.b PFNProcess32First(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Prototype.b PFNProcess32Next(hSnapshot.i, *lppe.PROCESSENTRY32) ;
Procedure GetPidByName(p_name$)
	Protected hDLL.i, process_name$
	Protected PEntry.PROCESSENTRY32, hTool32.i
	Protected pCreateToolhelp32Snapshot.PFNCreateToolhelp32Snapshot
	Protected pProcess32First.PFNProcess32First
	Protected pProcess32Next.PFNProcess32Next
	Protected pid.i
	hDLL = OpenLibrary(#PB_Any,"kernel32.dll")
	If hDLL
		pCreateToolhelp32Snapshot = GetFunction(hDLL,"CreateToolhelp32Snapshot")
		pProcess32First = GetFunction(hDLL,"Process32First")
		pProcess32Next = GetFunction(hDLL,"Process32Next")
	Else
		ProcedureReturn 0
	EndIf
	PEntry\dwSize = SizeOf(PROCESSENTRY32)
	hTool32 = pCreateToolhelp32Snapshot(#TH32CS_SNAPPROCESS, 0)
	pProcess32First(hTool32, @PEntry)
	process_name$ = Space(#MAX_PATH)
	CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
	If UCase(process_name$) = UCase(p_name$)
		ProcedureReturn PEntry\th32ProcessID
	EndIf
	While pProcess32Next(hTool32, @PEntry) > 0
		process_name$ = Space(#MAX_PATH)
		CopyMemory(@PEntry\szExeFile,@process_name$,#MAX_PATH)
		If UCase(process_name$) = UCase(p_name$)
			ProcedureReturn PEntry\th32ProcessID
		EndIf
	Wend
	CloseLibrary(hDLL)
	ProcedureReturn 0
EndProcedure

;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}
; Features:
; (1) Modal (locks the calling window until done)
; (2) Prompt area is larger
; (3) Prompt area supports multi-line text with Chr(13)
; (4) Cancel button in addition to OK button
; (5) Returns the default string (def$) if the Cancel button is pressed
; (6) Returns "" if an error occurs
; (7) Standard Windows look-And-feel
; (8) Plays the "question" prompt sound
; (9) Works with or without a calling window
;(10) Emulates the Visual Basic InputBox() command
;(11) Supports all #PB_String_xxx flags
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)
	;If winBox And CreateGadgetList <- Original Code. Now Deprecated.
	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
			SetForegroundWindow_(box) : Sleep_(1)
			If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf
			SetActiveGadget(strInput); !!! : MessageBeep_(#MB_ICONQUESTION)
		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

;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$)
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(0)
	DeleteFile(File$)
EndIf
EndProcedure

If ReadFile(0,"7za.exe") = 0
	MessageRequester("xp2KeyCrypt","7za.exe Missing. Cannot Continue.",#MB_ICONSTOP)
	End
EndIf

;Get Executable's Name.
FullPath$ = ProgramFilename()
;Get Command Line
;http://forums.purebasic.com/english/viewtopic.php?f=13&t=43459
*s.String = GetCommandLine_()
CmdRaw$ = RTrim(PeekS(*s))
If CmdRaw$ = #DQUOTE$+ProgramFilename()+#DQUOTE$
	Cmd$ = ""
Else
	ExeName$ = GetFilePart(ProgramFilename())
	Cmd$ = LTrim(RemoveString(CmdRaw$,ExeName$))
EndIf

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

If ReadFile(0,"X2.DAT") = 0
	CloseFile(0)
	If ReadFile(0,"X2.LIC")
		SetFileAttributes("X2.LIC",#PB_FileSystem_Normal)
		CloseFile(0)
		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$ = ""
				End
			EndIf
			PassCheck$ = InputBox(300,20,"xp2KeyCrypt","Please Enter the Encryption Key Again:","",#PB_String_Password)
			If PassCheck$ = ""
				End
			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)
		MessageRequester("xp2KeyCrypt","Configuration Complete. Please Rerun xp2KeyCrypt.",#MB_ICONINFORMATION)
		Wipe("X2.LIC")
	Else
		MessageRequester("xp2KeyCrypt","X2.DAT and X2.LIC Not Found. Cannot Continue.",#MB_ICONSTOP)
	EndIf
Else
	Delay(250)
	Pass$ = InputBox(300,20,"xp2KeyCrypt","Decryption Key for X2.LIC:","",#PB_String_Password)
	If Pass$ = ""
		End
	EndIf
	RunProgram("7za.exe","e -p"+Pass$+" X2.DAT","",#PB_Program_Wait|#PB_Program_Hide)
	Delay(100)
	If ReadFile(0,"X2.LIC")
		SetFileAttributes("X2.LIC",#PB_FileSystem_Normal)
		CloseFile(0)
		OSBits = OSBits()
		If OSBits = 64
			xplorer2$ = "xplorer2_64.exe"
		Else
			xplorer2$ = "xplorer2_UC.exe"
		EndIf
		RunProgram(xplorer2$,Cmd$,"")
		Delay(1500)
		Wipe("X2.LIC")
	ElseIf ReadFile(0,"X2.LIC") = 0
		MessageRequester("xp2KeyCrypt","Wrong Decryption Key. Try Again.",#MB_ICONSTOP)
	EndIf
EndIf

; IDE Options = PureBasic 5.11 (Windows - x86)
; EnableThread
; UseIcon = 1375436159_12578.ICO
; Executable = xp2KeyCrypt.exe
; CPU = 1
; DisableDebugger
; IncludeVersionInfo
; VersionField0 = 1.3.0.0
; VersionField3 = xp2KeyCrypt
; VersionField6 = xplorer2 License Crypter
; VersionField8 = xp2KeyCrypt
; VersionField14 = http://www.zabkat.com/
; VersionField18 = xplorer2 User
; VersionField21 = Enternal

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 03, 23:00

No, the CLI arguments are still wrong. From your PassParameterTest.exe I can see what you're trying to do - take the full string and get rid of the programme-name/path itself. This approach is a little too blunt ("simple" is not always "better"), and isn't really working.

A quick perusal of the PureBasic manual tells me that you should use the functions CountProgramParameters() and ProgramParameter() to do this properly.

Now don't take this literally, I'm guessing at the PureBasic syntax, but you'll get the idea. The manual is a little unclear if the first indexed parameter is the programme-name itself or not, but that's what experimentation is for.

Say you create a shortcut like this:

"N:\Xplorer2\xp2KeyCrypt.exe" "C:\" "D:\"

...you'd end up with something like:

ProgramParameter(0) = N:\Xplorer2\xp2KeyCrypt.exe
ProgramParameter(1) = C:\
ProgramParameter(2) = D:\

So you'd just toss out parameter 0 (x2 doesn't need to know "xp2KeyCrypt.exe") and start with 1.

Rebuild the command line sequentially using something like:

Code: Select all

For x = 1 to CountProgramParameters()
   CLine$ = Cline$ + " " + Chr(34) + ProgramParameter(x) + Chr(34)
next

RunProgram(..., CLine$, "")
Again, I'm guessing at the syntax, but the logic is the same no matter what the language is. Essentially, if CLine$ doesn't look like "C:\" "D:\" (replete with quotes) when you're done, it's not right. :wink: x2 should then open with C:\ in the left/top pane and D:\ in the right/lower pane.

You should be reading the command-line arguments this way all the time anyway, as when you want to write a programme which will process its own arguments, you don't want to waste your time picking apart one big string when you can just iterate a bunch of small ones which are ready-made. :D

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 04, 00:14

You were guessing at the syntax? You got it perfectly!

Anyways, base on your code, I wrote a new program just to make it easy to test it out:

Code: Select all

ParamN = CountProgramParameters()
For p = 1 To ParamN
   CLine$ = Cline$ + " " + Chr(34) + ProgramParameter() + Chr(34)
Next
MessageRequester("CLine$",CLine$)
Now if I use CMD and send:

Code: Select all

ParameterPass.exe /R "C:\Users" D:\Path With Space
I get:
"/R" "C:\Users" D:\Path With Space"

Is that how it supposed to look? It seems that if the parameter I pass has quotations, it does not double the quotations but if the parameter does not have quotations, it will automatically add a quotation. I was thinking that it's not passing the parameter RAW as in, it's not passing what you put in. So I decide to pass exactly those parameters into it, shouldn't I want it to be passing EXACTLY what I put into it?

Pass In: I Am Crazy "Chicken of the Sea" /R
Get Out: I Am Crazy "Chicken of the Sea" /R
Current Pass In: I Am Crazy "Chicken of the Sea" /R
Current Get Out: "I" "Am" "Crazy" "Chicken of the Sea" "/R"

Sorry if my question is odd. This is my first time writing a program this complex to me since I generally always been doing very simple stuff. Also my first time have to deal with passing parameters around. Also thank you very much for spending the time working with me on this. I don't know if there will be many people using it but I do think that it's as least useful.

EDIT: Oh sorry. I did not read the "(replete with quotes)". So it's exactly at you said it supposed to do. Anyways, I changed the code slightly just to make it a bit simpler and shorter (which is now much closer to your example). I have updated the executable once again. I'm going to leave in a bit so my next reply might be a bit slow.

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 04, 09:45

I think you got it right this time - the beta works as described. As a slight tweak, I would probably make the LIC-existence pause a little longer than 1.5 seconds (probably be more generous - up to 4 or 5) because it's expected to be used on USB sticks (which are slow to begin with) on other people's systems which have a myriad of security software which will initially check 'xp2KeyCrypt.exe' the first time its run, thus introducing more delays. (For example, the first time I ran xp2KeyCrypt.exe x2 choked and asked for a license-key, but subsequent runs work fine.) So a few extra seconds of daylight won't hurt the poor lad.

In a perfect world, you'd just wait until the x2 window (CLASS:ATL:ExplorerFrame) was verified to be extant - but I don't see a nice simple means of doing that in PureBasic, outside of FindWindow_(), but the proper documentation is scarce. :shrug:
Enternal wrote:Is that how it supposed to look? It seems that if the parameter I pass has quotations, it does not double the quotations but if the parameter does not have quotations, it will automatically add a quotation. I was thinking that it's not passing the parameter RAW as in, it's not passing what you put in. So I decide to pass exactly those parameters into it, shouldn't I want it to be passing EXACTLY what I put into it?
Well, the word "raw" can be a bit misleading when you're talking about things being passed through the shell - it's an accepted paradigm that double-quotes (when supplied via command-line) will preserve the integrity of whatever is between them, but they themselves will not be passed. For example, if you passed a filename you wanted to open into a programme and that filename included the quotes, you'd probably find that the programme would not open the file correctly, as literal double-quotes are not legal characters in file-names. So they're treated as delimiters, "surrounding" that data which you expect to be kept intact, as the shell will "naturally" use <Space> characters to separate arguments. Placing quotes around all arguments is somewhat superfluous ("/R" is the same as /R) because contiguous characters are always taken as a group anyway, but it's better to be safe than sorry, so it's no harm no foul. This way the end user gets what he expects - until they ask for more... and more... and more... those end users are a scary bunch. :wink:
Enternal wrote:I don't know if there will be many people using it but I do think that it's as least useful.
Oh this is quite useful and in its final form I have no problem suggesting to the ever-lurking moderator that this thread be moved to its proper place. The nakedness of the LIC file has always been a weird oversight on Nikos' part, so this certainly fills a niche on the portable-user's side. Like you say it's not exactly super-secure, but it doesn't need to be - it's more than enough to keep the mosquitoes at bay.
Enternal wrote:Also thank you very much for spending the time working with me on this.
No problem - learning is always worthwhile. Considering that I tend to specialise in making things that are somewhat intentionally useless :twisted:, it's nice to see others using their heads and learning at the same time. :D

(I'm not crazy about your choice of medium - proprietary programming languages tend to exclude people participating in the creation process - most things around here are done in any of the many free scripting languages so users are free to mod them as necessary. That said, PureBasic's apparent cross-platform support of Mac/Linux/Windows is admirable. Not 80-quid's worth of admirable, but admirable enough to be noticed. :D If I ruled the world, everyone would just be locked in a closet and fed a thin gruel until they learned C-proper, and then they would be free to learn other languages - the world would be a far better place, but I'm a fuddy-duddy that way. :wink:)

Addendum: A little research suggests that the proper way to check if a file exists is to use something like 'FileSize(<File>) <> -1' not FileRead(), as FileRead() seems to be reserved for opening files for reading - as you are only checking "existence", if the FileRead succeeds then it seems to be left open and you aren't closing it. This is no great harm in the scheme of things, as I imagine PureBasic is intelligent enough to close all open handles when the programme exits just in case the coder is a little mentally lopsided that day, but FileSize() seems to be the recommended method. :shrug:

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 04, 21:38

Kilmatead wrote:I think you got it right this time - the beta works as described. As a slight tweak, I would probably make the LIC-existence pause a little longer than 1.5 seconds (probably be more generous - up to 4 or 5) because it's expected to be used on USB sticks (which are slow to begin with) on other people's systems which have a myriad of security software which will initially check 'xp2KeyCrypt.exe' the first time its run, thus introducing more delays. (For example, the first time I ran xp2KeyCrypt.exe x2 choked and asked for a license-key, but subsequent runs work fine.) So a few extra seconds of daylight won't hurt the poor lad.

In a perfect world, you'd just wait until the x2 window (CLASS:ATL:ExplorerFrame) was verified to be extant - but I don't see a nice simple means of doing that in PureBasic, outside of FindWindow_(), but the proper documentation is scarce. :shrug:
Yeah that is what I would want to do too but the documentation is a bit scarce at times so that's one problem with PureBasic. The documentation for it can be good at times and kind of limited other times. Anyways, I'm currently trying to use this code to see if it's a reasonable way of testing whether xplorer2.exe did run or not:

Code: Select all

xplorer2 = RunProgram(xplorer2$,CParam$,"",#PB_Program_Open)
xp2Run = 0
xp2RunE = 0
While xp2Run < 4
	If xp2RunE = 20
		MessageRequester("xp2KeyCrypt","xplorer2 Not Starting Correctly. Quitting.",#MB_ICONSTOP)
		Break 1
	ElseIf ProgramRunning(xplorer2)
		xp2Run = xp2Run+1
		Delay(500)
	Else
		xp2RunE = xp2RunE+1
		Delay(500)
	EndIf
Wend
Wipe("X2.LIC")
PureBasic has the ability to tell if the program it launched using RunProgram is still running or not. What I'm attempting to do is that if xplorer2 runs for at least 2 seconds, it's safe to assume that xplorer2 loaded fine and will move on. If it does not detect xplorer2, it will continue to wait until 10 seconds which it will then quit assuming that xplorer2 either quit early or was not working. This should also prevent the need to kill the program if for some reason xplorer2 went kaput and it will still continue on to wipe the license file.
EDIT: Currently not working. Somehow crashing the program.
EDIT2: Now working. PureBasic hard copy documentation (help file that comes with PureBasic) did not have any examples and proper usage of the RunCommand(). The online version has much better examples.
Kilmatead wrote:Well, the word "raw" can be a bit misleading when you're talking about things being passed through the shell - it's an accepted paradigm that double-quotes (when supplied via command-line) will preserve the integrity of whatever is between them, but they themselves will not be passed. For example, if you passed a filename you wanted to open into a programme and that filename included the quotes, you'd probably find that the programme would not open the file correctly, as literal double-quotes are not legal characters in file-names. So they're treated as delimiters, "surrounding" that data which you expect to be kept intact, as the shell will "naturally" use <Space> characters to separate arguments. Placing quotes around all arguments is somewhat superfluous ("/R" is the same as /R) because contiguous characters are always taken as a group anyway, but it's better to be safe than sorry, so it's no harm no foul. This way the end user gets what he expects - until they ask for more... and more... and more... those end users are a scary bunch. :wink:
Ah that makes sense. So it's also a way of making sure that the users are getting what they EXPECT so it's safer to be ready for odd inputs. End users are always asking for more lol.
Kilmatead wrote:Oh this is quite useful and in its final form I have no problem suggesting to the ever-lurking moderator that this thread be moved to its proper place. The nakedness of the LIC file has always been a weird oversight on Nikos' part, so this certainly fills a niche on the portable-user's side. Like you say it's not exactly super-secure, but it doesn't need to be - it's more than enough to keep the mosquitoes at bay.
Haha glad to hear that it does fill a niche for the portable users. Also worried about losing the key and someone taking it and then distributing it. At least with this, they can feel a bit more safe. Of course, it does not mean they can be reckless lol.
Kilmatead wrote:No problem - learning is always worthwhile. Considering that I tend to specialise in making things that are somewhat intentionally useless :twisted:, it's nice to see others using their heads and learning at the same time. :D

(I'm not crazy about your choice of medium - proprietary programming languages tend to exclude people participating in the creation process - most things around here are done in any of the many free scripting languages so users are free to mod them as necessary. That said, PureBasic's apparent cross-platform support of Mac/Linux/Windows is admirable. Not 80-quid's worth of admirable, but admirable enough to be noticed. :D If I ruled the world, everyone would just be locked in a closet and fed a thin gruel until they learned C-proper, and then they would be free to learn other languages - the world would be a far better place, but I'm a fuddy-duddy that way. :wink:)

Addendum: A little research suggests that the proper way to check if a file exists is to use something like 'FileSize(<File>) <> -1' not FileRead(), as FileRead() seems to be reserved for opening files for reading - as you are only checking "existence", if the FileRead succeeds then it seems to be left open and you aren't closing it. This is no great harm in the scheme of things, as I imagine PureBasic is intelligent enough to close all open handles when the programme exits just in case the coder is a little mentally lopsided that day, but FileSize() seems to be the recommended method. :shrug:
Haha these "useless" things sometimes tend to be important things that are not exactly "shiny". It's like the bass in music. Not always "upfront" but without it, music does not sound right. ALso I really like how that program not only seems functional but looks good too. I know functional is supposed to be a main thing but looking good should not be completely cast aside as well.

That is a problem with PureBasic. I actually do know C a bit since I'm a graduate level student for mechanical engineering but the C that I know is more focused on embedded systems so in terms of system programming, I suck since this is in many ways my first time. I always been doing little scripts to automate certain things. The reason why I picked PureBasic is that it's interesting how it works on all the major operating systems, has a good enough library, can use Windows API if needed, compiles to machine code, small executable (mine is a bit big due to the icon file), and it does not have an issue with false positives with AV software unlike AutoIt at times. So it looks kind of fun!

Ah! FileSize is indeed much better! I was getting annoyed with making sure I use CloseFile but I keep on forgetting it at times. That reminds me, I had to set the file attribute of the license file to remove the Read-Only flag (it's on by default) because with it on, I could not wipe the file. Should I try to maintain that Read-Only flag? I don't think it's exactly necessary but just to be safe. Currently with my code, I'm working on making it a bit more streamlined and just found out about ternary operators by accident since it's not mentioned anywhere in the documentations. Hopefully I can get the new code up tonight and also test it.

EDIT: New code and executable up:
https://www.dropbox.com/sh/qh0wx571kdyqtjp/aIKAIKNa2M
Could you please check it again. This should be the last version and if it works well, it will be the final version! Yeah!

Current code as of now:

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
;
;Note: SetFileAttributes(File$,#PB_FileSystem_Normal) Required To Remove Read-Only Attributes
;
;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?f=13&t=51825
;
;Instructions: Extract 7za.exe and xp2KeyCrypt.exe in Root Directory of xplorer2
;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;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}
; Features:
; (1) Modal (locks the calling window until done)
; (2) Prompt area is larger
; (3) Prompt area supports multi-line text with Chr(13)
; (4) Cancel button in addition to OK button
; (5) Returns the default string (def$) if the Cancel button is pressed
; (6) Returns "" if an error occurs
; (7) Standard Windows look-And-feel
; (8) Plays the "question" prompt sound
; (9) Works with or without a calling window
;(10) Emulates the Visual Basic InputBox() command
;(11) Supports all #PB_String_xxx flags
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)
	;If winBox And CreateGadgetList <- Original Code. Now Deprecated.
	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
			SetForegroundWindow_(box) : Sleep_(1)
			If thread1<>thread2 : AttachThreadInput_(thread1,thread2,#False) : EndIf
			SetActiveGadget(strInput); !!! : MessageBeep_(#MB_ICONQUESTION)
		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)
	If OpenFile(#PB_Any,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

If FileSize("7za.exe") = -1
	MessageRequester("xp2KeyCrypt","7za.exe Missing. Cannot Continue.",#MB_ICONSTOP)
	End
EndIf
OSBits = OSBits()
If OSBits = 64
	xplorer2$ = "xplorer2_64.exe"
Else
	xplorer2$ = "xplorer2_UC.exe"
EndIf
If FileSize(xplorer2$) = -1
	MessageRequester("xp2KeyCrypt",xplorer2$+" Missing. Cannot Continue.",#MB_ICONSTOP)
	End
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$ = "" : End : EndIf
			PassCheck$ = InputBox(300,20,"xp2KeyCrypt","Please Enter the Encryption Key Again:","",#PB_String_Password)
			If PassCheck$ = ""
				End
			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)
		Delay(1000)
		Wipe("X2.LIC")
		MessageRequester("xp2KeyCrypt","Configuration Complete. Please Rerun xp2KeyCrypt.",#MB_ICONINFORMATION)
	Else
		MessageRequester("xp2KeyCrypt","X2.DAT and X2.LIC Not Found. Cannot Continue.",#MB_ICONSTOP)
	EndIf
Else
	Delay(250)
	Pass$ = InputBox(300,20,"xp2KeyCrypt","Decryption Key for X2.LIC:","",#PB_String_Password)
	If Pass$ = "" : End : EndIf
	RunProgram("7za.exe","e -p"+Pass$+" X2.DAT","",#PB_Program_Wait|#PB_Program_Hide)
	Delay(200)
	If FileSize("X2.LIC") <> -1
		xplorer2 = RunProgram(xplorer2$,CParam$,"",#PB_Program_Open)
		xp2Run = 0
		xp2RunE = 0
		While xp2Run < 4
			If xp2RunE = 20
				MessageRequester("xp2KeyCrypt","xplorer2 Not Starting Correctly. Quitting.",#MB_ICONSTOP)
				Break 1
			ElseIf ProgramRunning(xplorer2)
				xp2Run = xp2Run+1
				Delay(500)
			Else
				xp2RunE = xp2RunE+1
				Delay(500)
			EndIf
		Wend
		Wipe("X2.LIC")
	Else
		MessageRequester("xp2KeyCrypt","Wrong Decryption Key. Try Again.",#MB_ICONSTOP)
		End
	EndIf
EndIf
Also, this forum is driving me nuts with how it sometimes fail to load or some other odd site issues. Oh well, I save my posts in a text file first before copy, paste, and submitting.
Last edited by Enternal on 2013 Aug 05, 07:49, edited 1 time in total.

Kilmatead
Platinum Member
Platinum Member
Posts: 4569
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Kilmatead » 2013 Aug 05, 07:03

Ok, far better now... - not perfect - but workable. Like you, I'm not mad about the convoluted method of checking to see if x2 is successfully running or not... for example, xp2KeyCrypt.exe gets a little unhappy if you start a second or third instance from the shortcut. It doesn't start screaming for its stash of diazepam or anything, but it's "grumpy". :wink: Not a big deal at the end of the day.

That's actually one of the things I don't like about scripting languages (such as AutoIt) - they're vastly uneven... for manipulating physical Windows they take all the fun out of it (WinWaitActive, WinWaitNotActive, WinExists, WinGetProcess, etc) it's almost designed for dummies. But then in the same breath you still have to jump through the WM_NOTIFY malarkey just to see if someone double-clicked an item in a ListView in your own GUI. Messy.

Then again, I suppose that's why all the kids run around learning C# - it's so easy to design over the top GUI's that a monkey could do it (bloody language is just virtual-scripting anyway). Suicide by .NET - maybe everyone should just be forced to learn assembler; at least that way you could tell a Java-junkie from a Script-kiddie in the unemployment lines. <Sigh> I'm just getting old.

"Anyway, I most likely won't work on this any further..." (This would make an excellent epitaph!)

Thanks for the addition to the x2 utility-pantheon - took a few days but you got there. :D

Enternal
Member
Member
Posts: 54
Joined: 2013 Aug 03, 05:28

Re: xp2KeyCrypt 1.2 - August 2, 2013

Post by Enternal » 2013 Aug 05, 08:41

Kilmatead wrote:Ok, far better now... - not perfect - but workable. Like you, I'm not mad about the convoluted method of checking to see if x2 is successfully running or not... for example, xp2KeyCrypt.exe gets a little unhappy if you start a second or third instance from the shortcut. It doesn't start screaming for its stash of diazepam or anything, but it's "grumpy". :wink: Not a big deal at the end of the day.

That's actually one of the things I don't like about scripting languages (such as AutoIt) - they're vastly uneven... for manipulating physical Windows they take all the fun out of it (WinWaitActive, WinWaitNotActive, WinExists, WinGetProcess, etc) it's almost designed for dummies. But then in the same breath you still have to jump through the WM_NOTIFY malarkey just to see if someone double-clicked an item in a ListView in your own GUI. Messy.

Then again, I suppose that's why all the kids run around learning C# - it's so easy to design over the top GUI's that a monkey could do it (bloody language is just virtual-scripting anyway). Suicide by .NET - maybe everyone should just be forced to learn assembler; at least that way you could tell a Java-junkie from a Script-kiddie in the unemployment lines. <Sigh> I'm just getting old.

"Anyway, I most likely won't work on this any further..." (This would make an excellent epitaph!)

Thanks for the addition to the x2 utility-pantheon - took a few days but you got there. :D
Hahaha so it's a bit "grumpy". However I think typically people who put it on their flash drive will most likely only use one instance of xplorer2 so hopefully they won't encounter to much of an issue with that.

The good things about scripting languages is also exactly that! It's pretty much the yin/yang issue. The good is that it's quick to get things done but the bad is that it makes things boring at times. However, at least they're quite productive when you have something you need it to do quickly. I can't imagine myself writing this program if I had to write it in C... or Assembly (lol!).

Lol! I'm guessing you're really are getting older hahaha. But it comes with the territory? Experience + Age? But wow, assembler? *runs away. Fortran is supposed to be better but... *runs away. I know they have their uses but learning them will put off a lot of potential programmers. At the same time, some of these languages makes programmers lazy. But that's a whole different topic.
"Anyway, I most likely won't work on this any further..." (This would make an excellent epitaph!)
:twisted:

Anyway, once again, thank you for everything! It has been a wonderful experience and it's great learning so much more from writing this program and also from your detailed explanations. Thank you! :beer: :biggrin:

Well, I'm now leaving this forum and going back to XYplorer's forum since it's actually my main file manager. I do use xplorer2 (together with Directory Opus and Q-Dir lol) though but using XYplorer for so long, it has become my standard file manager. However I made sure that any PM sent to me will email me to let me know so if the program needs anything, I will see what I can do. BUT Anyway, I most likely won't work on this any further... :lol:

Now... :party:

User avatar
drac
Bronze Member
Bronze Member
Posts: 138
Joined: 2013 Jan 08, 00:14

Re: xp2KeyCrypt 1.3 FINAL - August 5, 2013

Post by drac » 2013 Aug 05, 20:10

If someone is not willing and able to learn assembler language they should not be allowed to be a programmer. AFTER they learn assembler AND have written at least 10,000 lines of production code, then they can be allowed to start learning and working in a higher level language. We would have much better software with way fewer bugs if we had some kind of programming standards.

And I am not just getting old - I am already there. And yes, I was working in assembler (at my first job out of college) long before I started using higher level languages (though I did use HLH's in college).

Tuxman
Platinum Member
Platinum Member
Posts: 1483
Joined: 2009 Aug 19, 07:49

Re: xp2KeyCrypt 1.3 FINAL - August 5, 2013

Post by Tuxman » 2013 Aug 05, 20:46

Why would anyone want to make his life harder?
Tux. ; tuxproject.de ; Windows 10 x64
registered xplorer² pro user since Oct 2009, ultimated in Mar 2012

Post Reply