MCPcopy Create free account
hub / github.com/ReversecLabs/C3 / HandleActionsPacket

Method HandleActionsPacket

Src/Core/Profiler.cpp:30–66  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

28
29////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
30void FSecure::C3::Core::Profiler::HandleActionsPacket(ByteView actionsPacket)
31{
32 std::scoped_lock lock(m_AccessMutex);
33
34 try
35 {
36 auto actions = json::parse(std::string{ actionsPacket });
37 auto jActions = actions.find("Command");
38 if (jActions == actions.end())
39 throw std::runtime_error{ "Command object is missing" };
40
41 (*jActions)["ByteForm"] = base64::encode(TranslateCommand(*jActions));
42
43 // Helper lambda that read particular element from actions JSON.
44 auto ReadJsonElement = [&actions](std::string_view elementName)
45 {
46 auto element = actions.find(elementName);
47 if (element != actions.end())
48 return element;
49
50 throw std::runtime_error{ std::string{ elementName } +" is not specified." };
51 };
52
53 // Parse AgentId.
54 if (auto relayAgentId = ReadJsonElement("relayAgentId"); relayAgentId->is_null())
55 m_Gateway->ParseAndRunCommand(actions);
56 else if (auto agent = m_Gateway->m_Agents.Find(relayAgentId->get<std::string>()))
57 agent->ParseAndRunCommand(actions);
58 else
59 throw std::runtime_error{ "Unknown AgentId." };
60 }
61 catch (std::exception& exception)
62 {
63 if (auto gateway = m_Gateway->m_Gateway.lock())
64 gateway->Log({ "Caught an exception while parsing Action. "s + exception.what(), FSecure::C3::LogMessage::Severity::Error});
65 }
66}
67
68////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
69FSecure::C3::Core::Profiler::Profile FSecure::C3::Core::Profiler::Get()

Callers 1

HandleMessageMethod · 0.80

Calls 9

parseFunction · 0.85
encodeFunction · 0.85
ParseAndRunCommandMethod · 0.80
findMethod · 0.45
endMethod · 0.45
FindMethod · 0.45
lockMethod · 0.45
LogMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected