Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Searching binary file for a particular string location


edwinrajeev Aug 2, 2019 06:21 PM

Hi , 

I am trying to write a code to search for a hex string within a binary file and extracting a subsequent data value which is locate 12 bytes from the location of the string. The following is the code. But I am not able to successfully locate it within the file. 


Public FileHandle

Public Ensemblestring

Const MaxEnsembleLength = 400000

Public offset As Long

Public Instring As Long

Const distancebyte = 12

Public Distance As Float

DataTable (Test,True,-1)
    Sample (1,Distance,String)
EndTable




    'Main Program

BeginProg

    Scan (1,Sec,0,0)
        FileHandle = FileOpen ("CRD:2019-02-16-21-30.bin","rb",0)       

        Ensemblestring = FileRead (FileHandle,Distance,MaxEnsembleLength)       

         Instring = InStr (offset,EnsembleString,CHR(48)&CHR(120)&CHR(48)&CHR(48)&CHR(54)&CHR(49),2)     

         Distance = HexToDec(Mid (EnsembleString,Instring+distancebyte,32))     

         FileClose (FileHandle)                       

         CallTable Test   

NextScan

EndProg    

Log in or register to post/reply in the forum.