Skip to content

Commit

Permalink
Forbidden filesystem opcodes from accessing outside game locations.
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Jul 28, 2024
1 parent 16afb29 commit d49d10c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- new opcode **2102 ([log_to_file](https://library.sannybuilder.com/#/sa/debug/2102))**
- implemented support of opcodes **0662**, **0663** and **0664** (original Rockstar's script debugging opcodes. See DebugUtils.ini)
- new [FileSystemOperations](https://github.com/cleolibrary/CLEO5/tree/master/cleo_plugins/FileSystemOperations) plugin
- forbidden scripts from accessing and changing any files outside game root or game settings directory
- file related opcodes moved from CLEO core into separated plugin
- opcode **0A9E ([write_to_file](https://library.sannybuilder.com/#/sa/file/0A9E))** now supports literal numbers and strings
- fixed bug causing file stream opcodes not working correctly when read-write modes are used
Expand Down
6 changes: 5 additions & 1 deletion cleo_plugins/FileSystemOperations/FileSystemOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
using namespace CLEO;
using namespace plugin;

const char* Gta_User_Dir_Path = (char*)0x00C92368;

#define OPCODE_READ_PARAM_FILE_HANDLE(handle) auto handle = (DWORD)OPCODE_READ_PARAM_PTR(); \
if(m_hFiles.find(handle) == m_hFiles.end()) { auto info = ScriptInfoStr(thread); SHOW_ERROR("Invalid or already closed '0x%X' file handle param in script %s \nScript suspended.", handle, info.c_str()); return thread->Suspend(); }
if(m_hFiles.find(handle) == m_hFiles.end()) { SHOW_ERROR("Invalid or already closed '0x%X' file handle param in script %s \nScript suspended.", handle, ScriptInfoStr(thread).c_str()); return thread->Suspend(); } \
if(_strnicmp(path, CFileMgr::ms_rootDirName, strlen(CFileMgr::ms_rootDirName)) != 0 && _strnicmp(path, Gta_User_Dir_Path, strlen(Gta_User_Dir_Path)) != 0) { SHOW_ERROR("Forbidden access to file path '%s' outside game directory in script %s \nScript suspended.", path, ScriptInfoStr(thread).c_str()); return thread->Suspend(); }


class FileSystemOperations
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ if defined GTA_SA_DIR (
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.cpp" />
<ClCompile Include="FileSystemOperations.cpp" />
<ClCompile Include="FileUtils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\cleo_sdk\CLEO.h" />
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h" />
<ClInclude Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.h" />
<ClInclude Include="FileUtils.h" />
<ClInclude Include="Utils.h" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<ItemGroup>
<ClCompile Include="FileSystemOperations.cpp" />
<ClCompile Include="FileUtils.cpp" />
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="FileUtils.h" />
Expand All @@ -13,11 +16,17 @@
<ClInclude Include="..\..\cleo_sdk\CLEO_Utils.h">
<Filter>cleo_sdk</Filter>
</ClInclude>
<ClInclude Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CFileMgr.h">
<Filter>plugin_sdk</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="cleo_sdk">
<UniqueIdentifier>{a2c39c52-f49e-4ffe-bb0a-661ab07131b9}</UniqueIdentifier>
</Filter>
<Filter Include="plugin_sdk">
<UniqueIdentifier>{e9854345-7dae-4c93-a8be-6bd77536c7cd}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\Resource.rc" />
Expand Down

0 comments on commit d49d10c

Please sign in to comment.