Răsfoiți Sursa

Logging loaded modules

Source commit: 6e2579d144daa82243f77b5b667eb7c2837cd41f
Martin Prikryl 6 luni în urmă
părinte
comite
a22523d916
3 a modificat fișierele cu 42 adăugiri și 0 ștergeri
  1. 3 0
      source/WinSCP.cpp
  2. 38 0
      source/core/Common.cpp
  3. 1 0
      source/core/Common.h

+ 3 - 0
source/WinSCP.cpp

@@ -45,10 +45,12 @@ WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
     AppLogFmt(L"Mouse: %s", (BooleanToEngStr(Mouse->MousePresent)));
     AppLogFmt(L"Mouse wheel: %s, msg: %d, scroll lines: %d", (BooleanToEngStr(Mouse->WheelPresent), int(Mouse->RegWheelMessage), Mouse->WheelScrollLines));
     AppLogFmt(L"ACP: %d", (static_cast<int>(GetACP())));
+    AppLogFmt(L"Windows version: %s", (WindowsVersion()));
     AppLogFmt(L"Win32 platform: %d", (Win32Platform()));
     AppLogFmt(L"Windows product type: %x", (static_cast<int>(GetWindowsProductType())));
     AppLogFmt(L"Win64: %s", (BooleanToEngStr(IsWin64())));
     AddStartupSequence(L"T");
+    LogModules();
 
     WinInitialize();
     Application->Initialize();
@@ -93,6 +95,7 @@ WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
       FinalizeWinHelp();
       CoreFinalize();
       WinFinalize();
+      LogModules();
       AppLog(L"Finalizing done");
       OnAppLog = NULL;
       SAFE_DESTROY_EX(TApplicationLog, ApplicationLog);

+ 38 - 0
source/core/Common.cpp

@@ -4524,6 +4524,44 @@ UnicodeString GetAncestorProcessNames()
   return AncestorProcessNames;
 }
 //---------------------------------------------------------------------------
+void LogModules()
+{
+  bool DoLogModules = ApplicationLog->Logging;
+  if (DoLogModules)
+  {
+    const int Max = 1024;
+    HMODULE Modules[Max];
+    HANDLE Process = GetCurrentProcess();
+    DWORD Needed;
+    if (!EnumProcessModules(Process, Modules, sizeof(Modules), &Needed))
+    {
+      AppLog(L"Failed to enumerate modules");
+    }
+    else
+    {
+      int NeededCount = Needed / sizeof(HMODULE);
+      int Count = NeededCount;
+      if (Count > Max)
+      {
+        AppLog(L"Too many modules");
+        Count = Max;
+      }
+      for (int Index = 0; Index < Count; ++Index)
+      {
+        TCHAR ModuleFileName[MAX_PATH];
+        if (!GetModuleFileNameEx(Process, Modules[Index], ModuleFileName, MAX_PATH))
+        {
+          AppLog(L"Failed to retrieve module path");
+        }
+        else
+        {
+          AppLogFmt(L"Module: %s", (ModuleFileName));
+        }
+      }
+    }
+  }
+}
+//---------------------------------------------------------------------------
 NORETURN void NotImplemented()
 {
   DebugFail();

+ 1 - 0
source/core/Common.h

@@ -207,6 +207,7 @@ UnicodeString GetEnvironmentInfo();
 void SetStringValueEvenIfEmpty(TStrings * Strings, const UnicodeString & Name, const UnicodeString & Value);
 UnicodeString __fastcall GetAncestorProcessName(int Levels = 1);
 UnicodeString GetAncestorProcessNames();
+void LogModules();
 NORETURN void NotSupported();
 NORETURN void NotImplemented();
 UnicodeString GetDividerLine();