CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007
    Posts
    52

    Hex reading problems

    I have a huge binary file and I want to quicky edit it with a python script.
    I want to search the file for the bytes

    Code:
    54 45 58 30 00 00 20 40 00 00 00 01 FF FF FE E0
    00 00 00 40 00 04 CF 44 00 00 00 00 00 80 00 80
    00 00 00 0E 00 00 00 01 00 00 00 00 00 00 00 00
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
    or the string
    Code:
    TEX0 @ÿÿþ*@ÏD€€
    and replace all the bytes after that to the next occurrence of the string with a different hex file that I want to read in.

    I'm having problem reading in these huge (534kb) files. When I say huge I mean to big to edit by hand. I'm not familiar with hex or how its read. The literal string that I copied from my hex editor was turned into that when it looks nothing like that in the actual editor.
    KTNXBYE

  2. #2
    Join Date
    Oct 2008
    Posts
    51

    Re: Hex reading problems

    Open the file as binary
    Code:
    f = open('filename', 'rwb')
    lostString = string # Lost because we are searching for it ;) but seriously this is a list of hex e.g. 0xAB
    count = 0
    while count != len(lostString):
        if f.read(1) == lostString[count]:
            count += 1
        else:
            count = 0
    This should put you at your byte then you just have to modify that byte and shift the rest of the data down.

    Also refrence http://snippets.dzone.com/posts/show/740

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured