Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 41 additions & 17 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,6 @@ private static void Main(string[] args)
result = dlg.ShowDialog();
}

Log($"User clicked: {result}");

if (result == DialogResult.Yes)
{
Log("User confirmed. Opening in real browser.");
OpenInRealBrowser(url);
}
else
{
Log("User declined. Not opening URL.");
}


Log($"User clicked: {result}");

if (result == DialogResult.Yes)
Expand Down Expand Up @@ -345,8 +332,10 @@ private static bool IsCallerOutlook()
if (parentId <= 0)
break;

using var parent = Process.GetProcessById(parentId);
var name = parent.ProcessName.ToLowerInvariant();
var name = GetProcessNameById(parentId);
if (string.IsNullOrWhiteSpace(name))
name = $"pid-{parentId}";
name = name.ToLowerInvariant();
Log($"Ancestor[{depth}]: {name} (PID={parentId})");

if (IsOutlookProcessName(name))
Expand Down Expand Up @@ -404,6 +393,41 @@ private static int GetParentProcessId(int pid)
return 0;
}


private static string GetProcessNameById(int pid)
{
const uint TH32CS_SNAPPROCESS = 0x00000002;

IntPtr snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == IntPtr.Zero || snapshot.ToInt64() == -1)
return string.Empty;

try
{
PROCESSENTRY32 procEntry = new PROCESSENTRY32();
procEntry.dwSize = (uint)Marshal.SizeOf(typeof(PROCESSENTRY32));

if (!Process32First(snapshot, ref procEntry))
return string.Empty;

do
{
if (procEntry.th32ProcessID == pid)
{
var exeName = procEntry.szExeFile ?? string.Empty;
return Path.GetFileNameWithoutExtension(exeName) ?? string.Empty;
}
}
while (Process32Next(snapshot, ref procEntry));
}
finally
{
CloseHandle(snapshot);
}

return string.Empty;
}

[StructLayout(LayoutKind.Sequential)]
private struct PROCESSENTRY32
{
Expand Down Expand Up @@ -459,7 +483,7 @@ internal sealed class ConfirmDialog : Form
{
public ConfirmDialog(string message, Image? logo)
{
Text = "Security Warning LinkAction";
Text = "Security Warning – LinkAction";
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
Expand Down Expand Up @@ -544,7 +568,7 @@ public ConfirmDialog(string message, Image? logo)
// Apply as ClientSize so borders are accounted for by WinForms
ClientSize = new Size(desiredW, desiredH);

// Dont let the OS shrink us to nothing because of DPI/AutoSize quirks
// Don’t let the OS shrink us to nothing because of DPI/AutoSize quirks
MinimumSize = new Size(480, 180);
}
}
Expand Down