Skip to content

Commit

Permalink
Some GDI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
momo5502 committed Feb 14, 2025
1 parent 39ffa6c commit 665ff99
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/common/platform/kernel_mapped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ typedef struct _PEB64
ULONG MaximumNumberOfHeaps;
std::uint64_t** ProcessHeaps; // PHEAP

std::uint64_t* GdiSharedHandleTable; // PGDI_SHARED_MEMORY
std::uint64_t GdiSharedHandleTable; // PGDI_SHARED_MEMORY
std::uint64_t* ProcessStarterHelper;
ULONG GdiDCAttributeList;

Expand Down
5 changes: 5 additions & 0 deletions src/common/platform/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,13 @@ struct GDI_HANDLE_ENTRY64
struct GDI_SHARED_MEMORY64
{
GDI_HANDLE_ENTRY64 Handles[GDI_MAX_HANDLE_COUNT];
char pad[0xC8];
uint64_t Objects[0x20];
uint64_t Data[0x200]; // ?
};

static_assert(offsetof(GDI_SHARED_MEMORY64, Objects) == 0x1800B0);

struct CLIENT_ID64
{
DWORD64 UniqueProcess;
Expand Down
32 changes: 26 additions & 6 deletions src/windows-emulator/emulator_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,24 @@ class emulator_object
}

template <typename F>
void access(const F& accessor, const size_t index = 0) const
void access_safe(const F& accessor, const size_t index = 0) const
{
T obj{};
this->memory_->read_memory(this->address_ + index * this->size(), &obj, sizeof(obj));

accessor(obj);
auto obj = std::make_unique<T>();
this->access_object(accessor, *obj, index);
}

this->write(obj, index);
template <typename F>
void access(const F& accessor, const size_t index = 0) const
{
if constexpr (sizeof(T) < 0x4000)
{
T obj{};
this->access_object(accessor, obj, index);
}
else
{
this->access_safe(accessor, index);
}
}

void serialize(utils::buffer_serializer& buffer) const
Expand All @@ -145,6 +155,16 @@ class emulator_object
private:
memory_interface* memory_{};
uint64_t address_{};

template <typename F>
void access_object(const F& accessor, T& obj, const size_t index = 0) const
{
this->memory_->read_memory(this->address_ + index * this->size(), &obj, sizeof(obj));

accessor(obj);

this->write(obj, index);
}
};

// TODO: warning emulator_utils is hardcoded for 64bit unicode_string usage
Expand Down
10 changes: 8 additions & 2 deletions src/windows-emulator/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2669,8 +2669,14 @@ namespace
c.proc.peb.access([&](PEB64& peb) {
if (!peb.GdiSharedHandleTable)
{
peb.GdiSharedHandleTable = reinterpret_cast<EmulatorTraits<Emu64>::PVOID*>(
c.proc.base_allocator.reserve<GDI_SHARED_MEMORY64>().ptr());
const auto shared_memory = c.proc.base_allocator.reserve<GDI_SHARED_MEMORY64>();

shared_memory.access([](GDI_SHARED_MEMORY64& mem) {
mem.Objects[0x12] = 1;
mem.Objects[0x13] = 1;
});

peb.GdiSharedHandleTable = shared_memory.value();
}
});

Expand Down

0 comments on commit 665ff99

Please sign in to comment.