| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/src/sandbox_nt_util.h" | 5 #include "sandbox/src/sandbox_nt_util.h" |
| 6 | 6 |
| 7 #include "sandbox/src/pe_image.h" | 7 #include "sandbox/src/pe_image.h" |
| 8 #include "sandbox/src/sandbox_factory.h" | 8 #include "sandbox/src/sandbox_factory.h" |
| 9 #include "sandbox/src/target_services.h" | 9 #include "sandbox/src/target_services.h" |
| 10 | 10 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 out_name = AnsiToUnicode(name); | 294 out_name = AnsiToUnicode(name); |
| 295 } | 295 } |
| 296 | 296 |
| 297 PIMAGE_NT_HEADERS headers = pe.GetNTHeaders(); | 297 PIMAGE_NT_HEADERS headers = pe.GetNTHeaders(); |
| 298 if (headers) { | 298 if (headers) { |
| 299 if (headers->OptionalHeader.AddressOfEntryPoint) | 299 if (headers->OptionalHeader.AddressOfEntryPoint) |
| 300 *flags |= MODULE_HAS_ENTRY_POINT; | 300 *flags |= MODULE_HAS_ENTRY_POINT; |
| 301 if (headers->OptionalHeader.SizeOfCode) | 301 if (headers->OptionalHeader.SizeOfCode) |
| 302 *flags |= MODULE_HAS_CODE; | 302 *flags |= MODULE_HAS_CODE; |
| 303 } | 303 } |
| 304 | |
| 305 } while (false); | 304 } while (false); |
| 306 } __except(EXCEPTION_EXECUTE_HANDLER) { | 305 } __except(EXCEPTION_EXECUTE_HANDLER) { |
| 307 } | 306 } |
| 308 | 307 |
| 309 return out_name; | 308 return out_name; |
| 310 } | 309 } |
| 311 | 310 |
| 312 UNICODE_STRING* GetBackingFilePath(PVOID address) { | 311 UNICODE_STRING* GetBackingFilePath(PVOID address) { |
| 313 // We'll start with something close to max_path charactes for the name. | 312 // We'll start with something close to max_path charactes for the name. |
| 314 ULONG buffer_bytes = MAX_PATH * 2; | 313 ULONG buffer_bytes = MAX_PATH * 2; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 342 } | 341 } |
| 343 | 342 |
| 344 UNICODE_STRING* ExtractModuleName(const UNICODE_STRING* module_path) { | 343 UNICODE_STRING* ExtractModuleName(const UNICODE_STRING* module_path) { |
| 345 if ((!module_path) || (!module_path->Buffer)) | 344 if ((!module_path) || (!module_path->Buffer)) |
| 346 return NULL; | 345 return NULL; |
| 347 | 346 |
| 348 wchar_t* sep = NULL; | 347 wchar_t* sep = NULL; |
| 349 int start_pos = module_path->Length / sizeof(wchar_t) - 1; | 348 int start_pos = module_path->Length / sizeof(wchar_t) - 1; |
| 350 int ix = start_pos; | 349 int ix = start_pos; |
| 351 | 350 |
| 352 for(; ix >= 0; --ix) { | 351 for (; ix >= 0; --ix) { |
| 353 if (module_path->Buffer[ix] == L'\\') { | 352 if (module_path->Buffer[ix] == L'\\') { |
| 354 sep = &module_path->Buffer[ix]; | 353 sep = &module_path->Buffer[ix]; |
| 355 break; | 354 break; |
| 356 } | 355 } |
| 357 } | 356 } |
| 358 | 357 |
| 359 // Ends with path separator. Not a valid module name. | 358 // Ends with path separator. Not a valid module name. |
| 360 if ((ix == start_pos) && sep) | 359 if ((ix == start_pos) && sep) |
| 361 return NULL; | 360 return NULL; |
| 362 | 361 |
| 363 // No path separator found. Use the entire name. | 362 // No path separator found. Use the entire name. |
| 364 if ((ix == 0) && !sep) { | 363 if (!sep) { |
| 365 sep = &module_path->Buffer[-1]; | 364 sep = &module_path->Buffer[-1]; |
| 366 } | 365 } |
| 367 | 366 |
| 368 // Add one to the size so we can null terminate the string. | 367 // Add one to the size so we can null terminate the string. |
| 369 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t); | 368 size_t size_bytes = (start_pos - ix + 1) * sizeof(wchar_t); |
| 370 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)]; | 369 char* str_buffer = new(NT_ALLOC) char[size_bytes + sizeof(UNICODE_STRING)]; |
| 371 if (!str_buffer) | 370 if (!str_buffer) |
| 372 return NULL; | 371 return NULL; |
| 373 | 372 |
| 374 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer); | 373 UNICODE_STRING* out_string = reinterpret_cast<UNICODE_STRING*>(str_buffer); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 UNREFERENCED_PARAMETER(type); | 494 UNREFERENCED_PARAMETER(type); |
| 496 return buffer; | 495 return buffer; |
| 497 } | 496 } |
| 498 | 497 |
| 499 void __cdecl operator delete(void* memory, void* buffer, | 498 void __cdecl operator delete(void* memory, void* buffer, |
| 500 sandbox::AllocationType type) { | 499 sandbox::AllocationType type) { |
| 501 UNREFERENCED_PARAMETER(memory); | 500 UNREFERENCED_PARAMETER(memory); |
| 502 UNREFERENCED_PARAMETER(buffer); | 501 UNREFERENCED_PARAMETER(buffer); |
| 503 UNREFERENCED_PARAMETER(type); | 502 UNREFERENCED_PARAMETER(type); |
| 504 } | 503 } |
| OLD | NEW |