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
6 changes: 3 additions & 3 deletions cbxp/cbxp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include "cbxp_result.h"
#include "control_block_explorer.hpp"

const cbxp_result_t* cbxp(const char* control_block_name,
const char* includes_string, bool debug) {
cbxp_result_t* cbxp(const char* control_block_name, const char* includes_string,
const char* filters_string, bool debug) {
nlohmann::json control_block_json;
std::string control_block = control_block_name;

Expand All @@ -17,7 +17,7 @@ const cbxp_result_t* cbxp(const char* control_block_name,
CBXP::ControlBlockExplorer explorer =
CBXP::ControlBlockExplorer(&cbxp_result, debug);

explorer.exploreControlBlock(control_block, includes_string);
explorer.exploreControlBlock(control_block, includes_string, filters_string);

return &cbxp_result;
}
4 changes: 2 additions & 2 deletions cbxp/cbxp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
extern "C" {
#endif

const cbxp_result_t* cbxp(const char* control_block_name,
const char* includes_string, bool debug);
cbxp_result_t* cbxp(const char* control_block_name, const char* includes_string,
const char* filters_string, bool debug);

#ifdef __cplusplus
}
Expand Down
7 changes: 6 additions & 1 deletion cbxp/control_block_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __CONTROL_BLOCK_ERROR_H_

namespace CBXP {
enum Error { BadControlBlock = 1, BadInclude };
enum Error { BadControlBlock = 1, BadInclude, BadFilter };
class CBXPError : public std::exception {
private:
Error error_code_;
Expand All @@ -22,6 +22,11 @@ class IncludeError : public CBXPError {
IncludeError() : CBXPError(Error::BadInclude) {}
};

class FilterError : public CBXPError {
public:
FilterError() : CBXPError(Error::BadFilter) {}
};

} // namespace CBXP

#endif
45 changes: 24 additions & 21 deletions cbxp/control_block_explorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@

namespace CBXP {

std::vector<std::string> ControlBlockExplorer::createIncludeList(
const std::string& includes_string) {
if (includes_string == "") {
std::vector<std::string> ControlBlockExplorer::createOptionsList(
const std::string& comma_separated_string) {
if (comma_separated_string == "") {
return {};
}

std::vector<std::string> includes = {};
std::vector<std::string> options_list = {};

Logger::getInstance().debug(
"Creating include list from the provided include list string: " +
includes_string);
"Creating options list from the provided comma-separated list string: " +
comma_separated_string);

const std::string del = ",";
std::string entry;
size_t index = 0;

auto pos = includes_string.find(del);
auto pos = comma_separated_string.find(del);

while (pos != std::string::npos) {
entry = includes_string.substr(index, pos);
includes.push_back(entry);
entry = comma_separated_string.substr(index, pos);
options_list.push_back(entry);
index += pos + 1;
pos = includes_string.substr(index, std::string::npos).find(del);
pos = comma_separated_string.substr(index, std::string::npos).find(del);
}
entry = includes_string.substr(index, pos);
includes.push_back(entry);
entry = comma_separated_string.substr(index, pos);
options_list.push_back(entry);
Logger::getInstance().debug("Done.");

return includes;
return options_list;
}

ControlBlockExplorer::ControlBlockExplorer(cbxp_result_t* p_result,
Expand All @@ -65,27 +65,30 @@ ControlBlockExplorer::ControlBlockExplorer(cbxp_result_t* p_result,
}

void ControlBlockExplorer::exploreControlBlock(
const std::string& control_block_name, const std::string& includes_string) {
const std::string& control_block_name, const std::string& includes_string,
const std::string& filters_string) {
std::vector<std::string> includes =
ControlBlockExplorer::createIncludeList(includes_string);
ControlBlockExplorer::createOptionsList(includes_string);
std::vector<std::string> filters =
ControlBlockExplorer::createOptionsList(filters_string);

Logger::getInstance().debug("Extracting '" + control_block_name +
"' control block data...");

nlohmann::json control_block_json;
try {
if (control_block_name == "psa") {
control_block_json = PSA(includes).get();
control_block_json = PSA(includes, filters).get();
} else if (control_block_name == "cvt") {
control_block_json = CVT(includes).get();
control_block_json = CVT(includes, filters).get();
} else if (control_block_name == "ecvt") {
control_block_json = ECVT(includes).get();
control_block_json = ECVT(includes, filters).get();
} else if (control_block_name == "ascb") {
control_block_json = ASCB(includes).get();
control_block_json = ASCB(includes, filters).get();
} else if (control_block_name == "asvt") {
control_block_json = ASVT(includes).get();
control_block_json = ASVT(includes, filters).get();
} else if (control_block_name == "assb") {
control_block_json = ASSB(includes).get();
control_block_json = ASSB(includes, filters).get();
} else {
throw ControlBlockError();
}
Expand Down
7 changes: 4 additions & 3 deletions cbxp/control_block_explorer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ namespace CBXP {
class ControlBlockExplorer {
private:
cbxp_result_t* p_result_;
static std::vector<std::string> createIncludeList(
const std::string& includes_string);
static std::vector<std::string> createOptionsList(
const std::string& comma_separated_string);

public:
ControlBlockExplorer(cbxp_result_t* p_result, bool debug);
void exploreControlBlock(const std::string& control_block_name,
const std::string& includes_string);
const std::string& includes_string,
const std::string& filters_string);
};
} // namespace CBXP

Expand Down
20 changes: 16 additions & 4 deletions cbxp/control_blocks/ascb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ nlohmann::json ASCB::get(void* __ptr32 p_control_block) {
p_ascb_addr++;
continue;
}
ascbs.push_back(ASCB::get(reinterpret_cast<void* __ptr32>(*p_ascb_addr)));
nlohmann::json next_ascb =
ASCB::get(reinterpret_cast<void* __ptr32>(*p_ascb_addr));
if (!next_ascb.is_null()) {
ascbs.push_back(next_ascb);
}
p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes.
}
return ascbs;
Expand All @@ -53,10 +57,14 @@ nlohmann::json ASCB::get(void* __ptr32 p_control_block) {
ascb_json["ascbassb"] = formatter_.getHex<uint32_t>(&(p_ascb->ascbassb));
ascb_json["ascbasxb"] = formatter_.getHex<uint32_t>(&(p_ascb->ascbasxb));

for (const auto& [include, include_includes] : include_map_) {
for (const auto& [include, cbxp_options] : options_map_) {
if (include == "assb") {
ascb_json["ascbassb"] =
CBXP::ASSB(include_includes).get(p_ascb->ascbassb);
CBXP::ASSB(cbxp_options.include_patterns, cbxp_options.filters)
.get(p_ascb->ascbassb);
if (ascb_json["ascbassb"].is_null()) {
return {};
}
}
}

Expand Down Expand Up @@ -90,6 +98,10 @@ nlohmann::json ASCB::get(void* __ptr32 p_control_block) {
ascb_json["ascbxtcb"] = formatter_.getHex<uint32_t>(&(p_ascb->ascbxtcb));
ascb_json["ascbzcx"] = formatter_.getBitmap<uint32_t>(p_ascb->ascbzcx);

return ascb_json;
if (ASCB::matchFilter(ascb_json)) {
return ascb_json;
} else {
return {};
}
}
} // namespace CBXP
5 changes: 3 additions & 2 deletions cbxp/control_blocks/ascb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace CBXP {
class ASCB : public ControlBlock {
public:
nlohmann::json get(void* __ptr32 p_control_block = nullptr) override;
explicit ASCB(const std::vector<std::string>& includes)
: ControlBlock("ascb", {"assb"}, includes) {}
explicit ASCB(const std::vector<std::string>& includes,
const std::vector<std::string>& filters)
: ControlBlock("ascb", {"assb"}, includes, filters) {}
};

} // namespace CBXP
Expand Down
11 changes: 8 additions & 3 deletions cbxp/control_blocks/assb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ nlohmann::json ASSB::get(void* __ptr32 p_control_block) {
//
const struct ascb* __ptr32 p_ascb =
reinterpret_cast<struct ascb* __ptr32>(*p_ascb_addr);
assbs.push_back(
ASSB::get(reinterpret_cast<void* __ptr32>(p_ascb->ascbassb)));
nlohmann::json next_assb =
ASSB::get(reinterpret_cast<void* __ptr32>(p_ascb->ascbassb));
if (!next_assb.is_null()) assbs.push_back(next_assb);
p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes.
}
return assbs;
Expand Down Expand Up @@ -195,6 +196,10 @@ nlohmann::json ASSB::get(void* __ptr32 p_control_block) {
formatter_.uint<uint64_t>(p_assb->assbinitiatorjobid);
assb_json["assbend"] = formatter_.uint<uint64_t>(p_assb->assbend);

return assb_json;
if (ASSB::matchFilter(assb_json)) {
return assb_json;
} else {
return {};
}
}
} // namespace CBXP
5 changes: 3 additions & 2 deletions cbxp/control_blocks/assb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace CBXP {
class ASSB : public ControlBlock {
public:
nlohmann::json get(void* __ptr32 p_control_block = nullptr) override;
explicit ASSB(const std::vector<std::string>& includes)
: ControlBlock("assb", {}, includes) {}
explicit ASSB(const std::vector<std::string>& includes,
const std::vector<std::string>& filters)
: ControlBlock("assb", {}, includes, filters) {}
};

} // namespace CBXP
Expand Down
14 changes: 10 additions & 4 deletions cbxp/control_blocks/asvt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ nlohmann::json ASVT::get(void* __ptr32 p_control_block) {
Logger::getInstance().debug("ASVT hex dump:");
Logger::getInstance().hexDump(reinterpret_cast<const char*>(p_asvt),
sizeof(asvt_t));
for (const auto& [include, include_includes] : include_map_) {
for (const auto& [include, cbxp_options] : options_map_) {
if (include == "ascb") {
nlohmann::json ascbs_json;
CBXP::ASCB ascb(include_includes);
CBXP::ASCB ascb(cbxp_options.include_patterns, cbxp_options.filters);
uint32_t* __ptr32 p_ascb_addr = const_cast<uint32_t* __ptr32>(
reinterpret_cast<const uint32_t* __ptr32>(&p_asvt->asvtenty));
for (int i = 0; i < p_asvt->asvtmaxu; i++) {
Expand All @@ -62,7 +62,9 @@ nlohmann::json ASVT::get(void* __ptr32 p_control_block) {
}
nlohmann::json ascb_json =
ascb.get(reinterpret_cast<void*>(*p_ascb_addr));
ascbs_json.push_back(ascb_json);
if (!ascb_json.is_null()) {
ascbs_json.push_back(ascb_json);
}
p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes.
}
asvt_json["asvtenty"] = ascbs_json;
Expand All @@ -85,6 +87,10 @@ nlohmann::json ASVT::get(void* __ptr32 p_control_block) {
asvt_json["asvtmdsc"] = p_asvt->asvtmdsc;
asvt_json["asvtfrst"] = formatter_.getHex<uint32_t>(p_asvt->asvtfrst);

return asvt_json;
if (ASVT::matchFilter(asvt_json)) {
return asvt_json;
} else {
return {};
}
}
} // namespace CBXP
5 changes: 3 additions & 2 deletions cbxp/control_blocks/asvt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ namespace CBXP {
class ASVT : public ControlBlock {
public:
nlohmann::json get(void* __ptr32 p_control_block = nullptr) override;
explicit ASVT(const std::vector<std::string>& includes)
: ControlBlock("asvt", {"ascb"}, includes) {}
explicit ASVT(const std::vector<std::string>& includes,
const std::vector<std::string>& filters)
: ControlBlock("asvt", {"ascb"}, includes, filters) {}
};

} // namespace CBXP
Expand Down
Loading