<commit_before>﻿using PeNet.Header.Pe;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PeNet
{
    public partial class PeFile
    {

        /// <summary>
        /// Add a new import to the PE file.
        /// If you intend to add multiple imports, use "AddImports" instead.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="function"></param>
        public void AddImport(string module, string function)
        {
            var ai = new AdditionalImport(module, new List<string> { function });
            AddImports(new List<AdditionalImport> { ai });
        }

        /// <summary>
        /// Add imports to the PE file.
        /// </summary>
        /// <param name="additionalImports">List with additional imports.</param>
        public void AddImports(List<AdditionalImport> additionalImports)
        {
            if (ImageNtHeaders is null || ImageSectionHeaders is null)
                throw new Exception("NT Headers and Section Headers must not be null.");

            const int sizeOfImpDesc = 0x14;
            var sizeOfThunkData = Is32Bit ? 4 : 8;
            var numAddImpDescs = additionalImports.Count();
            var importRva = ImageNtHeaders.OptionalHeader.DataDirectory[(int)DataDirectoryType.Import].VirtualAddress;
            var importSize = ImageNtHeaders.OptionalHeader.DataDirectory[(int)DataDirectoryType.Import].Size;

            ImageSectionHeader GetImportSection()
                => ImageSectionHeaders.First(sh => sh.VirtualAddress + sh.VirtualSize >= importRva);


            //var impSection = GetImportSection();

            int EstimateAdditionalNeededSpace()
                => (int)(additionalImports.Select(ai => ai.Functions).Count() * 64 + importSize);

            var newUnalignedRawSecSize = EstimateAdditionalNeededSpace();<commit_msg>cleanup<commit_after>﻿using PeNet.Header.Pe;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PeNet
{
    public partial class PeFile
    {

        /// <summary>
        /// Add a new import to the PE file.
        /// If you intend to add multiple imports, use "AddImports" instead.
        /// </summary>
        /// <param name="module"></param>
        /// <param name="function"></param>
        public void AddImport(string module, string function)
        {
            var ai = new AdditionalImport(module, new List<string> { function });
            AddImports(new List<AdditionalImport> { ai });
        }

        /// <summary>
        /// Add imports to the PE file.
        /// </summary>
        /// <param name="additionalImports">List with additional imports.</param>
        public void AddImports(List<AdditionalImport> additionalImports)
        {
            if (ImageNtHeaders is null || ImageSectionHeaders is null)
                throw new Exception("NT Headers and Section Headers must not be null.");

            const int sizeOfImpDesc = 0x14;
            var sizeOfThunkData = Is32Bit ? 4 : 8;
            var numAddImpDescs = additionalImports.Count();
            var importRva = ImageNtHeaders.OptionalHeader.DataDirectory[(int)DataDirectoryType.Import].VirtualAddress;
            var importSize = ImageNtHeaders.OptionalHeader.DataDirectory[(int)DataDirectoryType.Import].Size;

            int EstimateAdditionalNeededSpace()
                => (int)(additionalImports.Select(ai => ai.Functions).Count() * 64 + importSize);

            var newUnalignedRawSecSize = EstimateAdditionalNeededSpace();
{'fraction_non_alphanumeric': 0.10601398601398601, 'fraction_numerical': 0.005034965034965035, 'mean_word_length': 2.4024738344433874, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 36, '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': '4862240', 'n_tokens_mistral': 940, 'n_tokens_neox': 899, 'n_words': 244}