Skip to content

Commit 0bd123b

Browse files
committed
Skip textures with too long names in editor
Fixes #212
1 parent 90395da commit 0bd123b

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

docs/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Version 1.8.1 (not released yet)
1515
- Fix "Play (camera)" editor button for level filenames with spaces
1616
- Fix a patch for a possible buffer overflow in "Play" editor button caused by a long filepath
1717
- Fix cull radius for particle emitters with growing particles
18+
- Skip textures with too long names (32+ characters) in editor to avoid buffer overflow
1819

1920
Version 1.8.0 (released 2022-09-17)
2021
-----------------------------------

editor_patch/main.cpp

+43-6
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222

2323
#define LAUNCHER_FILENAME "DashFactionLauncher.exe"
2424

25+
constexpr size_t max_texture_name_len = 31;
26+
2527
HMODULE g_module;
2628
bool g_skip_wnd_set_text = false;
2729

28-
static auto& g_log_view = addr_as_ref<std::byte*>(0x006F9E68);
2930
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+
3035

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+
}
3245

3346
HWND GetMainFrameHandle()
3447
{
@@ -163,8 +176,7 @@ void __fastcall group_mode_handle_selection_new(void* self)
163176
group_mode_handle_selection_hook.call_target(self);
164177
g_skip_wnd_set_text = false;
165178
// TODO: print
166-
auto* log_view = *reinterpret_cast<void**>(g_log_view + 692);
167-
log_wnd_append(log_view, "");
179+
LogDlg_Append(GetLogDlg(), "");
168180
}
169181
FunHook<group_mode_handle_selection_type> group_mode_handle_selection_hook{0x00423460, group_mode_handle_selection_new};
170182

@@ -176,8 +188,7 @@ void __fastcall brush_mode_handle_selection_new(void* self)
176188
brush_mode_handle_selection_hook.call_target(self);
177189
g_skip_wnd_set_text = false;
178190
// TODO: print
179-
auto* log_view = *reinterpret_cast<void**>(g_log_view + 692);
180-
log_wnd_append(log_view, "");
191+
LogDlg_Append(GetLogDlg(), "");
181192

182193
}
183194
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{
410421
},
411422
};
412423

424+
CodeInjection texture_name_buffer_overflow_injection1{
425+
0x00445297,
426+
[](auto &regs) {
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 &regs) {
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+
413446
extern "C" DWORD DF_DLL_EXPORT Init([[maybe_unused]] void* unused)
414447
{
415448
InitLogging();
@@ -535,6 +568,10 @@ extern "C" DWORD DF_DLL_EXPORT Init([[maybe_unused]] void* unused)
535568
// Remove uid limit (50k) by removing cmp and jge instructions in FindBiggestUid function
536569
AsmWriter{0x004844AC, 0x004844B3}.nop();
537570

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+
538575
return 1; // success
539576
}
540577

0 commit comments

Comments
 (0)