Blame src/internal/gdi/gdi.c

388229
#include <psxtypes/psxtypes.h>
388229
#include <pemagine/pemagine.h>
388229
#include <ntapi/ntapi.h>
388229
#include <gdi/gdi.h>
388229
388229
#ifndef GDI_ADDRESS_SPACE_OCD
388229
#define GDI_ADDRESS_SPACE_OCD 0
388229
#endif
388229
388229
int32_t __fastcall gdi_vtbl_init(gdi_vtbl * gdi)
388229
{
388229
	int32_t			status;
388229
	void *			hgdi32;
388229
	void *			huser32;
388229
388229
	ntapi_vtbl *		ntapi;
388229
	struct dalist_ex	ldr_module_list;
388229
	struct dalist_node *	node;
388229
388229
	uintptr_t		block[0x80];
388229
	wchar16_t		gdi32_base_name[]  = {'g','d','i','3','2','.','d','l','l',0};
388229
	wchar16_t		user32_base_name[] = {'u','s','e','r','3','2','.','d','l','l',0};
388229
388229
	/* init */
388229
	if ((status = ntapi_init(&ntapi)))
388229
		return status;
388229
388229
	ntapi->tt_aligned_block_memset(
388229
		block,0,sizeof(block));
388229
388229
	/* module list */
388229
	if ((status = dalist_init_ex(
388229
			&ldr_module_list,
388229
			0,0,0,
388229
			DALIST_MEMFN_CUSTOM)))
388229
		return status;
388229
388229
	if ((status = dalist_deposit_memory_block(
388229
			&ldr_module_list,
388229
			block,sizeof(block))))
388229
		return status;
388229
388229
	if ((status = ntapi->ldr_create_state_snapshot(
388229
			&ldr_module_list)))
388229
		return status;
388229
388229
	/* load gdi32 (explicit), user32 (implicit) */
388229
	hgdi32  = 0;
388229
	huser32 = 0;
388229
388229
	if ((status = ntapi->ldr_load_system_dll(
388229
			0,
388229
			gdi32_base_name,
388229
			sizeof(gdi32_base_name),
388229
			0,&hgdi32)))
388229
		return status;
388229
388229
	hgdi32  = pe_get_module_handle(gdi32_base_name);
388229
	huser32 = pe_get_module_handle(user32_base_name);
388229
388229
	if (!hgdi32 || !huser32)
388229
		return NT_STATUS_INTERNAL_ERROR;
388229
388229
	/* address space ocd */
388229
	if ((status = dalist_get_node_by_key(
388229
			&ldr_module_list,
388229
			(struct dalist_node_ex **)&node,
388229
			(uintptr_t)hgdi32,
388229
			DALIST_NODE_TYPE_EXISTING | DALIST_NODE_TYPE_NEW,
388229
			0)))
388229
		return status;
388229
388229
	if ((status = dalist_get_node_by_key(
388229
			&ldr_module_list,
388229
			(struct dalist_node_ex **)&node,
388229
			(uintptr_t)huser32,
388229
			DALIST_NODE_TYPE_EXISTING | DALIST_NODE_TYPE_NEW,
388229
			0)))
388229
		return status;
388229
388229
	if (GDI_ADDRESS_SPACE_OCD)
388229
		if ((status = ntapi->ldr_revert_state_to_snapshot(&ldr_module_list)))
388229
			return status;
388229
388229
	/* gdi vtbl */
388229
	gdi->get_system_metrics = (gdi_get_system_metrics *)pe_get_procedure_address(
388229
		huser32,
388229
		"GetSystemMetrics");
388229
388229
	gdi->is_iconic = (gdi_is_iconic *)pe_get_procedure_address(
388229
		huser32,
388229
		"IsIconic");
388229
388229
	gdi->is_zoomed = (gdi_is_zoomed *)pe_get_procedure_address(
388229
		huser32,
388229
		"IsZoomed");
388229
388229
	gdi->peek_message = (gdi_peek_message *)pe_get_procedure_address(
388229
		huser32,
388229
		"PeekMessageW");
388229
388229
	gdi->move_window = (gdi_move_window *)pe_get_procedure_address(
388229
		huser32,
388229
		"MoveWindow");
388229
388229
	gdi->set_window_pos = (gdi_set_window_pos *)pe_get_procedure_address(
388229
		huser32,
388229
		"SetWindowPos");
388229
388229
	gdi->get_window_rect = (gdi_get_window_rect *)pe_get_procedure_address(
388229
		huser32,
388229
		"GetWindowRect");
388229
388229
	gdi->get_client_rect = (gdi_get_client_rect *)pe_get_procedure_address(
388229
		huser32,
388229
		"GetClientRect");
388229
388229
	gdi->get_desktop_window = (gdi_get_desktop_window *)pe_get_procedure_address(
388229
		huser32,
388229
		"GetDesktopWindow");
388229
388229
	if (sizeof(size_t) == 8)
388229
		gdi->set_window_long_ptr = (gdi_set_window_long_ptr *)pe_get_procedure_address(
388229
			huser32,
388229
			"SetWindowLongPtrW");
388229
	else
388229
		gdi->set_window_long_ptr = (gdi_set_window_long_ptr *)pe_get_procedure_address(
388229
			huser32,
388229
			"SetWindowLongW");
388229
388229
	return NT_STATUS_SUCCESS;
388229
}