134 lines
5.7 KiB
Plaintext
134 lines
5.7 KiB
Plaintext
|
readme for interpreted thunks
|
||
|
|
||
|
Interpreted Thunks are an attempt to replace the simplest thunk functions
|
||
|
in WOW with a bit of data. Each thunk consists of a pointer to the Win32
|
||
|
API routine (actually to a callable loader thunk in one of the pages set
|
||
|
aside for fixups if needed) and a pointer to a variable-length byte stream
|
||
|
which dictates how to convert arguments and return values. The first byte
|
||
|
is an opcode indicating how to thunk the leftmost argument, the last byte
|
||
|
is distinguished by having its high bit set (0x8?) and indicates how to
|
||
|
thunk the return value.
|
||
|
|
||
|
A tool called genwowit reads a source file called wow.it which contains
|
||
|
psuedo-prototypes (really thunk descriptions) and generates wowit.h
|
||
|
and wowit.c with the actualy thunk table and assiociated instruction
|
||
|
"swamp" containing all the bytecode instruction streams. See
|
||
|
\nt\private\sdktools\genwowit\readme.txt for details.
|
||
|
|
||
|
Note that the major restriction of interpreted thunks as implemented is
|
||
|
that pointers to structures which need thunking are not supported.
|
||
|
|
||
|
Here's a tiny wow.it and the wowit.h and wowit.c that result.
|
||
|
|
||
|
----- wow.it begin
|
||
|
INT UpdateColors(HGDI);
|
||
|
INT StartPage(HGDI);
|
||
|
INT EndPage(HGDI);
|
||
|
DWORD GetFontData(HGDI, DWORD, DWORD, PTR, DWORD);
|
||
|
WORD GetRasterizerCaps(PTR, INT);
|
||
|
WORD IsGDIObject=GetObjectType(HGDI);
|
||
|
WORD GetTextAlign(HGDI);
|
||
|
INT GetTextCharacterExtra(HGDI);
|
||
|
INT SetTextCharacterExtra(HGDI, INT);
|
||
|
DWORD GetTextColor(HGDI);
|
||
|
INT GetTextFace(HGDI, INT, PTR);
|
||
|
INT SetTextJustification(HGDI, INT, INT);
|
||
|
WORD TextOut(HGDI, INT, INT, PTR, INT);
|
||
|
----- wow.it end
|
||
|
|
||
|
here's the output genwowit produces on the console:
|
||
|
|
||
|
Generated wowit.h and wowit.c from wow.it
|
||
|
13 thunks, 8 unique instruction streams, 29 instruction bytes, 5 max args.
|
||
|
|
||
|
And the files:
|
||
|
|
||
|
----- wowit.h begin
|
||
|
//
|
||
|
// wowit.h generated by genwowit.exe from wow.it, DO NOT EDIT.
|
||
|
//
|
||
|
|
||
|
#include "intthunk.h"
|
||
|
|
||
|
#define MAX_IT_ARGS 5
|
||
|
|
||
|
#define IT_WORD ( (UCHAR) 0x0 )
|
||
|
#define IT_INT ( (UCHAR) 0x1 )
|
||
|
#define IT_DWORD ( (UCHAR) 0x2 )
|
||
|
#define IT_LPDWORD ( (UCHAR) 0x3 )
|
||
|
#define IT_PTR ( (UCHAR) 0x4 )
|
||
|
#define IT_PTRORATOM ( (UCHAR) 0x5 )
|
||
|
#define IT_HGDI ( (UCHAR) 0x6 )
|
||
|
#define IT_HUSER ( (UCHAR) 0x7 )
|
||
|
#define IT_COLOR ( (UCHAR) 0x8 )
|
||
|
#define IT_HINST ( (UCHAR) 0x9 )
|
||
|
#define IT_HICON ( (UCHAR) 0xa )
|
||
|
#define IT_16ONLY ( (UCHAR) 0xb )
|
||
|
#define IT_32ONLY ( (UCHAR) 0xc )
|
||
|
|
||
|
#define IT_RETMASK ( (UCHAR) 0x80 )
|
||
|
#define IT_DWORDRET ( IT_RETMASK | (UCHAR) 0x0 )
|
||
|
#define IT_WORDRET ( IT_RETMASK | (UCHAR) 0x1 )
|
||
|
#define IT_INTRET ( IT_RETMASK | (UCHAR) 0x2 )
|
||
|
#define IT_HGDIRET ( IT_RETMASK | (UCHAR) 0x3 )
|
||
|
#define IT_HUSERRET ( IT_RETMASK | (UCHAR) 0x4 )
|
||
|
#define IT_ZERORET ( IT_RETMASK | (UCHAR) 0x5 )
|
||
|
#define IT_HICONRET ( IT_RETMASK | (UCHAR) 0x6 )
|
||
|
#define IT_ONERET ( IT_RETMASK | (UCHAR) 0x7 )
|
||
|
#define IT_HPRNDWPRET ( IT_RETMASK | (UCHAR) 0x8 )
|
||
|
|
||
|
#define ITID_UpdateColors 0
|
||
|
#define ITID_StartPage 1
|
||
|
#define ITID_EndPage 2
|
||
|
#define ITID_GetFontData 3
|
||
|
#define ITID_GetRasterizerCaps 4
|
||
|
#define ITID_IsGDIObject 5
|
||
|
#define ITID_GetTextAlign 6
|
||
|
#define ITID_GetTextCharacterExtra 7
|
||
|
#define ITID_SetTextCharacterExtra 8
|
||
|
#define ITID_GetTextColor 9
|
||
|
#define ITID_GetTextFace 10
|
||
|
#define ITID_SetTextJustification 11
|
||
|
#define ITID_TextOut 12
|
||
|
|
||
|
#define ITID_MAX 12
|
||
|
----- wowit.h end
|
||
|
|
||
|
----- wowit.c begin
|
||
|
//
|
||
|
// wowit.c generated by genwowit.exe from wow.it, DO NOT EDIT.
|
||
|
//
|
||
|
|
||
|
#include "precomp.h"
|
||
|
#pragma hdrstop
|
||
|
#define WOWIT_C
|
||
|
#include "wowit.h"
|
||
|
|
||
|
CONST BYTE InstrSwamp[] = {
|
||
|
/* 0 0x0 */ IT_HGDI, IT_INTRET,
|
||
|
/* 1 0x2 */ IT_HGDI, IT_DWORD, IT_DWORD, IT_PTR, IT_DWORD, IT_DWORDRET,
|
||
|
/* 2 0x8 */ IT_HGDI, IT_INT, IT_INT, IT_PTR, IT_INT, IT_WORDRET,
|
||
|
/* 3 0xe */ IT_HGDI, IT_WORDRET,
|
||
|
/* 4 0x10 */ IT_HGDI, IT_INT, IT_INTRET,
|
||
|
/* 5 0x13 */ IT_HGDI, IT_DWORDRET,
|
||
|
/* 6 0x15 */ IT_HGDI, IT_INT, IT_PTR, IT_INTRET,
|
||
|
/* 7 0x19 */ IT_HGDI, IT_INT, IT_INT, IT_INTRET,
|
||
|
};
|
||
|
|
||
|
INT_THUNK_TABLEENTRY IntThunkTable[] = {
|
||
|
/* 0 */ { (FARPROC) UpdateColors, InstrSwamp + 0x0 }, /* 0 */
|
||
|
/* 1 */ { (FARPROC) StartPage, InstrSwamp + 0x0 }, /* 0 */
|
||
|
/* 2 */ { (FARPROC) EndPage, InstrSwamp + 0x0 }, /* 0 */
|
||
|
/* 3 */ { (FARPROC) GetFontData, InstrSwamp + 0x2 }, /* 1 */
|
||
|
/* 4 */ { (FARPROC) GetRasterizerCaps, InstrSwamp + 0xb }, /* 2 + 3 */
|
||
|
/* 5 */ { (FARPROC) GetObjectType, InstrSwamp + 0xe }, /* 3 */
|
||
|
/* 6 */ { (FARPROC) GetTextAlign, InstrSwamp + 0xe }, /* 3 */
|
||
|
/* 7 */ { (FARPROC) GetTextCharacterExtra, InstrSwamp + 0x0 }, /* 0 */
|
||
|
/* 8 */ { (FARPROC) SetTextCharacterExtra, InstrSwamp + 0x10 }, /* 4 */
|
||
|
/* 9 */ { (FARPROC) GetTextColor, InstrSwamp + 0x13 }, /* 5 */
|
||
|
/* 10 */ { (FARPROC) GetTextFace, InstrSwamp + 0x15 }, /* 6 */
|
||
|
/* 11 */ { (FARPROC) SetTextJustification, InstrSwamp + 0x19 }, /* 7 */
|
||
|
/* 12 */ { (FARPROC) TextOut, InstrSwamp + 0x8 }, /* 2 */
|
||
|
};
|
||
|
----- wowit.c end
|