OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SANDBOX_SRC_SANDBOX_NT_UTIL_H_ | 5 #ifndef SANDBOX_SRC_SANDBOX_NT_UTIL_H_ |
6 #define SANDBOX_SRC_SANDBOX_NT_UTIL_H_ | 6 #define SANDBOX_SRC_SANDBOX_NT_UTIL_H_ |
7 | 7 |
8 #include <intrin.h> | 8 #include <intrin.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 WRITE | 87 WRITE |
88 }; | 88 }; |
89 | 89 |
90 // Performs basic user mode buffer validation. In any case, buffers access must | 90 // Performs basic user mode buffer validation. In any case, buffers access must |
91 // be protected by SEH. intent specifies if the buffer should be tested for read | 91 // be protected by SEH. intent specifies if the buffer should be tested for read |
92 // or write. | 92 // or write. |
93 // Note that write intent implies destruction of the buffer content (we actually | 93 // Note that write intent implies destruction of the buffer content (we actually |
94 // write) | 94 // write) |
95 bool ValidParameter(void* buffer, size_t size, RequiredAccess intent); | 95 bool ValidParameter(void* buffer, size_t size, RequiredAccess intent); |
96 | 96 |
97 | |
98 // Copies data from a user buffer to our buffer. Returns the operation status. | |
99 NTSTATUS CopyData(void* destination, const void* source, size_t bytes); | |
100 | |
101 // Copies the name from an object attributes. | |
102 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, | |
103 wchar_t** out_name, uint32* attributes, HANDLE* root); | |
104 | |
105 // Initializes our ntdll level heap | 97 // Initializes our ntdll level heap |
106 bool InitHeap(); | 98 bool InitHeap(); |
107 | 99 |
108 // Returns true if the provided handle refers to the current process. | 100 // Returns true if the provided handle refers to the current process. |
109 bool IsSameProcess(HANDLE process); | 101 bool IsSameProcess(HANDLE process); |
110 | 102 |
111 enum MappedModuleFlags { | 103 enum MappedModuleFlags { |
112 MODULE_IS_PE_IMAGE = 1, // Module is an executable. | 104 MODULE_IS_PE_IMAGE = 1, // Module is an executable. |
113 MODULE_HAS_ENTRY_POINT = 2, // Execution entry point found. | 105 MODULE_HAS_ENTRY_POINT = 2, // Execution entry point found. |
114 MODULE_HAS_CODE = 4 // Non zero size of executable sections. | 106 MODULE_HAS_CODE = 4 // Non zero size of executable sections. |
(...skipping 14 matching lines...) Expand all Loading... |
129 // InsertYourLogicHere(name); | 121 // InsertYourLogicHere(name); |
130 // operator delete(name, NT_ALLOC); | 122 // operator delete(name, NT_ALLOC); |
131 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags); | 123 UNICODE_STRING* GetImageInfoFromModule(HMODULE module, uint32* flags); |
132 | 124 |
133 // Returns the full path and filename for a given dll. | 125 // Returns the full path and filename for a given dll. |
134 // May return NULL if the provided address is not backed by a named section, or | 126 // May return NULL if the provided address is not backed by a named section, or |
135 // if the current OS version doesn't support the call. The returned buffer must | 127 // if the current OS version doesn't support the call. The returned buffer must |
136 // be freed with a placement delete (see GetImageNameFromModule example). | 128 // be freed with a placement delete (see GetImageNameFromModule example). |
137 UNICODE_STRING* GetBackingFilePath(PVOID address); | 129 UNICODE_STRING* GetBackingFilePath(PVOID address); |
138 | 130 |
139 // Returns the last component of a path that contains the module name. | |
140 // It will return NULL if the path ends with the path separator. The returned | |
141 // buffer must be freed with a placement delete (see GetImageNameFromModule | |
142 // example). | |
143 UNICODE_STRING* ExtractModuleName(const UNICODE_STRING* module_path); | |
144 | |
145 // Returns true if the parameters correspond to a dll mapped as code. | 131 // Returns true if the parameters correspond to a dll mapped as code. |
146 bool IsValidImageSection(HANDLE section, PVOID *base, PLARGE_INTEGER offset, | 132 bool IsValidImageSection(HANDLE section, PVOID *base, PLARGE_INTEGER offset, |
147 PSIZE_T view_size); | 133 PSIZE_T view_size); |
148 | 134 |
149 // Converts an ansi string to an UNICODE_STRING. | 135 // Converts an ansi string to an UNICODE_STRING. |
150 UNICODE_STRING* AnsiToUnicode(const char* string); | 136 UNICODE_STRING* AnsiToUnicode(const char* string); |
151 | 137 |
152 // Provides a simple way to temporarily change the protection of a memory page. | 138 // Provides a simple way to temporarily change the protection of a memory page. |
153 class AutoProtectMemory { | 139 class AutoProtectMemory { |
154 public: | 140 public: |
(...skipping 21 matching lines...) Expand all Loading... |
176 | 162 |
177 // Returns true if the file_rename_information structure is supported by our | 163 // Returns true if the file_rename_information structure is supported by our |
178 // rename handler. | 164 // rename handler. |
179 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, DWORD length, | 165 bool IsSupportedRenameCall(FILE_RENAME_INFORMATION* file_info, DWORD length, |
180 uint32 file_info_class); | 166 uint32 file_info_class); |
181 | 167 |
182 } // namespace sandbox | 168 } // namespace sandbox |
183 | 169 |
184 | 170 |
185 #endif // SANDBOX_SRC_SANDBOX_NT_UTIL_H__ | 171 #endif // SANDBOX_SRC_SANDBOX_NT_UTIL_H__ |
OLD | NEW |