最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

hex - Converting (I think) hexidecimal data to an image; possibly Delphi file format - Stack Overflow

programmeradmin2浏览0评论

NOTE: I deliberately didn't tag this with Python, even though that's what the code I've tried so far has been in, because I'm happy to use any language to solve this, it's really a data conversion problem and the language isn't relevant, feel free to suggest C or Java or anything really.

I've used eXeScope to access the resources in an old freeware .exe (Jetmen Revival 2D). One of the texts found there has a bunch of hexadecimal (I think, they're alphanumeric at least) codes representing sound effects that I've successfully parsed and converted to .wmv in Python, but there's also a bunch of entries that seem to be representing images or fonts (I assume those are just bitmaps of all the letters) in the file that I'm having more trouble with. ChatGPT keeps telling me it's a Delphi (.dfm) image format, but I can't actually find a converter to convert it to .bmp or .raw, and pasting the hex files into various converters gives me corrupted files every time, even after manually removing all the whitespace. I've officially reached the limit of my zoomer knowledge of image formats from 2003.

The file it's all in is called TFORM1 and has a long header with keybinds, stuff about pixels and window size and fonts.

ChatGPT suggested a similar solution to the sound file conversion (which did work for those), also in Python:

hex_data = hex_data.replace("\n", "").replace(" ", "")

# Convert hex to bytes
binary_data = binascii.unhexlify(hex_data)

# Save as BMP file
with open("output.bmp", "wb") as bmp_file:
    bmp_file.write(binary_data)

print("BMP file saved as output.bmp")

...which just gave me a:

not valid .bmp file

in GIMP, then corrected itself to:

hex_data = hex_data.replace("\n", "").replace(" ", "")

# Convert hex to bytes
binary_data = binascii.unhexlify(hex_data)

# Delphi Picture.Data starts with a header, so we need to find the BMP header (starts with 'BM')
bmp_start = binary_data.find(b'BM')
if bmp_start == -1:
    print("No valid BMP header found!")
else:
    bmp_data = binary_data[bmp_start:]  # Extract BMP portion

    # Save as BMP file
    with open("output.bmp", "wb") as bmp_file:
        bmp_file.write(bmp_data)

    print("BMP file saved as output.bmp")

The execution just trips the initial if statement and prints:

No valid BMP header found!

every time, so I think this is just beyond what ChatGPT knows how to do. Here's one of the images:

  item
    Name = 'Medal5'
    PatternHeight = 0
    PatternWidth = 0
    Picture.Data = {
      045444494228000000140000002C000000010008000000000070030000000000
      0000000000000000000000000000000000FFFFFF000683A00095911400AE9F4C
      00AC9D4B00A79949009E904500BBAB5200B8A85100B6A75000B4A54F00B2A34E
      00B1A24E00B0A14D00AFA04D00AD9E4C00AB9C4B00AA9B4B00A99B4A00A09246
      00918D13008986120089851200827E1100817E11007A771000949014008F8C13
      008C8913008784120086821200858112007F7C11007E7B11007D7A1100777410
      00928E14008A861300009DBA000098B200008FA70000829A0000627300029DB7
      00049BB50010A2BD0020A1B80024ABC30030ABC10035ACC20000A9CC0000A3C5
      00009EBF00009DBF00009EBD00009CBD00009BBC00009BBA000098B8000097B7
      000098B7000096B4000094B1000093B1000093AF000091AF00008FAE000091AC
      00008CAA00008EA900008CA900008BA9000089A700008AA700008AA5000088A5
      000089A3000087A2000085A2000087A00000839F0000839C0000819B00007D97
      00007B9500007C95000078900000748B0000708500005F730000596C00005566
      0000516200004C5B00003E4B00003B4700002E3800029CBD00029BBC000AAFD3
      000999B6000B97B50012ABCC0015A5C40015A3C20020AFCE001D9FBB0023B9D9
      0020A9C60024ABC5002EBBD7002FB2CB002FAFCA002FADC8002FA6C0002FA9C0
      0045BAD20045BAD00045B8CF0045B7CE0045B6CD0045B4CC004CB8CF004CB3C7
      004CB2C5004CB0C5005BBFD40082CFDF0082CDDD008ED3E10090D3E10094D6E3
      00009EC500009CC100009EC100009BBE000099BC000096BB000099BB000097B9
      000095B8000093B7000095B6000094B5000093B5000091B400008FB3000092B2
      000090B000008DAC00008BAB000087A9000084A100007E9B00007D9900007B97
      000079940000718A000069800000627A00005669000051650000526400004D5E
      00004B5C00004858000046560000435200003F4D000036420000313D00029EC2
      000597B70007A6CA0005789300057792000576900005758F0008A9CD0006829F
      0006819E0006809D00067F9C00067E9A0005748E0005728C0005728B0005718A
      0005708900056F8800056E8700056D8500056B8300056A810005698100067D98
      00067C9700067B9700067A9500067994000678930005677D0005657C000B9DBF
      0011A0C100139DBF0019A4C3001DADCD0021A7C60024B2D3002BB7D8002DB4D6
      002DADCA0033B5D2002FA1BA003FB0C90045B7D00045B5CE0047B8D10045B3CD
      004CB9D2004CB3CA004CACC20061C1D80070C2D60082CFE00082CDDE0082CBDC
      00ACDEE9000082A40082CEE200DCE1E500DADFE300D7DCE000D6DBDF00F4F9FD
      00F1F6FA00F0F5F900EFF4F800ECF1F500EAEFF300E9EEF200E5EAEE00E4E9ED
      00DFE4E800DEE3E700F5FAFF00F4F9FE00F3F8FD00D9DDE100D0D4D800E7EBF0
      00E3E7EC00DFE3E8000000000000000000000000000000000000000000000000
      0000000000000000A5A85FA960610000000000000000000000005B5A5854549F
      A0A1A9610000000000000000002B9EE68A85713B56989DA3AB00000000000000
      5850958D8E8DD2684A933953A1AA0000000000524A3B388B8BCF386B679B3D3D
      9A5CAA00000000468A853636AC6A4566D649428B8F9DA70000002D2D928D368B
      69644839D4B3998A35475A600000322F8F393963D0432787CE6F4B943A3D575E
      00007C743B8786CDAE4A8D8A3BD6334D3A894FA200007D73888B39D04A3F3991
      3ECED349948C51A200007E73398B64B32A414040282CD534518F4E5D0000DFD7
      35386C974A95404229406B3054964EA40000DE7090652E4C412942409543ADD6
      904A57A600007B703C6E488F2C28404041443C6DD1559C5E0000DD728C77638E
      8E3E91393D428B627A88565E0000E0DBCC373535393B8A8D3B8C8B86873B2A5C
      000084827F79D97778DC75767AD97978DAD84459000000E583E2E2E3E2E780E3
      E2E381E2E4E13100000000000000000002F70808F70200000000000000000000
      0000000002F70808F702000000000000000000000000000202F70808F7020200
      00000000000000000000020202F70808F7020202000000000000000000000202
      02F70808F7B4B6B70000000000000000000202B4B6EE0909EEC5B2BDBE000000
      0000000000C4B8C4C7F40E0CF1B0BFC2C3000000000000001EBCBCBBBAEA0605
      FCC4C7B0B22600000000000020BDBEBEBCFB0714E8B8B4B5B51B000000000026
      1EB0B1B0C7F30F0EF2B50202020303000000002616C8C8C6B6F90808F8020202
      020303000000001E1FB1B0C8C4F00B09F702020202030300000000191AC3C1BF
      BBEB060FEDB6C4C4C41C1B000000002023C1C0BDB2F61110FDBBC1C2C1211E00
      000000151DC8C9AFB0F61306EBC2CACBCB2423000000001B25B7B7C6C8F51211
      E9BDBFBEBD2017000000001C1DC7C7C6C7F50504F3C6C4C4B8251B0000000017
      1EB0B1B1B1E90606FEC8C4B6020303000000002118B0C7C6C6F41206FABAB9C7
      B61B0300000000221AC0BBB1C7F20B0BF0C4C6C4B61B03000000001619BFBFBB
      BAEA130DEDB4B4B4B40303000000001C17B1B9B2C9FE1304EFB4020202030300
      0000001B15B7C6C6B6ED0A09EC020202020303000000000303B4B5B5B4F70808
      F702020202030300000000000000000000000000000000000000000000}
    SystemMemory = False
    Transparent = True
    TransparentColor = clBlack
  end

Yes, I noticed the } at the end of the text - that's not the problem.

发布评论

评论列表(0)

  1. 暂无评论