2021-10-31 13:12:50 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstring>
|
2022-06-22 23:37:46 -04:00
|
|
|
#include <string>
|
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2023-09-09 17:06:39 -04:00
|
|
|
#include "decompiler/ObjectFile/LinkedObjectFile.h"
|
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
namespace decompiler {
|
|
|
|
class DecompilerTypeSystem;
|
|
|
|
class LinkedObjectFile;
|
|
|
|
} // namespace decompiler
|
|
|
|
|
|
|
|
class Type;
|
|
|
|
|
|
|
|
struct Ref {
|
|
|
|
const decompiler::LinkedObjectFile* data = nullptr;
|
|
|
|
int seg = -1;
|
|
|
|
int byte_offset = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypedRef {
|
|
|
|
Ref ref;
|
|
|
|
Type* type = nullptr;
|
2022-05-11 22:53:53 -04:00
|
|
|
|
|
|
|
TypedRef() = default;
|
|
|
|
TypedRef(const Ref& r, Type* t) : ref(r), type(t) {}
|
2021-10-31 13:12:50 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
void read_plain_data_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts,
|
|
|
|
int size_bytes,
|
|
|
|
u8* out);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
T read_plain_data_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts) {
|
|
|
|
u8 data[sizeof(T)];
|
|
|
|
read_plain_data_field(object, field_name, dts, sizeof(T), data);
|
|
|
|
T result;
|
|
|
|
memcpy(&result, data, sizeof(T));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-09-09 17:06:39 -04:00
|
|
|
void memcpy_from_plain_data(u8* dest, const Ref& source, int size_bytes);
|
|
|
|
std::vector<u8> bytes_from_plain_data(const Ref& source, int size_bytes);
|
|
|
|
|
|
|
|
decompiler::LinkedWord::Kind get_word_kind_for_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts);
|
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
TypedRef get_and_check_ref_to_basic(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const std::string& expected_type,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts);
|
|
|
|
|
|
|
|
std::string read_symbol_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts);
|
|
|
|
|
2023-09-09 17:06:39 -04:00
|
|
|
std::string read_symbol(const Ref& object);
|
|
|
|
std::string read_type(const Ref& object);
|
|
|
|
std::string read_string_ref(const Ref& object);
|
|
|
|
|
2021-10-31 13:12:50 -04:00
|
|
|
std::string read_type_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts,
|
|
|
|
bool ignore_field_type);
|
|
|
|
|
|
|
|
std::string read_string_field(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts,
|
|
|
|
bool ignore_field_type);
|
|
|
|
|
|
|
|
Ref get_field_ref(const TypedRef& object,
|
|
|
|
const std::string& field_name,
|
|
|
|
const decompiler::DecompilerTypeSystem& dts);
|
|
|
|
|
|
|
|
std::string get_type_of_basic(const Ref& object);
|
|
|
|
|
|
|
|
TypedRef typed_ref_from_basic(const Ref& object, const decompiler::DecompilerTypeSystem& dts);
|
|
|
|
|
|
|
|
Ref deref_label(const Ref& object);
|
2022-05-11 22:53:53 -04:00
|
|
|
u32 deref_u32(const Ref& ref, int word_offset);
|
|
|
|
u16 deref_u16(const Ref& ref, int array_idx);
|
|
|
|
s8 deref_s8(const Ref& ref, int byte);
|
|
|
|
u8 deref_u8(const Ref& ref, int byte);
|
2023-09-09 17:06:39 -04:00
|
|
|
float deref_float(const Ref& ref, int array_idx);
|
2022-05-11 22:53:53 -04:00
|
|
|
u64 deref_u64(const Ref& ref, int dw_offset);
|
2021-12-04 12:33:18 -05:00
|
|
|
std::string inspect_ref(const Ref& ref);
|
2023-10-14 16:49:23 -04:00
|
|
|
std::vector<int> find_objects_with_type(const decompiler::LinkedObjectFile& file,
|
|
|
|
const std::string& name);
|