summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/chrome.gyp13
-rw-r--r--chrome/tools/safe_browsing/sb_sigutil.cc57
2 files changed, 70 insertions, 0 deletions
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 6dabc34..3067ff7 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1304,6 +1304,19 @@
},
},
},
+ {
+ 'target_name': 'sb_sigutil',
+ 'type': 'executable',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ 'safe_browsing_proto',
+ ],
+ 'sources': [
+ 'browser/safe_browsing/signature_util.h',
+ 'browser/safe_browsing/signature_util_win.cc',
+ 'tools/safe_browsing/sb_sigutil.cc',
+ ],
+ },
]}, # 'targets'
], # OS=="win"
], # 'conditions'
diff --git a/chrome/tools/safe_browsing/sb_sigutil.cc b/chrome/tools/safe_browsing/sb_sigutil.cc
new file mode 100644
index 0000000..07da752
--- /dev/null
+++ b/chrome/tools/safe_browsing/sb_sigutil.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Simple tool that uses the SignatureUtil class to extract signature
+// information from an executable. The output is an encoded
+// ClientDownloadRequest_SignatureInfo protocol buffer.
+//
+// Example usage: sb_sigutil --executable=blah.exe --output=siginfo.pb
+
+#include <string>
+
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "chrome/browser/safe_browsing/signature_util.h"
+#include "chrome/common/safe_browsing/csd.pb.h"
+
+// Command-line switch for the executable to extract a signature from.
+static const char kExecutable[] = "executable";
+
+// File to write the output protocol buffer to.
+static const char kOutputFile[] = "output";
+
+int main(int argc, char* argv[]) {
+ CommandLine::Init(argc, argv);
+
+ CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+ if (!cmd_line->HasSwitch(kExecutable)) {
+ LOG(ERROR) << "Must specify executable to open with --executable";
+ return 1;
+ }
+ if (!cmd_line->HasSwitch(kOutputFile)) {
+ LOG(ERROR) << "Must specify output file with --output";
+ return 1;
+ }
+
+ scoped_refptr<safe_browsing::SignatureUtil> sig_util(
+ new safe_browsing::SignatureUtil());
+ safe_browsing::ClientDownloadRequest_SignatureInfo signature_info;
+ sig_util->CheckSignature(cmd_line->GetSwitchValuePath(kExecutable),
+ &signature_info);
+
+ std::string serialized_info = signature_info.SerializeAsString();
+ int bytes_written = file_util::WriteFile(
+ cmd_line->GetSwitchValuePath(kOutputFile),
+ serialized_info.data(),
+ serialized_info.size());
+ if (bytes_written != static_cast<int>(serialized_info.size())) {
+ LOG(ERROR) << "Error writing output file";
+ return 1;
+ }
+
+ return 0;
+}