diff options
author | Andrew Shadura <andrew@shadura.me> | 2015-07-23 20:18:23 +0200 |
---|---|---|
committer | Andrew Shadura <andrew@shadura.me> | 2015-07-23 20:18:23 +0200 |
commit | bbdde4f585db77fa94fa2f08cabdfa16f707b0c5 (patch) | |
tree | 9b238e2f20cc31e02c6073507e0329b55f7b317e | |
parent | 21e59cac0b64115a7cca9a4cd3cfaea0f3e83f56 (diff) |
Apply patches.debian/0.4.0-3
-rw-r--r-- | src/analysis/cifs_parser.cpp | 14 | ||||
-rw-r--r-- | src/analysis/print_analyzer.cpp | 41 | ||||
-rw-r--r-- | src/analysis/rpc_sessions.h | 11 | ||||
-rw-r--r-- | src/api/cifs_pc_to_net.h | 45 | ||||
-rw-r--r-- | src/protocols/cifs2/cifs2_utils.h | 13 | ||||
-rw-r--r-- | tests/unit/protocols/cifsv2.cpp | 15 |
6 files changed, 93 insertions, 46 deletions
diff --git a/src/analysis/cifs_parser.cpp b/src/analysis/cifs_parser.cpp index 44a5697..033615f 100644 --- a/src/analysis/cifs_parser.cpp +++ b/src/analysis/cifs_parser.cpp @@ -19,8 +19,6 @@ along with Nfstrace. If not, see <http://www.gnu.org/licenses/>. */ //------------------------------------------------------------------------------ -#include <iostream> - #include "analysis/cifs_parser.h" #include "api/cifs_types.h" #include "utils/log.h" @@ -28,8 +26,8 @@ using namespace NST::protocols; using namespace NST::analysis; -CIFSParser::CIFSParser(Analyzers& a) : - analyzers(a) +CIFSParser::CIFSParser(Analyzers& a) +: analyzers(a) { } @@ -95,9 +93,7 @@ void CIFSParser::parse_packet(const CIFSv2::MessageHeader* header, utils::Filter // It is response if (Session* session = sessions.get_session(ptr->session, ptr->direction, MsgType::REPLY)) { - //Loosing precision: conversion from int64_t to uint32_t - const uint32_t messageId = static_cast<uint32_t>(header->messageId); - FilteredDataQueue::Ptr&& requestData = session->get_call_data(messageId); + FilteredDataQueue::Ptr&& requestData = session->get_call_data(header->messageId); if (requestData) { if (const MessageHeader* request = get_header(requestData->data)) @@ -119,9 +115,7 @@ void CIFSParser::parse_packet(const CIFSv2::MessageHeader* header, utils::Filter { return analyse_operation(session, header, nullptr, std::move(ptr), std::move(nullptr)); } - //Loosing precision: conversion from int64_t to uint32_t - const uint32_t messageId = static_cast<uint32_t>(header->messageId); - return session->save_call_data(messageId, std::move(ptr)); + return session->save_call_data(header->messageId, std::move(ptr)); } LOG("Can't get right CIFS session"); } diff --git a/src/analysis/print_analyzer.cpp b/src/analysis/print_analyzer.cpp index 7d8315b..1d68420 100644 --- a/src/analysis/print_analyzer.cpp +++ b/src/analysis/print_analyzer.cpp @@ -266,28 +266,19 @@ std::ostream& print_session(std::ostream& out, CommandType* cmd) } template<typename CommandType> -std::ostream& print_smbv2_common_info(std::ostream& out, SMBv2Commands cmdEnum, CommandType* cmd, const std::string& cmdComment) -{ - out << print_cifs2_procedures(cmdEnum) - << " " - << cmdComment << " ("; - print_hex16(out, to_integral(cmdEnum)); - out << ")\n" - << " Structure size = "; - print_hex16(out, cmd->structureSize); - return out; -} - -template<typename CommandType> -std::ostream& print_smbv2_common_info_req(std::ostream& out, SMBv2Commands cmdEnum, CommandType* cmd) +std::ostream& print_smbv2_common_info_req(std::ostream& out, SMBv2Commands, CommandType* cmd) { - return print_smbv2_common_info(out, cmdEnum, cmd->parg, "request"); + out << " Structure size = "; + print_hex16(out, cmd->parg->structureSize); + return out; } template<typename CommandType> -std::ostream& print_smbv2_common_info_resp(std::ostream& out, SMBv2Commands cmdEnum, CommandType* cmd) +std::ostream& print_smbv2_common_info_resp(std::ostream& out, SMBv2Commands, CommandType* cmd) { - return print_smbv2_common_info(out, cmdEnum, cmd->pres, "response"); + out << " Structure size = "; + print_hex16(out, cmd->pres->structureSize); + return out; } std::ostream& print_smbv2_header(std::ostream& out, const RawMessageHeader* header) @@ -511,10 +502,12 @@ void PrintAnalyzer::treeConnectSMBv2(const SMBv2::TreeConnectCommand* cmd, print_session(out, cmd) << "\n"; print_smbv2_header(out, cmd->req_header) << "\n"; print_smbv2_common_info_req(out, cmdEnum, cmd) << "\n"; - if(cmd->parg->PathLength > 0) + + const auto plen = NST::API::SMBv2::pc_to_net(cmd->parg->PathLength); + if(plen > 0) { out << " Tree ="; - print_buffer(out,cmd->parg->Buffer, cmd->parg->PathLength) << "\n"; + print_buffer(out,cmd->parg->Buffer, plen) << "\n"; } print_smbv2_header(out, cmd->res_header) << "\n"; print_smbv2_common_info_resp(out, cmdEnum, cmd) << "\n"; @@ -556,11 +549,12 @@ void PrintAnalyzer::createSMBv2(const SMBv2::CreateCommand* cmd, print_enum(out, "Disposition", cmd->parg->createDisposition) << "\n"; print_enum(out, "Create Options", cmd->parg->createOptions) << "\n"; - if(cmd->parg->NameLength > 0) + const auto len = NST::API::SMBv2::pc_to_net(cmd->parg->NameLength); + if(len > 0) { out << " File name = "; - print_buffer(out, cmd->parg->Buffer, cmd->parg->NameLength) << "\n"; - out << " File length = " << cmd->parg->NameLength << "\n"; + print_buffer(out, cmd->parg->Buffer, len) << "\n"; + out << " File length = " << len << "\n"; } print_smbv2_header(out, cmd->res_header) << "\n"; @@ -736,7 +730,8 @@ void PrintAnalyzer::queryDirSMBv2(const SMBv2::QueryDirCommand* cmd, out << " File index = " << cmd->parg->FileIndex << "\n" << " Output buffer length = " << cmd->parg->OutputBufferLength << "\n" << " Search pattern ="; - print_buffer(out, cmd->parg->Buffer, cmd->parg->FileNameLength) << "\n"; + const auto len = NST::API::SMBv2::pc_to_net(cmd->parg->FileNameLength); + print_buffer(out, cmd->parg->Buffer, len) << "\n"; print_smbv2_header(out, cmd->res_header) << "\n"; print_smbv2_common_info_resp(out, cmdEnum, cmd); } diff --git a/src/analysis/rpc_sessions.h b/src/analysis/rpc_sessions.h index 91f0ff1..bd2c23a 100644 --- a/src/analysis/rpc_sessions.h +++ b/src/analysis/rpc_sessions.h @@ -22,6 +22,7 @@ #ifndef RPC_SESSIONS_H #define RPC_SESSIONS_H //------------------------------------------------------------------------------ +#include <cinttypes> #include <memory> #include <string> #include <vector> @@ -54,17 +55,17 @@ public: Session(const Session&) = delete; Session& operator=(const Session&) = delete; - void save_call_data(const uint32_t xid, FilteredDataQueue::Ptr&& data) + void save_call_data(const std::uint64_t xid, FilteredDataQueue::Ptr&& data) { FilteredDataQueue::Ptr& e = operations[xid]; if(e) // xid call already exists { - LOG("replace RPC Call XID:%u for %s", xid, str().c_str()); + LOG("replace RPC Call XID:%" PRIu64 " for %s", xid, str().c_str()); } e = std::move(data); // replace existing or set new } - inline FilteredDataQueue::Ptr get_call_data(const uint32_t xid) + inline FilteredDataQueue::Ptr get_call_data(const std::uint64_t xid) { auto i = operations.find(xid); if(i != operations.end()) @@ -75,7 +76,7 @@ public: } else { - LOG("RPC Call XID:%u is not found for %s", xid, str().c_str()); + LOG("RPC Call XID:%" PRIu64 " is not found for %s", xid, str().c_str()); } return FilteredDataQueue::Ptr{}; @@ -86,7 +87,7 @@ private: // TODO: add custom allocator based on BlockAllocator // to decrease cost of expensive insert/erase operations - std::unordered_map<uint32_t, FilteredDataQueue::Ptr> operations; + std::unordered_map<std::uint64_t, FilteredDataQueue::Ptr> operations; }; template <typename Session> diff --git a/src/api/cifs_pc_to_net.h b/src/api/cifs_pc_to_net.h index 5b9ef6b..2587bd2 100644 --- a/src/api/cifs_pc_to_net.h +++ b/src/api/cifs_pc_to_net.h @@ -51,11 +51,24 @@ namespace SMBv2 template<class T> constexpr T pc_to_net(T t) { - static_assert(t == 0, "try to not use pc_to_net w/o specialization"); + static_assert(t == T{}, "try to not use pc_to_net w/o specialization"); return t; } template<> +constexpr std::uint64_t pc_to_net(std::uint64_t t) +{ + return ((t & 0xFF00000000000000) >> 56) + | ((t & 0x00FF000000000000) >> 40) + | ((t & 0x0000FF0000000000) >> 24) + | ((t & 0x000000FF00000000) >> 8) + | ((t & 0x00000000FF000000) << 8) + | ((t & 0x0000000000FF0000) << 24) + | ((t & 0x000000000000FF00) << 40) + | ((t & 0x00000000000000FF) << 56); +} + +template<> constexpr uint32_t pc_to_net(uint32_t t) { return ((t & 0xFF000000) >> 24) @@ -71,6 +84,36 @@ constexpr uint16_t pc_to_net(uint16_t t) | ((t & 0x00FF) << 8); } +template<> +constexpr std::uint8_t pc_to_net(std::uint8_t v) +{ + return v; +} + +template<> +constexpr std::int64_t pc_to_net(std::int64_t v) +{ + return pc_to_net((std::uint64_t)v); +} + +template<> +constexpr std::int32_t pc_to_net(std::int32_t v) +{ + return pc_to_net((std::uint32_t)v); +} + +template<> +constexpr std::int16_t pc_to_net(std::int16_t v) +{ + return pc_to_net((std::uint16_t)v); +} + +template<> +constexpr std::int8_t pc_to_net(std::int8_t v) +{ + return pc_to_net((std::uint8_t)v); +} + # else # if NFSTRACE_BYTE_ORDER == NFSTRACE_LITTLE_ENDIAN diff --git a/src/protocols/cifs2/cifs2_utils.h b/src/protocols/cifs2/cifs2_utils.h index 9666630..800fa1f 100644 --- a/src/protocols/cifs2/cifs2_utils.h +++ b/src/protocols/cifs2/cifs2_utils.h @@ -22,12 +22,12 @@ #ifndef CIFS2_UTILS_H #define CIFS2_UTILS_H //------------------------------------------------------------------------------ -#include <iosfwd> -#include <sstream> +#include <ostream> #include "api/cifs2_commands.h" +#include "api/cifs_pc_to_net.h" +#include "protocols/cifs2/cifs2.h" #include "protocols/nfs/nfs_utils.h" -#include "cifs2.h" //------------------------------------------------------------------------------ namespace NST { @@ -75,13 +75,14 @@ std::ostream& operator<<(std::ostream& out, const SMBv2::SecurityMode value); std::ostream& operator<<(std::ostream& out, Flags value); template <typename T> -std::ostream& print_enum(std::ostream& out, const std::string name, T value ) +std::ostream& print_enum(std::ostream& out, const std::string name, T value) { using namespace NST::protocols::NFS; out << " " << name << " = "; - auto int_value = to_integral(value); + // Duty hack for fix issues in PrintAnalyzer on BE platforms + auto int_value = NST::API::SMBv2::pc_to_net(to_integral(value)); print_hex(out, int_value); - out << " " << value; + out << " " << (T)int_value; return out; } diff --git a/tests/unit/protocols/cifsv2.cpp b/tests/unit/protocols/cifsv2.cpp index 59e854d..2d5508f 100644 --- a/tests/unit/protocols/cifsv2.cpp +++ b/tests/unit/protocols/cifsv2.cpp @@ -40,11 +40,24 @@ TEST(CIFSv2, check_CIFS_constants_helpers) // be compared with constants with corresponded BE byte order. union TestData { + std::uint64_t ui64; std::uint32_t ui32; std::uint16_t ui16; - std::uint8_t bytes[4]; + std::uint8_t bytes[8]; } data; + constexpr auto cui64 = pc_to_net<std::uint64_t>(0x0011223344556677); + + data.ui64 = cui64; + EXPECT_EQ(data.bytes[0], 0x77); + EXPECT_EQ(data.bytes[1], 0x66); + EXPECT_EQ(data.bytes[2], 0x55); + EXPECT_EQ(data.bytes[3], 0x44); + EXPECT_EQ(data.bytes[4], 0x33); + EXPECT_EQ(data.bytes[5], 0x22); + EXPECT_EQ(data.bytes[6], 0x11); + EXPECT_EQ(data.bytes[7], 0x00); + constexpr auto cui32 = pc_to_net<std::uint32_t>(0xAABBCCDD); data.ui32 = cui32; |