| OLD | NEW |
| (Empty) |
| 1 // Copyright 2003-2010 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 // Utility functions for getting app and module information. | |
| 17 | |
| 18 #ifndef OMAHA_BASE_APP_UTIL_H_ | |
| 19 #define OMAHA_BASE_APP_UTIL_H_ | |
| 20 | |
| 21 #include <windows.h> | |
| 22 #include <atlstr.h> | |
| 23 #include "base/basictypes.h" | |
| 24 #include "omaha/base/constants.h" | |
| 25 | |
| 26 namespace omaha { | |
| 27 | |
| 28 namespace app_util { | |
| 29 | |
| 30 // Gets the handle to the module containing the given executing address. | |
| 31 HMODULE GetModuleHandleFromAddress(void* address); | |
| 32 | |
| 33 // Gets the handle to the currently executing module. | |
| 34 HMODULE GetCurrentModuleHandle(); | |
| 35 | |
| 36 // Gets the path of the loaded module. | |
| 37 // If module_handle == NULL returns the path of the current executable. | |
| 38 CString GetModulePath(HMODULE module_handle); | |
| 39 | |
| 40 // Gets the directory of the specified module | |
| 41 // Returns the part of the module path, before the last '\'. | |
| 42 // Returns the dir from where the module was loaded (could be exe or dll). | |
| 43 CString GetModuleDirectory(HMODULE module_handle); | |
| 44 | |
| 45 // Gets the name of the specified module | |
| 46 // Returns the part of the module path, after the last '\'. | |
| 47 CString GetModuleName(HMODULE module_handle); | |
| 48 | |
| 49 // Gets the name of the specified module without the extension. | |
| 50 CString GetModuleNameWithoutExtension(HMODULE module_handle); | |
| 51 | |
| 52 // Gets the current app name (i.e. exe name). | |
| 53 CString GetAppName(); | |
| 54 | |
| 55 // Gets the current app name without the extension. | |
| 56 CString GetAppNameWithoutExtension(); | |
| 57 | |
| 58 // Gets the current module path | |
| 59 // returns the path from where the module was loaded (could be exe or dll). | |
| 60 CString GetCurrentModulePath(); | |
| 61 | |
| 62 // Gets the current module directory | |
| 63 // returns the dir from where the module was loaded (could be exe or dll). | |
| 64 CString GetCurrentModuleDirectory(); | |
| 65 | |
| 66 // Gets the current module name. | |
| 67 CString GetCurrentModuleName(); | |
| 68 | |
| 69 // Gets the current module name without the extension. | |
| 70 CString GetCurrentModuleNameWithoutExtension(); | |
| 71 | |
| 72 // Checks if the given address is in the current module. | |
| 73 bool IsAddressInCurrentModule(void* address); | |
| 74 | |
| 75 // Gets the host machine name. | |
| 76 CString GetHostName(); | |
| 77 | |
| 78 // Gets the Windows directory. | |
| 79 CString GetWindowsDir(); | |
| 80 | |
| 81 // Gets the System directory. | |
| 82 CString GetSystemDir(); | |
| 83 | |
| 84 // Gets the TEMP directory for the current user. The directory path ends | |
| 85 // with a '\'. | |
| 86 CString GetTempDir(); | |
| 87 | |
| 88 // Gets a temporary directory for the impersonated user. Returns the temporary | |
| 89 // directory of the process if the caller is not impersonated or an error | |
| 90 // occurs. The directory path ends with a '\'. | |
| 91 CString GetTempDirForImpersonatedOrCurrentUser(); | |
| 92 | |
| 93 // Helper that gets us the version of a DLL in a DWORD format, | |
| 94 // with the major and minor versions squeezed into it. | |
| 95 DWORD DllGetVersion(const CString& dll_path); | |
| 96 | |
| 97 // Helper that gets us the version of a System DLL in a DWORD format, | |
| 98 // with the major and minor versions squeezed into it. The assumption | |
| 99 // is that the dll_name is only a name, and not a path. Using this | |
| 100 // function (over DllGetVersion directly) for System DLLs is recommended | |
| 101 // from a security perspective. | |
| 102 // However, this may not work for DLLs that are loaded from the side-by-side | |
| 103 // location (WinSxS) instead of the system directory. | |
| 104 DWORD SystemDllGetVersion(const TCHAR* dll_name); | |
| 105 | |
| 106 // Gets the version from a module. | |
| 107 ULONGLONG GetVersionFromModule(HMODULE instance); | |
| 108 | |
| 109 // Gets the version from a file path. | |
| 110 ULONGLONG GetVersionFromFile(const CString& file_path); | |
| 111 | |
| 112 // Helper to check if a module handle is valid. | |
| 113 bool IsModuleHandleValid(HMODULE module_handle); | |
| 114 | |
| 115 inline CString GetAppName() { | |
| 116 return GetModuleName(NULL); | |
| 117 } | |
| 118 | |
| 119 inline CString GetAppNameWithoutExtension() { | |
| 120 return GetModuleNameWithoutExtension(NULL); | |
| 121 } | |
| 122 | |
| 123 } // namespace app_util | |
| 124 | |
| 125 } // namespace omaha | |
| 126 | |
| 127 #endif // OMAHA_BASE_APP_UTIL_H_ | |
| 128 | |
| OLD | NEW |