//---------------------------------------------------------------------- // find_cstring_in_heap // // Finds a C string inside one or more currently valid malloc blocks. //---------------------------------------------------------------------- malloc_match * find_cstring_in_heap (const char *s, int check_vm_regions) { g_matches.clear(); if (s == NULL || s[0] == '\0') { printf ("error: invalid argument (empty cstring)\n"); return NULL; } // Setup "info" to look for a malloc block that contains data // that is the C string passed in aligned on a 1 byte boundary range_contains_data_callback_info_t data_info; data_info.type = eDataTypeContainsData; // Check each block for data data_info.data.buffer = (uint8_t *)s; // What data? The C string passed in data_info.data.size = strlen(s); // How many bytes? The length of the C string data_info.data.align = 1; // Data doesn't need to be aligned, so set the alignment to 1 data_info.match_count = 0; // Initialize the match count to zero data_info.done = false; // Set done to false so searching doesn't stop data_info.unique = false; // Set to true when iterating on the vm_regions range_callback_info_t info = { enumerate_range_in_zone, range_info_callback, &data_info, check_vm_regions }; foreach_zone_in_this_process (&info); g_matches.dump(); return g_matches.data(); }
//---------------------------------------------------------------------- // find_pointer_in_heap // // Finds a pointer value inside one or more currently valid malloc // blocks. //---------------------------------------------------------------------- malloc_match * find_pointer_in_heap (const void * addr, int check_vm_regions) { g_matches.clear(); // Setup "info" to look for a malloc block that contains data // that is the a pointer if (addr) { range_contains_data_callback_info_t data_info; data_info.type = eDataTypeContainsData; // Check each block for data data_info.data.buffer = (uint8_t *)&addr; // What data? The pointer value passed in data_info.data.size = sizeof(addr); // How many bytes? The byte size of a pointer data_info.data.align = sizeof(addr); // Align to a pointer byte size data_info.match_count = 0; // Initialize the match count to zero data_info.done = false; // Set done to false so searching doesn't stop data_info.unique = false; // Set to true when iterating on the vm_regions range_callback_info_t info = { enumerate_range_in_zone, range_info_callback, &data_info, check_vm_regions }; foreach_zone_in_this_process (&info); } g_matches.dump(); return g_matches.data(); }