Skip to content

Commit

Permalink
fix(all): fix various compilation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiesec committed Nov 17, 2021
1 parent bb50c3a commit 718cb84
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 49 deletions.
26 changes: 13 additions & 13 deletions rpcFirewall/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ std::basic_string<CHAR> privateConfigBuffer = {};
std::vector<LineConfig> configVectorOne = {};
std::vector<LineConfig> configVectorTwo = {};

enum ActiveConfigBufferNumber { One, Two};
ActiveConfigBufferNumber activeConfBufferNumber = One;
enum class ActiveConfigBufferNumber { One, Two};
ActiveConfigBufferNumber activeConfBufferNumber = ActiveConfigBufferNumber::One;
CHAR* mappedBuf = NULL;
BOOL AuditOnly = FALSE;
BOOL detouredFunctions = FALSE;
Expand Down Expand Up @@ -94,19 +94,19 @@ std::basic_string<T> to_tstring(U arg)

void changeActiveConfigurationNumber()
{
if (activeConfBufferNumber == One)
if (activeConfBufferNumber == ActiveConfigBufferNumber::One)
{
activeConfBufferNumber = Two;
activeConfBufferNumber = ActiveConfigBufferNumber::Two;
}
else
{
activeConfBufferNumber = One;
activeConfBufferNumber = ActiveConfigBufferNumber::One;
}
}

std::vector<LineConfig>& getActiveConfigurationVector()
{
if (activeConfBufferNumber == One)
if (activeConfBufferNumber == ActiveConfigBufferNumber::One)
{
return configVectorOne;
}
Expand All @@ -115,7 +115,7 @@ std::vector<LineConfig>& getActiveConfigurationVector()

std::vector<LineConfig>& getNonActiveConfigurationVector()
{
if (activeConfBufferNumber == One)
if (activeConfBufferNumber == ActiveConfigBufferNumber::One)
{
return configVectorTwo;
}
Expand Down Expand Up @@ -220,7 +220,7 @@ BOOL checkIfReleventRegisteredEndpointsForProcess()
RPC_STATUS status = RpcServerInqBindings(&binding_vector);
if (status == RPC_S_OK)
{
for (int i = 0; i < binding_vector->Count; i++)
for (unsigned long i = 0; i < binding_vector->Count; i++)
{
status = RpcBindingToStringBinding(binding_vector->BindingH[i], &szStringBinding);
if (status == RPC_S_OK)
Expand Down Expand Up @@ -261,7 +261,7 @@ BOOL checkIfRegisteredUUIDsForProcess()
RPC_STATUS status = RpcMgmtInqIfIds(NULL, &if_id_vector);
if (status == RPC_S_OK)
{
for (int i = 0; i < if_id_vector->Count; i++)
for (unsigned long i = 0; i < if_id_vector->Count; i++)
{
status = UuidToString(&(if_id_vector->IfId[i]->Uuid), &szStringUuid);
if (status == RPC_S_OK)
Expand Down Expand Up @@ -320,7 +320,7 @@ std::basic_string<TCHAR> convertAuthSvcToString(unsigned long authSvc)
return TEXT("UNKNOWN");
}

std::tuple<DWORD, DWORD, BOOL> getConfigOffsets(std::basic_string<CHAR> confStr)
std::tuple<size_t, size_t, BOOL> getConfigOffsets(std::basic_string<CHAR> confStr)
{
size_t start_pos = confStr.find("!start!");
size_t end_pos = confStr.find("!end!");
Expand Down Expand Up @@ -390,7 +390,7 @@ OpNumStruct extractOpNumFromConfigLine(std::basic_string<TCHAR> confLine)
opnumStruct.opnum = std::stoi(opnumString);
opnumStruct.anyOpnum = FALSE;
}
catch (const std::invalid_argument& ia) {
catch (const std::invalid_argument&) {
opnumStruct.anyOpnum = TRUE;
WRITE_DEBUG_MSG(_T("Invalid opnum provided: ") + opnumString);
}
Expand Down Expand Up @@ -989,10 +989,10 @@ BOOL processRPCCallInternal(TCHAR* functionName, PRPC_MESSAGE pRpcMsg)
if (auditCall) rpcFunctionCalledEvent(allowCall, eventParams);
}
catch (const std::runtime_error& re) {
WRITE_DEBUG_MSG_WITH_GETLASTERROR(TEXT("Exception: Runtime error during call"), (TCHAR*)re.what());
WRITE_DEBUG_MSG_WITH_ERROR_MSG(TEXT("Exception: Runtime error during call"), (TCHAR*)re.what());
}
catch (const std::exception& ex) {
WRITE_DEBUG_MSG_WITH_GETLASTERROR(TEXT("Exception: Runtime error during call"), (TCHAR*)ex.what());
WRITE_DEBUG_MSG_WITH_ERROR_MSG(TEXT("Exception: Runtime error during call"), (TCHAR*)ex.what());
}
catch (...) {
WRITE_DEBUG_MSG_WITH_GETLASTERROR(TEXT("Exception: Runtime error during call"));
Expand Down
3 changes: 1 addition & 2 deletions rpcFwManager/Injections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ void hookProcessLoadLibrary(DWORD processID, WCHAR* dllToInject) {
if (hProcess == NULL)
{
_tprintf(TEXT("OpenProcess failed for pid %u: [%d]\n"), processID,GetLastError());
return;
}

const char* szInjectionDLLName = _bstr_t(dllToInject);
Expand Down Expand Up @@ -84,8 +85,6 @@ std::pair<BOOL,BOOL> containsRPCModules(DWORD dwPID)

void classicHookRPCProcesses(DWORD processID, TCHAR* dllToInject)
{
DWORD cbNeeded;

std::pair<BOOL,BOOL> containsModules = containsRPCModules(processID);
BOOL containsRPC = containsModules.first;
BOOL containsRPCFW = containsModules.second;
Expand Down
26 changes: 12 additions & 14 deletions rpcFwManager/RPCMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
#include "stdafx.h"

HANDLE globalMappedMemory = NULL;

HANDLE globalUnprotectlEvent = NULL;

enum eventSignal {signalSetEvent, signalResetEvent};
enum class eventSignal {signalSetEvent, signalResetEvent};

typedef std::vector<std::pair<DWORD, std::basic_string<TCHAR>>> ProcVector;

CHAR configBuf[MEM_BUF_SIZE];

void concatArguments(int argc, _TCHAR* argv[], TCHAR command[])
{
_tcscpy_s(command, MAX_PATH *2, argv[0]);
Expand Down Expand Up @@ -61,7 +62,7 @@ void crawlProcesses(DWORD pid, TCHAR* pName)
ProcVector procToHook = getRelevantProcVector(pid, pName);

unsigned int i;
unsigned int vSize = procToHook.size();
size_t vSize = procToHook.size();
for (i = 0; i < vSize; i++)
{
DWORD pid = procToHook[i].first;
Expand Down Expand Up @@ -134,20 +135,19 @@ void writeFileToSysfolder(std::basic_string<TCHAR> sourcePath, std::basic_string
}
}

TCHAR* getFullPathOfFile(TCHAR* filename)
std::basic_string<TCHAR> getFullPathOfFile(const std::basic_string<TCHAR> &filename)
{
TCHAR filePath[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;

if (!GetCurrentDirectory(bufCharCount, filePath))
{
_tprintf(TEXT("ERROR: Couldn't get the current directory [%d].\n"), GetLastError());
return NULL;
return std::basic_string<TCHAR>();
}
_tcscat_s(filePath, TEXT("\\"));
_tcscat_s(filePath, filename);

return filePath;
return std::basic_string<TCHAR>(filePath) + _T("\\") + filename;
}

BOOL createSecurityAttributes(SECURITY_ATTRIBUTES * psa, PSECURITY_DESCRIPTOR psd)
Expand Down Expand Up @@ -230,9 +230,7 @@ HANDLE mapNamedMemory()

CHAR* readConfigFile(DWORD * bufLen)
{
CHAR configBuf[MEM_BUF_SIZE];

std::basic_string<TCHAR> cfgFwPath = getFullPathOfFile((TCHAR*)CONF_FILE_NAME);
std::basic_string<TCHAR> cfgFwPath = getFullPathOfFile(std::basic_string<TCHAR>(CONF_FILE_NAME));
HANDLE hFile = CreateFile(cfgFwPath.c_str(),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);

if (hFile == INVALID_HANDLE_VALUE)
Expand Down Expand Up @@ -326,7 +324,7 @@ void sendSignalToGlobalEvent(TCHAR* globalEventName, eventSignal eSig)
return;
}

if (eSig == signalSetEvent)
if (eSig == eventSignal::signalSetEvent)
{
if (SetEvent(hEvent) == 0)
{
Expand All @@ -347,8 +345,8 @@ void cmdInstall()
_tprintf(TEXT("installing RPCFW ...\n"));
elevateCurrentProcessToSystem();

writeFileToSysfolder(getFullPathOfFile((TCHAR*)RPC_FW_DLL_NAME), RPC_FW_DLL_NAME);
writeFileToSysfolder(getFullPathOfFile((TCHAR*)RPC_MESSAGES_DLL_NAME), RPC_MESSAGES_DLL_NAME);
writeFileToSysfolder(getFullPathOfFile(std::basic_string<TCHAR>(RPC_FW_DLL_NAME)), RPC_FW_DLL_NAME);
writeFileToSysfolder(getFullPathOfFile(std::basic_string<TCHAR>(RPC_MESSAGES_DLL_NAME)), RPC_MESSAGES_DLL_NAME);

addEventSource();
}
Expand Down Expand Up @@ -381,7 +379,7 @@ void cmdUnprotect()
{
elevateCurrentProcessToSystem();
_tprintf(TEXT("Dispatching unprotect request...\n"));
sendSignalToGlobalEvent((TCHAR*)GLOBAL_RPCFW_EVENT_UNPROTECT, signalSetEvent);
sendSignalToGlobalEvent((TCHAR*)GLOBAL_RPCFW_EVENT_UNPROTECT, eventSignal::signalSetEvent);
}

void cmdProcess(int argc, _TCHAR* argv[])
Expand Down
5 changes: 2 additions & 3 deletions rpcFwManager/elevation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ BOOL amISYSTEM()
DWORD dwError = ERROR_SUCCESS;

PTOKEN_MANDATORY_LABEL pTIL = NULL;
LPWSTR pStringSid;
DWORD dwIntegrityLevel;

hProcess = GetCurrentProcess();
Expand Down Expand Up @@ -121,7 +120,7 @@ BOOL setPrivilege(
lpszPrivilege, // privilege to lookup
&luid)) // receives LUID of privilege
{
_tprintf(TEXT("LookupPrivilegeValue error: %u\n", GetLastError()));
_tprintf(TEXT("LookupPrivilegeValue error: %u\n"), GetLastError());
return FALSE;
}

Expand All @@ -142,7 +141,7 @@ BOOL setPrivilege(
(PTOKEN_PRIVILEGES)NULL,
(PDWORD)NULL))
{
_tprintf(TEXT("AdjustTokenPrivileges error: %u\n", GetLastError()));
_tprintf(TEXT("AdjustTokenPrivileges error: %u\n"), GetLastError());
return FALSE;
}

Expand Down
1 change: 0 additions & 1 deletion rpcFwManager/rpcFwManager.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ copy /Y "$(SolutionDir)easyhook\Deploy\NetFX3.5\EasyHook*.lib" $(TargetDir)</Com
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<AdditionalIncludeDirectories>$(SolutionDir)rpcMessages\</AdditionalIncludeDirectories>
</ClCompile>
Expand Down
15 changes: 7 additions & 8 deletions rpcMessages/rpcMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ BOOL compareStringsCaseinsensitive(TCHAR* str1, TCHAR* str2)
return true;
}

BOOL compareStringsCaseinsensitive(TCHAR* str1, TCHAR* str2, DWORD maxLen)
BOOL compareStringsCaseinsensitive(TCHAR* str1, TCHAR* str2, size_t maxLen)
{
TCHAR tcharEnd = _T("\0")[0];

for (int i = 0; i < maxLen; i++)
for (size_t i = 0; i < maxLen; i++)
{
if ((str1[i] == tcharEnd) || (str2[i] == tcharEnd))
{
Expand Down Expand Up @@ -173,15 +173,15 @@ void addEventSource()
}

// Register EventMessageFile
if (RegSetValueEx(hRegKey, _T("EventMessageFile"), 0, REG_EXPAND_SZ, (PBYTE)szDLLPath, (_tcslen(szDLLPath) + 1) * sizeof TCHAR) != ERROR_SUCCESS)
if (RegSetValueEx(hRegKey, _T("EventMessageFile"), 0, REG_EXPAND_SZ, (PBYTE)szDLLPath, (DWORD)((_tcslen(szDLLPath) + 1) * (DWORD)sizeof(TCHAR))) != ERROR_SUCCESS)
{
_tprintf(TEXT("ERROR: setting value to EventMessageFile failed: [%d].\n"), GetLastError());
return;
}

// Register supported event types
DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
if (RegSetValueEx(hRegKey, _T("TypesSupported"), 0, REG_DWORD, (LPBYTE)&dwTypes, sizeof dwTypes) != ERROR_SUCCESS)
if (RegSetValueEx(hRegKey, _T("TypesSupported"), 0, REG_DWORD, (LPBYTE)&dwTypes, sizeof(dwTypes)) != ERROR_SUCCESS)
{
_tprintf(TEXT("ERROR: setting value to TypesSupported failed: [%d].\n"), GetLastError());
return;
Expand All @@ -194,7 +194,7 @@ void addEventSource()
BOOL processProtectedEvent(BOOL successfulInjection, TCHAR* processName, TCHAR* processID) {

bool bSuccess = FALSE;
DWORD eventType = EVENTLOG_AUDIT_SUCCESS;
WORD eventType = EVENTLOG_AUDIT_SUCCESS;
LPCTSTR aInsertions[2] = { NULL, NULL };

if (!successfulInjection) {
Expand Down Expand Up @@ -229,7 +229,7 @@ BOOL processProtectedEvent(BOOL successfulInjection, TCHAR* processName, TCHAR*
BOOL processUnprotectedEvent(BOOL successfulIUnloading, TCHAR* processName, TCHAR* processID) {

bool bSuccess = FALSE;
DWORD eventType = EVENTLOG_AUDIT_SUCCESS;
WORD eventType = EVENTLOG_AUDIT_SUCCESS;
LPCTSTR aInsertions[2] = { NULL, NULL };

if (!successfulIUnloading) {
Expand Down Expand Up @@ -280,7 +280,7 @@ std::basic_string<TCHAR> escapeIpv6Address(TCHAR* sourceAddress)
BOOL rpcFunctionCalledEvent(BOOL callSuccessful, RpcEventParameters eventParams)
{
bool bSuccess = FALSE;
DWORD eventType = EVENTLOG_AUDIT_SUCCESS;
WORD eventType = EVENTLOG_AUDIT_SUCCESS;
LPCWSTR aInsertions[11] = {NULL};

if (!callSuccessful) {
Expand Down Expand Up @@ -319,7 +319,6 @@ BOOL rpcFunctionCalledEvent(BOOL callSuccessful, RpcEventParameters eventParams)
NULL
);
}
else

return bSuccess;
}
Expand Down
18 changes: 10 additions & 8 deletions rpcMessages/rpcMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define GLOBAL_SHARED_MEMORY TEXT("Global\\RpcFwRules")
#define MEM_BUF_SIZE 0xFFFF

#define DllExport __declspec( dllexport )

struct RpcEventParameters
{
BOOL rpcAllowd;
Expand All @@ -29,18 +31,18 @@ struct RpcEventParameters
std::basic_string<TCHAR> authnSvc;
};

LIBRARY_API BOOL deleteEventSource();
DllExport BOOL deleteEventSource();

LIBRARY_API void addEventSource();
DllExport void addEventSource();

LIBRARY_API BOOL processProtectedEvent(BOOL , TCHAR*, TCHAR* );
DllExport BOOL processProtectedEvent(BOOL , TCHAR*, TCHAR* );

LIBRARY_API BOOL processUnprotectedEvent(BOOL, TCHAR*, TCHAR* );
DllExport BOOL processUnprotectedEvent(BOOL, TCHAR*, TCHAR* );

LIBRARY_API BOOL rpcFunctionCalledEvent(BOOL , RpcEventParameters );
DllExport BOOL rpcFunctionCalledEvent(BOOL , RpcEventParameters );

LIBRARY_API BOOL compareCharCaseInsensitive(TCHAR , TCHAR );
DllExport BOOL compareCharCaseInsensitive(TCHAR , TCHAR );

LIBRARY_API BOOL compareStringsCaseinsensitive(TCHAR*, TCHAR* );
DllExport BOOL compareStringsCaseinsensitive(TCHAR*, TCHAR* );

LIBRARY_API BOOL compareStringsCaseinsensitive(TCHAR* , TCHAR* , DWORD );
DllExport BOOL compareStringsCaseinsensitive(TCHAR* , TCHAR* , size_t);

0 comments on commit 718cb84

Please sign in to comment.