mrPuh Posted July 22, 2018 Share Posted July 22, 2018 Hi! In XML-file (attach) xd:inline parameter contains BASE64 encoded images. I decoding images and save to jpg-file with this function: Func _Encoding_Base64Decode($sData) Local $struct = DllStructCreate("int") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $sData, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $sData, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") ; error decoding EndIf Return BinaryToString(DllStructGetData($a, 1)) EndFunc But last image decoded only small part and image incorrect. In output data I see that image is gif and not jpg. Help me please decode this images. I need decode many images. Sorry for my English) xml.rar Link to comment Share on other sites More sharing options...
careca Posted July 22, 2018 Share Posted July 22, 2018 Come on, do we have to do everything to test this? Add code to open and read the file and whatnot. You get help faster if the script you post is reproducible out-of-the-box. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Danyfirex Posted July 22, 2018 Share Posted July 22, 2018 Hello Try this: expandcollapse popup#include <String.au3> #include <Array.au3> Local $sData = FileRead("xml.xml") Local $aData = _StringBetween($sData, 'xd:inline="', '"') _ArrayDisplay($aData) Local $sImageName = "" Local $hFile = 0 For $i = 0 To UBound($aData) - 1 $sImageName = "Image-" & $i + 1 & "." & _Base64ImageType($aData[$i]) $hFile=FileOpen($sImageName, 18) FileWrite($hFile, _Encoding_Base64Decode($aData[$i])) FileClose($hFile) Next Func _Base64ImageType($sBase64Image) Local $sType = "" Local $sChar = StringMid($sBase64Image, 1, 1) Switch $sChar Case "/" $sType = "jpg" Case "R" $sType = "gif" Case "i" $sType = "png" Case Else EndSwitch Return $sType EndFunc ;==>_Base64ImageType Func _Encoding_Base64Decode($sData) Local $struct = DllStructCreate("int") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $sData, _ "int", 0, _ "int", 1, _ "ptr", 0, _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(1, 0, "") ; error calculating the length of the buffer needed EndIf Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]") $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _ "str", $sData, _ "int", 0, _ "int", 1, _ "ptr", DllStructGetPtr($a), _ "ptr", DllStructGetPtr($struct, 1), _ "ptr", 0, _ "ptr", 0) If @error Or Not $a_Call[0] Then Return SetError(2, 0, "") ; error decoding EndIf Return BinaryToString(DllStructGetData($a, 1)) EndFunc ;==>_Encoding_Base64Decode Saludos mLipok 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mrPuh Posted July 23, 2018 Author Share Posted July 23, 2018 7 hours ago, Danyfirex said: Hello Try this: Hello Danyfirex! Thank you for you answer! But last image incorrect ( Screenshot in attachment. Link to comment Share on other sites More sharing options...
mrPuh Posted July 23, 2018 Author Share Posted July 23, 2018 I found that if there is a (;) character in the string then images is corrupted after decoding. But how I can solve this... Link to comment Share on other sites More sharing options...
Deye Posted July 23, 2018 Share Posted July 23, 2018 insert this to skip that one line .. For $i = 0 To UBound($aData) - 1 If StringInStr($aData[$i] ,';') Then ContinueLoop Link to comment Share on other sites More sharing options...
careca Posted July 23, 2018 Share Posted July 23, 2018 (edited) Not only that, but there's a pattern of 
 so maybe it's more than just the ; Edited July 23, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
jchd Posted July 23, 2018 Share Posted July 23, 2018 (edited) It's the escape sequence for linefeed (0x0A). Replace "
" before base64-decode. Edited July 23, 2018 by jchd Danyfirex 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
mrPuh Posted July 28, 2018 Author Share Posted July 28, 2018 On 23.07.2018 at 4:42 PM, jchd said: It's the escape sequence for linefeed (0x0A). Replace "
" before base64-decode. jchd thank you very much! I replace this symbol and problem is solved. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now