forked from jan/mem_edit
		
	Add utils.search_buffer_verbatim()
This commit is contained in:
		
							parent
							
								
									9f71883fbe
								
							
						
					
					
						commit
						3b766be616
					
				@ -23,9 +23,32 @@ class MemEditError(Exception):
 | 
				
			|||||||
    pass
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def search_buffer_verbatim(needle_buffer: ctypes_buffer_t, haystack_buffer: ctypes_buffer_t) -> List[int]:
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Search for a buffer inside another buffer, using a direct (bitwise) comparison
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    :param needle_buffer: Buffer to search for.
 | 
				
			||||||
 | 
					    :param haystack_buffer: Buffer to search in.
 | 
				
			||||||
 | 
					    :return: List of offsets where the needle_buffer was found.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    found = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    haystack = bytes(haystack_buffer)
 | 
				
			||||||
 | 
					    needle = bytes(needle_buffer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    start = 0
 | 
				
			||||||
 | 
					    result = haystack.find(needle, start)
 | 
				
			||||||
 | 
					    while start < len(haystack) and result != -1:
 | 
				
			||||||
 | 
					        found.append(result)
 | 
				
			||||||
 | 
					        start = result + 1
 | 
				
			||||||
 | 
					        result = haystack.find(needle, start)
 | 
				
			||||||
 | 
					    return found
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def search_buffer(needle_buffer: ctypes_buffer_t, haystack_buffer: ctypes_buffer_t) -> List[int]:
 | 
					def search_buffer(needle_buffer: ctypes_buffer_t, haystack_buffer: ctypes_buffer_t) -> List[int]:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Search for a buffer inside another buffer.
 | 
					    Search for a buffer inside another buffer, using ctypes_equal for comparison.
 | 
				
			||||||
 | 
					    Much slower than search_buffer_verbatim.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    :param needle_buffer: Buffer to search for.
 | 
					    :param needle_buffer: Buffer to search for.
 | 
				
			||||||
    :param haystack_buffer: Buffer to search in.
 | 
					    :param haystack_buffer: Buffer to search in.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user