UEZ

File to Base64 String Code Generator v1.20 Build 2015-01-20 (embed your files easily)

123 posts in this topic




I wanted to try your example but when mouse is over bottom button, merlin disapears...


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Very similar to this script:

I make use of Base64 encoding features, the compression is much better!

João Carlos.

Indeed, very similar script. Well, I implemented also a Base64 version but the compression wasn't better. Have a look here: Base64 version

Either I missed something or it is as it is.

I wanted to try your example but when mouse is over bottom button, merlin disapears...

This appears with Windows XP only. Just move these 2 lines

_WinAPI_DeleteObject($Bmp_Logo)
_WinAPI_DeleteObject($Bmp_Button)

to

Case $GUI_EVENT_CLOSE
            _WinAPI_DeleteObject($Bmp_Logo)
            _WinAPI_DeleteObject($Bmp_Button)
            GUIDelete($hGUI)
            Exit

and should work. Btw, the button looks awful on WinXP :D

Thanks for your feedback!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

@UEZ

I have a sample image with 296 KB when converted with your script the size is 573 KB and with my script is 397 KB!

João Carlos.


http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Share this post


Link to post
Share on other sites

Changed the code from binary string to base64 string to save some more bytes :D

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Your first version worked fine, this one crashes on my Win7-64bit while converting.

Strange, because I'm using Win7 x64 in general, too! Which file your are converting and on which stage it is crashing (while compression or base64 converting)? What is the error code?

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

It crashes in the _Base64Encode() function. I've got DEP activated, and I guess you're missing a _MemVirtualAlloc() for the codebuffer there.

Edit: Btw, this one came exactly at the right time and the "File to Hex Binary Converter" version went right into :D, thanks a lot! I'll switch to the Base64 on the next release.

Edit #2:

Add #include <Memory.au3> at the top and change the _Base64Encode() function to this :oops:...

Func _Base64Encode($Data, $LineBreak = 0)
    Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152" _
                                  & "535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778" _
                                  & "797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB6" _
                                  & "33C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB633" _
                                  & "83E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E806" _
                                  & "0FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6" _
                                  & "730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC0475" _
                                  & "0C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000"
    Local $pProc = _MemVirtualAlloc(0, BinaryLen($Opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]",$pProc)
    DllStructSetData($CodeBuffer, 1, $Opcode)
    $Data = Binary($Data)
    Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
    DllStructSetData($Input, 1, $Data)
    $LineBreak = Floor($LineBreak / 4) * 4
    Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3)
    $OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4
    Local $Ouput = DllStructCreate("char[" & $OputputSize & "]")
    DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), "ptr", DllStructGetPtr($Input), "int", BinaryLen($Data), "ptr", DllStructGetPtr($Ouput), "uint", $LineBreak)
    _MemVirtualFree($pProc, BinaryLen($Opcode), $MEM_DECOMMIT)
    Return DllStructGetData($Ouput, 1)
EndFunc   ;==>_Base64Encode
Edited by KaFu

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Fixed some bugs (no base64 conversation on small files and checkbox logic issues) and added DEP check to add program to the exclusion list to avoid hard crash.

Edit: I will add the modified _Base64Encode() function by KaFu in the next release!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#12 ·  Posted

Grrr, sorry, found another bug when compression is unselected! Last 2 lines of the function have been forgotten! :D

Br,

UEZ :oops:


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#13 ·  Posted

Updated to v0.94 Build 2011-11-01 Beta.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#14 ·  Posted

Updated to v0.99 -> added multi file support.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

@jscript: your are welcome.

Updated to v1.00 final and changed name to File to Base64 String Code Generator.

If you find bugs or have any suggestions please let me know!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#17 ·  Posted

Very nice script!

Would suggest to check if compression reduced size, if not continue with uncompressed data.

Share this post


Link to post
Share on other sites

#18 ·  Posted

Very nice script!

Would suggest to check if compression reduced size, if not continue with uncompressed data.

Thanks for you suggestion - makes sense!

Next release will check whether compression increases the size and skip to uncompressed binary automatically!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#19 ·  Posted

UEZ, you are giving me credit for base64 code but that code is not mine as far as I know. The only base64 code I have ever used in that form is Ward's and it's inside AutoItObject.au3, working in both x86 and x64 versions of interpreter.

I have written base64 UDF code using Windows API for, but not this.


 

.

eMyvnE

Share this post


Link to post
Share on other sites

#20 ·  Posted

You're right, seems to be Wards code and I would recommend to switch to Wards code as these functions support x64 as well :D (+ this is already DEP save).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • 31290
      Download file with name changing
      By 31290
      Hi Guys, 
      Hope you're doing fine today.
      Well, I'm trying to achieve something I want to integrate to a tool I already created.
      At work, we deploy computers massively and we use the tool to perform automatic operations. Then, we have to update the BIOS to the latest version. To avoid a heavy tool, I'd like to automatically download the latest BIOS on the Dell Website but the thing is that the name of the fail change when a new version is published. Of course, I cannot know what version will be deployed by Dell but I have this when connecting to the website:

      Thus, I don't know if the FOLDERXXXXX of the download URL will change if a new version ins deployed. 

      Here's one of the pages of a model we also use: http://www.dell.com/support/home/us/en/19/product-support/product/latitude-e5450-laptop/drivers/advanced
      Well, i'm kind of stuck here and maybe someone could point something out
      Thanks in advance
    • bobbyab9987
      How to open multiple files in only one instance of the corresponding program?
      By bobbyab9987
      Hi friends,
      Suppose MyProgram is a tabbed program, meaning that it allows for opening multiple files in the same instance.
      I want to open File1, File2 and File3 in one instance of MyProgram from an AutoIT script. How can I do this?
      I have read the AutoIT Help File about "ShellExecute" and "Run", but I have found nothing helpful.
      Thanks for reading my question. Any answer would be very appreciated.
       
       
    • noorm
      Base64 decoder/encoder, Internet header decoders, email subject decoder, UTF-8, ISO-8859-1, telnet negociations
      By noorm
      Hello!
      I've been lurking around for a loooong time... and I decided to finally share a little. I do a lot of internet stuff, mostly machine to machine for work (instrumentation) so I have quite a few "RFC" scripts.
      Disclaimer these work for me... but I sometime use... "shortcuts" based on my particular requirement. An example, the Base64 encoding snippet might not be too good for binary data. I pad the original data with spaces to avoid the "==" padding of base64.
      So... first is the base64 encoding snippet. It is not in a function, it was in a sequential program, used only once! It encode $Graph to $SMTPMessage:
      ; Create the base64 encoding table Dim $Base64EncodingTable[0] For $Cpt = Asc("A") to Asc("Z") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next For $Cpt = Asc("a") to Asc("z") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next For $Cpt = Asc("0") to Asc("9") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next _ArrayAdd($Base64EncodingTable, "+") _ArrayAdd($Base64EncodingTable, "/") ; Pad the SVG Graph to attach with space(s). Lazy way to avoid base64 == pading While Mod(StringLen($Graph), 3) <> 0 $Graph &= " " WEnd ; Start from the first character $Cpt = 1 Do ; Extract the 3 characters to encode $Char1 = Asc(StringMid($Graph, $Cpt, 1)) $Char2 = Asc(StringMid($Graph, $Cpt+1, 1)) $Char3 = Asc(StringMid($Graph, $Cpt+2, 1)) ; Encode them to 4 characters $SMTPMessage &= $Base64EncodingTable[BitShift(BitAND($Char1, 252), 2)] $SMTPMessage &= $Base64EncodingTable[BitShift(BitAND($Char1, 3), -4) + BitShift(BitAND($Char2, 240), 4)] $SMTPMessage &= $Base64EncodingTable[BitShift(BitAND($Char2, 15), -2) + BitShift(BitAND($Char3, 192), 6)] $SMTPMessage &= $Base64EncodingTable[BitAND($Char3, 63)] ; Increment the counter, and if required, add a @CRLF to split in multiples lines $Cpt += 3 If Mod($Cpt, 57) = 1 Then $SMTPMessage &= @CRLF ; Do this until all the graph has been encoded Until $Cpt >= StringLen($Graph)  
      Second... I just finished this one and was allready thinking about sharing it... so it's been encapsulated into function a bit more. I use it to decode email subjects in a system where you can update something by email. I separated the Base64Decode function so it can be grabbed more easily. Please note that it return an hex string so you would still need to convert it if it's a string with BinaryToString or whatever suit your needs.
      If can be copied as is and runned directly... it include my test strings! (Yes... I'm french!)
      ; For the $SB_UTF8 and $SB_ANSI Variable #include <StringConstants.au3> ; For _ArrayAdd and _ArraySearch used in the Base64 decoder #include <Array.au3> ; Various test sentences... ;$text = "=?UTF-8?Q?Ce=c3=a7i_est_un_autre_test!_h=c3=a9h=c3=a9!?=" ; Normal UTF-8 ;$text = "=?UTF-8?Q?Encore_=3d_un_autre_test_=c3=a9_?=" ; "=" added ;$text = "=?UTF-8?Q?un_autre_test_=5f_=c3=a9?=" ; "_" added ;$text = "=?UTF-8?B?Q2XDp2kgZXN0IHVuIGF1dHJlIHRlc3QhID0gXyBow6low6kh?=" ; UTF-8 Base64 $text = "=?UTF-8?B?ZcOnaSBlc3QgdW4gYXV0cmUgdGVzdCEgPSBfIGjDqWjDqSE=?=" ; UTF-8 Base64 with padding ;$text = "=?iso-8859-1?Q?Ce=E7i_est_un_test!?=" ; iso-8859-1 MsgBox(0, "", DecodeHeader($text)) Func DecodeHeader($lString) ; Check and store encoding type If StringInStr($lString, "?Q?") Then ; Quoted printable content $lType = "?Q?" ElseIf StringInStr($lString, "?B?") Then ; Base64 encoding $lType = "?B?" Else ; No encoding (or unknown encoding) return($lString) EndIf ; Start of the charset string $lStart = StringInStr($lString, "=?") + 2 ; End of the charset string $lStop = StringInStr($lString, $lType) ; Charset variable, storing "UTF-8" or "iso-8859-1" $lEncoding = StringMid($lString, $lStart, $lStop-$lStart) ; Change encoding type for the BinaryToString flag If $lEncoding = "UTF-8" Then $lEncoding = $SB_UTF8 ElseIf $lEncoding = "iso-8859-1" Then $lEncoding = $SB_ANSI Else MsgBox(0, "", "Unknown character set") Exit EndIf ; Start of the actual encoded content $lStart = $lStop + 3 ; End of the actual encoded content $lStop = StringInStr($lString, "?=") ; Actual content to decode $lString = StringMid($lString, $lStart, $lStop-$lStart) ; For Quoted printable content If $lType == "?Q?" Then ; Restore underscore encoded spaces $lString = StringReplace($lString, "_", " ") ; Starting with the first character of the string $lCpt = 1 ; "=XX" search and convert loop While 1 ; There will be 0 characters to convert in that block unless... $lConvertableLenght = 0 ; That character, and another one 3 bytes over... and the next, and the next... For $lCpt2 = 0 to 100 ; Is equal to "=" If StringMid($lString, $lCpt+($lCpt2*3), 1) == "=" Then ; In that case, yes, we will have to convert 3 more characters $lConvertableLenght += 3 Else ; But if we fail to find or reach the end of a block of encoded characters, exit the search ExitLoop EndIf Next ; If we did in fact find some encoded characters If $lConvertableLenght > 0 Then ; Extract that block of encoded characters $lConvertableString = StringMid($lString, $lCpt, $lConvertableLenght) ; Convert it $lConvertedString = BinaryToString("0x" & StringReplace($lConvertableString, "=", ""), $lEncoding) ; Replace it in the original $lString = StringReplace($lString, $lConvertableString, $lConvertedString) EndIf ; Increment the "=XX" search and convert loop counter $lCpt += 1 ; If we reached the end of the string, exit the "=XX" search and convert loop If $lCpt >= StringLen($lString) Then ExitLoop ; Continue searching in the "=XX" search and convert loop WEnd ; For Base64 encoded strings Else ; Use the separate Base64Decode function $lString = Base64Decode($lString) $lString = BinaryToString($lString, $lEncoding) EndIf return($lString) EndFunc Func Base64Decode($lEncoded) ; Create the base64 encoding table Dim $Base64EncodingTable[0] For $Cpt = Asc("A") to Asc("Z") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next For $Cpt = Asc("a") to Asc("z") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next For $Cpt = Asc("0") to Asc("9") _ArrayAdd($Base64EncodingTable, Chr($Cpt)) Next _ArrayAdd($Base64EncodingTable, "+") _ArrayAdd($Base64EncodingTable, "/") ; Start from the first character $Cpt = 1 $Decoded = "0x" Do ; Extract the 4 characters to encode $Char1 = StringMid($lEncoded, $Cpt, 1) $Char2 = StringMid($lEncoded, $Cpt+1, 1) $Char3 = StringMid($lEncoded, $Cpt+2, 1) $Char4 = StringMid($lEncoded, $Cpt+3, 1) ; Decode them $Decoded &= Hex(BitShift(_ArraySearch($Base64EncodingTable, $Char1, 0, 0, 1), -2) + BitShift(BitAnd(_ArraySearch($Base64EncodingTable, $Char2, 0, 0, 1), 48), 4), 2) If $Char3 <> "=" Then $Decoded &= Hex(BitShift(BitAnd(_ArraySearch($Base64EncodingTable, $Char2, 0, 0, 1), 15), -4) + BitShift(BitAnd(_ArraySearch($Base64EncodingTable, $Char3, 0, 0, 1), 60), 2), 2) If $Char4 <> "=" Then $Decoded &= Hex(BitShift(BitAnd(_ArraySearch($Base64EncodingTable, $Char3, 0, 0, 1), 3), -6) + _ArraySearch($Base64EncodingTable, $Char4, 0, 0, 1), 2) ; Increment the counter $Cpt += 4 ; Do this until all the encoded string has been decoded Until $Cpt >= StringLen($lEncoded) return($Decoded) EndFunc  
      Last thing... I may update it into a better format for you, like a standalone telnet program with GUI. It is my telnet options negociations loops. The basic concept is systematically deny all request for special options and keep it "raw".
      If server says "Will", I reply "Don't". If it says "Do", I reply "Wont"... unless it's the terminal type subnegociation, in which case I reply xterm!
      $Data for now needs to be Global. You still need to know what you're doing, opening sockets and making a basic communication loop or something.
      Global $T_Is = Chr(0) Global $T_Send = Chr(1) Global $T_TerminalType = Chr(24) Global $T_SE = Chr(240) Global $T_SB = Chr(250) Global $T_Will = Chr(251) Global $T_Wont = Chr(252) Global $T_Do = Chr(253) Global $T_Dont = Chr(254) Global $T_IAC = Chr(255) Func NegotiateTelnetOptions() $NegotiationCommandsToSendBack = "" While StringInStr($Data, $T_IAC) $IACPosition = StringInStr($Data, $T_IAC) Switch StringMid($Data, $IACPosition+1, 1) Case $T_Will $NegotiationCommandsToSendBack &= CraftReply_CleanUpData($IACPosition, $T_Dont) Case $T_Do If StringMid($Data, $IACPosition+2, 1) = $T_TerminalType Then $NegotiationCommandsToSendBack &= CraftReply_CleanUpData($IACPosition, $T_Will) Else $NegotiationCommandsToSendBack &= CraftReply_CleanUpData($IACPosition, $T_Wont) EndIf Case $T_SB If StringMid($Data, $IACPosition, 6) = ($T_IAC & $T_SB & $T_TerminalType & $T_Send & $T_IAC & $T_SE) Then $NegotiationCommandsToSendBack &= $T_IAC & $T_SB & $T_TerminalType & $T_Is & "xterm" & $T_IAC & $T_SE $Data = StringReplace($Data, StringMid($Data, $IACPosition, 6), "") Else MsgBox(0, "", "Unknown Subnegotiation...") ; Should never happen. Exit EndIf EndSwitch WEnd Return $NegotiationCommandsToSendBack EndFunc Func CraftReply_CleanUpData($IACPosition, $Reply) $PartialCommandToSendBack = $T_IAC & $Reply & StringMid($Data, $IACPosition+2, 1) $Data = StringReplace($Data, StringMid($Data, $IACPosition, 3), "") Return $PartialCommandToSendBack EndFunc  
    • Wicked_Caty
      Problems with DirMove
      By Wicked_Caty
      I want to move the content of D:\downloads to D:\pictures in my program. I found DirMove, but that causes problems...
      Func Move($dest) DirMove("D:\downloads\", "D:\pictures\ABC\" & $dest) DirCreate("D:\downloads") EndFunc In a prior program exactly this piece of code did the job always properly, but now not anymore. The source path stays untouched, and a destination folder is created but empty.
      I don't have a clue why it doesn't work anymore now. I've checked it dozens of times, read the article about DirMove, tried it with dozens of different combinations, but none lead to the result. I want the content of D:\downloads in D:\pictures\ABC without having another downloads folder within the destination folder or anything else... Thanks!
      D:\downloads\cute_kitten.jpg should be D:\pictures\ABC\cute_kitten.jpg afterwards.
    • NiceBoy1234
      get modificaton date of folder
      By NiceBoy1234
      Whats is the best method to know if a specific folder has changed his files.
      In my case I want to check if pictures in my folder have been changed or not.
      (If someone is interest in future plans I want to count afterwards the files in that folder, but that is not important now)
      Can anyone help me out, I though of something like getting the current modification date and comparing it somehow with the future one but I do not know if something like that is even possible.

      SO basically again I "Just" want to check if a specific folder ( files in that folder) have been changed.