Python Forum
Find offset of binary data in file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find offset of binary data in file
#1
Going back to a thread about .wav files (https://python-forum.io/Thread-From-theory-to-practice) it was brought up that some files contain additional information above that provided for in the original format.  I thought I would try and account for the 'extras'.  I thought I would start by checking the file for the word "data" and found this solution on SO which seems to work in determining if it exists or not.  
The problem I can't seem to grasp is how to determine the offset (or where the text begins) in the file.  For instance, I know in my test file, the word "data" begins at dec 36, hex 0x24.  

I've searched the Google and can't seem to find anything.  So I'm wondering if anyone has any suggestions as to where I might start looking.

Thanks
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#2
I think that s.find(b'data') returns starting position of first occurence of b'data', so 36 with your data.
Reply
#3
Absolutely right!   Clap

Thank you very much.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
position = file_handle.tell()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question in this code, I input Key_word, it can not find although all data was exact Help me! duchien04x4 3 971 Aug-31-2023, 05:36 PM
Last Post: deanhystad
  FileNotFoundError: [WinError 2] The system cannot find the file specified NewBiee 2 1,489 Jul-31-2023, 11:42 AM
Last Post: deanhystad
  How do I read and write a binary file in Python? blackears 6 5,999 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Cannot find py credentials file standenman 5 1,553 Feb-25-2023, 08:30 PM
Last Post: Jeff900
  selenium can't find a file in my desk ? SouAmego22 0 701 Feb-14-2023, 03:21 PM
Last Post: SouAmego22
  Find (each) element from a list in a file tester_V 3 1,155 Nov-15-2022, 08:40 PM
Last Post: tester_V
  get data from excel and find max/min Timmy94 1 1,076 Jul-27-2022, 08:23 AM
Last Post: Larz60+
  what will be the best way to find data in txt file? korenron 2 1,125 Jul-25-2022, 10:03 AM
Last Post: korenron
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
  Find and delete above a certain line in text file cubangt 12 3,349 Mar-18-2022, 07:49 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020