acme_pjz
12 Jun 2008, 13:11
I had discovered the compress and decompress algorithm of *.img file by decompile landgen.exe using IDA+HexRays Decompiler.
These are decompress codes:
Private Sub DecompressTest(lpbm() As Byte, lpbuf() As Byte)
On Error GoTo a
Dim v5 As Long 'repeat count
Dim nbm As Long 'lpbm
Dim nbuf As Long 'lpbuf
Dim nOffset As Long
'////////////////compress format
'////////////////1 byte:
'0xxxxxxx
'x=color=0-127
'////////////////2-byte: repeat=3-17
'1rrrrooo oooooooo
'r+2=repeat
'o+1=offset=1-&h800&
'////////////////3-byte: repeat=18-273
'10000ooo oooooooo rrrrrrrr
'r+18=repeat
'o=offset=1-&h7ff&
'////////////////2 byte: EOF
'10000000 00000000=&h80 &h00
Do
Do
Do
v5 = lpbuf(nbuf)
If v5 And &H80& Then Exit Do
lpbm(nbm) = v5 'm_clrs(v5)
nbuf = nbuf + 1
nbm = nbm + 1
Loop
nOffset = (v5 * 256& + lpbuf(nbuf + 1)) And &H7FF&
v5 = (v5 \ 8&) And &HF&
If v5 = 0 Then Exit Do
nOffset = nOffset + 1
v5 = v5 + 2
Do
lpbm(nbm) = lpbm(nbm - nOffset)
nbm = nbm + 1
v5 = v5 - 1
Loop While v5
nbuf = nbuf + 2
Loop
If nOffset = 0 Then Exit Do
v5 = lpbuf(nbuf + 2) + 18&
Do
lpbm(nbm) = lpbm(nbm - nOffset)
nbm = nbm + 1
v5 = v5 - 1
Loop While v5
nbuf = nbuf + 3
Loop
Exit Sub
a:
MsgBox "Error in decompressing data!", vbExclamation
End Sub
and the compress algorithm:
These are decompress codes:
Private Sub DecompressTest(lpbm() As Byte, lpbuf() As Byte)
On Error GoTo a
Dim v5 As Long 'repeat count
Dim nbm As Long 'lpbm
Dim nbuf As Long 'lpbuf
Dim nOffset As Long
'////////////////compress format
'////////////////1 byte:
'0xxxxxxx
'x=color=0-127
'////////////////2-byte: repeat=3-17
'1rrrrooo oooooooo
'r+2=repeat
'o+1=offset=1-&h800&
'////////////////3-byte: repeat=18-273
'10000ooo oooooooo rrrrrrrr
'r+18=repeat
'o=offset=1-&h7ff&
'////////////////2 byte: EOF
'10000000 00000000=&h80 &h00
Do
Do
Do
v5 = lpbuf(nbuf)
If v5 And &H80& Then Exit Do
lpbm(nbm) = v5 'm_clrs(v5)
nbuf = nbuf + 1
nbm = nbm + 1
Loop
nOffset = (v5 * 256& + lpbuf(nbuf + 1)) And &H7FF&
v5 = (v5 \ 8&) And &HF&
If v5 = 0 Then Exit Do
nOffset = nOffset + 1
v5 = v5 + 2
Do
lpbm(nbm) = lpbm(nbm - nOffset)
nbm = nbm + 1
v5 = v5 - 1
Loop While v5
nbuf = nbuf + 2
Loop
If nOffset = 0 Then Exit Do
v5 = lpbuf(nbuf + 2) + 18&
Do
lpbm(nbm) = lpbm(nbm - nOffset)
nbm = nbm + 1
v5 = v5 - 1
Loop While v5
nbuf = nbuf + 3
Loop
Exit Sub
a:
MsgBox "Error in decompressing data!", vbExclamation
End Sub
and the compress algorithm: