22
22
23
23
#define LAUNCHER_FILENAME " DashFactionLauncher.exe"
24
24
25
+ constexpr size_t max_texture_name_len = 31 ;
26
+
25
27
HMODULE g_module;
26
28
bool g_skip_wnd_set_text = false ;
27
29
28
- static auto & g_log_view = addr_as_ref<std::byte*>(0x006F9E68 );
29
30
static const auto g_editor_app = reinterpret_cast <std::byte*>(0x006F9DA0 );
31
+ static auto & g_main_frame = addr_as_ref<std::byte*>(0x006F9E68 );
32
+
33
+ static auto & LogDlg_Append = addr_as_ref<int (void * self, const char * format, ...)>(0x00444980 );
34
+
30
35
31
- static auto & log_wnd_append = addr_as_ref<int (void * self, const char * format, ...)>(0x00444980 );
36
+ void *GetMainFrame ()
37
+ {
38
+ return struct_field_ref<void *>(g_editor_app, 0xC8 );
39
+ }
40
+
41
+ void *GetLogDlg ()
42
+ {
43
+ return struct_field_ref<void *>(GetMainFrame (), 692 );
44
+ }
32
45
33
46
HWND GetMainFrameHandle ()
34
47
{
@@ -163,8 +176,7 @@ void __fastcall group_mode_handle_selection_new(void* self)
163
176
group_mode_handle_selection_hook.call_target (self);
164
177
g_skip_wnd_set_text = false ;
165
178
// TODO: print
166
- auto * log_view = *reinterpret_cast <void **>(g_log_view + 692 );
167
- log_wnd_append (log_view, " " );
179
+ LogDlg_Append (GetLogDlg (), " " );
168
180
}
169
181
FunHook<group_mode_handle_selection_type> group_mode_handle_selection_hook{0x00423460 , group_mode_handle_selection_new};
170
182
@@ -176,8 +188,7 @@ void __fastcall brush_mode_handle_selection_new(void* self)
176
188
brush_mode_handle_selection_hook.call_target (self);
177
189
g_skip_wnd_set_text = false ;
178
190
// TODO: print
179
- auto * log_view = *reinterpret_cast <void **>(g_log_view + 692 );
180
- log_wnd_append (log_view, " " );
191
+ LogDlg_Append (GetLogDlg (), " " );
181
192
182
193
}
183
194
FunHook<brush_mode_handle_selection_type> brush_mode_handle_selection_hook{0x0043F430 , brush_mode_handle_selection_new};
@@ -410,6 +421,28 @@ CodeInjection CDedEvent_Copy_injection{
410
421
},
411
422
};
412
423
424
+ CodeInjection texture_name_buffer_overflow_injection1{
425
+ 0x00445297 ,
426
+ [](auto ®s) {
427
+ const char *filename = regs.esi ;
428
+ if (std::strlen (filename) > max_texture_name_len) {
429
+ LogDlg_Append (GetLogDlg (), " Texture name too long: %s\n " , filename);
430
+ regs.eip = 0x00445273 ;
431
+ }
432
+ },
433
+ };
434
+
435
+ CodeInjection texture_name_buffer_overflow_injection2{
436
+ 0x004703EC ,
437
+ [](auto ®s) {
438
+ const char *filename = regs.ebp ;
439
+ if (std::strlen (filename) > max_texture_name_len) {
440
+ LogDlg_Append (GetLogDlg (), " Texture name too long: %s\n " , filename);
441
+ regs.eip = 0x0047047F ;
442
+ }
443
+ },
444
+ };
445
+
413
446
extern " C" DWORD DF_DLL_EXPORT Init ([[maybe_unused]] void * unused)
414
447
{
415
448
InitLogging ();
@@ -535,6 +568,10 @@ extern "C" DWORD DF_DLL_EXPORT Init([[maybe_unused]] void* unused)
535
568
// Remove uid limit (50k) by removing cmp and jge instructions in FindBiggestUid function
536
569
AsmWriter{0x004844AC , 0x004844B3 }.nop ();
537
570
571
+ // Ignore textures with filename longer than 31 characters to avoid buffer overflow errors
572
+ texture_name_buffer_overflow_injection1.install ();
573
+ texture_name_buffer_overflow_injection2.install ();
574
+
538
575
return 1 ; // success
539
576
}
540
577
0 commit comments