exploitability.cc
1 // Copyright 2010 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 // exploitability_engine.cc: Generic exploitability engine. 30 // 31 // See exploitable_engine.h for documentation. 32 // 33 // Author: Cris Neckar 34 35 36 #ifdef HAVE_CONFIG_H 37 #include <config.h> // Must come first 38 #endif 39 40 #include <cassert> 41 42 #include "common/scoped_ptr.h" 43 #include "google_breakpad/processor/exploitability.h" 44 #include "google_breakpad/processor/minidump.h" 45 #include "google_breakpad/processor/process_state.h" 46 #include "processor/exploitability_linux.h" 47 #include "processor/exploitability_win.h" 48 #include "processor/logging.h" 49 50 namespace google_breakpad { 51 52 Exploitability::Exploitability(Minidump *dump, 53 ProcessState *process_state) 54 : dump_(dump), 55 process_state_(process_state) {} 56 57 ExploitabilityRating Exploitability::CheckExploitability() { 58 return CheckPlatformExploitability(); 59 } 60 61 Exploitability *Exploitability::ExploitabilityForPlatform( 62 Minidump *dump, 63 ProcessState *process_state) { 64 return ExploitabilityForPlatform(dump, process_state, false); 65 } 66 67 Exploitability *Exploitability::ExploitabilityForPlatform( 68 Minidump *dump, 69 ProcessState *process_state, 70 bool enable_objdump) { 71 Exploitability *platform_exploitability = NULL; 72 MinidumpSystemInfo *minidump_system_info = dump->GetSystemInfo(); 73 if (!minidump_system_info) 74 return NULL; 75 76 const MDRawSystemInfo *raw_system_info = 77 minidump_system_info->system_info(); 78 if (!raw_system_info) 79 return NULL; 80 81 switch (raw_system_info->platform_id) { 82 case MD_OS_WIN32_NT: 83 case MD_OS_WIN32_WINDOWS: { 84 platform_exploitability = new ExploitabilityWin(dump, process_state); 85 break; 86 } 87 case MD_OS_LINUX: { 88 platform_exploitability = new ExploitabilityLinux(dump, 89 process_state, 90 enable_objdump); 91 break; 92 } 93 case MD_OS_MAC_OS_X: 94 case MD_OS_IOS: 95 case MD_OS_UNIX: 96 case MD_OS_SOLARIS: 97 case MD_OS_ANDROID: 98 case MD_OS_PS3: 99 case MD_OS_FUCHSIA: 100 default: { 101 platform_exploitability = NULL; 102 break; 103 } 104 } 105 106 BPLOG_IF(ERROR, !platform_exploitability) << 107 "No Exploitability module for platform: " << 108 process_state->system_info()->os; 109 return platform_exploitability; 110 } 111 112 bool Exploitability::AddressIsAscii(uint64_t address) { 113 for (int i = 0; i < 8; i++) { 114 uint8_t byte = (address >> (8*i)) & 0xff; 115 if ((byte >= ' ' && byte <= '~') || byte == 0) 116 continue; 117 return false; 118 } 119 return true; 120 } 121 122 } // namespace google_breakpad 123