<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ClrPh;

namespace ClrPhTester
{
    class Program
    {
        static void PrintKnownDlls()
        {
            Console.WriteLine("64-bit KnownDlls : ");
            foreach (String KnownDll in Phlib.GetKnownDlls(false))
            {
                Console.WriteLine("\t{0:s}", KnownDll);
            }
            Console.WriteLine("");

            Console.WriteLine("32-bit KnownDlls : ");
            foreach (String KnownDll in Phlib.GetKnownDlls(true))
            {
                Console.WriteLine("\t{0:s}", KnownDll);
            }
            Console.WriteLine("");
        }

        static void Main(string[] args)
        {
            Phlib.InitializePhLib();
            PrintKnownDlls();


            //String FileName = "F:\\Dev\\processhacker2\\TestBt\\ClangDll\\Release\\ClangDll.dll";
            String FileName = "C:\\Windows\\System32\\kernelbase.dll";
            PE Pe = new PE(FileName);
            List<PeExport> Exports = Pe.GetExports();
            List<PeImportDll> Imports = Pe.GetImports();


            Console.WriteLine("Export listing for file : {0}" , FileName);
            foreach(PeExport Export in Exports)
            {
                Console.WriteLine("Export {0:d} :", Export.Ordinal);
                Console.WriteLine("\t Name : {0:s}", Export.Name);
                Console.WriteLine("\t VA : 0x{0:X}", (int) Export.VirtualAddress);
                if (Export.ForwardedName.Length > 0)
                    Console.WriteLine("\t ForwardedName : {0:s}", Export.ForwardedName);
            }

            Console.WriteLine("Export listing done");

            Console.WriteLine("Import listing for file : {0}", FileName);
            foreach (PeImportDll DllImport in Imports)
            {<commit_msg>[ClrPhTester] Add manifest extraction example<commit_after>﻿using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.ClrPh;

namespace ClrPhTester
{
    class Program
    {
        static void PrintKnownDlls()
        {
            Console.WriteLine("64-bit KnownDlls : ");
            foreach (String KnownDll in Phlib.GetKnownDlls(false))
            {
                Console.WriteLine("\t{0:s}", KnownDll);
            }
            Console.WriteLine("");

            Console.WriteLine("32-bit KnownDlls : ");
            foreach (String KnownDll in Phlib.GetKnownDlls(true))
            {
                Console.WriteLine("\t{0:s}", KnownDll);
            }
            Console.WriteLine("");
        }



        static void PrintApplicationManifest(PE Application)
        {
            String PeManifest = Application.GetManifest();
            if (PeManifest.Length == 0)
            {
                return;
            }

            // Use a memory stream to correctly handle BOM encoding for manifest resource
            using (var stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(PeManifest)))
            {
                XDocument XmlManifest = XDocument.Load(stream);
                XNamespace Namespace = XmlManifest.Root.GetDefaultNamespace();
                Console.WriteLine(XmlManifest);

                // Extracting assemblyIdentity
                String DependencyNodeName = String.Format("{{{0}}}dependency", Namespace);
                String AssemblyIdentityNodeName = String.Format("{{{0}}}assemblyIdentity", Namespace);
                foreach (XElement SxsDependency in XmlManifest.Descendants(DependencyNodeName))
                {
                    Console.WriteLine("SxsDependency : \n{0}", SxsDependency);

                    foreach (XElement SxsAssembly in SxsDependency.Descendants(AssemblyIdentityNodeName))
                    {
                        Console.WriteLine("SxsAssembly : {0}", SxsAssembly);
                    }
                }
            }
        }


        static void Main(string[] args)
        {
            Phlib.InitializePhLib();
            

            Console.WriteLine("Printing system KnownDll");
            PrintKnownDlls();


            //String FileName = "F:\\Dev\\processhacker2\\TestBt\\ClangDll\\Release\\ClangDll.dll";
            //String FileName = "C:\\Windows\\System32\\kernelbase.dll";
            String FileName = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
            PE Pe = new PE(FileName);
            List<PeExport> Exports = Pe.GetExports();
            List<PeImportDll> Imports = Pe.GetImports();

            Console.WriteLine("Printing selected Pe manifest");
            PrintApplicationManifest(Pe);


            Console.WriteLine("Export listing for file : {0}" , FileName);
            foreach(PeExport Export in Exports)
            {
                Console.WriteLine("Export {0:d} :", Export.Ordinal);
                Console.WriteLine("\t Name : {0:s}", Export.Name);
                Console.WriteLine("\t VA : 0x{0:X}", (int) Export.VirtualAddress);
                if (Export.ForwardedName.Length > 0)
                    Console.WriteLine("\t ForwardedName : {0:s}", Export.ForwardedName);
            }

            Console.WriteLine("Export listing done");

            Console.WriteLine("Import listing for file : {0}", FileName);
            foreach (PeImportDll DllImport in Imports)
            {
{'fraction_non_alphanumeric': 0.11597132879985297, 'fraction_numerical': 0.007719169270354714, 'mean_word_length': 1.8299531981279251, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3180843', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1399, 'n_words': 286}