diff options
Diffstat (limited to 'vgui_surface030_vtable_identification.md')
| -rw-r--r-- | vgui_surface030_vtable_identification.md | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/vgui_surface030_vtable_identification.md b/vgui_surface030_vtable_identification.md new file mode 100644 index 0000000..7adbda8 --- /dev/null +++ b/vgui_surface030_vtable_identification.md | |||
| @@ -0,0 +1,227 @@ | |||
| 1 | # ISurface VGUI_Surface030 VTable Identification | ||
| 2 | |||
| 3 | ## Binary Info | ||
| 4 | - **File**: `/home/salmon/.local/share/Steam/steamapps/common/Half-Life 2/bin/vguimatsurface.so` | ||
| 5 | - **Format**: ELF 32-bit LSB shared object, Intel i386, **not stripped** | ||
| 6 | - **Load bias**: `0xe2dee000` | ||
| 7 | - **VTable location**: `.data.rel.ro` at file offset `0x246e60`, virtual address `0x247e60` | ||
| 8 | - **Total vtable entries**: 179 | ||
| 9 | - **Typeinfo**: CMatSystemSurface typeinfo at vaddr `0x24a500`, referenced at vtable[-1] | ||
| 10 | |||
| 11 | ## Methodology | ||
| 12 | |||
| 13 | The vtable was located by finding the CMatSystemSurface `__si_class_type_info` object at vaddr `0x24a500` (identified by its `__type_name` pointing to `"17CMatSystemSurface"` at `0x1ec4ec`), then finding where that address is stored in `.data.rel.ro` as a vtable typeinfo pointer. The vtable entries (consecutive `R_386_RELATIVE` relocations in `.data.rel.ro` pointing into `.text`) start immediately after the typeinfo pointer. | ||
| 14 | |||
| 15 | Each function was identified by disassembling the function body and matching behavioral patterns against the ISurface.h header from the project. | ||
| 16 | |||
| 17 | ## VTable Layout (Itanium ABI) | ||
| 18 | |||
| 19 | ``` | ||
| 20 | vtable[-2] = offset-to-top = 0x00000000 (vaddr 0x247e58) | ||
| 21 | vtable[-1] = typeinfo* = 0x0024a500 (vaddr 0x247e5c) → CMatSystemSurface | ||
| 22 | vtable[ 0] = func ptr = 0x0006c010 (vaddr 0x247e60) → Connect (IAppSystem) | ||
| 23 | ... | ||
| 24 | vtable[178]= 0x0006b250 | ||
| 25 | ``` | ||
| 26 | |||
| 27 | --- | ||
| 28 | |||
| 29 | ## Identified Function Slot Numbers | ||
| 30 | |||
| 31 | ### 1. DrawSetTextFont(HFont) → **Slot 17** | ||
| 32 | - **File offset**: `0x00069360` | ||
| 33 | - **Runtime**: `0xe2e57360` (load_bias + 0x69360) | ||
| 34 | - **Member offset**: `this+0x290` | ||
| 35 | |||
| 36 | ```asm | ||
| 37 | 00069360: push %ebp | ||
| 38 | 00069361: mov %esp,%ebp | ||
| 39 | 00069363: mov 0x8(%ebp),%eax ; eax = this | ||
| 40 | 00069366: mov 0xc(%ebp),%edx ; edx = HFont | ||
| 41 | 00069369: mov %edx,0x290(%eax) ; this->m_hCurrentFont = font | ||
| 42 | 0006936f: pop %ebp | ||
| 43 | 00069370: ret | ||
| 44 | ``` | ||
| 45 | |||
| 46 | **Evidence**: Trivially stores a single int (HFont) at `this+0x290`. Cross-validated: slot 22 (DrawPrintText) reads from `0x290(%esi)` to get the current font. | ||
| 47 | |||
| 48 | --- | ||
| 49 | |||
| 50 | ### 2. DrawSetTextColor(int r, int g, int b, int a) → **Slot 18** | ||
| 51 | - **File offset**: `0x00069380` | ||
| 52 | - **Runtime**: `0xe2e57380` (load_bias + 0x69380) | ||
| 53 | - **Member offsets**: `this+0x28` (R), `this+0x29` (G), `this+0x2a` (B), `this+0x2b` (A) | ||
| 54 | |||
| 55 | ```asm | ||
| 56 | 00069380: push %ebp | ||
| 57 | 00069381: pxor %xmm0,%xmm0 | ||
| 58 | 00069385: mov %esp,%ebp | ||
| 59 | 0006938d: mov 0x8(%ebp),%edi ; edi = this | ||
| 60 | 00069390: cvtsi2ss 0x18(%ebp),%xmm0 ; xmm0 = (float)a | ||
| 61 | 00069395: mov 0xc(%ebp),%ebx ; ebx = r | ||
| 62 | 00069398: mulss 0x10(%edi),%xmm0 ; xmm0 *= this->m_flAlphaMultiplier | ||
| 63 | 0006939d: movzbl 0x28(%edi),%ecx ; load current R | ||
| 64 | 000693a1: cvttss2si %xmm0,%esi ; esi = (int)(a * alphaMul) | ||
| 65 | 000693a5: cmp %ebx,%ecx ; if (currentR == newR) | ||
| 66 | 000693a7: je 693d8 ; skip vtable call | ||
| 67 | 000693a9: mov (%edi),%ecx ; vtable ptr | ||
| 68 | 000693af: call *0x60(%ecx) ; call vtable[24] (notification callback) | ||
| 69 | 000693b6: mov %bl,0x28(%edi) ; this->textColor.r = r | ||
| 70 | 000693bc: mov al,0x29(%edi) ; this->textColor.g = g (from 0x10(%ebp)) | ||
| 71 | 000693c3: mov al,0x2a(%edi) ; this->textColor.b = b (from 0x14(%ebp)) | ||
| 72 | 000693c8: mov al,0x2b(%edi) ; this->textColor.a = a (clamped/int) | ||
| 73 | 000693d2: ret | ||
| 74 | ``` | ||
| 75 | |||
| 76 | **Evidence**: Stores 4 consecutive bytes (RGBA) at `this+0x28..0x2b`. The alpha is multiplied by `m_flAlphaMultiplier` at `this+0x10` before clamping. If the red component changed, it calls a notification callback via vtable[0x60/4=24]. Cross-validated: DrawSetColor (slot 10) stores at `this+0x24..0x27` (shape color, different location). | ||
| 77 | |||
| 78 | --- | ||
| 79 | |||
| 80 | ### 3. DrawSetTextPos(int x, int y) → **Slot 20** | ||
| 81 | - **File offset**: `0x00069440` | ||
| 82 | - **Runtime**: `0xe2e57440` (load_bias + 0x69440) | ||
| 83 | - **Member offsets**: `this+0x2c` (x), `this+0x30` (y) | ||
| 84 | |||
| 85 | ```asm | ||
| 86 | 00069440: push %ebp | ||
| 87 | 00069441: mov %esp,%ebp | ||
| 88 | 00069443: mov 0x8(%ebp),%eax ; eax = this | ||
| 89 | 00069446: mov 0xc(%ebp),%edx ; edx = x | ||
| 90 | 00069449: mov %edx,0x2c(%eax) ; this->m_nTextX = x | ||
| 91 | 0006944c: mov 0x10(%ebp),%edx ; edx = y | ||
| 92 | 0006944f: mov %edx,0x30(%eax) ; this->m_nTextY = y | ||
| 93 | 00069452: pop %ebp | ||
| 94 | 00069453: ret | ||
| 95 | ``` | ||
| 96 | |||
| 97 | **Evidence**: Stores 2 ints at `this+0x2c` and `this+0x30`. Cross-validated: DrawGetTextPos (slot 21) at `0x69460` reads from the same offsets (`0x2c(%eax)` and `0x30(%eax)`). | ||
| 98 | |||
| 99 | --- | ||
| 100 | |||
| 101 | ### 4. DrawPrintText(const wchar_t* text, int textLen, FontDrawType_t drawType) → **Slot 22** | ||
| 102 | - **File offset**: `0x00072980` | ||
| 103 | - **Runtime**: `0xe2e60980` (load_bias + 0x72980) | ||
| 104 | |||
| 105 | ```asm | ||
| 106 | 00072980: push %ebp | ||
| 107 | 00072981: mov %esp,%ebp | ||
| 108 | 00072983: push %edi | ||
| 109 | 00072984: push %esi | ||
| 110 | 00072985: push %ebx | ||
| 111 | 00072986: call 624a9 ; __x86.get_pc_thunk (PIC setup) | ||
| 112 | 0007298b: add $0x1fe675,%ebx | ||
| 113 | 00072991: sub $0x9c,%esp ; large stack frame | ||
| 114 | 00072997: mov 0xc(%ebp),%edi ; edi = text (wchar_t*) | ||
| 115 | 000729a5: mov 0x8(%ebp),%esi ; esi = this | ||
| 116 | 000729a8: test %edi,%edi ; if (!text) return | ||
| 117 | 000729b0: mov 0x290(%esi),%eax ; load current font (HFont) | ||
| 118 | 000729b6: test %eax,%eax ; if (!font) return | ||
| 119 | 000729be: mov 0x8(%esi),%edx ; base x | ||
| 120 | 000729c4: add 0x2c(%esi),%edx ; + text offset x | ||
| 121 | 000729db: push %eax ; font | ||
| 122 | 000729dc: push %esi ; this | ||
| 123 | 000729dd: call *0x114(%edx) ; vtable[0x114/4=69] → GetFontTall or similar | ||
| 124 | ``` | ||
| 125 | |||
| 126 | **Evidence**: Large function (~800+ bytes) that: | ||
| 127 | 1. Reads the current font from `this+0x290` (matching DrawSetTextFont's store) | ||
| 128 | 2. Computes render position from base coordinates + text offset | ||
| 129 | 3. Calls vtable[0x114] (a font metrics function) | ||
| 130 | 4. Contains complex text layout/rendering logic with stack frame of 0x9c bytes | ||
| 131 | 5. References the `FinishDrawing` string indirectly through the rendering pipeline | ||
| 132 | |||
| 133 | --- | ||
| 134 | |||
| 135 | ### 5. CreateFont() → **Slot 66** | ||
| 136 | - **File offset**: `0x0006a2d0` | ||
| 137 | - **Runtime**: `0xe2e582d0` (load_bias + 0x6a2d0) | ||
| 138 | |||
| 139 | ```asm | ||
| 140 | 0006a2d0: push %ebp | ||
| 141 | 0006a2d1: mov %esp,%ebp | ||
| 142 | 0006a2d3: push %ebx | ||
| 143 | 0006a2d4: call 624a9 ; __x86.get_pc_thunk | ||
| 144 | 0006a2d9: add $0x206d27,%ebx | ||
| 145 | 0006a2df: sub $0x4,%esp | ||
| 146 | 0006a2e2: call 1693b0 ; → get CFontManager* (PIC global lookup) | ||
| 147 | 0006a2e7: sub $0xc,%esp | ||
| 148 | 0006a2ea: push %eax ; pass font manager | ||
| 149 | 0006a2eb: call 16a200 ; → CFontManager::CreateFont() → returns HFont | ||
| 150 | 0006a2f0: mov -0x4(%ebp),%ebx | ||
| 151 | 0006a2f3: leave | ||
| 152 | 0006a2f4: ret ; return HFont in eax | ||
| 153 | ``` | ||
| 154 | |||
| 155 | **Evidence**: Calls `0x1693b0` which returns a pointer to the global CFontManager singleton (PIC-computed from GOT), then calls `0x16a200` which allocates a new font entry and returns its HFont handle. Simple wrapper — no arguments besides `this`. | ||
| 156 | |||
| 157 | --- | ||
| 158 | |||
| 159 | ### 6. AddGlyphSetToFont(HFont font, const char* windowsFontName, int tall, int weight, int blur, int scanlines, int flags, int nRangeMin, int nRangeMax) → **Slot 67** | ||
| 160 | - **File offset**: `0x0006a300` | ||
| 161 | - **Runtime**: `0xe2e58300` (load_bias + 0x6a300) | ||
| 162 | |||
| 163 | ```asm | ||
| 164 | 0006a300: push %ebp | ||
| 165 | 0006a301: mov %esp,%ebp | ||
| 166 | 0006a303: push %ebx | ||
| 167 | 0006a304: call 624a9 ; __x86.get_pc_thunk | ||
| 168 | 0006a309: add $0x206cf7,%ebx | ||
| 169 | 0006a30f: sub $0x4,%esp | ||
| 170 | 0006a312: call 1693b0 ; → get CFontManager* | ||
| 171 | 0006a317: sub $8,%esp | ||
| 172 | 0006a31a: push 0x2c(%ebp) ; arg 9: nRangeMax | ||
| 173 | 0006a31d: push 0x28(%ebp) ; arg 8: nRangeMin | ||
| 174 | 0006a320: push 0x24(%ebp) ; arg 7: flags | ||
| 175 | 0006a323: push 0x20(%ebp) ; arg 6: scanlines | ||
| 176 | 0006a326: push 0x1c(%ebp) ; arg 5: blur | ||
| 177 | 0006a329: push 0x18(%ebp) ; arg 4: weight | ||
| 178 | 0006a32c: push 0x14(%ebp) ; arg 3: tall | ||
| 179 | 0006a32f: push 0x10(%ebp) ; arg 2: windowsFontName (const char*) | ||
| 180 | 0006a332: push 0x0c(%ebp) ; arg 1: font (HFont) | ||
| 181 | 0006a335: push %eax ; font manager | ||
| 182 | 0006a336: call 16a550 ; → CFontManager::SetFontGlyphSet() | ||
| 183 | 0006a33b: mov -0x4(%ebp),%ebx | ||
| 184 | 0006a33e: leave | ||
| 185 | 0006a33f: ret | ||
| 186 | ``` | ||
| 187 | |||
| 188 | **Evidence**: Pushes all 9 user-visible arguments (HFont + const char* + 7 ints) plus the font manager pointer onto the stack and calls `0x16a550`. That inner function: | ||
| 189 | - Multiplies HFont by `0x3c` (60 bytes per font entry) to index into the font array | ||
| 190 | - Calls `0x169ec0` to resolve the font name string | ||
| 191 | - Calls `0x16a220` to configure the font with FreeType parameters | ||
| 192 | |||
| 193 | Note: The ISurface.h header in the project names this `SetFontGlyphSet`, but older Source SDK versions (VGUI_Surface030 from HL2) call it `AddGlyphSetToFont`. Same function, different name. | ||
| 194 | |||
| 195 | --- | ||
| 196 | |||
| 197 | ## Summary Table | ||
| 198 | |||
| 199 | | Slot | Function | File Offset | Runtime Address | Member Offset | | ||
| 200 | |------|----------|-------------|-----------------|---------------| | ||
| 201 | | 17 | `DrawSetTextFont(HFont)` | `0x00069360` | `0xe2e57360` | `this+0x290` | | ||
| 202 | | 18 | `DrawSetTextColor(int,int,int,int)` | `0x00069380` | `0xe2e57380` | `this+0x28..0x2b` | | ||
| 203 | | 20 | `DrawSetTextPos(int,int)` | `0x00069440` | `0xe2e57440` | `this+0x2c, +0x30` | | ||
| 204 | | 22 | `DrawPrintText(wchar_t*,int,FontDrawType_t)` | `0x00072980` | `0xe2e60980` | reads `this+0x290` | | ||
| 205 | | 66 | `CreateFont()` | `0x0006a2d0` | `0xe2e582d0` | returns HFont | | ||
| 206 | | 67 | `AddGlyphSetToFont(HFont, const char*, int×7)` | `0x0006a300` | `0xe2e58300` | calls `0x16a550` | | ||
| 207 | |||
| 208 | ## Related Slots | ||
| 209 | |||
| 210 | | Slot | Function | Evidence | | ||
| 211 | |------|----------|----------| | ||
| 212 | | 10 | `DrawSetColor(int,int,int,int)` | stores at `this+0x24..0x27` (shape color) | | ||
| 213 | | 11 | `DrawSetColor(Color_t)` | extracts packed int, stores at `this+0x24..0x27` | | ||
| 214 | | 19 | `DrawSetTextColor(Color_t)` | stores at `this+0x28..0x2b` (text color, via packed Color_t) | | ||
| 215 | | 21 | `DrawGetTextPos(int&,int&)` | reads from `this+0x2c, +0x30` (inverse of DrawSetTextPos) | | ||
| 216 | |||
| 217 | ## CMatSystemSurface Member Layout (inferred) | ||
| 218 | |||
| 219 | | Offset | Type | Field | | ||
| 220 | |--------|------|-------| | ||
| 221 | | `+0x00` | `void**` | vtable pointer | | ||
| 222 | | `+0x10` | `float` | `m_flAlphaMultiplier` | | ||
| 223 | | `+0x24` | `uint8[4]` | `drawColor` (RGBA for shapes) | | ||
| 224 | | `+0x28` | `uint8[4]` | `textColor` (RGBA for text) | | ||
| 225 | | `+0x2c` | `int` | `m_nTextX` | | ||
| 226 | | `+0x30` | `int` | `m_nTextY` | | ||
| 227 | | `+0x290` | `HFont` | `m_hCurrentFont` | | ||
