Cockatrice/tools/installer-holder-probe/holder_line.h
BruebachL bbc6003f0a
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 26 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
[CrashReporting] Name the files and processes behind a failed installer purge (#7590)
* [CrashReporting] Log which files and processes blocked the installer purge

A purge that fails aborts the upgrade with a message that can only guess
at the cause, and the log only listed which DLLs survived. Record what
Windows reports for each survivor and which processes still have the
install directory mapped, then repeat the holder list in the abort
message.

The diagnostics are additive and run only on the abort path: they open
each survivor for DELETE access and close it again without deleting, so a
failed upgrade can never end up half-removed. The purge itself is
unchanged.

* [CrashReporting] Name the holders of a failed purge with Restart Manager

The process-and-module scan could only name a holder whose image lives in the
install directory or that loaded one of its DLLs, so the case this diagnostic
exists for - an antivirus scanner holding a plain handle - was reported as "no
holder named, only a code". Reaching the Restart Manager from the NSIS script
would have meant marshalling RM_PROCESS_INFO through System::Call as a table of
hand-computed offsets, which cannot be checked without a Windows toolchain, and
that is why it was dropped when this diagnostics was written.

Move the call into tools/installer-holder-probe: a small executable the same
Windows build compiles, linking nothing from this project so it still starts
when the installed runtime is what the purge could not replace. It rides inside
the installer and is extracted to $PLUGINSDIR only when the purge has already
failed, so the successful path is unchanged and nothing new is installed.

.ci/compile.sh runs it against a file held with FileShare.None on the Windows
runners, so the lookup is exercised on real Windows instead of only compiled.

* [CrashReporting] Fix the holder probe check and cap the holder line

The probe block ran after the package steps, where the working directory is
already the build dir, so its $BUILD_DIR-prefixed paths named build/build and
the PowerShell file could not be written. Move it ahead of install/package,
where the build dir is still the cwd, and name both files relative to it.
Guard it on MAKE_NO_CLIENT, since the probe is only built with the client.

Cap the rendered holder line at HOLDER_LINE_CHAR_MAX: the count limit alone
does not keep long service names inside the NSIS string that also carries the
abort text and the log path. Whole entries are kept and the rest counted, with
the first holder always shown.

Also run cmake-format on the probe's CMakeLists so the lint job accepts it.

* [CrashReporting] Report a read-only purge survivor and bound the probe check

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-10-24 00:46:54 +02:00

59 lines
2.3 KiB
C++

#ifndef HOLDER_LINE_H
#define HOLDER_LINE_H
#include <cstddef>
#include <string>
#include <vector>
/**
* @brief One application or service that has an installer file open or mapped.
*
* Deliberately free of Windows types: the wording is what the abort dialog shows,
* and it is the only part of the probe that can be exercised off Windows.
*/
struct Holder
{
std::wstring imageName; ///< "cockatrice.exe", empty when the image could not be read
std::wstring appName; ///< Restart Manager's name for the application or service
std::wstring serviceShortName; ///< service short name, empty when this is not a service
unsigned long processId = 0;
bool isService = false;
};
/// How many holders the single-line summary names before it says how many were left out.
inline constexpr std::size_t HOLDER_LINE_MAX = 5;
/**
* @brief How many characters the summary may spend on the holders it names.
*
* The line is not the whole string: the abort dialog puts it after a fixed paragraph and
* before the path of the installer log, inside an NSIS string of 1024 characters. Windows
* caps one application or service name well below this budget, so it bounds the list
* without ever cutting a single holder short.
*/
inline constexpr std::size_t HOLDER_LINE_CHAR_MAX = 400;
/**
* @brief Renders one holder the way the user has to recognise it, e.g.
* "cockatrice.exe (pid 24340, running)".
*
* The image name is preferred over the application name because it is what Task
* Manager shows, and the application name is what remains for a process whose
* image cannot be opened (another account, a protected process). A service is
* named by Restart Manager's long name and identified by its short name, because
* both are how the user finds it again in services.msc.
*/
std::wstring formatHolder(const Holder &holder);
/**
* @brief Renders every holder as a single "; "-joined line.
*
* One line because it is written to the installer log as one and repeated in a
* message box, where nsExec hands the text back as one string. Only the first
* HOLDER_LINE_MAX are named, and only while they fit in HOLDER_LINE_CHAR_MAX
* characters; the rest are counted, so a machine with a dozen open handles cannot
* push the real answer off the dialog.
*/
std::wstring formatHolders(const std::vector<Holder> &holders);
#endif