many changes, see description [skip ci]

Note: currently only works via manual injection, Rundll32Entry has been removed

- Fixed conflict with UpdatePack7R2 (and WuaCpuFix) by hooking `RegQueryValueExW` and fixing the path to `wuaueng.dll`. (fixes #100)
- Eliminated lots of redundant and unnecessary code.
- Other reliability improvements and bug fixes.
- Removed the error message that displays in the installers when `wuaueng.dll` is below the minimum supported version, and added an internal check that will skip the patching procedure if the version of `wuaueng.dll` is too low. **This means you can now safely install wufuc prior to any updates, and it will automatically start working once it's needed, without any potential side effects.** (fixes #99)
- Added `/UNATTENDED` flag to the batch installer and uninstaller. You can use this to bypass the confirmation for a fully automated installation/uninstallation. To use it, you invoke the batch script from an elevated command prompt, like so: `"wufuc_installer.bat" /UNATTENDED`
- Improved logging framework to allow multiple processes to safely write to the same `.log` file.
This commit is contained in:
zeffy
2017-09-21 19:09:03 -07:00
parent 9ec707e3f5
commit ab40ad39a2
32 changed files with 600 additions and 809 deletions

72
wufuc/tracing.c Normal file
View File

@@ -0,0 +1,72 @@
#include "tracing.h"
#include <stdio.h>
#include <time.h>
#include <Windows.h>
#include <tchar.h>
static FILE *m_pStream;
static HANDLE m_hMutex;
static BOOL m_bDeinitializing;
BOOL InitTracing(void) {
if ( m_bDeinitializing )
return FALSE;
if ( !m_hMutex )
m_hMutex = CreateMutex(NULL, FALSE, _T("Global\\wufuc_TracingMutex"));
if ( m_hMutex && !m_pStream ) {
TCHAR path[MAX_PATH];
GetModuleFileName(HINST_THISCOMPONENT, path, _countof(path));
TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME];
_tsplitpath_s(path, drive, _countof(drive), dir, _countof(dir), fname, _countof(fname), NULL, 0);
_tmakepath_s(path, _countof(path), drive, dir, fname, _T(".log"));
m_pStream = _tfsopen(path, _T("at"), _SH_DENYNO);
}
return m_pStream && m_hMutex;
}
DWORD WaitForTracingMutex(void) {
return WaitForSingleObject(m_hMutex, INFINITE);
}
BOOL ReleaseTracingMutex(void) {
return ReleaseMutex(m_hMutex);
}
void trace_(LPCTSTR format, ...) {
if ( InitTracing() ) {
TCHAR datebuf[9], timebuf[9];
_tstrdate_s(datebuf, _countof(datebuf));
_tstrtime_s(timebuf, _countof(timebuf));
if ( !WaitForTracingMutex() ) {
_ftprintf_s(m_pStream, _T("%s %s [PID: %d TID: %d] "), datebuf, timebuf, GetCurrentProcessId(), GetCurrentThreadId());
va_list argptr;
va_start(argptr, format);
_vftprintf_s(m_pStream, format, argptr);
va_end(argptr);
fflush(m_pStream);
}
ReleaseTracingMutex();
}
}
BOOL DeinitTracing(void) {
m_bDeinitializing = TRUE;
BOOL result = TRUE;
if ( m_hMutex ) {
result = CloseHandle(m_hMutex);
m_hMutex = NULL;
}
if ( m_pStream ) {
result = result && !fclose(m_pStream);
m_pStream = NULL;
}
return result;
}