-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
83 lines (76 loc) · 3.09 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.IO;
using System.IO.Compression;
using System.Runtime.Versioning;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
namespace AppPackageInfo
{
class Program
{
static string ReadAppxManifestFromZip(Stream stream)
{
using (var zip = new ZipArchive(stream))
{
foreach (var entry in zip.Entries)
{
if (entry.Name.Equals("appxmanifest.xml", StringComparison.OrdinalIgnoreCase))
{
using (var manifestStream = new StreamReader(entry.Open()))
{
return manifestStream.ReadToEnd();
}
}
else if (entry.Name.EndsWith(".appx", StringComparison.OrdinalIgnoreCase) || entry.Name.EndsWith(".msix", StringComparison.OrdinalIgnoreCase))
{
using (var appxStream = entry.Open())
{
return ReadAppxManifestFromZip(appxStream);
}
}
}
}
return null;
}
[SupportedOSPlatform("windows")]
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("AppPackageInfo <appxmanifest.xml|package.appxmanifest|<package>.[appx|appxbundle]>|<package>.[msix|msixbundle]>");
return;
}
var filename = args[0];
string manifestText = null;
try
{
using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
manifestText = ReadAppxManifestFromZip(fileStream);
}
}
catch
{
}
if (manifestText == null)
{
manifestText = File.ReadAllText(filename);
}
var doc = XDocument.Parse(manifestText);
var ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("x", "http://schemas.microsoft.com/appx/manifest/foundation/windows10");
var identity = doc.XPathSelectElement("/x:Package/x:Identity", ns);
var packageName = identity?.Attribute("Name")?.Value;
Console.WriteLine($"Package/Identity/Name = {packageName}");
var publisher = identity?.Attribute("Publisher")?.Value;
Console.WriteLine($"Package/Identity/Publisher = {publisher}");
var publisherDisplayName = doc.XPathSelectElement("/x:Package/x:Properties/x:PublisherDisplayName", ns)?.Value;
Console.WriteLine($"Package/Properties/PublisherDisplayName = {publisherDisplayName}");
var pfn = AppxPackagingHelper.GetPfnFromPackageName(packageName, publisher);
Console.WriteLine($"Package Family Name (PFN) = {pfn}");
var sid = AppxPackagingHelper.GetSidFromPackageFamilyName(pfn);
Console.WriteLine($"Package SID = {sid}");
}
}
}