Skip to content
Open
Show file tree
Hide file tree
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
Binary file modified DPIAwarenessPerWindow/client/DpiAwarenessContextRes.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<NoWarn>$(NoWarn);NU1507</NoWarn>
<VanaraVer>5.0.4</VanaraVer>
<VanaraVer>5.0.5</VanaraVer>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AvalonEdit" Version="6.3.1.120" />
Expand Down
32 changes: 32 additions & 0 deletions Sampler/CodeIndexBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Sampler;

/// <summary>
/// Given a list of assemblies, this class will build an index of all the public types and members in those assemblies, so that we can
/// quickly look up information about them later.
/// </summary>
internal static class CodeIndexBuilder
{
//public static CodeIndex BuildIndex(IEnumerable<Assembly> assemblies)
//{
// var index = new CodeIndex();
// foreach (var assembly in assemblies)
// {
// foreach (var type in assembly.GetExportedTypes())
// {
// index.Types[type.FullName] = type;
// foreach (var member in type.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static))
// {
// index.Members[$"{type.FullName}.{member.Name}"] = member;
// }
// }
// }
// return index;
//}
}
14 changes: 7 additions & 7 deletions Sampler/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public partial class Form1 : Form
private const string folderKey = "5EEB255733234c4dBECF9A128E896A1E";
private const char sep = '\\';

private DirectoryInfo[] topDirs;
private DirectoryInfo[] topDirs = [];

public Form1() => InitializeComponent();

Expand Down Expand Up @@ -56,9 +56,9 @@ private static TreeNode AddSystemNode(TreeNodeCollection parent, string systemIt
try
{
if (ilkey == folderKey)
imageList.Images.Add(ilkey, GetSystemIcon());
imageList.Images.Add(ilkey, GetSystemIcon()!);
else
imageList.Images.Add(ilkey, IconExtension.GetFileIcon(ext, IconSize.Small).ToBitmap());
imageList.Images.Add(ilkey, IconExtension.GetFileIcon(ext, IconSize.Small)!.ToBitmap());
}
catch (ArgumentException ex)
{
Expand All @@ -68,11 +68,11 @@ private static TreeNode AddSystemNode(TreeNodeCollection parent, string systemIt
return parent.Add(systemItemPath, Path.GetFileName(systemItemPath), ilkey, ilkey);
}

private static Bitmap GetSystemIcon()
private static Bitmap? GetSystemIcon()
{
var shfi = new SHFILEINFO();
HIMAGELIST hSystemImageList = SHGetFileInfo("", 0, ref shfi, SHFILEINFO.Size, SHGFI.SHGFI_SYSICONINDEX | SHGFI.SHGFI_SMALLICON);
return hSystemImageList.IsNull ? null : ImageList_GetIcon(hSystemImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT).ToBitmap();
return hSystemImageList.IsNull ? null : ImageList_GetIcon(hSystemImageList, shfi.iIcon, IMAGELISTDRAWFLAGS.ILD_TRANSPARENT)?.ToBitmap();
}

private void explorerBrowser_SelectionChanged(object sender, EventArgs e)
Expand All @@ -94,14 +94,14 @@ private void LoadTree()
root.Expand();
foreach (var fi in RootPath.EnumerateFiles("*.csproj", SearchOption.AllDirectories))
{
if (!fi.DirectoryName.EndsWith("\\Sampler"))
if (!fi.DirectoryName!.EndsWith("\\Sampler"))
AddLeaf(root, fi, projectView.ImageList);
}
}

private void projectView_AfterSelect(object sender, TreeViewEventArgs e)
{
var di = new DirectoryInfo(e.Node.Name);
var di = new DirectoryInfo(e.Node!.Name);
var prj = di.Exists ? di.EnumerateFiles("*.csproj").FirstOrDefault() : null;
explorerBrowser.Navigate(new ShellFolder(e.Node.Name));
if (prj != null)
Expand Down
1 change: 0 additions & 1 deletion Sampler/NuGetPackages.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions Sampler/NuGetPackages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public partial class NuGetPackages : Form
static readonly ILogger logger = NullLogger.Instance; // TODO: Replace with actual logger if needed
static readonly CancellationToken cancellationToken = CancellationToken.None; // TODO: Replace with actual cancellation token if needed

public NuGetPackages()
{
InitializeComponent();
}
public NuGetPackages() => InitializeComponent();

private void NuGetPackages_Load(object sender, EventArgs e)
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
listBox1.Format += (s, args) => args.Value = args.ListItem is IPackageSearchMetadata r ? r.Title : args.ListItem?.ToString() ?? string.Empty;
Task.Factory.StartNew(async () =>
{
Expand Down
3 changes: 1 addition & 2 deletions Sampler/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Runtime.Versioning;
using System.Windows.Forms;
using System.Windows.Forms;

namespace Sampler;

Expand Down
4 changes: 2 additions & 2 deletions Win7Samples/security/authorization/aclapi/aclapi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ private static int Main(string[] args)
BuildExplicitAccessWithName(out var explicitaccess, TrusteeName, AccessMask, option, InheritFlag);

// add specified access to the object
SetEntriesInAcl(1, [explicitaccess], ExistingDacl, out var NewAcl).ThrowIfFailed();
SetEntriesInAcl([explicitaccess], ExistingDacl, out var NewAcl).ThrowIfFailed();

// apply new security to file
SetNamedSecurityInfo(FileName, SE_OBJECT_TYPE.SE_FILE_OBJECT, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, default, default, NewAcl, default).ThrowIfFailed();
SetNamedSecurityInfo(FileName, SE_OBJECT_TYPE.SE_FILE_OBJECT, SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, ppDacl: NewAcl).ThrowIfFailed();

return 0;
}
Expand Down
9 changes: 0 additions & 9 deletions Win7Samples/security/authorization/authz/authz.cs

This file was deleted.

123 changes: 123 additions & 0 deletions Win7Samples/security/authorization/authz/authzcli.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Vanara.InteropServices;
using Vanara.PInvoke;
using static Common;
using static Vanara.PInvoke.Kernel32;

internal partial class Program
{
const string pwd = "Pa$$w0rd";
static readonly ManualResetEventSlim svrExit = new(false);
static readonly Dictionary<string, ACCESS_FUND> ExTypes = new(StringComparer.InvariantCultureIgnoreCase)
{
["Personal"] = ACCESS_FUND.ACCESS_FUND_PERSONAL,
["Corporate"] = ACCESS_FUND.ACCESS_FUND_CORPORATE,
["Transfer"] = ACCESS_FUND.ACCESS_FUND_TRANSFER,
};

private static void Main()
{
string szServerName = "\\\\.";
EX_BUF exBuf = default;

Console.Write("\nRun client as 1) Joe (Employee), 2) Martha (Manager), 3) Bob (VP): ");
var key = Console.ReadKey();
var userId = key.KeyChar switch
{
'1' => "Joe",
'2' => "Martha",
'3' => "Bob",
_ => null
};

Console.Write("\nRun server as 1) Joe (Employee), 2) Martha (Manager), 3) Bob (VP): ");
key = Console.ReadKey();
SafeLPWSTR serverId = key.KeyChar switch
{
'1' => "Joe",
'2' => "Martha",
'3' => "Bob",
_ => ""
};
Console.WriteLine();

if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(serverId))
{
Console.WriteLine("Invalid selection. Exiting.");
return;
}

CreateLocalAcct(userId, pwd);
CreateLocalAcct(serverId!, pwd);

if (!Impersonate(userId, pwd, out var hClientToken))
HandleError(GetLastError(), "Impersonate", true, true);

using var svr = SafeHTHREAD.Create(AuthzSvr, serverId, out _);

Usage();
string? input;
while (!string.IsNullOrEmpty(input = Console.ReadLine()))
{
var args = input.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries);
try
{
//
// Verify expnese input
//
if (args.Length < 2 || !ExTypes.TryGetValue(args[0], out exBuf.dwType) || !int.TryParse(args[1], out int amt) || amt == 0)
{
Usage();
continue;
}

Console.Write($"expense: {ExNames[(int)exBuf.dwType]} Ammount: {exBuf.dwAmmount}\n");

var szPipeName = $"{szServerName}\\pipe\\AuthzSamplePipe";

// Wait for an instance of the pipe
if (!WaitNamedPipe(szPipeName, NMPWAIT_WAIT_FOREVER))
HandleError(GetLastError(), "WaitNamedPipe", true, true);

// Connect to pipe
using var hPipe = CreateFile(szPipeName, FileAccess.GENERIC_READ | FileAccess.GENERIC_WRITE, 0,
default, CreationOption.OPEN_EXISTING, 0, default);
if (hPipe.IsInvalid)
HandleError(GetLastError(), "CreateFile", true, true);

// Send off request
WriteToPipe(hPipe, exBuf);

// wait till server responds with one uint
if (ReadFromPipe(hPipe, out uint dwResponse) == 0)
{
Console.Write("Error reading form Svr\n");
return;
}

switch (dwResponse)
{
case EXPENSE_APPROVED:
Console.Write("Expense Approved.\n");
break;

case Win32Error.ERROR_ACCESS_DENIED:
Console.Write("Expense denied: Access denied.\n");
break;

case ERROR_INSUFFICIENT_FUNDS:
Console.Write("Expense denied: Insufficient funds.\n");
break;

default:
Console.Write("Expense failed: unexpected error.\n");
break;
}
}
catch { }
}
svrExit.Set();
svr.Wait();

static void Usage() => Console.Write("Usage: <Personal|Corporate|Transfer> <Ammount (cents)>\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<ItemGroup>
<PackageReference Include="Vanara.PInvoke.Security" />
<PackageReference Include="Vanara.PInvoke.NetApi32" />
<PackageReference Include="Vanara.PInvoke.User32" />
</ItemGroup>

</Project>
Loading