OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 // | |
5 // Simple tool that uses the SignatureUtil class to extract signature | |
6 // information from an executable. The output is an encoded | |
7 // ClientDownloadRequest_SignatureInfo protocol buffer. | |
8 // | |
9 // Example usage: sb_sigutil --executable=blah.exe --output=siginfo.pb | |
10 | |
11 #include <string> | |
mattm
2011/12/14 02:41:09
blank space
Brian Ryner
2011/12/14 21:25:22
Done.
| |
12 #include "base/command_line.h" | |
13 #include "base/file_path.h" | |
14 #include "base/file_util.h" | |
15 #include "base/logging.h" | |
16 #include "base/memory/ref_counted.h" | |
17 #include "chrome/browser/safe_browsing/signature_util.h" | |
18 #include "chrome/common/safe_browsing/csd.pb.h" | |
19 | |
20 // Command-line switch for the executable to extract a signature from. | |
21 static const char kExecutable[] = "executable"; | |
22 | |
23 // File to write the output protocol buffer to. | |
24 static const char kOutputFile[] = "output"; | |
25 | |
26 int main(int argc, char* argv[]) { | |
27 CommandLine::Init(argc, argv); | |
28 | |
29 CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
30 if (!cmd_line->HasSwitch(kExecutable)) { | |
31 LOG(ERROR) << "Must specify executable to open with --executable"; | |
32 return 1; | |
33 } | |
34 if (!cmd_line->HasSwitch(kOutputFile)) { | |
35 LOG(ERROR) << "Must specify output file with --output"; | |
36 return 1; | |
37 } | |
38 | |
39 scoped_refptr<safe_browsing::SignatureUtil> sig_util( | |
40 new safe_browsing::SignatureUtil()); | |
41 safe_browsing::ClientDownloadRequest_SignatureInfo signature_info; | |
42 sig_util->CheckSignature(cmd_line->GetSwitchValuePath(kExecutable), | |
43 &signature_info); | |
44 | |
45 std::string serialized_info = signature_info.SerializeAsString(); | |
46 int bytes_written = file_util::WriteFile( | |
47 cmd_line->GetSwitchValuePath(kOutputFile), | |
48 serialized_info.data(), | |
49 serialized_info.size()); | |
50 if (bytes_written != static_cast<int>(serialized_info.size())) { | |
51 LOG(ERROR) << "Error writing output file"; | |
52 return 1; | |
53 } | |
54 | |
55 return 0; | |
56 } | |
OLD | NEW |