Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
use READ_CONTROL instead of GENERIC_READ
  • Loading branch information
zodiacon committed Jun 19, 2023
1 parent 32375a8 commit c99753d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions ObjExp/ObjExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ int Run(LPTSTR /*lpstrCmdLine*/ = nullptr, int nCmdShow = SW_SHOWDEFAULT) {

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow) {
SecurityHelper::EnablePrivilege(SE_DEBUG_NAME, true);
SecurityHelper::EnablePrivilege(SE_SECURITY_NAME, true);

HRESULT hRes = ::CoInitialize(nullptr);
ATLASSERT(SUCCEEDED(hRes));
Expand Down
7 changes: 5 additions & 2 deletions ObjExp/ObjectManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ NTSTATUS ObjectManager::OpenObject(PCWSTR path, PCWSTR typeName, HANDLE& hObject
// special case: find a handle to this named object and duplicate the handle
//
auto [handle, pid] = FindFirstHandle(path, GetType(typeName)->TypeIndex);
hObject = DriverHelper::DupHandle(handle, pid, GENERIC_READ, 0);
if(handle)
hObject = DriverHelper::DupHandle(handle, pid, access, 0);
}
else if (type == L"Section")
status = NT::NtOpenSection(&hObject, access, &attr);
Expand All @@ -212,6 +213,8 @@ NTSTATUS ObjectManager::OpenObject(PCWSTR path, PCWSTR typeName, HANDLE& hObject
status = NT::NtOpenKey(&hObject, access, &attr);
else if (type == L"Job")
status = NT::NtOpenJobObject(&hObject, access, &attr);
else if (type == L"Session")
status = NT::NtOpenSession(&hObject, access, &attr);
else if (type == L"WindowStation") {
hObject = NT::NtUserOpenWindowStation(&attr, access);
status = hObject ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
Expand Down Expand Up @@ -366,7 +369,7 @@ std::shared_ptr<ObjectTypeInfo> ObjectManager::GetType(USHORT index) {
}

CString ObjectManager::GetObjectName(HANDLE hObject, ULONG pid, USHORT type) {
HANDLE hDup = DriverHelper::DupHandle(hObject, pid, 0);
HANDLE hDup = DriverHelper::DupHandle(hObject, pid, READ_CONTROL);
CString name;
if (hDup) {
name = GetObjectName(hDup, type);
Expand Down
4 changes: 2 additions & 2 deletions ObjExp/ObjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class ObjectManager {

const std::vector<std::shared_ptr<ObjectInfo>>& GetObjects() const;

static HANDLE DupHandle(HANDLE h, DWORD pid, ACCESS_MASK access = GENERIC_READ, DWORD flags = 0);
static NTSTATUS OpenObject(PCWSTR path, PCWSTR type, HANDLE& handle, DWORD access = GENERIC_READ);
static HANDLE DupHandle(HANDLE h, DWORD pid, ACCESS_MASK access = READ_CONTROL, DWORD flags = 0);
static NTSTATUS OpenObject(PCWSTR path, PCWSTR type, HANDLE& handle, DWORD access = READ_CONTROL);
static std::pair<HANDLE, DWORD> FindFirstHandle(PCWSTR name, USHORT index, DWORD pid = 0);

enum class ChangeType {
Expand Down

0 comments on commit c99753d

Please sign in to comment.