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

using Workshell.PE.Annotations;
using Workshell.PE.Extensions;
using Workshell.PE.Native;

namespace Workshell.PE
{

    public sealed class ImportDirectoryEntry : ISupportsLocation, ISupportsBytes
    {

        private ImportDirectory directory;
        private IMAGE_IMPORT_DESCRIPTOR descriptor;
        private Location location;
        private string name;

        internal ImportDirectoryEntry(ImportDirectory importDirectory, IMAGE_IMPORT_DESCRIPTOR entry, Location entryLocation)
        {
            directory = importDirectory;
            descriptor = entry;
            location = entryLocation;
            name = null;
        }

        #region Methods

        public override string ToString()
        {
            return GetName();
        }

        public byte[] GetBytes()
        {
            int size = Utils.SizeOf<IMAGE_IMPORT_DESCRIPTOR>();
            byte[] buffer = new byte[size];

            Utils.Write<IMAGE_IMPORT_DESCRIPTOR>(descriptor, buffer, 0, size);

            return buffer;
        }
        
        public DateTime GetTimeDateStamp()
        {
            return Utils.ConvertTimeDateStamp(descriptor.TimeDateStamp);
        }

        public string GetName()
        {
            if (String.IsNullOrWhiteSpace(name))
            {           
                StringBuilder builder = new StringBuilder(256);
                LocationCalculator calc = directory.DataDirectory.Directories.Image.GetCalculator();
                Stream stream = directory.DataDirectory.Directories.Image.GetStream();
                ulong offset = calc.RVAToOffset(descriptor.Name);

                stream.Seek(offset.ToInt64(), SeekOrigin.Begin);

                name = Utils.ReadString(stream);
            }

            return name;
        }<commit_msg>Another quick tweak.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Workshell.PE.Annotations;
using Workshell.PE.Extensions;
using Workshell.PE.Native;

namespace Workshell.PE
{

    public sealed class ImportDirectoryEntry : ISupportsLocation, ISupportsBytes
    {

        private ImportDirectory directory;
        private IMAGE_IMPORT_DESCRIPTOR descriptor;
        private Location location;
        private string name;

        internal ImportDirectoryEntry(ImportDirectory importDirectory, IMAGE_IMPORT_DESCRIPTOR entry, Location entryLocation)
        {
            directory = importDirectory;
            descriptor = entry;
            location = entryLocation;
            name = null;
        }

        #region Methods

        public override string ToString()
        {
            return GetName();
        }

        public byte[] GetBytes()
        {
            int size = Utils.SizeOf<IMAGE_IMPORT_DESCRIPTOR>();
            byte[] buffer = new byte[size];

            Utils.Write<IMAGE_IMPORT_DESCRIPTOR>(descriptor, buffer, 0, size);

            return buffer;
        }
        
        public DateTime GetTimeDateStamp()
        {
            return Utils.ConvertTimeDateStamp(descriptor.TimeDateStamp);
        }

        public string GetName()
        {
            if (name == null)
            {           
                StringBuilder builder = new StringBuilder(256);
                LocationCalculator calc = directory.DataDirectory.Directories.Image.GetCalculator();
                Stream stream = directory.DataDirectory.Directories.Image.GetStream();
                ulong offset = calc.RVAToOffset(descriptor.Name);

                stream.Seek(offset.ToInt64(), SeekOrigin.Begin);

                name = Utils.ReadString(stream);
            }

            return name;
        }
{'fraction_non_alphanumeric': 0.0759297520661157, 'fraction_numerical': 0.0030991735537190084, 'mean_word_length': 2.0616600790513835, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5038704', 'n_tokens_mistral': 978, 'n_tokens_neox': 937, 'n_words': 215}