SKCIDLOL Posted March 28, 2012 Share Posted March 28, 2012 I am trying to extract some PNG images from a binary file. I thought I had it figured out but the images are coming out scrambled. Does anybody know why or how to fix them?Here's a sample of the binary file which contains two images. Test.binThis is what the images look like when I extract them. Image 1 - 0000.png Image 2 - 3900_1.pngEach image has a variable sized header before it. This is what I've worked out, but I'm unsure of its veracity.10 bytes constant, unknown 08 bytes variable, unknown 04 bytes (dword), Image data size + 5 04 bytes (dword), Image data size - 15 02 bytes (word), Length of image name 02 bytes (word), Offset of image data from end of file name - 5Here is the code I'm using to extract the images.#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include _Main() Func _Main() Local $s_File = @ScriptDir & "\Test.bin", $h_Temp, $i_Length, $i_Offset, $i_Read, $i_Size, $i_Written, $s_Path, $t_File, $t_Header Local $h_File = _WinAPI_CreateFile($s_File, 2, 2), $tag_Header = "align 1;byte[10];byte[8];dword;dword;word;word;" While 1 $t_Header = DllStructCreate($tag_Header) _WinAPI_ReadFile($h_File, DllStructGetPtr($t_Header), DllStructGetSize($t_Header), $i_Read) If Not $i_Read Then ExitLoop $i_Size = DllStructGetData($t_Header, 3) - 5 $i_Length = DllStructGetData($t_Header, 5) $i_Offset = DllStructGetData($t_Header, 6) + 5 $t_File = DllStructCreate("align 1;char[" & $i_Length & "];byte[" & $i_Offset & "];byte[" & $i_Size & "];") _WinAPI_ReadFile($h_File, DllStructGetPtr($t_File), DllStructGetSize($t_File), $i_Read) $s_Path = StringReplace(@ScriptDir & "\" & DllStructGetData($t_File, 1), "/", "\") DirCreate(StringTrimRight($s_Path, (StringLen($s_Path) - StringInStr($s_Path, "\", 0, -1)))) $h_Temp = _WinAPI_CreateFile($s_Path, 1) _WinAPI_WriteFile($h_Temp, DllStructGetPtr($t_File, 3), $i_Size, $i_Written) _WinAPI_CloseHandle($h_Temp) WEnd _WinAPI_CloseHandle($h_File) EndFuncP.S. I have an identical topic on r/learnprogramming if you would rather post there. Link to comment Share on other sites More sharing options...
Skitty Posted March 28, 2012 Share Posted March 28, 2012 (edited) I am trying to extract some PNG images from a binary file. I thought I had it figured out but the images are coming out scrambled. Does anybody know why or how to fix them?Apparently there's nothing wrong with your script there, it's just that the images are compressed or modified in some way, shape or form, I extracted them with a hex editor and got the same result, this can only lead to the previously said conclusion. Edited March 28, 2012 by ApudAngelorum Link to comment Share on other sites More sharing options...
Blue_Drache Posted March 28, 2012 Share Posted March 28, 2012 Yay! game related post! Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 28, 2012 Moderators Share Posted March 28, 2012 SKCIDLOL,Looking at the images I can see why Blue_Drache has reported this thread as "game-related". However, you are not trying to automate the game (which is what the rules forbid) just extract images from a file - so I would normally be inclined to let this run. But, looking at the corrupted images you posted, I believe that your quest is doomed to failure because it looks as if the game authors have added some form of encryption to them - almost certainly to prevent someone doing what you are trying to do. So I feel you are almost certainly breaching the "[do not] violate the license agreement for software" clause in the rules - so I am locking the thread anyway. Besides, it appears there is nothing wrong with your code, so there is little more we can offer in the way of help with your AutoIt script. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts