how to hooking d3dx library and change font and size
Hello, when I examined the exe I used with ida, the font was created with the "d3dxcreatefontindirecta" function. I tried to hook this function with the minhook library, but the client gave an error. I think my mistake is in calling the function.
My code;
Code:
// Hooks.h
#pragma once
#include "Core.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <d3dx9.h>
#include "MinHook.h"
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "kernel32.lib")
// Connect
typedef int (WINAPI* CONNECT)(SOCKET, const struct sockaddr*, int);
extern CONNECT oConnect;
int WINAPI HookedConnect(SOCKET s, const struct sockaddr* name, int namelen);
// CreateFileA
bool IsAllowedDirectory(const std::string& dir);
std::tuple<std::string, std::string, std::string>SplitPath(const std::string& filePath);
typedef HANDLE(WINAPI* tCreateFileA)(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
extern tCreateFileA oCreateFileA;
HANDLE WINAPI HookedCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
// Font
typedef int(__thiscall* tFont)(char*);
extern tFont oFont;
BOOL hookedFont(char *thisPtr);
typedef HRESULT(WINAPI* tD3DXCreateFontIndirectA)(LPDIRECT3DDEVICE9, CONST D3DXFONT_DESCA*, LPD3DXFONT*);
extern tD3DXCreateFontIndirectA oD3DXCreateFontIndirectA;
HRESULT WINAPI HookedD3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 pDevice, CONST D3DXFONT_DESCA* pDesc, LPD3DXFONT* ppFont);
// Declare the function to install and uninstall the hook
DWORD InstallHook();
DWORD UninstallHook();
// Hooks.cpp
#include "Hooks.h"
DWORD InstallHook()
{
// Initialize MinHook
if (MH_Initialize() != MH_OK) {
// Handle initialization error
return 1;
}
// Create a hook for the connect function
if (MH_CreateHookApi(L"ws2_32.dll", "connect", &HookedConnect, reinterpret_cast<LPVOID*>(&oConnect)) != MH_OK) {
// Handle hook creation error
return 1;
}
// Create a hook for the CreateFileA function
if (MH_CreateHookApi(L"kernel32.dll", "CreateFileA", &HookedCreateFileA, reinterpret_cast<LPVOID*>(&oCreateFileA)) != MH_OK) {
// Handle hook creation error
return 1;
}
// Create a hook for the Font function
oFont = reinterpret_cast<tFont>(0x004BDF60); // Replace with the actual address
if (MH_CreateHook(reinterpret_cast<void*>(oFont), &hookedFont, reinterpret_cast<void**>(&oFont)) != MH_OK) {
// Handle hook creation error
return 1;
}
if (MH_CreateHookApi(L"D3DX9_42.dll", "D3DXCreateFontIndirectA", &HookedD3DXCreateFontIndirectA, reinterpret_cast<LPVOID*>(&oD3DXCreateFontIndirectA)) != MH_OK) {
// Handle hook creation error
MessageBoxA(NULL, "MinHook Error", "MinHook Error", MB_OK);
return 1;
}
// Enable the hook
if (MH_EnableHook(MH_ALL_HOOKS) != MH_OK) {
// Handle hook enable error
return 1;
}
return 0;
}
DWORD UninstallHook()
{
// Disable the hook
if (MH_DisableHook(MH_ALL_HOOKS) != MH_OK) {
// Handle hook disable error
return 1;
}
// Uninitialize MinHook
if (MH_Uninitialize() != MH_OK) {
// Handle uninitialization error
return 2;
}
return 0;
}
// CreateFileA.cpp
#include "Hooks.h"
#include <Shlwapi.h>
tFont oFont = nullptr;
BOOL hookedFont(char *thisPtr)
{
std::string fontPath = "G01_GFONT\\gigassoft_12.ttf";
if (!PathFileExistsA(fontPath.c_str())) {
return 0;
}
else {
if (!AddFontResourceA(fontPath.c_str())) {
return 0;
}
else {
return 1;
}
}
}
tD3DXCreateFontIndirectA oD3DXCreateFontIndirectA = nullptr;
HRESULT WINAPI HookedD3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 pDevice, CONST D3DXFONT_DESCA* pDesc, LPD3DXFONT* ppFont) {
// Yeni font parametreleri
D3DXFONT_DESCA newFontDesc;
ZeroMemory(&newFontDesc, sizeof(newFontDesc));
newFontDesc.Height = 48; // Punto boyutu
newFontDesc.Width = 0;
newFontDesc.Weight = FW_NORMAL;
newFontDesc.MipLevels = 1;
newFontDesc.Italic = FALSE;
newFontDesc.CharSet = DEFAULT_CHARSET;
newFontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
newFontDesc.Quality = DEFAULT_QUALITY;
newFontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
strcpy_s(newFontDesc.FaceName, "Arial"); // Font adı
HRESULT result = oD3DXCreateFontIndirectA(pDevice, &newFontDesc, ppFont);
if (result >= 0)
{
MessageBoxA(NULL, "test", "test", NULL);
}
return result;
}
More than font size would need to change the positions it renders and size of areas it might wrap too if any.
I suspect that you can hook d3d functions through patching the vtable.
The addresses are different you need a signature scan to find the device then get the vtable.
But in saying this I have not hooked the font stuff.
More than font size would need to change the positions it renders and size of areas it might wrap too if any.
I suspect that you can hook d3d functions through patching the vtable.
The addresses are different you need a signature scan to find the device then get the vtable.
But in saying this I have not hooked the font stuff.
[SIZE="4"][FONT="Arial Black"][B] Server 1 Gold [S] E*Gold/PSC[/FONT][/SIZE] 03/04/2013 - Nostale Trading - 23 Replies Wie im Titel erwähnt, verkaufe ich mein NosTale-Gold...
Ich nehme als Zahlungsmittel an...:
1. E*Gold
2. Paysafecard, diese könnt ihr auch gleich einlösen, und dann kann ich euch 26 E*Gold für jeweils 1,5kk verkaufen,,.... dann habt ihr auch eine Sicherheit^^
Ich wähle meinen Kurs 1€= 1,5kk
EDIT--> 4.03.2013
Sonderangebot:
[FONT="Arial Black"][SIZE="7"]Need for Speed World down ?[/SIZE][/FONT] 06/10/2012 - Need for Speed World - 0 Replies ist ned for speed down weil ich komme rein nur bis stüzpunkt und wen ich auf den welter fahren will ladet er 20 min lang und pasiert nixx auser laden neustarte neue instalieren alles versucht und so xD
VK 1st Lt [FONT="Tahoma"][SIZE="6"][/SIZE][/FONT] 11/14/2011 - CrossFire Trading - 3 Replies Verkaufe meinen VK 1st Lt & 4 Striche voll.
Waffen : Ak47 Silver, Anaconda Adv, AWM, DE , M4 Custom, QBZ, M16A2, Thompson.
ca. 23k GP & 5503 BP
Char : SWAT , STAR , SPOP
17 Ribbons
[SIZE="3"][FONT="Arial Black"]Vk Acc (kommt aufs Angebot an)[/FONT][/SIZE] 10/26/2010 - 4Story Trading - 5 Replies hi leute,
möchte hier meinen xhadra/valo acc vllt verkaufen. kommt auf das angebot drauf an ^^
ist ein bogi lvl 29 aber viel gold.
sehr gutes eq wird dann bei intresse genauer beschrieben.
bei interesse schreiben.
sry wegen der Beschreibung ;)