@@ -63,13 +63,11 @@ bool XRulez::Application::ProcessInputParameters()
63
63
{
64
64
DllProcessStringTableParameters ();
65
65
PerformInjection ();
66
- return true ;
67
66
}
68
67
else
69
- {
70
- // Process executable's input.
71
- return ExeProcessParameters ();
72
- }
68
+ ExeProcessParameters ();
69
+
70
+ return true ;
73
71
}
74
72
75
73
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -123,49 +121,53 @@ void XRulez::Application::ProcessPreprocessorParameters()
123
121
}
124
122
125
123
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
126
- bool XRulez::Application::ExeProcessParameters ()
124
+ void XRulez::Application::ExeProcessParameters ()
127
125
{
128
126
// This function should not be called in DLL builds.
129
127
CHECK (!Enviro::IsDllBuild);
130
128
if (Enviro::IsDllBuild)
131
- return false ;
129
+ return ;
132
130
133
131
// Access command line params.
134
132
auto & commandLineArgs = Enviro::AccessCommandLineParams ();
135
133
136
134
// Sanity validation.
137
135
if (commandLineArgs.size () < 2 || commandLineArgs[1 ].size () != 2 || commandLineArgs[1 ][0 ] != TEXT (' -' ))
138
- return ExeShowUsage (true ), false ;
136
+ return ExeShowUsage (true );
139
137
140
138
// Handle commands separately.
141
139
switch (commandLineArgs[1 ][1 ])
142
140
{
143
141
case TEXT (' l' ): // < Display a list of available MAPI profiles.
144
- return ExeListOutlookProfiles (), false ;
142
+ return ExeListOutlookProfiles ();
145
143
146
144
case TEXT (' r' ): // < Disable security patch KB3191883.
147
145
return ExeDisableSecurityPatchKB3191883 ();
148
146
149
147
case TEXT (' a' ): // < Process command line values, validate them and proceed to message injection.
150
- return ExeProcessCommandLineValues () && PerformInjection ();
148
+ ExeProcessCommandLineValues () && PerformInjection ();
149
+ return ;
151
150
152
151
case TEXT (' d' ): // < Display parameters default (precompiled) values.
153
- return ExeShowDefaultParamsValues (), false ;
152
+ return ExeShowDefaultParamsValues ();
154
153
155
154
// case TEXT('i'): //< Perform interactive configuration and proceed to message injection.
156
155
// return ExePerformInteractiveConfiguration(), true;
157
156
158
157
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();
160
162
161
163
case TEXT (' h' ): // < Display help.
162
- return ExeShowUsage (false ), false ;
164
+ return ExeShowUsage (false );
163
165
164
166
case TEXT (' o' ): // < Check if Outlook is running at the moment.
165
- return ExeCheckIfOutlookIsRunning (), false ;
167
+ return ExeCheckIfOutlookIsRunning ();
166
168
167
169
default : // < Wrong input.
168
- return ExeShowUsage (true ), false ;
170
+ return ExeShowUsage (true );
169
171
}
170
172
}
171
173
@@ -388,6 +390,47 @@ void XRulez::Application::ExeDisplayAllRules()
388
390
}
389
391
}
390
392
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:\n XRulez.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.:\n XRulez.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
+
391
434
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
392
435
void XRulez::Application::ExeListOutlookProfiles ()
393
436
{
@@ -501,24 +544,22 @@ bool XRulez::Application::PerformInjection()
501
544
}
502
545
503
546
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
504
- bool XRulez::Application::ExeDisableSecurityPatchKB3191883 ()
547
+ void XRulez::Application::ExeDisableSecurityPatchKB3191883 ()
505
548
{
549
+ // Helper lambda to set one particular entry in the registry.
506
550
auto DisablePathForOutlookVersion = [](std::wstring const & registyKey, std::tstring const & outlookVersionName)
507
551
{
508
552
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 (" . " )
510
554
<< WinTools::ConvertHresultToMessageWithHresult (hr).c_str () << std::endl << std::endl, false ;
511
-
512
- return true ;
513
555
};
514
556
557
+ // Disable all patches.
515
558
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" ));
520
562
Comment (TEXT (" Done.\n " ));
521
- return success;
522
563
}
523
564
524
565
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0 commit comments