473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pattern Search in Binary FIle

3 New Member
I have loaded a large binary file into memory and now I want to search for 10101. I was using file.get to return the next hex number and see if it was equal to 0x15. This is not correct as part of my seach pattern (10101) may straggle over two hex numbers.

Does anyone know of a way to find the pattern 10101 in a binary file loaded into memory?

Any help is appreciated.
Jul 25 '08 #1
1 4563
boxfish
469 Recognized Expert Contributor
Hi,
One thing that might help is a function that finds a bit at a particular index in a char array. It would take a char array and an index as arguments and return a boolean value for the bit at that index. Indices 0-7 would be bits in the first character, 8-15 would be in the second, and so on. What the function would do is:
1: calculate the char to look in (with the / operator),
2: calculate the bit in that char (with the % operator),
3: return the value there.

In case you don't know get a bit at a certain position out of a char already, here's how:
1: Make a char that only has a bit at that position, by starting with the value 1 and bit shifting it into that position, like this:
1 << thatPosition
OK, I lied, that's not a char, it's an int, but it works just as well.
2: Compare that value to the char with the bitwise & operator, like this:
thatValue & theChar
Here's an example:
00000100 &
10101100
See, that would only evaluate to true if the char had a true bit in that position.

Hope this helps.
Jul 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
15195
by: yaipa | last post by:
What would be the common sense way of finding a binary pattern in a ..bin file, say some 200 bytes, and replacing it with an updated pattern of the same length at the same offset? Also, the...
1
2134
by: kittykat | last post by:
Hi, I want to read the input variables from a user, and then compare this with data in the text file. If the input variables and the data in the text file match, then i would like to create a...
1
1795
by: junkmauler | last post by:
I need a pre-made class (this is way over my head.. I can imagine the pseudo code but cant implement it myself) that can search a file for a specified binary pattern. Actually what I really need...
1
2709
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
2
2522
by: Timmy | last post by:
The bigger problem is with the Binary Search. The program crashes when it's excuted. and Visual Studio 2005 indicates stack over flow and shows a break at that function. Sequential search is...
9
2298
by: Owen Zhang | last post by:
I have a file loaded into virtual memory space by mmap. I need to search some key word inside the memory opened by mmap. What is the best and efficient way to do?
1
1618
by: mravik | last post by:
Hi All, I have different subsystems in my application, if one is down it will through some error message in log file. I have a collection of error messages in another file and I want to check each...
16
8920
by: vizzz | last post by:
Hi there, i need to find an hex pattern like 0x650A1010 in a binary file. i can make a small algorithm that fetch all the file for the match, but this file is huge, and i'm scared about...
4
1744
by: Russell Mangel | last post by:
Hi, The code I have posted searches for a pattern of bytes starting from the end of Byte array *backwords*, if a match is found, return the starting index of those found bytes. Since one of...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1566
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.