OLD | NEW |
| (Empty) |
1 // Copyright 2007-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 #ifndef OMAHA_COMMON_APPLY_TAG_H__ | |
17 #define OMAHA_COMMON_APPLY_TAG_H__ | |
18 | |
19 #include <atlbase.h> | |
20 #include <atlstr.h> | |
21 | |
22 #include <vector> | |
23 | |
24 #include "base/basictypes.h" | |
25 #include "base/scoped_ptr.h" | |
26 #include "omaha/base/error.h" | |
27 | |
28 namespace omaha { | |
29 | |
30 // This regular expression represents the valid characters allowed in the | |
31 // binary tag. | |
32 // When changing this regular expression make sure that string patterns on | |
33 // the server are also updated. | |
34 const char* const kValidTagStringRegEx = "^[-%{}/&=.,_a-zA-Z0-9_]*$"; | |
35 | |
36 // Stamps the tag_string into the signed_exe_file. | |
37 // Appends the tag_string to the existing tag if append is | |
38 // true, else errors out. Note that we do not support a | |
39 // overwrite. | |
40 // The tagging is done by adding bytes to the signature | |
41 // directory in the PE flie. | |
42 // The modified signature directory looks something like this | |
43 // <Signature>Gact.<tag_len><tag_string> | |
44 // There are no restrictions on the tag_string, it is just treated | |
45 // as a sequence of bytes. | |
46 class ApplyTag { | |
47 public: | |
48 ApplyTag(); | |
49 HRESULT Init(const TCHAR* signed_exe_file, | |
50 const char* tag_string, | |
51 int tag_string_length, | |
52 const TCHAR* tagged_file, | |
53 bool append); | |
54 HRESULT EmbedTagString(); | |
55 | |
56 private: | |
57 static uint32 GetUint32(const void* p); | |
58 static void PutUint32(uint32 i, void* p); | |
59 bool ReadExistingTag(std::vector<byte>* binary); | |
60 bool CreateBufferToWrite(); | |
61 bool ApplyTagToBuffer(int* output_len); | |
62 bool IsValidTagString(const char* tag_string); | |
63 | |
64 // The string to be tagged into the binary. | |
65 std::vector<char> tag_string_; | |
66 | |
67 // Existing tag string inside the binary. | |
68 std::vector<char> prev_tag_string_; | |
69 | |
70 // This is prev_tag_string_.size - 1, to exclude the terminating null. | |
71 int prev_tag_string_length_; | |
72 | |
73 // Length of the certificate inside the binary. | |
74 int prev_cert_length_; | |
75 | |
76 // The input binary to be tagged. | |
77 CString signed_exe_file_; | |
78 | |
79 // The output binary name. | |
80 CString tagged_file_; | |
81 | |
82 // Whether to append the tag string to the existing one. | |
83 bool append_; | |
84 | |
85 // Internal buffer to hold the appended string. | |
86 std::vector<char> tag_buffer_; | |
87 | |
88 // The output buffer that contains the original binary | |
89 // data with the tagged information. | |
90 std::vector<char> buffer_data_; | |
91 | |
92 DISALLOW_EVIL_CONSTRUCTORS(ApplyTag); | |
93 }; | |
94 | |
95 } // namespace omaha | |
96 | |
97 #endif // OMAHA_COMMON_APPLY_TAG_H__ | |
OLD | NEW |