| 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 // The main file for a simple tool to apply a tag to a signed file. | |
| 17 #include <Windows.h> | |
| 18 #include <TCHAR.h> | |
| 19 #include "omaha/base/apply_tag.h" | |
| 20 #include "omaha/base/file.h" | |
| 21 #include "omaha/base/path.h" | |
| 22 #include "omaha/base/utils.h" | |
| 23 | |
| 24 using omaha::CreateDir; | |
| 25 using omaha::ConcatenatePath; | |
| 26 using omaha::File; | |
| 27 using omaha::GetCurrentDir; | |
| 28 using omaha::GetDirectoryFromPath; | |
| 29 using omaha::GetFileFromPath; | |
| 30 | |
| 31 int _tmain(int argc, TCHAR* argv[]) { | |
| 32 if (argc != 4 && argc != 5) { | |
| 33 _tprintf(_T("Incorrect number of arguments!\n")); | |
| 34 _tprintf(_T("Usage: ApplyTag <signed_file> <outputfile> <tag> [append]\n")); | |
| 35 return -1; | |
| 36 } | |
| 37 | |
| 38 const TCHAR* file = argv[1]; | |
| 39 if (!File::Exists(file)) { | |
| 40 _tprintf(_T("File \"%s\" not found!\n"), file); | |
| 41 return -1; | |
| 42 } | |
| 43 | |
| 44 bool append = false; | |
| 45 if (argc == 5 && _tcsicmp(argv[4], _T("append")) == 0) { | |
| 46 append = true; | |
| 47 } | |
| 48 | |
| 49 CString dir = GetDirectoryFromPath(argv[2]); | |
| 50 CString path = ConcatenatePath(GetCurrentDir(), dir); | |
| 51 ASSERT1(!path.IsEmpty()); | |
| 52 if (!File::Exists(path)) { | |
| 53 HRESULT hr = CreateDir(path, NULL); | |
| 54 if (FAILED(hr)) { | |
| 55 _tprintf(_T("Could not create dir %s\n"), path); | |
| 56 return hr; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 CString file_name = GetFileFromPath(argv[2]); | |
| 61 CString out_path = ConcatenatePath(path, file_name); | |
| 62 ASSERT1(!out_path.IsEmpty()); | |
| 63 ASSERT1(File::Exists(path)); | |
| 64 omaha::ApplyTag tag; | |
| 65 HRESULT hr = tag.Init(argv[1], | |
| 66 CT2CA(argv[3]), | |
| 67 lstrlenA(CT2CA(argv[3])), | |
| 68 out_path, | |
| 69 append); | |
| 70 if (hr == E_INVALIDARG) { | |
| 71 _tprintf(_T("The tag_string %s contains invalid characters."), argv[3]); | |
| 72 _tprintf(_T(" We accept the following ATL RegEx '[-%{}/\a&=._]*'\n")); | |
| 73 return hr; | |
| 74 } | |
| 75 | |
| 76 if (FAILED(hr)) { | |
| 77 _tprintf(_T("Tag.Init Failed hr = %x\n"), hr); | |
| 78 return hr; | |
| 79 } | |
| 80 | |
| 81 hr = tag.EmbedTagString(); | |
| 82 if (hr == APPLYTAG_E_ALREADY_TAGGED) { | |
| 83 _tprintf(_T("The binary %s is already tagged."), argv[1]); | |
| 84 _tprintf(_T(" In order to append the tag string, use the append flag.\n")); | |
| 85 _tprintf(_T("Usage: ApplyTag <signed_file> <outputfile> <tag> [append]\n")); | |
| 86 } | |
| 87 | |
| 88 return 0; | |
| 89 } | |
| OLD | NEW |