Chromium Code Reviews| Index: third_party/omaha/base/extractor.h |
| diff --git a/third_party/omaha/base/extractor.h b/third_party/omaha/base/extractor.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..10041c107ae70d71defd3346ccba7742695045a3 |
| --- /dev/null |
| +++ b/third_party/omaha/base/extractor.h |
| @@ -0,0 +1,105 @@ |
| +// Copyright 2005-2009 Google Inc. |
|
grt (UTC plus 2)
2014/07/30 15:05:37
put the files pulled from the omaha repository int
grt (UTC plus 2)
2014/07/30 15:05:37
since this is windows-specific, i think the right
grt (UTC plus 2)
2014/07/30 15:05:37
please have this reviewed as per: http://www.chrom
grt (UTC plus 2)
2014/07/30 15:05:37
add /third_party/omaha to .gitignore and do the sv
grt (UTC plus 2)
2014/07/30 15:05:37
have you made any modifications to this file or to
jackhou1
2014/07/31 03:24:56
Done. svn part committed at r286698.
jackhou1
2014/07/31 03:24:56
I'll update this CL when the new repo is available
jackhou1
2014/07/31 03:24:56
I needed to make a slight change in order to put t
jackhou1
2014/07/31 03:24:56
Done.
jackhou1
2014/07/31 03:24:56
Filed a bug for a repo. http://crbug.com/399167
grt (UTC plus 2)
2014/07/31 20:48:05
I've never done that, so I'm not sure if the third
|
| +// |
|
grt (UTC plus 2)
2014/07/30 15:05:37
have you run "src/tools/licenses.py scan" and "src
jackhou1
2014/07/31 03:24:56
These pass.
BTW checklicenses.py doesn't seem to
|
| +// Licensed under the Apache License, Version 2.0 (the "License"); |
| +// you may not use this file except in compliance with the License. |
| +// You may obtain a copy of the License at |
| +// |
| +// http://www.apache.org/licenses/LICENSE-2.0 |
| +// |
| +// Unless required by applicable law or agreed to in writing, software |
| +// distributed under the License is distributed on an "AS IS" BASIS, |
| +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| +// See the License for the specific language governing permissions and |
| +// limitations under the License. |
| +// ======================================================================== |
| + |
| + |
| +#ifndef OMAHA_COMMON_EXTRACTOR_H_ |
| +#define OMAHA_COMMON_EXTRACTOR_H_ |
| + |
| +#include <windows.h> |
| + |
| +namespace omaha { |
| + |
| +class TagExtractor { |
| + public: |
| + TagExtractor(); |
| + virtual ~TagExtractor(); |
| + |
| + /** |
| + * @return true if we successfully opened the file. |
| + */ |
| + bool OpenFile(const TCHAR* filename); |
| + |
| + /** |
| + * @return true if we currently have a handle to an open file. |
| + */ |
| + bool IsFileOpen() const; |
| + |
| + void CloseFile(); |
| + |
| + /** |
| + * Returns the tag in the current file. |
| + * |
| + * We're exploiting the empirical observation that Windows checks the |
| + * signature on a PEF but doesn't care if the signature container includes |
| + * extra bytes after the signature. |
| + * |
| + * Logic: |
| + * |
| + * - Sanity-check that we're a PEF image. |
| + * - Find the signature, which should be stored in the PE "Certificates |
| + * Directory" (dumpbin.exe /headers "Firefox Setup 1.0.7.exe") in a |
| + * WIN_CERTIFICATE structure. |
| + * - Crudely parse the ASN.1 signature to determine its end. |
| + * - Read the signature starting from the first byte past the ASN.1. |
| + * |
| + * @param tag_buffer: a buffer that will be filled with the extracted tag as |
| + * a null-terminated string, or NULL if the caller doesn't want the tag. |
| + * |
| + * @param tag_buffer_len: a pointer to an int that represents the length in |
| + * bytes of the buffer pointed to by tag_buffer. If tag_buffer is NULL and |
| + * there is a tag to extract, then we fill this int with the size of the |
| + * smallest buffer needed to contain the tag (plus the null terminator). |
| + * |
| + * @return true if we found a tag and either successfully copied all of it |
| + * into tag_buffer, or tag_buffer was NULL and we successfully returned |
| + * the required buffer size in tag_buffer_len. |
| + */ |
| + bool ExtractTag(char* tag_buffer, int* tag_buffer_len); |
| + bool ExtractTag(const char* binary_file, |
| + size_t binary_file_length, |
| + char* tag_buffer, |
| + int* tag_buffer_len); |
| + |
| + int cert_length() const { return cert_length_; } |
| + const void* cert_dir_base() const { return cert_dir_base_; } |
| + |
| + private: |
| + HANDLE file_handle_; |
| + HANDLE file_mapping_; |
| + LPVOID file_base_; |
| + size_t file_length_; |
| + int cert_length_; |
| + const void* cert_dir_base_; |
| + |
| + bool ReadTag(const char* tag_pointer, |
| + char* tag_buffer, |
| + int* tag_buffer_len) const; |
| + |
| + const void* GetCertificateDirectoryPointer(const void* base) const; |
| + |
| + const void* GetASN1SignaturePointer(const void* base) const; |
| + |
| + int GetASN1SignatureLength(const void* base) const; |
| + |
| + bool InternalExtractTag(const char* file_buffer, |
| + char* tag_buffer, |
| + int* tag_buffer_len); |
| + |
| + bool InternalReadCertificate(const char* file_buffer); |
| +}; |
| + |
| +} // namespace omaha |
| + |
| +#endif // OMAHA_COMMON_EXTRACTOR_H_ |