Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7438297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:31:56+00:00 2026-05-29T10:31:56+00:00

I am writing a program that reads ‘.exe’ files and stores their hex values

  • 0

I am writing a program that reads ‘.exe’ files and stores their hex values in an array of bytes for comparison with an array containing a series of values. (like a very simple virus scanner)

byte[] buffer = File.ReadAllBytes(currentDirectoryContents[j]);

I have then used BitConverter to create a single string of these values

string hex = BitConverter.ToString(buffer);

The next step is to search this string for a series of values(definitions) and return positive for a match. This is where I am running into problems. My definitions are hex values but created and saved in notepad as defintions.xyz

string[] definitions = File.ReadAllLines(@"C:\definitions.xyz");

I had been trying to read them into a string array and compare the definition elements of the array with string hex

bool[] test = new bool[currentDirectoryContents.Length];

test[j] = hex.Contains(definitions[i]);

This IS a section from a piece of homework, which is why I am not posting my entire code for the program. I had not used C# before last Friday so am most likely making silly mistakes at this point.

Any advice much appreciated 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:31:57+00:00Added an answer on May 29, 2026 at 10:31 am

    I expect you understand that this is a very inefficient way to do it. But except for that, you should just do something like this:

    bool[] test = new bool[currentDirectoryContents.Length];
    for(int i=0;i<test.Length;i++){
      byte[] buffer = File.ReadAllBytes(currentDirectoryContents[j]);
      string hex = BitConverter.ToString(buffer);
      test[i] = ContainsAny(hex, definitions);
    }
    
    bool ContainsAny(string s, string[] values){
      foreach(string value in values){
        if(s.Contains(value){
          return true;
        }
      }
      return false;
    }
    

    If you can use LINQ, you can do it like this:

    var test = currentDirectoryContents.Select(
                 file=>definitions.Any(
                   definition => 
                     BitConverter.ToString(
                       File.ReadAllBytes(file)
                     ).Contains(definition)
                 )
               ).ToArray();
    

    Also, make sure that your definitions-file is formatted in a way that matches the output of BitConverter.ToString(): upper-case with dashes separating each encoded byte:

    12-AB-F0-34
    54-AC-FF-01-02 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a program that reads from a list of files. The each file
I am writing a program that reads the input from a file and then
I'm writing a simple program that reads and processes file content using a BufferedReader
I'm writing a simple little ocaml program that reads an algebraic statement in from
Currently I'm working on a small program that reads large files and sorts them.
I'm writing a program that reads content from a user provided URL. My problem
I'm writing a program that reads a series of tasks from an XML file
I am writing a program that reads data packets from a file, and assigns
I am writing a function for my Clojure program that reads user input from
I'm writing a program that reads a text file of city names into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.