Skip to content

Commit d01e9a0

Browse files
committed
Increased version number to the same value as it is in release + WIP rule deleting feature.
1 parent a971bcf commit d01e9a0

File tree

3 files changed

+71
-28
lines changed

3 files changed

+71
-28
lines changed

XRulez/XRulez/Application.cpp

+65-24
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ bool XRulez::Application::ProcessInputParameters()
6363
{
6464
DllProcessStringTableParameters();
6565
PerformInjection();
66-
return true;
6766
}
6867
else
69-
{
70-
// Process executable's input.
71-
return ExeProcessParameters();
72-
}
68+
ExeProcessParameters();
69+
70+
return true;
7371
}
7472

7573
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -123,49 +121,53 @@ void XRulez::Application::ProcessPreprocessorParameters()
123121
}
124122

125123
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126-
bool XRulez::Application::ExeProcessParameters()
124+
void XRulez::Application::ExeProcessParameters()
127125
{
128126
// This function should not be called in DLL builds.
129127
CHECK(!Enviro::IsDllBuild);
130128
if (Enviro::IsDllBuild)
131-
return false;
129+
return;
132130

133131
// Access command line params.
134132
auto& commandLineArgs = Enviro::AccessCommandLineParams();
135133

136134
// Sanity validation.
137135
if (commandLineArgs.size() < 2 || commandLineArgs[1].size() != 2 || commandLineArgs[1][0] != TEXT('-'))
138-
return ExeShowUsage(true), false;
136+
return ExeShowUsage(true);
139137

140138
// Handle commands separately.
141139
switch (commandLineArgs[1][1])
142140
{
143141
case TEXT('l'): //< Display a list of available MAPI profiles.
144-
return ExeListOutlookProfiles(), false;
142+
return ExeListOutlookProfiles();
145143

146144
case TEXT('r'): //< Disable security patch KB3191883.
147145
return ExeDisableSecurityPatchKB3191883();
148146

149147
case TEXT('a'): //< Process command line values, validate them and proceed to message injection.
150-
return ExeProcessCommandLineValues() && PerformInjection();
148+
ExeProcessCommandLineValues() && PerformInjection();
149+
return;
151150

152151
case TEXT('d'): //< Display parameters default (precompiled) values.
153-
return ExeShowDefaultParamsValues(), false;
152+
return ExeShowDefaultParamsValues();
154153

155154
//case TEXT('i'): //< Perform interactive configuration and proceed to message injection.
156155
//return ExePerformInteractiveConfiguration(), true;
157156

158157
case TEXT('e'): //< Shows all existing rules.
159-
return ExeDisplayAllRules(), true;
158+
return ExeDisplayAllRules();
159+
160+
//case TEXT('x'): //< Shows all existing rules.
161+
//return ExeRemoveRule();
160162

161163
case TEXT('h'): //< Display help.
162-
return ExeShowUsage(false), false;
164+
return ExeShowUsage(false);
163165

164166
case TEXT('o'): //< Check if Outlook is running at the moment.
165-
return ExeCheckIfOutlookIsRunning(), false;
167+
return ExeCheckIfOutlookIsRunning();
166168

167169
default: //< Wrong input.
168-
return ExeShowUsage(true), false;
170+
return ExeShowUsage(true);
169171
}
170172
}
171173

@@ -388,6 +390,47 @@ void XRulez::Application::ExeDisplayAllRules()
388390
}
389391
}
390392

393+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
394+
void XRulez::Application::ExeRemoveRule()
395+
{
396+
Comment(TEXT("Parsing rule ID..."));
397+
398+
// Sanity check.
399+
if (Enviro::AccessCommandLineParams().size() < 3)
400+
return CommentError(TEXT("[-] Error - rule ID not provided after '-x' switch. Try something like:\nXRulez.exe -x 1234567890ABCDEF"));
401+
if (Enviro::AccessCommandLineParams()[2].size() < 1 OR Enviro::AccessCommandLineParams()[2].size() > 16)
402+
return CommentError(TEXT("[-] Error - rule ID should provided as a hex 64-bit value, e.g.:\nXRulez.exe -x 1234567890ABCDEF"));
403+
404+
// Parse Rule ID.
405+
LARGE_INTEGER ruleId;
406+
ruleId.QuadPart = 0x1000001ADAD7CE1;// _wcstoui64(Enviro::AccessCommandLineParams()[2].c_str(), nullptr, 16);
407+
Comment(TEXT("Trying to remove rule ") + std::to_tstring((std::uint64_t)ruleId.QuadPart) + TEXT("..."));
408+
409+
try
410+
{
411+
// Initialize MapiTools Module.
412+
auto xeInitializeMapi = MapiTools::InitializeMapi(m_IsRunningInMultithreadedProcess, m_IsRunningInWindowsService);
413+
if (xeInitializeMapi.IsFailure())
414+
return ReportError(TEXT("MapiTools::InitializeMapi"), xeInitializeMapi);
415+
SCOPE_GUARD{ MapiTools::UninitializeMapi(); };
416+
417+
// Login to a shared session, then open default message store, then inbox folder, and then enlist all existing rules.
418+
if (MapiTools::MapiSession{ MAPI_EXTENDED | MAPI_ALLOW_OTHERS | MAPI_NEW_SESSION | MAPI_USE_DEFAULT | (m_IsRunningInWindowsService ? MAPI_NT_SERVICE : 0), m_ProfileName }
419+
.OpenDefaultMessageStore().OpenDefaultReceiveFolder().OpenRulesTable().DeleteRule(ruleId))
420+
Comment(TEXT("Done."));
421+
else
422+
CommentError(TEXT("Error: specified rule ID not found."));
423+
}
424+
catch (CppTools::XException& e)
425+
{
426+
CommentError(TEXT("Error. ") + CppTools::StringConversions::Mbcs2Tstring(e.what()) + TEXT("\n") + e.ComposeFullMessage());
427+
}
428+
catch (std::exception& e)
429+
{
430+
CommentError(TEXT("Error. ") + CppTools::StringConversions::Mbcs2Tstring(e.what()));
431+
}
432+
}
433+
391434
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
392435
void XRulez::Application::ExeListOutlookProfiles()
393436
{
@@ -501,24 +544,22 @@ bool XRulez::Application::PerformInjection()
501544
}
502545

503546
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
504-
bool XRulez::Application::ExeDisableSecurityPatchKB3191883()
547+
void XRulez::Application::ExeDisableSecurityPatchKB3191883()
505548
{
549+
// Helper lambda to set one particular entry in the registry.
506550
auto DisablePathForOutlookVersion = [](std::wstring const& registyKey, std::tstring const& outlookVersionName)
507551
{
508552
if (auto hr = WinTools::Registry::SetValue(WinTools::Registry::HKey::CurrentUser, registyKey, L"EnableUnsafeClientMailRules", 1))
509-
return Enviro::tcerr << TEXT("[-] Couldn't re-enable run-actions for ") << CppTools::StringConversions::Convert<std::tstring>(outlookVersionName.c_str()) << TEXT(". ")
553+
Enviro::tcerr << TEXT("[-] Couldn't re-enable run-actions for ") << CppTools::StringConversions::Convert<std::tstring>(outlookVersionName.c_str()) << TEXT(". ")
510554
<< WinTools::ConvertHresultToMessageWithHresult(hr).c_str() << std::endl << std::endl, false;
511-
512-
return true;
513555
};
514556

557+
// Disable all patches.
515558
Comment(TEXT("Disabling security patch for Outlook 2010, 2013 and 2016..."));
516-
auto success = DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\14.0\Outlook\Security)", TEXT("Outlook 2010"))
517-
&& DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\15.0\Outlook\Security)", TEXT("Outlook 2013"))
518-
&& DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\16.0\Outlook\Security)", TEXT("Outlook 2016"));
519-
559+
DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\14.0\Outlook\Security)", TEXT("Outlook 2010"));
560+
DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\15.0\Outlook\Security)", TEXT("Outlook 2013"));
561+
DisablePathForOutlookVersion(LR"(Software\Microsoft\Office\16.0\Outlook\Security)", TEXT("Outlook 2016"));
520562
Comment(TEXT("Done.\n"));
521-
return success;
522563
}
523564

524565
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

XRulez/XRulez/Application.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace XRulez
4343

4444
/// Processes executable's input. Should not be called from DLL builds.
4545
/// @return false if parameters are not valid and program should exit.
46-
bool ExeProcessParameters();
46+
void ExeProcessParameters();
4747

4848
/// Displays usage/help. Should not be called from DLL builds.
4949
/// @param error if set then output message is slightly changed and std::terr instead of std::tcout is used.
@@ -65,8 +65,7 @@ namespace XRulez
6565
bool PerformInjection();
6666

6767
/// Disables security patch KB3191883 (re-enables run-actions for Outlook 2010, 2013 and 2016).
68-
/// @return false if couldn't modify registry.
69-
bool ExeDisableSecurityPatchKB3191883();
68+
void ExeDisableSecurityPatchKB3191883();
7069

7170
/// Another executable command line processing helper function. Handles one single command-line command. Should not be called from DLL builds.
7271
/// @param commandKey name-part the a command to process.
@@ -81,6 +80,9 @@ namespace XRulez
8180
/// Shows all existing rules.
8281
void ExeDisplayAllRules();
8382

83+
/// Removes a rule from the server.
84+
void ExeRemoveRule();
85+
8486
/// Displays a list of available MAPI profiles. Should not be called from DLL builds.
8587
void ExeListOutlookProfiles();
8688

XRulez/XRulez/Configuration.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
22

3-
#define APPLICATION_NAME TEXT("XRulez 2.0")
3+
#define APPLICATION_NAME TEXT("XRulez 2.2")
44

55
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66
// MSVC related includes.

0 commit comments

Comments
 (0)