fuzzed binary annotator (#7188)

This commit is contained in:
Derek Bailey
2022-03-25 22:58:15 -07:00
committed by GitHub
parent e2be0c0b06
commit ae4ce72651
20 changed files with 2241 additions and 2094 deletions

View File

@@ -1,5 +1,8 @@
#include "annotated_binary_text_gen.h"
#include <sstream>
#include <string>
#include "flatbuffers/util.h"
namespace flatbuffers {
@@ -37,6 +40,16 @@ static bool IsOffset(const BinaryRegionType type) {
return type == BinaryRegionType::UOffset || type == BinaryRegionType::SOffset;
}
template<typename T> std::string ToString(T value) {
if (std::is_floating_point<T>::value) {
std::stringstream ss;
ss << value;
return ss.str();
} else {
return std::to_string(value);
}
}
template<typename T>
std::string ToValueString(const BinaryRegion &region, const uint8_t *binary) {
std::string s;
@@ -47,7 +60,7 @@ std::string ToValueString(const BinaryRegion &region, const uint8_t *binary) {
s += ToHex(binary[start_index - i]);
}
s += " (";
s += std::to_string(val);
s += ToString(val);
s += ")";
return s;
}