New mon rr GDB command for reading target registers
This commit is contained in:
17
src/Services/IntegerService.cpp
Normal file
17
src/Services/IntegerService.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "IntegerService.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace Services
|
||||
{
|
||||
std::uint64_t IntegerService::toUint64(const std::vector<unsigned char>& data) {
|
||||
assert(data.size() <= 8);
|
||||
auto output = std::uint64_t{0};
|
||||
|
||||
for (const auto& byte : data) {
|
||||
output = (output << 8) | byte;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
13
src/Services/IntegerService.hpp
Normal file
13
src/Services/IntegerService.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace Services
|
||||
{
|
||||
class IntegerService
|
||||
{
|
||||
public:
|
||||
static std::uint64_t toUint64(const std::vector<unsigned char>& data);
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <bitset>
|
||||
|
||||
namespace Services
|
||||
{
|
||||
@@ -41,6 +42,12 @@ namespace Services
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string StringService::toHex(std::uint64_t value) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0') << std::setw(16) << static_cast<unsigned int>(value);
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string StringService::toHex(std::uint32_t value) {
|
||||
auto stream = std::stringstream{};
|
||||
stream << std::hex << std::setfill('0') << std::setw(8) << static_cast<unsigned int>(value);
|
||||
@@ -75,6 +82,20 @@ namespace Services
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string StringService::toBinaryStringWithMask(std::uint64_t value, std::uint64_t mask) {
|
||||
auto output = std::string{};
|
||||
|
||||
const auto maskBitset = std::bitset<64>{mask};
|
||||
for (auto i = std::size_t{0}; i < maskBitset.size(); ++i) {
|
||||
const auto& bit = maskBitset[i];
|
||||
if (bit) {
|
||||
output.insert(output.begin(), (value & (0x01 << i)) != 0 ? '1' : '0');
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> StringService::dataFromHex(const std::string& hexData) {
|
||||
auto output = std::vector<unsigned char>{};
|
||||
|
||||
@@ -126,4 +147,77 @@ namespace Services
|
||||
|
||||
return {std::ranges::begin(range), std::ranges::end(range)};
|
||||
}
|
||||
|
||||
std::string StringService::applyTerminalColor(const std::string& string, TerminalColor color) {
|
||||
auto colorCode = std::string{};
|
||||
|
||||
switch (color) {
|
||||
case TerminalColor::BLACK: {
|
||||
colorCode = "\033[30m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_RED: {
|
||||
colorCode = "\033[31m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_GREEN: {
|
||||
colorCode = "\033[32m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_YELLOW: {
|
||||
colorCode = "\033[33m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_BLUE: {
|
||||
colorCode = "\033[34m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_MAGENTA: {
|
||||
colorCode = "\033[35m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_CYAN: {
|
||||
colorCode = "\033[36m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::LIGHT_GRAY: {
|
||||
colorCode = "\033[37m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::DARK_GRAY: {
|
||||
colorCode = "\033[90m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::RED: {
|
||||
colorCode = "\033[91m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::GREEN: {
|
||||
colorCode = "\033[92m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::ORANGE: {
|
||||
colorCode = "\033[93m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::BLUE: {
|
||||
colorCode = "\033[94m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::MAGENTA: {
|
||||
colorCode = "\033[95m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::CYAN: {
|
||||
colorCode = "\033[96m";
|
||||
break;
|
||||
}
|
||||
case TerminalColor::WHITE: {
|
||||
colorCode = "\033[97m";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return colorCode + string + "\033[0m";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,14 @@ namespace Services
|
||||
static bool isAscii(const std::string& str);
|
||||
static std::string replaceUnprintable(std::string str);
|
||||
|
||||
static std::string toHex(std::uint64_t value);
|
||||
static std::string toHex(std::uint32_t value);
|
||||
static std::string toHex(unsigned char value);
|
||||
static std::string toHex(const std::vector<unsigned char>& data);
|
||||
static std::string toHex(const std::string& data);
|
||||
|
||||
static std::string toBinaryStringWithMask(std::uint64_t value, std::uint64_t mask);
|
||||
|
||||
static std::vector<unsigned char> dataFromHex(const std::string& hexData);
|
||||
|
||||
static std::uint64_t toUint64(const std::string& str, int base = 0);
|
||||
@@ -54,5 +57,27 @@ namespace Services
|
||||
static std::size_t generateUniqueInteger(const std::string& str);
|
||||
|
||||
static std::vector<std::string_view> split(std::string_view str, char delimiter);
|
||||
|
||||
enum class TerminalColor: std::uint8_t
|
||||
{
|
||||
BLACK,
|
||||
DARK_RED,
|
||||
DARK_GREEN,
|
||||
DARK_YELLOW,
|
||||
DARK_BLUE,
|
||||
DARK_MAGENTA,
|
||||
DARK_CYAN,
|
||||
LIGHT_GRAY,
|
||||
DARK_GRAY,
|
||||
RED,
|
||||
GREEN,
|
||||
ORANGE,
|
||||
BLUE,
|
||||
MAGENTA,
|
||||
CYAN,
|
||||
WHITE,
|
||||
};
|
||||
|
||||
static std::string applyTerminalColor(const std::string& string, TerminalColor color);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user