Jump to content

Extracting PNG images from a binary file, why are they scrambled?


Recommended Posts

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.bin

This is what the images look like when I extract them. Image 1 - 0000.png Image 2 - 3900_1.png

Each 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 - 5

Here 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)
EndFunc

P.S. I have an identical topic on r/learnprogramming if you would rather post there.

Link to comment
Share on other sites

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 by ApudAngelorum
Link to comment
Share on other sites

  • Moderators

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. :bye:

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. :oops:

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. :doh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...