7#include <cosmos/formatting.hxx>
8#include <cosmos/io/ILogger.hxx>
11#include <clues/format.hxx>
12#include <clues/items/items.hxx>
13#include <clues/logger.hxx>
14#include <clues/Tracee.hxx>
16using namespace std::string_literals;
18namespace clues::item {
22template <
typename INT>
23std::string format_number(INT value,
const Base base) {
25 default: [[fallthrough]];
26 case Base::DEC:
return std::to_string(value);
27 case Base::OCT:
return static_cast<std::string
>(cosmos::OctNum<INT>{value, 0});
28 case Base::HEX:
return static_cast<std::string
>(cosmos::HexNum<INT>{value, 0});
44template <
typename INT>
46 return format_number(m_value, m_base);
49template <
typename INT>
50void PointerToScalar<INT>::fetchValue(
const Tracee &tracee) {
55 if (m_ptr == ForeignPtr::NO_POINTER)
62 }
catch (
const std::exception &) {
67template <
typename INT>
69 if (m_ptr == ForeignPtr::NO_POINTER) {
73 return format::pointer(m_ptr, m_val ? scalarToString() :
"???"s);
76template <
typename INT>
77std::string PointerToScalar<INT>::scalarToString()
const {
78 if constexpr (std::is_enum_v<INT>) {
79 return format_number(cosmos::to_integral(*m_val), m_base);
81 if constexpr (!std::is_enum_v<INT>) {
82 if constexpr (std::is_pointer_v<INT>) {
83 return format_number(
reinterpret_cast<uintptr_t
>(*m_val), clues::Base::HEX);
85 if constexpr (!std::is_pointer_v<INT>) {
86 return format_number(*m_val, m_base);
110void BufferPointer::fillBuffer(
const Tracee &tracee) {
111 const auto to_fetch = std::min(tracee.maxBufferPrefetch(),
availableBytes());
112 m_data.resize(to_fetch);
115 tracee.
readBlob(asPtr(),
reinterpret_cast<char*
>(m_data.data()), to_fetch);
116 }
catch (
const cosmos::CosmosError &e) {
117 LOG_ERROR(
"Failed to fetch buffer data from Tracee: " << e.what());
123 return m_size_par.valueAs<
size_t>();
128 auto ret = format::buffer(m_data.data(), m_data.size());
143template class CLUES_API PointerToScalar<unsigned long>;
144template class CLUES_API PointerToScalar<unsigned int>;
145template class CLUES_API PointerToScalar<int>;
146template class CLUES_API PointerToScalar<cosmos::ProcessID>;
147template class CLUES_API PointerToScalar<cosmos::FileNum>;
148template class CLUES_API PointerToScalar<void*>;
149template class CLUES_API PointerToScalar<ForeignPtr>;
150template class CLUES_API IntValueT<int>;
151template class CLUES_API IntValueT<uint32_t>;
152template class CLUES_API IntValueT<unsigned long>;
153template class CLUES_API IntValueT<off_t>;
Base class for any kind of system call parameter or return value.
OTHER valueAs() const
Helper to cast the strongly typed Word m_val to other strong enum types.
Base class for traced processes.
bool readStruct(const ForeignPtr addr, T &out) const
Reads a system call struct from the tracee's address space into out.
void readBlob(const ForeignPtr addr, char *buffer, const size_t bytes) const
Reads an arbitrary binary blob of fixed length from the tracee.
std::string str() const override
Returns a human readable string representation of the item.
size_t availableBytes() const
Returns the actual number of input bytes available in the Tracee.
void updateData(const Tracee &) override
Called upon exit of the system call to update possible out parameters.
void processValue(const Tracee &) override
Processes the value stored in m_val acc. to the actual item type.
std::string str() const override
Returns a human readable string representation of the item.
std::string str() const override
Returns a human readable string representation of the item.
std::string str() const override
Returns a human readable string representation of the item.
@ PARAM_IN
An input parameter to the system call.
Base
Integer number display base for formatting purposes.