• 0

Check if EXE is x64?


Question

8 answers to this question

Recommended Posts

  • 0

Okay, in that case the only real way I can think of is by loading the file and analyzing its header.

I've put together a basic example (minus error checking) that is all-managed:

private void button1_Click(object sender, EventArgs e)
{
	openFileDialog1.ShowDialog();
	Stream fs = openFileDialog1.OpenFile();

	BinaryReader br = new BinaryReader(fs);

	UInt16 mz = br.ReadUInt16();
	if (mz == 0x5a4d) // check if it's a valid image ("MZ")
	{
		fs.Position = 60; // this location contains the offset for the PE header
		UInt32 peoffset = br.ReadUInt32();

		fs.Position = peoffset + 4; // contains the architecture
		UInt16 machine = br.ReadUInt16();

		if (machine == 0x8664) // IMAGE_FILE_MACHINE_AMD64
			textBox1.Text = "AMD64";
		else if (machine == 0x014c) // IMAGE_FILE_MACHINE_I386
			textBox1.Text = "i386";
		else if (machine == 0x0200) // IMAGE_FILE_MACHINE_IA64
			textBox1.Text = "IA64";
		else
			textBox1.Text = "Unknown";
	}
	else
		textBox1.Text = "Invalid image";

	br.Close();
}

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.