osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Finding a text in raw data(size nearly 10GB) and Printing its memory address using python


On Tuesday, April 24, 2018 at 1:28:07 AM UTC+5:30, Paul Rubin wrote:
> Hac4u <samakshkaushik at gmail.com> writes:
> > I have a raw data of size nearly 10GB. I would like to find a text
> > string and print the memory address at which it is stored.
> 
> The simplest way is probably to mmap the file and use mmap.find:
> 
> https://docs.python.org/2/library/mmap.html#mmap.mmap.find

Thanks alot Buddy,

And yea I will try to convert it in mmap..

Ur code helped alot. But I have few doubts 
1. What is the use of overlap.
2. Ur code does not end..Like it does break even after searching through the entire file.


Bdw, I modified your code.. 




import os
import re
filename="E:/bitdefender/test.vmem"
read_data=2**24
offset=0
chunk_start=0
searchtext=b"bd:mongo:"
search_length=len(searchtext)
overlap_length = search_length - 1 
he=searchtext.encode('hex')
with open(filename, 'rb') as f:
	while True:
		data= f.read(read_data)
		if not data:
			break
		while True:
			offset=data.find(searchtext,offset)
			# print offset
			if offset < 0:
				break
			print "Found at",hex(chunk_start+offset)
			offset+=search_length

		chunk_start += len(data)  
		data=data[read_data:]     
		offset=0