Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #cs ----------------------------------------------------------------------------
- Auteur : iDuty
- Function :
- this script has for purpose to transform one file, in hexadecimal code,
- so that it can be included in a code. Like a bat file or au3 ...
- #ce ----------------------------------------------------------------------------
- #include <ButtonConstants.au3>
- #include <ComboConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <ProgressConstants.au3>
- #include <StaticConstants.au3>
- #include <WindowsConstants.au3>
- #Include <Clipboard.au3>
- #include <GUIConstants.au3>
- #include <File.au3>
- #include <string.au3>
- Global $Form1, $Button1, $Button2, $Button3, $Progress1, $sFile = Default, $Path = Default
- Global $Combo1, $Label1
- _CreatGui()
- While 1
- $nMsg = GUIGetMsg()
- Switch $nMsg
- Case $GUI_EVENT_CLOSE
- Exit
- Case $Button1
- $Path = FileOpenDialog("File to convert", @DesktopDir, "All Files (*.*)")
- if not @error Then
- $sFile = _FileGetName($Path, 1)
- WinSetTitle($Form1, "", "<b style="color:#E89512">Bexa</b> v3.3 |" & $sFile & " --> "& guictrlread($Combo1))
- EndIf
- Case $Button2
- if $sFile <> Default then
- if GUICtrlRead($Combo1) = "Convertion vers fichiers batch" then _File_Bexa($Path, $sFile)
- if GUICtrlRead($Combo1) = "Convertion vers fichier autoit" then _File_Au3xa($Path, $sFile)
- if GUICtrlRead($Combo1) = "retourne l'Hexadecimal seulement" then _GetHexaDec($Path)
- EndIf
- EndSwitch
- WEnd
- Func _CreatGui()
- #Region ### START Koda GUI section ### Form=
- $Form1 = GUICreate("<b style="color:#E89512">Bexa</b> v3.3", 331, 74, 282, 208)
- $Progress1 = GUICtrlCreateProgress(8, 40, 313, 25)
- $Button1 = GUICtrlCreateButton("...", 8, 8, 57, 25)
- GUICtrlSetTip($Button1, "Please, choose the file to convert...")
- $Combo1 = GUICtrlCreateCombo("Convertion vers fichiers batch", 72, 10, 209, 25, BitOR($GUI_SS_DEFAULT_COMBO,$CBS_SIMPLE))
- GUICtrlSetData($Combo1, "Convertion vers fichier autoit|retourne l'Hexadecimal seulement")
- $Button2 = GUICtrlCreateButton("GO", 288, 8, 33, 25)
- GUISetState(@SW_SHOW)
- #EndRegion ### END Koda GUI section ###
- Endfunc
- func _FileGetName($sLien, $sExt=Default)
- if not FileExists($sLien) then Exit
- Local $sName = StringSplit($sLien, "\"), $without_E
- $sName = $sName[$sName[0]]
- if $sExt = Default then
- Return $sName
- elseif $sExt = 1 then
- $without_E = StringSplit($sName, ".")
- $without_E = $without_E[$without_E[0]-1]
- Return $without_E
- Endif
- Return
- Endfunc
- Func _File_Bexa($Path, $sFile="")
- if not FileExists($Path) then exit
- if $sFile = "" then Return
- Local $WithExt = _FileGetName($Path)
- Local $sOp, $sRe, $sLi, $Ubound, $String
- Local $FilCompress = StringTrimRight($WithExt, 1) & "_"
- Local $PathCompress = stringreplace($path, $WithExt, $FilCompress)
- ConsoleWrite($FilCompress&@CRLF)
- $sOp = FileOpen($Path, 16)
- $sRe = FileRead($sOp)
- FileClose($sOp)
- $sLi = StringRegExp($sRe, "(.{1,64})", 3)
- $Ubound = UBound($sLi)
- $sLi[0] = StringTrimLeft($sLi[0], 2)
- If $Ubound = 1 Then
- $String &= '@echo off ' & @CRLF & ':' & $sFile & @CRLF & 'For %%b In (' & @CRLF & '"' & $sLi[0] & '"' & @CRLF
- $String &= ') Do >> "' & $FilCompress & '" (Echo.For b=1 To len^(%%b^) Step 2' & @CRLF & 'Echo WScript.StdOut.Write Chr^(Clng^("&H"^&Mid^(%%b,b,2^)^)^) : Next)' & @CRLF & _
- 'Cscript /b /e:vbs "' & $FilCompress & '" > "' & $WithExt & '"' & @CRLF & 'Del "' & $FilCompress & '" >nul 2>&1'
- GUICtrlSetData($Progress1, 100)
- _ClipBoard_SetData($String)
- FileDelete(@TempDir & "\BexaTmp.bat")
- FileWrite(@TempDir & "\BexaTmp.bat", $String)
- ShellExecute(@TempDir & "\BexaTmp.bat", '', '', "edit")
- elseif $Ubound > 1 Then
- $String &= '@echo off ' & @CRLF & ':"' & $sFile & '"' & @CRLF & 'For %%b In (' & @CRLF
- For $i = 0 To $Ubound - 1 Step 1
- $String &= ' "' & $sLi[$i] & '"' & @CRLF
- GUICtrlSetData($Progress1, $i/(($Ubound - 2)/100))
- Next
- $String &= ') Do >> "' & $FilCompress & '" (Echo.For b=1 To len^(%%b^) Step 2' & @CRLF & _
- 'Echo WScript.StdOut.Write Chr^(Clng^("&H"^&Mid^(%%b,b,2^)^)^) : Next)' & @CRLF & _
- 'Cscript /b /e:vbs "' & $FilCompress & '" > "' & $WithExt & '"' & @CRLF & 'Del "' & $FilCompress & '" >nul 2>&1'
- _ClipBoard_SetData($String)
- FileDelete(@TempDir & "\BexaTmp.bat")
- FileWrite(@TempDir & "\BexaTmp.bat", $String)
- ShellExecute(@TempDir & "\BexaTmp.bat", '', '', "edit")
- ;MsgBox(0, "<b style="color:#E89512">Bexa</b> v3.3", "Your file have been converted to hexadecimal and set in your batch file." & @CRLF & "ctrl + v if you want paste him")
- Endif
- FileRecycle($PathCompress)
- Endfunc
- Func _File_Au3xa($Path, $sFile="")
- if not FileExists($Path) then exit
- if $sFile = "" then Return
- Local $sOp, $sRe, $sLi, $Ubound, $String
- Local $WithExt = _FileGetName($Path)
- Local $GetExtention = StringSplit($WithExt, ".")
- $GetExtention = $GetExtention[$GetExtention[0]]
- $WithExt = StringReplace($WithExt, ".", "_")
- $sOp = FileOpen($Path, 16)
- $sRe = FileRead($sOp)
- FileClose($sOp)
- $sLi = StringRegExp($sRe, "(.{1,128})", 3)
- $Ubound = UBound($sLi)
- If $Ubound = 1 Then
- $String &= ';~ Local $Teste = _' & $sFile & '()' & @CRLF & ';~ _BinaryToFile(@DesktopDir & "\Teste.' &$GetExtention&'" , $Teste) ' & @CRLF
- $String &= 'Func _' & $sFile & '()' & @CRLF
- $String &= 'Local $FileName = ' & $WithExt & @CRLF
- $String &= 'Local _' & @CRLF & '$File_' & $sFile & ' = "' & $sLi[0] & '"' & @CRLF
- $String &= 'Return Binary(' & '$File_' & $sFile & ')' & @CRLF & 'Endfunc'
- _ClipBoard_SetData($String)
- GUICtrlSetData($Progress1, 100)
- elseif $Ubound > 1 Then
- $String &= ';~ Local $Teste = _' & $sFile & '()' & @CRLF & ';~ _BinaryToFile(@DesktopDir & "\Teste.' &$GetExtention&'" , $Teste) ' & @CRLF
- $String &= 'Func _' & $sFile & '()' & @CRLF
- $String &= 'Local $FileName = "' & $WithExt & '"' & @CRLF
- $String &= 'Local _' & @CRLF
- $String &= '$File_' & $sFile & ' = "' & $sLi[0] & '"' & @CRLF
- For $i = 1 To $Ubound - 1 Step 1
- $String &= '$File_' & $sFile & ' &= "' & $sLi[$i] & '"' & @CRLF
- GUICtrlSetData($Progress1, $i/(($Ubound - 2)/100))
- Next
- $String &= 'Return Binary(' & '$File_' & $sFile & ')' & @CRLF & 'Endfunc' & @crlf & @crlf
- $String &= 'Func _BinaryToFile($Path=Default, $Binary=Default)' & @CRLF
- $String &= 'if $Binary = Default or $Path = Default then Return' & @crlf
- $String &= 'FileDelete($Path)' & @CRLF
- $String &= 'FileWrite($Path, $Binary);~ ShellExecute($Path)' & @crlf & 'Return' & @CRLF & 'Endfunc'
- _ClipBoard_SetData($String)
- FileDelete(@TempDir & "\BexaTmp.au3")
- FileWrite(@TempDir & "\BexaTmp.au3", $String)
- ShellExecute(@TempDir & "\BexaTmp.au3", '', '', "edit")
- MsgBox(0, "<b style="color:#E89512">Bexa</b> v3.2", "Your file have been converted to hexadecimal and set in your Au3 file." & @CRLF & "ctrl + v if you want paste him")
- Return
- Endif
- Endfunc
- Func _GetHexaDec($Path=Default)
- if not FileExists($Path) then Return
- Local $sOp, $sRe, $sLi, $Ubound, $String
- $sOp = FileOpen($Path, 16)
- $sRe = FileRead($sOp)
- FileClose($sOp)
- $sLi = StringRegExp($sRe, "(.{1,256})", 3)
- $Ubound = UBound($sLi)
- $sLi[0] = StringTrimLeft($sLi[0], 2)
- if $Ubound = 1 Then
- $String &= $sLi[0] & @CRLF
- _ClipBoard_SetData($String)
- GUICtrlSetData($Progress1, 100)
- ElseIf $Ubound > 1 Then
- For $i = 0 To $Ubound - 1 Step 1
- $String &= $sLi[$i] & @CRLF
- GUICtrlSetData($Progress1, $i/(($Ubound - 2)/100))
- Next
- FileDelete(@TempDir&"\BexaTmp.txt")
- FileWrite(@TempDir&"\BexaTmp.txt", $String)
- ShellExecute(@TempDir&"\BexaTmp.txt", '', '', "edit")
- Endif
- Endfunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement