Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions KDemu/Elevator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "Elevator.h"

#include <Windows.h>

bool KDemu::Elevator::CanElevate() {
HANDLE hToken = nullptr;
TOKEN_ELEVATION_TYPE tokenType = TokenElevationTypeLimited;
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ALL_ACCESS,
&hToken))
return false;
DWORD len;
GetTokenInformation(hToken, TokenElevationType, &tokenType,
sizeof(TOKEN_ELEVATION_TYPE), &len);
CloseHandle(hToken);
return tokenType == TokenElevationTypeLimited;
}
8 changes: 8 additions & 0 deletions KDemu/Elevator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace KDemu {
class Elevator {
public:
static bool CanElevate();
};
}
7 changes: 7 additions & 0 deletions KDemu/KDemu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <windows.h>
#include <mutex>
#include "UnicornEmu.hpp"
#include "Elevator.h"

void gdbServer(uc_engine* uc, uint64_t entry) {
HMODULE hDll = LoadLibrary(TEXT("udbserver.dll"));
if (!hDll) {
Expand Down Expand Up @@ -180,6 +182,11 @@ void mainThread() {
}

int main(int argc, char** argv, char** envp) {
// Check if the program has all necessary privileges.
if (KDemu::Elevator::CanElevate()) {
std::cerr << "Please launch the program with administrator rights.";
return -1;
}
PEloader& peLoader = PEloader::GetInstance();
peLoader.LoadDmp();
InitializeCriticalSection(&peLoader.cs);
Expand Down
2 changes: 2 additions & 0 deletions KDemu/KDemu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Elevator.cpp" />
<ClCompile Include="Emulate.cpp" />
<ClCompile Include="Global.cpp" />
<ClCompile Include="KDemu.cpp" />
Expand All @@ -27,6 +28,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="cpu.h" />
<ClInclude Include="Elevator.h" />
<ClInclude Include="Emulate.hpp" />
<ClInclude Include="Global.h" />
<ClInclude Include="LoadPE.hpp" />
Expand Down
4 changes: 4 additions & 0 deletions KDemu/KDemu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ClCompile Include="KDemu.cpp" />
<ClCompile Include="Global.cpp" />
<ClCompile Include="unicorn.cpp" />
<ClCompile Include="Elevator.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="NtType.hpp" />
Expand All @@ -32,5 +33,8 @@
<ClInclude Include="UnicornEmu.hpp">
<Filter>標頭檔</Filter>
</ClInclude>
<ClInclude Include="Elevator.h">
<Filter>標頭檔</Filter>
</ClInclude>
</ItemGroup>
</Project>