OLD | NEW |
| (Empty) |
1 // Copyright 2008-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 #include "omaha/tools/goopdump/goopdump.h" | |
17 | |
18 #include <stdio.h> | |
19 | |
20 #include <vector> | |
21 | |
22 #include "omaha/common/debug.h" | |
23 #include "omaha/goopdate/config_manager.h" | |
24 #include "omaha/tools/goopdump/data_dumper.h" | |
25 #include "omaha/tools/goopdump/data_dumper_app_manager.h" | |
26 #include "omaha/tools/goopdump/data_dumper_goopdate.h" | |
27 #include "omaha/tools/goopdump/data_dumper_network.h" | |
28 #include "omaha/tools/goopdump/data_dumper_oneclick.h" | |
29 #include "omaha/tools/goopdump/data_dumper_osdata.h" | |
30 #include "omaha/tools/goopdump/process_commandline.h" | |
31 #include "omaha/tools/goopdump/process_monitor.h" | |
32 | |
33 namespace omaha { | |
34 | |
35 class GoopdateProcessMonitorCallback : public ProcessMonitorCallbackInterface { | |
36 public: | |
37 explicit GoopdateProcessMonitorCallback(const DumpLog& dump_log) | |
38 : dump_log_(dump_log) { | |
39 } | |
40 virtual ~GoopdateProcessMonitorCallback() {} | |
41 | |
42 virtual void OnProcessAdded(DWORD process_id, | |
43 const CString& process_pattern) { | |
44 CString cmd_line; | |
45 GetProcessCommandLine(process_id, &cmd_line); | |
46 dump_log_.WriteLine(_T("Process Added. ProcessId(%d) Pattern(%s) ") | |
47 _T("cmd_line(%s)"), | |
48 process_id, process_pattern, cmd_line); | |
49 } | |
50 | |
51 virtual void OnProcessRemoved(DWORD process_id) { | |
52 dump_log_.WriteLine(_T("Process Removed. ProcessId(%d)"), process_id); | |
53 } | |
54 | |
55 private: | |
56 const DumpLog& dump_log_; | |
57 | |
58 DISALLOW_EVIL_CONSTRUCTORS(GoopdateProcessMonitorCallback); | |
59 }; | |
60 | |
61 | |
62 Goopdump::Goopdump() { | |
63 } | |
64 | |
65 Goopdump::~Goopdump() { | |
66 } | |
67 | |
68 HRESULT Goopdump::Main(const TCHAR* cmd_line, int argc, TCHAR** argv) { | |
69 SetNewHandler(); | |
70 dump_log_.EnableConsole(true); | |
71 FileDumpLogHandler file_dumplog_handler; | |
72 | |
73 ::CoInitializeEx(NULL, COINIT_MULTITHREADED); | |
74 | |
75 cmd_line_ = cmd_line; | |
76 | |
77 PrintProgramHeader(); | |
78 dump_log_.WriteLine(_T("cmd_line_: %s"), cmd_line_); | |
79 | |
80 if (FAILED(ParseGoopdumpCmdLine(argc, argv, &args_))) { | |
81 PrintUsage(); | |
82 return E_FAIL; | |
83 } | |
84 | |
85 if (args_.is_write_to_file) { | |
86 file_dumplog_handler.set_filename(args_.log_filename); | |
87 dump_log_.AddLogHandler(&file_dumplog_handler); | |
88 } | |
89 | |
90 // Dump out any requested data. | |
91 std::vector<DataDumper*> data_dumpers; | |
92 | |
93 if (args_.is_dump_general) { | |
94 data_dumpers.push_back(new DataDumperOSData()); | |
95 data_dumpers.push_back(new DataDumperNetwork()); | |
96 data_dumpers.push_back(new DataDumperGoopdate()); | |
97 } | |
98 | |
99 if (args_.is_dump_oneclick) { | |
100 data_dumpers.push_back(new DataDumperOneClick()); | |
101 } | |
102 | |
103 if (args_.is_dump_app_manager) { | |
104 data_dumpers.push_back(new DataDumperAppManager()); | |
105 } | |
106 | |
107 std::vector<DataDumper*>::iterator it = data_dumpers.begin(); | |
108 for (; it != data_dumpers.end(); ++it) { | |
109 DataDumper* dumper = *it; | |
110 | |
111 dumper->Process(dump_log_, args_); | |
112 delete dumper; | |
113 } | |
114 data_dumpers.clear(); | |
115 | |
116 if (args_.is_monitor) { | |
117 // We want to monitor activity from GoogleUpdate.exe. | |
118 // Examples include: | |
119 // * Process start with arguments | |
120 // * Process exit | |
121 // * Others? | |
122 ProcessMonitor process_monitor; | |
123 GoopdateProcessMonitorCallback callback(dump_log_); | |
124 std::vector<CString> patterns; | |
125 patterns.push_back(CString(_T("googleupdate.exe"))); | |
126 patterns.push_back(CString(_T("notepad.exe"))); | |
127 process_monitor.StartWithPatterns(&callback, patterns); | |
128 getchar(); | |
129 process_monitor.Stop(); | |
130 } | |
131 | |
132 ::CoUninitialize(); | |
133 | |
134 return S_OK; | |
135 } | |
136 | |
137 void Goopdump::PrintProgramHeader() { | |
138 dump_log_.WriteLine(_T("")); | |
139 dump_log_.WriteLine(_T("Goopdump.exe -- Debug Utility for Google Update")); | |
140 dump_log_.WriteLine(_T("(c) Google, Inc.")); | |
141 dump_log_.WriteLine(_T("")); | |
142 } | |
143 | |
144 void Goopdump::PrintUsage() { | |
145 dump_log_.WriteLine(_T("Usage:")); | |
146 dump_log_.WriteLine(_T("")); | |
147 } | |
148 | |
149 void Goopdump::SetNewHandler() { | |
150 VERIFY1(set_new_handler(&Goopdump::OutOfMemoryHandler) == 0); | |
151 } | |
152 | |
153 void Goopdump::OutOfMemoryHandler() { | |
154 ::RaiseException(EXCEPTION_ACCESS_VIOLATION, | |
155 EXCEPTION_NONCONTINUABLE, | |
156 0, | |
157 NULL); | |
158 } | |
159 | |
160 CString Goopdump::cmd_line() const { | |
161 return cmd_line_; | |
162 } | |
163 | |
164 } // namespace omaha | |
165 | |
OLD | NEW |