[Memory] TranslateVirtual in shim and strings
This commit is contained in:
@@ -81,6 +81,35 @@ inline uint64_t get_arg_64(PPCContext* ppc_context, uint8_t index) {
|
||||
uint32_t stack_address = get_arg_stack_ptr(ppc_context, index - 8);
|
||||
return SHIM_MEM_64(stack_address);
|
||||
}
|
||||
|
||||
inline std::string TranslateAnsiString(const Memory* memory,
|
||||
const X_ANSI_STRING* ansi_string) {
|
||||
if (!ansi_string || !ansi_string->length) {
|
||||
return "";
|
||||
}
|
||||
return std::string(
|
||||
memory->TranslateVirtual<const char*>(ansi_string->pointer),
|
||||
ansi_string->length);
|
||||
}
|
||||
|
||||
inline std::string TranslateAnsiStringAddress(const Memory* memory,
|
||||
uint32_t guest_address) {
|
||||
if (!guest_address) {
|
||||
return "";
|
||||
}
|
||||
return TranslateAnsiString(
|
||||
memory, memory->TranslateVirtual<const X_ANSI_STRING*>(guest_address));
|
||||
}
|
||||
|
||||
inline std::wstring TranslateUnicodeString(
|
||||
const Memory* memory, const X_UNICODE_STRING* unicode_string) {
|
||||
if (!unicode_string || !unicode_string->length) {
|
||||
return L"";
|
||||
}
|
||||
return std::wstring(
|
||||
memory->TranslateVirtual<const wchar_t*>(unicode_string->pointer),
|
||||
unicode_string->length);
|
||||
}
|
||||
} // namespace util
|
||||
|
||||
#define SHIM_GET_ARG_8(n) util::get_arg_8(ppc_context, n)
|
||||
@@ -117,8 +146,9 @@ class Param {
|
||||
} else {
|
||||
uint32_t stack_ptr =
|
||||
uint32_t(init.ppc_context->r[1]) + 0x54 + (ordinal_ - 8) * 8;
|
||||
*out_value =
|
||||
xe::load_and_swap<V>(init.ppc_context->virtual_membase + stack_ptr);
|
||||
*out_value = xe::load_and_swap<V>(
|
||||
init.ppc_context->kernel_state->memory()->TranslateVirtual(
|
||||
stack_ptr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +183,10 @@ class ParamBase : public Param {
|
||||
class PointerParam : public ParamBase<uint32_t> {
|
||||
public:
|
||||
PointerParam(Init& init) : ParamBase(init) {
|
||||
host_ptr_ = value_ ? init.ppc_context->virtual_membase + value_ : nullptr;
|
||||
host_ptr_ =
|
||||
value_
|
||||
? init.ppc_context->kernel_state->memory()->TranslateVirtual(value_)
|
||||
: nullptr;
|
||||
}
|
||||
PointerParam(void* host_ptr) : ParamBase(), host_ptr_(host_ptr) {}
|
||||
PointerParam& operator=(void*& other) {
|
||||
@@ -191,8 +224,8 @@ template <typename T>
|
||||
class PrimitivePointerParam : public ParamBase<uint32_t> {
|
||||
public:
|
||||
PrimitivePointerParam(Init& init) : ParamBase(init) {
|
||||
host_ptr_ = value_ ? reinterpret_cast<xe::be<T>*>(
|
||||
init.ppc_context->virtual_membase + value_)
|
||||
host_ptr_ = value_ ? init.ppc_context->kernel_state->memory()
|
||||
->TranslateVirtual<xe::be<T>*>(value_)
|
||||
: nullptr;
|
||||
}
|
||||
PrimitivePointerParam(T* host_ptr) : ParamBase() {
|
||||
@@ -223,9 +256,11 @@ template <typename CHAR, typename STR>
|
||||
class StringPointerParam : public ParamBase<uint32_t> {
|
||||
public:
|
||||
StringPointerParam(Init& init) : ParamBase(init) {
|
||||
host_ptr_ = value_ ? reinterpret_cast<CHAR*>(
|
||||
init.ppc_context->virtual_membase + value_)
|
||||
: nullptr;
|
||||
host_ptr_ =
|
||||
value_
|
||||
? init.ppc_context->kernel_state->memory()->TranslateVirtual<CHAR*>(
|
||||
value_)
|
||||
: nullptr;
|
||||
}
|
||||
StringPointerParam(CHAR* host_ptr) : ParamBase(), host_ptr_(host_ptr) {}
|
||||
StringPointerParam& operator=(const CHAR*& other) {
|
||||
@@ -249,9 +284,9 @@ class TypedPointerParam : public ParamBase<uint32_t> {
|
||||
public:
|
||||
TypedPointerParam(Init& init) : ParamBase(init) {
|
||||
host_ptr_ =
|
||||
value_
|
||||
? reinterpret_cast<T*>(init.ppc_context->virtual_membase + value_)
|
||||
: nullptr;
|
||||
value_ ? init.ppc_context->kernel_state->memory()->TranslateVirtual<T*>(
|
||||
value_)
|
||||
: nullptr;
|
||||
}
|
||||
TypedPointerParam(T* host_ptr) : ParamBase(), host_ptr_(host_ptr) {}
|
||||
TypedPointerParam& operator=(const T*& other) {
|
||||
@@ -391,7 +426,7 @@ inline void AppendParam(StringBuffer* string_buffer,
|
||||
std::string name =
|
||||
name_string == nullptr
|
||||
? "(null)"
|
||||
: name_string->to_string(kernel_memory()->virtual_membase());
|
||||
: util::TranslateAnsiString(kernel_memory(), name_string);
|
||||
string_buffer->AppendFormat("(%.8X,%s,%.8X)",
|
||||
uint32_t(record->root_directory), name.c_str(),
|
||||
uint32_t(record->attributes));
|
||||
|
||||
Reference in New Issue
Block a user