node/lib/metasm/metasm/main.rb
def pattern_scan(pat, chunksz=nil, margin=nil)
		chunksz ||= 4*1024*1024 # scan 4MB at a time
		margin  ||= 65536        # add this much bytes at each chunk to find /pat/ over chunk boundaries
		pat = Regexp.new(Regexp.escape(pat)) if pat.kind_of?(::String)

		found = []
		chunkoff = 0
		while chunkoff < @data.length
			chunk = @data[chunkoff, chunksz+margin].to_str
			off = 0
			while match = chunk[off..-1].match(pat)
				off += match.pre_match.length
				m_l = match[0].length
				break if off >= chunksz	# match fully in margin
				match_addr = chunkoff + off
				found << match_addr if not block_given? or yield(match_addr)
				off += m_l
			end
			chunkoff += chunksz
		end
		found
	end
# returns a list of offsets where /pat/ can be found inside @data
# scan is done per chunk of chunksz bytes, with a margin for chunk-overlapping patterns
# yields each offset found, and only include it in the result if the block returns !false
returns a list of offsets where /pat/ can be found inside @data
scan is done per chunk of chunksz bytes, with a margin for chunk-overlapping patterns
yields each offset found, and only include it in the result if the block returns !false
returns a list of offsets where / pat / can be found inside @data scan is done per chunk of chunksz bytes with a margin for chunk - overlapping patterns yields each offset found and only include it in the result if the block returns !false
def pattern_scan(pat, chunksz=nil, margin=nil)
		chunksz ||= 4*1024*1024 
		margin  ||= 65536        
		pat = Regexp.new(Regexp.escape(pat)) if pat.kind_of?(::String)
		found = []
		chunkoff = 0
		while chunkoff < @data.length
			chunk = @data[chunkoff, chunksz+margin].to_str
			off = 0
			while match = chunk[off..-1].match(pat)
				off += match.pre_match.length
				m_l = match[0].length
				break if off >= chunksz	
				match_addr = chunkoff + off
				found << match_addr if not block_given? or yield(match_addr)
				off += m_l
			end
			chunkoff += chunksz
		end
		found
	end
def pattern_scan ( pat , chunksz = nil , margin = nil ) chunksz ||= 4 * 1024 * 1024 margin ||= 65536 pat = Regexp . new ( Regexp . escape ( pat ) ) if pat . kind_of? ( :: String ) found = [ ] chunkoff = 0 while chunkoff < @data . length chunk = @data [ chunkoff , chunksz + margin ] . to_str off = 0 while match = chunk [ off .. - 1 ] . match ( pat ) off += match . pre_match . length m_l = match [ 0 ] . length break if off >= chunksz match_addr = chunkoff + off found << match_addr if not block_given? or yield ( match_addr ) off += m_l end chunkoff += chunksz end found end
returns a list of offsets where /pat/ can be found inside @data
scan is done per chunk of chunksz bytes, with a margin for chunk-overlapping patterns
yields each offset found, and only include it in the result if the block returns !false
returns a list of offsets where / pat / can be found inside @data scan is done per chunk of chunksz bytes with a margin for chunk - overlapping patterns yields each offset found and only include it in the result if the block returns !false
# scan 4MB at a time # add this much bytes at each chunk to find /pat/ over chunk boundaries # match fully in margin
pat
chunksz
margin