| 202 | } |
| 203 | |
| 204 | int PointerScanModel::loadChains(const std::string& file) |
| 205 | { |
| 206 | std::vector<std::pair<uintptr_t, std::vector<int>>> loaded_pointer_chains; |
| 207 | std::ifstream ifs(file, std::ios::binary); |
| 208 | |
| 209 | if (!ifs) { |
| 210 | return -1; |
| 211 | } |
| 212 | |
| 213 | int ptr_size; |
| 214 | ifs.read(reinterpret_cast<char*>(&ptr_size), sizeof(ptr_size)); |
| 215 | if (ptr_size != sizeof(uintptr_t)) { |
| 216 | return -1; |
| 217 | } |
| 218 | |
| 219 | while (ifs) { |
| 220 | uintptr_t addr; |
| 221 | ifs.read(reinterpret_cast<char*>(&addr), sizeof(addr)); |
| 222 | if (!ifs) break; |
| 223 | |
| 224 | int size; |
| 225 | ifs.read(reinterpret_cast<char*>(&size), sizeof(size)); |
| 226 | if ((size < 0) || (size > 10)) { |
| 227 | return -1; |
| 228 | } |
| 229 | |
| 230 | std::vector<int> offsets(size); |
| 231 | ifs.read(reinterpret_cast<char*>(offsets.data()), size*sizeof(int)); |
| 232 | loaded_pointer_chains.emplace_back(addr, std::move(offsets)); |
| 233 | } |
| 234 | |
| 235 | /* Merge both pointer chain vectors */ |
| 236 | std::vector<std::pair<uintptr_t, std::vector<int>>> intersected_pointer_chains; |
| 237 | std::set_intersection(pointer_chains.begin(), pointer_chains.end(), |
| 238 | loaded_pointer_chains.begin(), loaded_pointer_chains.end(), |
| 239 | std::back_inserter(intersected_pointer_chains)); |
| 240 | |
| 241 | beginResetModel(); |
| 242 | pointer_chains = std::move(intersected_pointer_chains); |
| 243 | endResetModel(); |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | int PointerScanModel::rowCount(const QModelIndex & /*parent*/) const |
| 249 | { |