mirror of https://github.com/infosecn1nja/C3.git
Fix ambiguous conversions, unqalified lookup and others
parent
d095870f2a
commit
3f2ddcc3e8
|
@ -3,7 +3,7 @@
|
|||
/// Entry point of the application.
|
||||
/// @param argc number of program arguments.
|
||||
/// @param argv vector of program arguments.
|
||||
int main(DWORD argc, char* argv[])
|
||||
int main(int argc, char* argv[])
|
||||
try
|
||||
{
|
||||
std::cout << "Custom Command and Control - Channel linter. BUILD: " << C3_BUILD_VERSION << std::endl;
|
||||
|
|
|
@ -8,30 +8,27 @@ namespace MWR
|
|||
/// @warning Never use this class directly. Always use the SCOPE_GUARD macro.
|
||||
struct ScopeGuard
|
||||
{
|
||||
/// Class design.
|
||||
typedef ScopeGuard Type; ///< Can't use automatic LIGHT_CLASS_FILLER because of deleted constructors and operators.
|
||||
|
||||
/// Cleanup function signature.
|
||||
typedef std::function<void()> CleanupFunction_t;
|
||||
using CleanupFunction_t = std::function<void()>;
|
||||
|
||||
/// The only valid to call manual constructor.
|
||||
/// @param function cleanup function to call on scope leave.
|
||||
Type(const CleanupFunction_t& function) : m_CleanupFunction(function) { }
|
||||
ScopeGuard(const CleanupFunction_t& function) : m_CleanupFunction(function) { }
|
||||
|
||||
/// Deleted l-value constructor, to reject l-value references.
|
||||
Type(CleanupFunction_t&) = delete;
|
||||
ScopeGuard(CleanupFunction_t&) = delete;
|
||||
|
||||
/// R-value constructor, to accept r-value references.
|
||||
Type(CleanupFunction_t&& function) : m_CleanupFunction(function) { }
|
||||
ScopeGuard(CleanupFunction_t&& function) : m_CleanupFunction(function) { }
|
||||
|
||||
/// Destructor.
|
||||
~ScopeGuard() { m_CleanupFunction(); }
|
||||
|
||||
/// Operators.
|
||||
const Type& operator=(const Type&) = delete; ///< No copying between ScopeGuards is allowed.
|
||||
const ScopeGuard& operator=(const ScopeGuard&) = delete; ///< No copying between ScopeGuards is allowed.
|
||||
|
||||
/// Conversion operators.
|
||||
Type(const Type&) = delete; ///< Same as above - no copying between ScopeGuard objects.
|
||||
ScopeGuard(const ScopeGuard&) = delete; ///< Same as above - no copying between ScopeGuard objects.
|
||||
|
||||
/// Heap operators are rejected.
|
||||
void *operator new(size_t) = delete;
|
||||
|
@ -49,5 +46,5 @@ namespace MWR
|
|||
|
||||
/// SCOPE_GUARD macro definition. You should always use this macro instead of direct manipulations on ScopeGuard structure and it's objects.<br>
|
||||
/// Usage: SCOPE_GUARD { expressions; that; will; be; processed; on; scope; leave; }
|
||||
# define SCOPE_GUARD MWR::ScopeGuard SCOPE_GUARD_CAT(scope_guard_, __COUNTER__) = [&]
|
||||
# define SCOPE_GUARD(cleanupExpression) auto SCOPE_GUARD_CAT(scope_guard_, __COUNTER__) = MWR::ScopeGuard{[&]{cleanupExpression}}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace MWR
|
|||
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
|
||||
return false;
|
||||
|
||||
SCOPE_GUARD{ CloseHandle(hToken); };
|
||||
SCOPE_GUARD( CloseHandle(hToken); );
|
||||
TOKEN_ELEVATION Elevation;
|
||||
DWORD cbSize = sizeof(TOKEN_ELEVATION);
|
||||
if (!GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize))
|
||||
|
@ -69,7 +69,7 @@ namespace MWR
|
|||
LPWSTR buf = nullptr;
|
||||
if (NETSETUP_JOIN_STATUS status; NERR_Success == ::NetGetJoinInformation(nullptr, &buf, &status))
|
||||
{
|
||||
SCOPE_GUARD{ ::NetApiBufferFree(buf); };
|
||||
SCOPE_GUARD( ::NetApiBufferFree(buf); );
|
||||
if(status == NetSetupDomainName)
|
||||
m_Domain = WidestringToString(buf);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ size_t MWR::WinTools::WritePipe::Write(ByteView data)
|
|||
throw std::runtime_error{ OBF("Write error, too much data.") };
|
||||
|
||||
ConnectNamedPipe(m_Pipe.get(), nullptr);
|
||||
SCOPE_GUARD{ DisconnectNamedPipe(m_Pipe.get()); };
|
||||
SCOPE_GUARD( DisconnectNamedPipe(m_Pipe.get()); );
|
||||
DWORD written;
|
||||
uint32_t len = static_cast<uint32_t>(data.size());
|
||||
WriteFile(m_Pipe.get(), &len, sizeof(len), nullptr, nullptr);
|
||||
|
@ -99,7 +99,7 @@ MWR::ByteVector MWR::WinTools::ReadPipe::Read()
|
|||
if (pipe == INVALID_HANDLE_VALUE)
|
||||
return {};
|
||||
|
||||
SCOPE_GUARD{ CloseHandle(pipe); };
|
||||
SCOPE_GUARD( CloseHandle(pipe); );
|
||||
|
||||
DWORD chunkSize;
|
||||
uint32_t pipeBufferSize = 512u;
|
||||
|
|
|
@ -16,7 +16,7 @@ std::pair<MWR::CppCommons::WinTools::Services::ReturnEnum, HRESULT> MWR::CppComm
|
|||
|
||||
// Try to open the service
|
||||
if (SC_HANDLE service = ::OpenService(manager, serviceName.c_str(), SERVICE_QUERY_CONFIG))
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : XERROR_GETLASTERROR));
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : HRESULT_FROM_WIN32(GetLastError())));
|
||||
|
||||
// Failed to open the Service. Make sure to return the right error.
|
||||
auto retVal = XERROR_GETLASTERROR;
|
||||
|
@ -35,7 +35,7 @@ std::pair<MWR::CppCommons::WinTools::Services::ReturnEnum, HRESULT> MWR::CppComm
|
|||
// Create the service
|
||||
if (SC_HANDLE service = ::CreateServiceW(manager, serviceName.c_str(), serviceName.c_str(), SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
|
||||
binaryPath.c_str(), nullptr, nullptr, nullptr, nullptr, nullptr))
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : XERROR_GETLASTERROR));
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : HRESULT_FROM_WIN32(GetLastError())));
|
||||
|
||||
// Failed to open the Service. Make sure to return right error.
|
||||
auto retVal = XERROR_GETLASTERROR;
|
||||
|
@ -55,7 +55,7 @@ std::pair<MWR::CppCommons::WinTools::Services::ReturnEnum, HRESULT> MWR::CppComm
|
|||
if (SC_HANDLE service = ::OpenService(manager, serviceName.c_str(), STANDARD_RIGHTS_REQUIRED))
|
||||
{
|
||||
if (::DeleteService(service))
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : XERROR_GETLASTERROR));
|
||||
return std::make_pair(ReturnEnum::ClosingHandles, (::CloseServiceHandle(service) && ::CloseServiceHandle(manager) ? S_OK : HRESULT_FROM_WIN32(GetLastError())));
|
||||
|
||||
// Failed to open the Service. Make sure to return right error.
|
||||
auto retVal = XERROR_GETLASTERROR;
|
||||
|
@ -80,7 +80,7 @@ MWR::CppCommons::CppTools::XError<HRESULT> MWR::CppCommons::WinTools::Services::
|
|||
// Copy Service object and start the Service.
|
||||
s_Service = &theOnlyService;
|
||||
SERVICE_TABLE_ENTRY table[] = { { const_cast<LPTSTR>(serviceName.c_str()), ServiceMain }, { nullptr, nullptr } };
|
||||
return ::StartServiceCtrlDispatcher(table) ? S_OK : XERROR_GETLASTERROR;
|
||||
return ::StartServiceCtrlDispatcher(table) ? S_OK : HRESULT_FROM_WIN32(GetLastError());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -196,5 +196,5 @@ MWR::CppCommons::CppTools::XError<MWR::CppCommons::CppTools::SystemErrorCode> MW
|
|||
s_ServiceStatus.dwCheckPoint = (state == SERVICE_RUNNING || state == SERVICE_STOPPED ? 0 : checkPoint++);
|
||||
|
||||
// Report the status of the service to the SCM.
|
||||
return ::SetServiceStatus(s_ServiceStatusHandle, &s_ServiceStatus) ? NO_ERROR : GetLastError();
|
||||
return { ::SetServiceStatus(s_ServiceStatusHandle, &s_ServiceStatus) ? NO_ERROR : GetLastError() };
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace
|
|||
{
|
||||
try
|
||||
{
|
||||
return cppcodec::base64_rfc4648::decode<MWR::ByteVector>(keys[entryName].get<std::string>());
|
||||
return cppcodec::base64_rfc4648::decode<MWR::ByteVector>(keys[entryName].template get<std::string>());
|
||||
}
|
||||
catch (std::exception& exception)
|
||||
{
|
||||
|
|
|
@ -124,6 +124,7 @@ namespace MWR::C3::Core::ProceduresG2X
|
|||
|
||||
/// Forwarded constructors.
|
||||
using Query<ProcedureNumber>::Query;
|
||||
using Query<ProcedureNumber>::CompileQueryHeader;
|
||||
};
|
||||
|
||||
/// Helper to template creating Queries to Route
|
||||
|
|
Loading…
Reference in New Issue