From 6ce68192a24d1d1f9579e96319af83045725af1c Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 3 Nov 2025 18:05:42 +0100 Subject: [PATCH] EgtExecutor : - aggiunte funzioni exe e lua Base64Encode e Base64Decode. --- EXE_Base64.cpp | 66 +++++++++++++++++++++++++++++++++++++ EgtExecutor.vcxproj | 2 ++ EgtExecutor.vcxproj.filters | 6 ++++ LUA.h | 5 ++- LUA_Base.cpp | 5 +++ LUA_Base64.cpp | 65 ++++++++++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 EXE_Base64.cpp create mode 100644 LUA_Base64.cpp diff --git a/EXE_Base64.cpp b/EXE_Base64.cpp new file mode 100644 index 0000000..1a4e9fc --- /dev/null +++ b/EXE_Base64.cpp @@ -0,0 +1,66 @@ +//---------------------------------------------------------------------------- +// EgalTech 2025-2025 +//---------------------------------------------------------------------------- +// File : EXE_Base64.cpp Data : 03.11.25 Versione : 2.7k1 +// Contenuto : Funzioni per codificare/decodificare in Base64. +// +// +// +// Modifiche : 03.11.25 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EgtStringConverter.h" +#include "/EgtDev/Include/EgtBase64.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +ExeBase64Encode( const string& sFile, string& sB64Dest) +{ + // apro il file in modo binario + ifstream InFile( stringtoW( sFile), ios::in | ios::binary, _SH_DENYWR) ; + if ( InFile.fail()) { + if ( InFile.is_open()) + InFile.close() ; + return false ; + } + // leggo il file + string sSou( istreambuf_iterator( InFile), {}) ; + // lo chiudo + if ( InFile.is_open()) + InFile.close() ; + + // converto in Base64 + return B64Encode( sSou, sB64Dest) ; +} + +//---------------------------------------------------------------------------- +bool +ExeBase64Decode( const string& sB64Sou, const string& sFile) +{ + // converto da Base64 + string sDest ; + if ( ! B64Decode( sB64Sou, sDest)) + return false ; + + // apro il file in modo binario + ofstream OutFile( stringtoW( sFile), ios::out | ios::binary, _SH_DENYWR) ; + if ( ! OutFile.good()) { + if ( OutFile.is_open()) + OutFile.close() ; + return false ; + } + // scrivo sul file + OutFile.write( sDest.data(), sDest.size()) ; + // lo chiudo + if ( OutFile.is_open()) + OutFile.close() ; + return true ; +} diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj index 8c74b69..044ba37 100644 --- a/EgtExecutor.vcxproj +++ b/EgtExecutor.vcxproj @@ -251,6 +251,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -306,6 +307,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters index ac3bb43..b1e895f 100644 --- a/EgtExecutor.vcxproj.filters +++ b/EgtExecutor.vcxproj.filters @@ -419,6 +419,12 @@ File di origine\LUA + + File di origine\EXE + + + File di origine\LUA + diff --git a/LUA.h b/LUA.h index 1863da8..3a56eaf 100644 --- a/LUA.h +++ b/LUA.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- // EgalTech 2014-2025 //---------------------------------------------------------------------------- -// File : LUA.h Data : 24.03.24 Versione : 2.6c2 +// File : LUA.h Data : 03.11.25 Versione : 2.7k1 // Contenuto : Dichiarazioni locali per moduli LUA. // // @@ -138,3 +138,6 @@ bool LuaInstallCAvTool( LuaMgr& luaMgr) ; //---------------------------------- Redis ---------------------------------- bool LuaInstallRedis( LuaMgr& luaMgr) ; +//-------------------------- Base64 ------------------------------------------ +bool LuaInstallBase64( LuaMgr& luaMgr) ; + diff --git a/LUA_Base.cpp b/LUA_Base.cpp index 24cff18..fa1e8d4 100644 --- a/LUA_Base.cpp +++ b/LUA_Base.cpp @@ -190,6 +190,11 @@ LuaInstallEgtFunctions( LuaMgr& LuaMgr) LOG_ERROR( GetLogger(), "Error in LuaInstallRedis (LuaInstallEgtFunctions)") return false ; } + if ( ! LuaInstallBase64( LuaMgr)) { + LOG_ERROR( GetLogger(), "Error in LuaInstallBase64 (LuaInstallEgtFunctions)") + return false ; + } + return true ; } diff --git a/LUA_Base64.cpp b/LUA_Base64.cpp new file mode 100644 index 0000000..6612c67 --- /dev/null +++ b/LUA_Base64.cpp @@ -0,0 +1,65 @@ +//---------------------------------------------------------------------------- +// EgalTech 2025-2025 +//---------------------------------------------------------------------------- +// File : LUA_Base64.cpp Data : 03.11.25 Versione : 2.7k1 +// Contenuto : Funzioni per codificare/decodificare in Base64 per LUA. +// +// +// +// Modifiche : 03.11.25 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "LUA.h" +#include "/EgtDev/Include/EXeExecutor.h" + +using namespace std ; + +//------------------------------------------------------------------------------- +static int +LuaBase64Encode( lua_State* L) +{ + // 1 parametro : sFile + string sFile ; + LuaCheckParam( L, 1, sFile) ; + LuaClearStack( L) ; + // eseguo la codifica del contenuto del file + string sB64Dest ; + bool bOk = ExeBase64Encode( sFile, sB64Dest) ; + // restituisco il risultato + if ( bOk) + LuaSetParam( L, sB64Dest) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +static int +LuaBase64Decode( lua_State* L) +{ + // 2 parametro : sB64Sou, sFile + string sB64Sou ; + LuaCheckParam( L, 1, sB64Sou) ; + string sFile ; + LuaCheckParam( L, 2, sFile) ; + LuaClearStack( L) ; + // eseguo la decodifica della stringa nel file + bool bOk = ExeBase64Decode( sB64Sou, sFile) ; + // restituisco il risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//------------------------------------------------------------------------------- +bool +LuaInstallBase64( LuaMgr& luaMgr) +{ + bool bOk = ( &luaMgr != nullptr) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBase64Encode", LuaBase64Encode) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtBase64Decode", LuaBase64Decode) ; + return bOk ; +}