diff --git a/monitor/ActionMonitor/Action.cpp b/monitor/ActionMonitor/Action.cpp index 2c58cbec3b..2d63a45de8 100644 --- a/monitor/ActionMonitor/Action.cpp +++ b/monitor/ActionMonitor/Action.cpp @@ -13,6 +13,7 @@ #include "activebatchaction.h" #include "activecmdaction.h" #include "activecomaction.h" +#include "activeexeaction.h" #include "os\os.h" #include "ActivePowershellAction.h" @@ -463,6 +464,10 @@ ActiveAction* Action::CreateActiveActionDirect(CWnd* pWnd, const MYODD_STRING& s { return new ActiveComAction(*this, hTopHWnd, szCommandLine); } + if (myodd::files::IsExtension(m_szFile, _T("exe"))) + { + return new ActiveExeAction(*this, hTopHWnd, szCommandLine, isPrivileged); + } // run the default action. return new ActiveDefaultAction( *this, hTopHWnd, szCommandLine, isPrivileged ); diff --git a/monitor/ActionMonitor/ActionMonitor.vcxproj b/monitor/ActionMonitor/ActionMonitor.vcxproj index 6aa085c05e..7efab3d038 100644 --- a/monitor/ActionMonitor/ActionMonitor.vcxproj +++ b/monitor/ActionMonitor/ActionMonitor.vcxproj @@ -202,6 +202,7 @@ + @@ -249,6 +250,7 @@ + diff --git a/monitor/ActionMonitor/ActionMonitor.vcxproj.filters b/monitor/ActionMonitor/ActionMonitor.vcxproj.filters index c42bf7b57d..615a6988c6 100644 --- a/monitor/ActionMonitor/ActionMonitor.vcxproj.filters +++ b/monitor/ActionMonitor/ActionMonitor.vcxproj.filters @@ -132,6 +132,9 @@ actions + + actions + @@ -265,6 +268,9 @@ actions + + actions + diff --git a/monitor/ActionMonitor/ActionMonitor64.vcxproj b/monitor/ActionMonitor/ActionMonitor64.vcxproj index 890b4dae07..3e02ba2211 100644 --- a/monitor/ActionMonitor/ActionMonitor64.vcxproj +++ b/monitor/ActionMonitor/ActionMonitor64.vcxproj @@ -202,6 +202,7 @@ + @@ -248,6 +249,7 @@ + diff --git a/monitor/ActionMonitor/ActionMonitor64.vcxproj.filters b/monitor/ActionMonitor/ActionMonitor64.vcxproj.filters index 95ff90fe84..b89c262d83 100644 --- a/monitor/ActionMonitor/ActionMonitor64.vcxproj.filters +++ b/monitor/ActionMonitor/ActionMonitor64.vcxproj.filters @@ -132,6 +132,9 @@ actions + + actions + @@ -262,6 +265,9 @@ actions + + actions + diff --git a/monitor/ActionMonitor/ActiveExeAction.cpp b/monitor/ActionMonitor/ActiveExeAction.cpp new file mode 100644 index 0000000000..d2a51a9323 --- /dev/null +++ b/monitor/ActionMonitor/ActiveExeAction.cpp @@ -0,0 +1,43 @@ +#include "stdafx.h" +#include "ActiveExeAction.h" +#include "ActionMonitor.h" + +/** + * The Default active contructor + * @param const Action& src the action that is now active. + * @param HWND hTopHWnd the window that was on top at the time the command was given. + * @param const MYODD_STRING& szCommandLine the given command line that is, the words after the command itself + * @param bool isPrivileged if this action is privileged or not. + */ +ActiveExeAction::ActiveExeAction(const Action& src, HWND hTopHWnd, const MYODD_STRING& szCommandLine, bool isPrivileged) : + ActiveAction( src, hTopHWnd, szCommandLine, isPrivileged ) +{ +} + +ActiveExeAction::~ActiveExeAction() +{ +} + +bool ActiveExeAction::OnDeInitialize() +{ + // nothing to do. + return true; +} + +bool ActiveExeAction::OnInitialize() +{ + // all good + return true; +} + +void ActiveExeAction::OnExecuteInThread() +{ + auto szFile = File(); + auto szExt = myodd::files::GetExtension( szFile );; + auto szCommand = Command(); + + // we just launch the exe by itself. + std::vector argv; + argv.push_back( szFile); + Execute(argv, IsPrivileged(), nullptr ); +} diff --git a/monitor/ActionMonitor/ActiveExeAction.h b/monitor/ActionMonitor/ActiveExeAction.h new file mode 100644 index 0000000000..06a842c8b4 --- /dev/null +++ b/monitor/ActionMonitor/ActiveExeAction.h @@ -0,0 +1,15 @@ +#pragma once +#include "ActiveAction.h" + +class ActiveExeAction : + public ActiveAction +{ +public: + ActiveExeAction(const Action& src, HWND hTopHWnd, const MYODD_STRING& szCommandLine, bool isPrivileged); + virtual ~ActiveExeAction(); + +protected: + virtual bool OnInitialize(); + virtual bool OnDeInitialize(); + virtual void OnExecuteInThread(); +}; \ No newline at end of file diff --git a/monitor/ActionMonitor/res/version.h b/monitor/ActionMonitor/res/version.h index a30154e527..eaa0796e46 100644 --- a/monitor/ActionMonitor/res/version.h +++ b/monitor/ActionMonitor/res/version.h @@ -1,16 +1,16 @@ #include #define VERSION_MAJOR 0 -#define VERSION_MINOR 6 -#define VERSION_MAINTENANCE 16 -#define VERSION_BUILD 14 +#define VERSION_MINOR 7 +#define VERSION_MAINTENANCE 1 +#define VERSION_BUILD 4 -#define VERSION_HOUR 9 -#define VERSION_MINUTE 38 +#define VERSION_HOUR 8 +#define VERSION_MINUTE 40 #define VERSION_YEAR 2016 #define VERSION_MONTH 7 -#define VERSION_DAY 28 +#define VERSION_DAY 31 // // No need to edit below... diff --git a/myodd/files/files.cpp b/myodd/files/files.cpp index c66d897715..42303a140c 100644 --- a/myodd/files/files.cpp +++ b/myodd/files/files.cpp @@ -1263,22 +1263,20 @@ MYODD_STRING GetBaseFromFile } /** -* Get the absolute path given a relative path. -* It is up to the user to delete the container value. -* @param MYODD_STRING& container for the return value, unset in case of error. -* @param const MYODD_STRING& the relative path we would like to get the absolute path from. -* @param const MYODD_STRING& the original path, if empty we will use the current directory as origin. -* @return bool if we were able to get the absolute path, false if the given path is unrealistic/impossible. -*/ + * Get the absolute path given a relative path. + * It is up to the user to delete the container value. + * @param MYODD_STRING& container for the return value, unset in case of error. + * @param const MYODD_STRING& the relative path we would like to get the absolute path from. + * @param const MYODD_STRING& the original path, if empty we will use the current directory as origin. + * if the path is '.' or '.\xxx' the current path will be added to it. + * @return bool if we were able to get the absolute path, false if the given path is unrealistic/impossible. + */ bool GetAbsolutePath( MYODD_STRING& dest, const MYODD_STRING& givenRelative, const MYODD_STRING& givenOrigin ) { // // first do some house-keeping // - // reset the result. - dest.clear(); - // make copies. auto copyOfRelative = givenRelative; auto copyOfOrigin = givenOrigin; @@ -1299,37 +1297,51 @@ bool GetAbsolutePath( MYODD_STRING& dest, const MYODD_STRING& givenRelative, con // makes it easier if we are adding the working directory. files::AddTrailingBackSlash(copyOfOrigin); - // there is a special case for the origin been '.\' or '.' - // in this case we want to assume that the user wants the 'current directory' - regex::Regex2::Matches matches; + // save the unexpanded variables. + auto unExpandedCopyOfOrigin = copyOfOrigin; + auto unExpandedCopyOfRelative = copyOfRelative; + + // expand the relative path. + files::ExpandEnvironment(copyOfRelative, copyOfRelative); + + // assume we will not be using the origin, (the path given was good enough). + auto useOrigin = false; + + MYODD_STRING pathToEvaluate; - // ^((?:\.[\/\\])+) - const auto pattern = _T("^((?:\\.[\\/\\\\])+)"); - if (regex::Regex2::Match(pattern, copyOfOrigin, matches ) > 1 ) + // (?:\\\\[^.]|[a-zA-Z]:[\\\/]) + if (!regex::Regex2::Search(_T("(?:\\\\\\\\[^.]|[a-zA-Z]:[\\\\\\/])"), copyOfRelative)) { - // because we added a trailing back slash earlier - // we can replace the all the '././././' with the current directory - // even if the user just gave us a '.', (as it would be converted to '.' - // but if they gave us '.aaa' then this is not valid and would not be replace anyway. - MYODD_CHAR lpBuffer[T_MAX_PATH] = { 0 }; - if (0 == ::GetCurrentDirectory(T_MAX_PATH, lpBuffer)) + // we will be using the origin hrere. + useOrigin = true; + + // we need to expand the origine now. + files::ExpandEnvironment(copyOfOrigin, copyOfOrigin); + + // there is a special case for the origin been '.\' or '.' + // in this case we want to assume that the user wants the 'current directory' + regex::Regex2::Matches matches; + + // if the origin has a '.' or './' then we need to add the current path to it. + // that's an assumption made to make the life of the caller easier. + // ^((?:\.[\/\\])+) + const auto pattern = _T("^((?:\\.[\\/\\\\])+)"); + if (regex::Regex2::Match(pattern, copyOfOrigin, matches) > 1) { - // could not get the current directory??? - return false; + // we can replace the all the '././././' with the + // current directory even if the user just gave us a '.' + + // join the current directory and the origin without the '.' or './'. + files::Join(copyOfOrigin, GetAppPath(true), copyOfOrigin.substr(matches[1].length())); } - // join the current directory and the remainder. - files::Join( copyOfOrigin, lpBuffer, copyOfOrigin.substr( matches[1].length())); + // we can now join the origin and relative path. + files::Join(pathToEvaluate, copyOfOrigin, copyOfRelative); + } + else + { + pathToEvaluate = copyOfRelative; } - - // we can now join them both - MYODD_STRING pathToEvaluate; - files::Join(pathToEvaluate, copyOfOrigin, copyOfRelative); - - // Expand the environment variable. - // but we save the 'before' value. - const auto unexpandedPathToEvaluate = pathToEvaluate; - ExpandEnvironment(pathToEvaluate, pathToEvaluate); // now we need to get the absolute path of both of them. std::vector partsOfPathToEvaluate; @@ -1351,6 +1363,7 @@ bool GetAbsolutePath( MYODD_STRING& dest, const MYODD_STRING& givenRelative, con if( evaluatedParts.size() == 0 ) { // nope, we cannot go back onto ourselves. + dest.clear(); return false; } @@ -1376,10 +1389,27 @@ bool GetAbsolutePath( MYODD_STRING& dest, const MYODD_STRING& givenRelative, con // now check if we need to unexpand the data. // this is where we use the before expand value. - if (0 != strings::Compare(pathToEvaluate, unexpandedPathToEvaluate, false)) + if (0 != strings::Compare(copyOfOrigin, unExpandedCopyOfOrigin, false) || + (0 != strings::Compare(copyOfRelative, unExpandedCopyOfRelative, false)) + ) { files::UnExpandEnvironment(dest, dest); } + + // was the original file UNC? + // or, if we did not use the original, was the relative path UNC + if (useOrigin) + { + if (myodd::regex::Regex2::Search(_T("(?:\\\\{2})"), unExpandedCopyOfOrigin)) + { + dest = _T("\\\\") + dest; + } + } + else if (myodd::regex::Regex2::Search(_T("(?:\\\\{2})"), unExpandedCopyOfRelative)) + { + dest = _T("\\\\") + dest; + } + // success! return true; } diff --git a/myoddtest/files/testfiles_absolutepath.cpp b/myoddtest/files/testfiles_absolutepath.cpp index cc10afa381..340304ddcb 100644 --- a/myoddtest/files/testfiles_absolutepath.cpp +++ b/myoddtest/files/testfiles_absolutepath.cpp @@ -24,9 +24,15 @@ struct MyOddFilesAbsolutePath : testing::Test, testing::WithParamInterface