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