Skip to content

Commit a1be5e6

Browse files
committed
Supporting variadic arguments, and various other things.
1 parent 9282669 commit a1be5e6

File tree

87 files changed

+1885
-1490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1885
-1490
lines changed
Lines changed: 208 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,160 @@
11
#include <windows.h>
2+
#define USING_NAMESPACE_BCB6_STD
23
#include "bcb6_operator.h"
34
#include "TSSGCtrl.h"
45

56
EXTERN_C BOOL ExtensionTSSDir;
6-
EXTERN_C void __cdecl TSSGAttributeSelector_AddElement_MakeOnlyOneAtteribute(void *, void *);
7-
EXTERN_C void __cdecl TSSGAttributeSelector_MakeNowAttributeVec_push_back(void *, void *);
87
EXTERN_C void * __cdecl TSSGCtrl_ReadSSG_PushElement(void *, void *);
98

10-
static __declspec(naked) void __cdecl TSSGAttributeSelector_StartElementCheck_new_attributeSetMap()
9+
static unsigned seqElement = MAXDWORD;
10+
11+
static __declspec(naked) uint64_t __cdecl TSSGAttributeSelector_StartElementCheck_new_attributeSetMap(size_t __n)
12+
{
13+
__asm {
14+
xor eax, eax
15+
mov seqElement, eax
16+
mov edx, dword ptr [esi + TSSGAttributeSelector.attributeSetMap]
17+
test edx, edx
18+
jnz PASS
19+
20+
mov ecx, dword ptr [esp + 4]
21+
#if OPTIMIZE_ALLOCATOR
22+
call bcb6_operator_new
23+
#else
24+
push ecx
25+
call bcb6_operator_new
26+
pop ecx
27+
#endif
28+
xor edx, edx
29+
30+
PASS:
31+
ret
32+
}
33+
}
34+
35+
void *__cdecl TSSGAttributeSelector_AddElement_MakeOnlyOneAtteribute(TSSGAttributeSelector *const this, TAdjustmentAttribute *AElem)
36+
{
37+
static void *(__cdecl *const TSSGAttributeSelector_MakeOnlyOneAtteribute)(TSSGAttributeSelector *, void *) = (void *)0x004D5764;
38+
39+
AElem = TSSGAttributeSelector_MakeOnlyOneAtteribute(this, AElem);
40+
AElem->seqElement = TSSGAttributeElement_GetType(AElem) == atDEFINE
41+
? string_length(&((TDefineAttribute *)AElem)->inputCode)
42+
: seqElement++// renumbering when redeclared too
43+
;// store into allocator_type[1], except atSCOPE
44+
return AElem;
45+
}
46+
47+
static int __cdecl cmpElement(LPCVOID const A, LPCVOID const B)
48+
{
49+
const TAdjustmentAttribute *const a = *(TAdjustmentAttribute **)A;
50+
const TAdjustmentAttribute *const b = *(TAdjustmentAttribute **)B;
51+
signed diff = a->type - b->type;
52+
return diff ? diff : TSSGAttributeElement_GetType(a) == atDEFINE ?
53+
strcmp(a->c_str, b->c_str) : a->seqElement - b->seqElement;
54+
}
55+
56+
#pragma intrinsic(_BitScanForward)
57+
void __cdecl TSSGAttributeSelector_MakeNowAttributeVec_push_back(list *const allAtteributeVecList, vector *const *const __x)
58+
{
59+
static void(__cdecl *const list_vector_push_back)(list *, const vector *const *) = (void *)0x004D5FBC;
60+
61+
COORD coords[0x20] = { { 0, 0 } };
62+
vector const index = { coords, coords + _countof(coords) - 1, NULL, NULL, coords, MAXDWORD };
63+
64+
vector *const NewVec = *__x;
65+
qsort(vector_begin(NewVec), vector_size_by_type(NewVec, void *), sizeof(void *), cmpElement);
66+
67+
for (TSSGAttributeElement **VIt = vector_begin(NewVec);
68+
VIt < (TSSGAttributeElement **)vector_end(NewVec);
69+
VIt++)
70+
{
71+
DWORD Index;
72+
_BitScanForward(&Index, TSSGAttributeElement_GetType(*VIt));
73+
if (coords[Index].X++ == 0)
74+
coords[Index].Y = VIt - (TSSGAttributeElement **)vector_begin(NewVec);
75+
}
76+
77+
NewVec->allocator_type[0] = NULL;
78+
NewVec->allocator_type[1] = NULL;
79+
NewVec->tblIndex = SubjectStringTable_insert((string *)&index);
80+
list_vector_push_back(allAtteributeVecList, __x);
81+
}
82+
83+
CONSOLE_FONT_INFO __fastcall TSSGAttributeElement_GetViaCoord(AtType const Type, const vector *const AttrV)
84+
{
85+
DWORD Index;
86+
_BitScanForward(&Index, Type);
87+
COORD coord = vector_type_at(&vector_at(&SubjectStringTable_array, AttrV->tblIndex), COORD, Index);
88+
return (CONSOLE_FONT_INFO) { coord.X ? vector_type_at(AttrV, DWORD, coord.Y) : 0, coord };
89+
}
90+
91+
static BOOL __fastcall TSSGCtrl_AddressAttributeFilter_GetAddress_replace(TReplaceAttribute *tmpAE, TSSGSubject **SSGS)
1192
{
93+
if (tmpAE->context)
94+
*SSGS = tmpAE->context;
95+
return !!tmpAE->context;
96+
}
97+
98+
static __declspec(naked) void __cdecl TSSGCtrl_AddressAttributeFilter_GetAddress()
99+
{
12100
__asm {
13-
#define attributeSetMap (esi + 0x20)
14-
mov eax, ExtensionTSSDir
15-
neg eax
16-
and eax, dword ptr [attributeSetMap]
17-
jz NEW
18-
mov dword ptr [esp], 0x004D2E28
19-
ret 4// goto nowAttributeList = new list<TSSGAttributeElement *>;
20-
21-
align 16
22-
NEW:
23-
mov ecx, dword ptr [esp + 4]
24-
jmp bcb6_operator_new
25-
#undef attributeSetMap
101+
lea edx, [esp + 8]
102+
mov ecx, [ebx]
103+
call TSSGCtrl_AddressAttributeFilter_GetAddress_replace
104+
test eax, eax
105+
jz GET
106+
mov ecx, [ebp - 0x48]
107+
mov [edi], ecx// restore initial address
108+
GET:
109+
jmp TSSGCtrl_GetAddress
110+
ud2
26111
}
27112
}
28113

29-
static __declspec(naked) BOOLEAN __cdecl THeapAdjustmentAttribute_IsEqual_adaptScope() {
114+
static __declspec(naked) void __fastcall THeapAdjustmentAttribute_dtor_heapMap(THeapAdjustmentAttribute *this, struct _Rb_tree_node *root)
115+
{
116+
static void(__cdecl *const tree_ulong_pair_uu_erase)() = (void *)0x004D0A80;
117+
static void(__cdecl *const tree_string_double_erase)() = (void *)0x0051C168;
118+
30119
__asm {
31-
cmp dword ptr [ebx + 4], atSCOPE
32-
jne CONTINUE
33-
mov dword ptr [esp], 0x00523643
34-
CONTINUE:
35-
mov eax, 1
36-
ret
120+
mov eax, tree_ulong_pair_uu_erase
121+
cmp dword ptr [ecx + TSSGAttributeElement.type], atSCOPE
122+
cmove eax, tree_string_double_erase
123+
jmp eax
124+
ud2
37125
}
38126
}
39127

40128
#define CALL_REL (BYTE )0xE8
41129
#define JMP_REL32 (BYTE )0xE9
130+
#define JMP_REL8 (BYTE )0xEB
131+
#define JZ_SHORT (BYTE )0x74
132+
#define JNZ_SHORT (BYTE )0x75
42133
#define NOP (BYTE )0x90
43-
#define NOP_X4 (DWORD)0x90909090
134+
#define NOP_X4 (DWORD)0x00401F0F
44135

45136
EXTERN_C void __cdecl Attach_EnumReadSSG()
46137
{
47138
// TSSGAttributeSelector::StartElementCheck
48139
// attributeSetMap!=NULL => nowAttributeList!=NULL
49140
*(LPBYTE )(0x004D2D6D + 2) = offsetof(TSSGAttributeSelector, nowAttributeList);
50141
*(LPDWORD)(0x004D2D85 + 1) = (DWORD)TSSGAttributeSelector_StartElementCheck_new_attributeSetMap - (0x004D2D85 + 1 + sizeof(DWORD));
142+
*(LPDWORD)(0x004D2D90 + 2) = 0x004D2E25 - (0x004D2D90 + 2 + sizeof(DWORD));// EAX is NULL then use EDX
51143

52144
// TSSGAttributeSelector::EndElementCheck
53145
// retain attributeSetMap if caller isn't TSSGAttributeSelector::Clear
54-
*(LPWORD )0x004D3686 = BSWAP16(0x6690);
55-
*(LPDWORD)0x004D3688 = BSWAP32(0x33C08943);
56-
*(LPDWORD)0x004D368C = BSWAP32(0x28817D04);
57-
*(LPDWORD)0x004D3690 = 0x004D2D15;
58-
*(LPBYTE )0x004D3694 = 0x74;
59-
*(LPBYTE )0x004D3695 = 0x004D36A2 - (0x004D3695 + sizeof(BYTE));
60-
*(LPWORD )0x004D3696 = BSWAP16(0x3905);
61-
*(LPDWORD)0x004D3698 = (DWORD)&ExtensionTSSDir;
62-
*(LPWORD )0x004D369C = BSWAP16(0x0F85);
63-
*(LPDWORD)0x004D369E = 0x004D3722 - (0x004D369E + sizeof(DWORD));
146+
*(LPWORD )0x004D3686 = BSWAP16(0x33C9 );// xor ecx, ecx
147+
*(LPDWORD)0x004D3688 = BSWAP32(0x8B45042D);// mov eax, dword ptr [_AddressOfReturnAddress]
148+
*(LPDWORD)0x004D368C = 0x004D2D15 ;// sub eax, ...
149+
*(LPDWORD)0x004D3690 = BSWAP32(0xF7D81BD2);// neg eax; sbb edx, edx
150+
*(LPDWORD)0x004D3694 = BSWAP32(0x8B432089);// mov eax, dword ptr [attributeSetMap]
151+
*(LPDWORD)0x004D3698 = BSWAP32(0x4B288515);// mov dword ptr [nowAttributeVec], ecx
152+
*(LPDWORD)0x004D369C = (DWORD)&ExtensionTSSDir;// test edx, ds:
153+
*(LPBYTE )0x004D36A0 = JZ_SHORT;
154+
*(LPBYTE )0x004D36A1 = 0x004D36A5 - (0x004D36A1 + sizeof(BYTE));
155+
*(LPBYTE )0x004D36A2 = JMP_REL8;
156+
*(LPBYTE )0x004D36A3 = 0x004D3722 - (0x004D36A3 + sizeof(BYTE));
157+
*(LPBYTE )0x004D36A4 = NOP;
64158

65159
// TSSGAttributeSelector::AddElement
66160
*(LPDWORD)0x004D3DCA = (DWORD)TSSGAttributeSelector_AddElement_MakeOnlyOneAtteribute - (0x004D3DCA + sizeof(DWORD));
@@ -69,7 +163,21 @@ EXTERN_C void __cdecl Attach_EnumReadSSG()
69163
*(LPDWORD)0x004D5C88 = (DWORD)TSSGAttributeSelector_MakeNowAttributeVec_push_back - (0x004D5C88 + sizeof(DWORD));
70164

71165
// TSSGCtrl::ReadSSG
72-
*(LPDWORD)0x004E462A = (DWORD)TSSGCtrl_ReadSSG_PushElement - (0x004E462A + sizeof(DWORD));
166+
*(LPBYTE )(0x004E45C8 + 1) = sizeof(TDirAttribute);
167+
168+
*(LPBYTE )(0x004E45F7 + 0) = 0x89;// mov [eax]
169+
*(LPBYTE )(0x004E45F7 + 1) = 0x08;// ecx
170+
*(LPBYTE )(0x004E45F9 + 0) = 0x8B;// mov edx,
171+
*(LPBYTE )(0x004E45F9 + 1) = 0x93;// [ebx + ...
172+
*(LPDWORD)(0x004E45F9 + 2) = offsetof(TSSGCtrl, rootSubject);
173+
*(LPBYTE )(0x004E4601 + 1) = 0x48;// edx => eax
174+
*(LPWORD )(0x004E4604 + 0) = BSWAP16(0x8948);// mov [eax + ...], ecx
175+
*(LPBYTE )(0x004E4604 + 2) = offsetof(TDirAttribute, identity);
176+
*(LPBYTE )(0x004E4617 + 0) = 0x89;// mov [eax + ...]
177+
*(LPBYTE )(0x004E4617 + 1) = 0x50;// edx
178+
*(LPBYTE )(0x004E4617 + 2) = offsetof(TDirAttribute, ref);
179+
180+
*(LPDWORD)(0x004E4629 + 1) = (DWORD)TSSGCtrl_ReadSSG_PushElement - (0x004E4629 + 1 + sizeof(DWORD));
73181

74182
// TSSGCtrl::EnumReadSSG
75183
*(LPBYTE )0x004E5090 = JMP_REL32;
@@ -83,9 +191,70 @@ EXTERN_C void __cdecl Attach_EnumReadSSG()
83191
// attributeSelector.IsElementCheckMode()
84192
*(LPBYTE )(0x004FD49A + 2) = offsetof(TSSGCtrl, attributeSelector.nowAttributeList);
85193

194+
*(LPBYTE )(0x004FD549 + 1) = sizeof(TDirAttribute);
195+
*(LPWORD )(0x004FD594 + 0) = BSWAP16(0x894A);// mov [edx + ...], ecx
196+
*(LPBYTE )(0x004FD594 + 2) = offsetof(TDirAttribute, identity);
197+
*(LPBYTE )(0x004FD597 + 0) = 0x89;// mov [edx + ...]
198+
*(LPBYTE )(0x004FD597 + 1) = 0x4A;// ecx
199+
*(LPBYTE )(0x004FD597 + 2) = offsetof(TDirAttribute, ref);
200+
*(LPBYTE )(0x004FD59A + 1) = 0x42;// edx => eax
201+
202+
// TSSGCtrl::GetAttribute
203+
*(LPWORD )0x005038FE = BSWAP16(0x8BCB);// mov ecx, ebx
204+
*(LPWORD )0x00503900 = BSWAP16(0x5B5D);// pop ebx
205+
*(LPBYTE )0x00503902 = JMP_REL32 ;// pop ebp
206+
*(LPDWORD)0x00503903 = (DWORD)TSSGAttributeElement_GetViaCoord - (0x00503903 + sizeof(DWORD));
207+
208+
// TSSGCtrl::AddressAttributeFilter
209+
// keeping Address initial value.
210+
*(LPWORD )(0x00504133 + 1) = BSWAP16(0xEC48);// sub esp, 0x48
211+
*(LPDWORD) 0x0050414C = BSWAP16(0x8B0F);// mov ecx, dword ptr [Address]
212+
*(LPWORD ) 0x0050414E = BSWAP16(0x85C0);// test eax, eax
213+
*(LPBYTE ) 0x00504150 = JNZ_SHORT;
214+
*(LPBYTE )(0x00504150 + 1) = 0x00504161 - (0x00504150 + 1 + sizeof(BYTE));
215+
*(LPBYTE )(0x00504169 + 0) = 0x89 ;// mov dword ptr
216+
*(LPWORD )(0x00504169 + 1) = BSWAP16(0x4DB8);// [ebp - 0x48], ecx
217+
*(LPBYTE )(0x0050416C + 0) = JMP_REL32;
218+
*(LPDWORD)(0x0050416C + 1) = 0x00504266 - (0x0050416C + 1 + sizeof(DWORD));
219+
*(LPBYTE )(0x0050416C + 5) = NOP;
220+
// GetAddress(SSGS, tmpAE->GetOffsetCode(), 0)
221+
*(LPDWORD)(0x005041CF + 1) = (DWORD)TSSGCtrl_AddressAttributeFilter_GetAddress - (0x005041CF + 1 + sizeof(DWORD));
222+
223+
// THeapAdjustmentAttribute::~THeapAdjustmentAttribute
224+
#ifdef SCOPE_USE_STRING_KEY
225+
*(LPDWORD)(0x00523531 + 1) = (DWORD)THeapAdjustmentAttribute_dtor_heapMap - (0x00523531 + 1 + sizeof(DWORD));
226+
#endif
227+
86228
// THeapAdjustmentAttribute::IsEqual
87-
*(LPBYTE )0x005235C8 = 0xC0;
88-
*(LPBYTE )0x005235CB = CALL_REL;
89-
*(LPDWORD)0x005235CC = (DWORD)THeapAdjustmentAttribute_IsEqual_adaptScope - (0x005235CC + sizeof(DWORD));
90-
*(LPBYTE )0x005235D1 = 0xC0;
229+
// if (type == atSCOPE) return TRUE;
230+
*(LPBYTE )0x005235CA = 0x0052363A - (0x005235CA + sizeof(BYTE));
231+
*(LPBYTE )0x005235CB = 0x81;// cmp dword ptr
232+
*(LPBYTE )0x005235CC = 0x7B;// [ebx + ...
233+
*(LPBYTE )0x005235CD = offsetof(THeapAdjustmentAttribute, type);
234+
*(LPDWORD)0x005235CE = atSCOPE;
235+
*(LPBYTE )0x005235D3 = 0x0052363E - (0x005235D3 + sizeof(BYTE));
236+
237+
// TReplaceAttribute::IsEqual
238+
// if (context != X->context) return FALSE;
239+
*(LPBYTE )0x00527250 = JNZ_SHORT;
240+
*(LPWORD )0x00527251 = 0x0052726A - (0x00527251 + sizeof(BYTE));
241+
*(LPWORD )0x00527252 = BSWAP16 (0x8B47);// mov eax, dword ptr [edi + ...
242+
*(LPBYTE )0x00527254 = offsetof(TReplaceAttribute, context);
243+
*(LPBYTE )0x00527255 = 0x8B ;// mov ecx, dword ptr [ebp +
244+
*(LPWORD )0x00527256 = BSWAP16 (0x4D0C);// 0x0C]
245+
*(LPWORD )0x00527258 = BSWAP16 (0x8B51);// mov edx, dword ptr [ecx + ...
246+
*(LPBYTE )0x0052725A = offsetof(TReplaceAttribute, context);
247+
*(LPBYTE )0x0052725B = 0x3B ;// cmp eax, edx
248+
*(LPWORD )0x0052725C = BSWAP16 (0xC2 << 8 | JNZ_SHORT);
249+
250+
// TDirAttribute::IsEqual
251+
// if (identity != X->identity) return FALSE;
252+
*(LPBYTE )0x00527403 = JNZ_SHORT;
253+
*(LPBYTE )0x00527404 = 0x00527415 - (0x00527404 + sizeof(BYTE));
254+
*(LPBYTE )0x00527405 = 0x8B;// mov ecx,
255+
*(LPBYTE )0x00527406 = 0x48;// [eax + ...
256+
*(LPBYTE )0x00527407 = offsetof(TDirAttribute, identity);
257+
*(LPWORD )0x00527408 = BSWAP16(0x3B4A);// cmp ecx, [edx + ..
258+
*(LPBYTE )0x0052740A = offsetof(TDirAttribute, identity);
259+
*(LPBYTE )0x0052740B = JNZ_SHORT;
91260
}

SpoilerAL-winmm.dll/EnumReadSSG/Attribute_define.h

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern HANDLE hHeap;
1515

1616
__inline void Attribute_define(TSSGCtrl *this, LPVOID ParentStack, LPCSTR Line, LPCSTR EndOfLine)
1717
{
18-
#define stack_PTSSDir_top(Stack) ((TSSDir *)stack_dword_top((stack_dword *)Stack))
18+
#define stack_PTSSDir_top(Stack) stack_top((stack *)(Stack), TSSDir *)[0]
1919

2020
const char *key, *value, *p;
2121
char c;
@@ -43,42 +43,37 @@ __inline void Attribute_define(TSSGCtrl *this, LPVOID ParentStack, LPCSTR Line,
4343
while (--p >= value && ((c = *p) == ' ' || c == '\t'));
4444
valueLength = ++p - value;
4545

46-
for (TDefineAttribute **it = vector_begin(this->attributeSelector.nowAttributeVec), **end = vector_end(this->attributeSelector.nowAttributeVec); it < end; it++)
46+
if (attribute = TSSGAttributeSelector_GetNowAtteributeVec(TSSGCtrl_GetAttributeSelector(this)))
4747
{
48-
if ((*it)->type != atDEFINE)
49-
continue;
50-
if (string_length(&(*it)->inputCode) != keyLength + 2)
51-
continue;
52-
if (memcmp(string_c_str(&(*it)->inputCode) + 1, key, keyLength) != 0)
53-
continue;
54-
string_assign_cstr_with_length(&(*it)->outputCode, value, valueLength);
55-
return;
56-
}
57-
58-
if (attribute = stack_PTSSDir_top(ParentStack)->super.attribute)
59-
{
60-
for (TDefineAttribute **it = vector_begin(attribute), **end = vector_end(attribute); it < end; it++)
48+
signed rel;
49+
const COORD index = TSSGAttributeElement_GetViaCoord(atDEFINE, attribute).dwFontSize;
50+
for (TAdjustmentAttribute **cur,
51+
**base = &vector_type_at(attribute, TAdjustmentAttribute *, index.Y),
52+
**apex = base + index.X;
53+
base < apex; )
6154
{
62-
if ((*it)->type != atDEFINE)
63-
continue;
64-
if (string_length(&(*it)->inputCode) != keyLength + 2)
65-
continue;
66-
if (memcmp(string_c_str(&(*it)->inputCode) + 1, key, keyLength) != 0)
67-
continue;
68-
string_assign_cstr_with_length(&(*it)->outputCode, value, valueLength);
69-
return;
55+
cur = &base[apex - base >> 1];
56+
rel = strncmp((*cur)->c_str + 1, key, keyLength);
57+
if (rel > 0)
58+
apex = cur;
59+
else if (rel == 0 && (*cur)->seqElement == keyLength + 2)
60+
{
61+
string_assign_cstr_with_length(&((TDefineAttribute *)*cur)->outputCode, value, valueLength);
62+
return;
63+
}
64+
else
65+
base = cur + 1;
7066
}
7167
}
7268

73-
define = new_TIO_FEPAttribute();
74-
if (define)
69+
if (define = new_TIO_FEPAttribute())
7570
{
7671
define->type = atDEFINE;
7772
string_reserve(&define->inputCode, keyLength + 2);
7873
*string_begin(&define->inputCode) = '{';
7974
memcpy(string_begin(&define->inputCode) + 1, key, keyLength);
80-
string_end(&define->inputCode) = string_begin(&define->inputCode) + keyLength + 2;
81-
*(LPWORD)(string_end(&define->inputCode) - 1) = BSWAP16('}\0');
75+
string_at(&define->inputCode, 1 + keyLength) = '}';
76+
*(string_end(&define->inputCode) = string_begin(&define->inputCode) + keyLength + 2) = '\0';
8277
string_assign_cstr_with_length(&define->outputCode, value, valueLength);
8378
TSSGAttributeSelector_AddElement(&this->attributeSelector, define);
8479
}

0 commit comments

Comments
 (0)