VB icon

EXE Header Info

Email
Submitted on: 1/1/2015 1:50:00 PM
By: Shoots AndLadders (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 912
 
     Get .exe file header info
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :EXE Header Info
//**************************************
stdio.h
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: EXE Header Info
// Description:Get .exe file header info
// By: Shoots AndLadders (from psc cd)
//
// Inputs:a File to read header of.
//
// Returns:outputs header info
//**************************************

#include <stdio.h>
struct EXEHEAD
{
	char id[2];				// 'M' & 'Z'
	unsigned lastpg;		// no of bytes on last page
	unsigned size;			// total no of 512 byte pages
	unsigned reloc;			// no of relocation table items
	unsigned headersize;	// header size in paras
	unsigned minpara;		// min. paras reqd. by prog.
	unsigned maxpara;		// max. paras reqd. by prog.
	unsigned stackseg;		// initial value of stack seg.
	unsigned stackoff;		// initial value of SP
	unsigned chksum;		// header check sum
	unsigned IP;			// entry point IP
	unsigned CS;			// entry point CS
	unsigned relocoff;		// offset of 1st relocation item
	unsigned char overlay;	// overlay number
};
int main(int argc, char *argv[])
{
	FILE *fp;
	struct EXEHEAD exehead;
	if((fp = fopen(argv[1], "rb")) == NULL)
	{
		printf("ERROR: file open error: %s\n", argv[1]);
		return 1;
	}
	fread(&exehead, sizeof(exehead), 1, fp);
	printf("EXE file signature: %c%c\n", exehead.id[0], exehead.id[1]);
	printf("Total bytes on last sectors: %u\n", exehead.lastpg);
	printf("Total sectors(1 sector = 512 bytes): %u\n", exehead.size);
	printf("No. of relocation table items: %u\n", exehead.reloc);
	printf("Header size in paragraphs: %u\n", exehead.headersize);
	printf("Min. paras. reqd. by program: %u\n", exehead.minpara);
	printf("Max. paras. reqd. by program: %u\n", exehead.maxpara);
	printf("Initial value of SS: %u\n", exehead.stackseg);
	printf("Initial value of SP: %u\n", exehead.stackoff);
	printf("Header checksum: %u\n", exehead.chksum);
	printf("Initial value of IP: %u\n", exehead.IP);
	printf("Initial value of CS: %u\n", exehead.CS);
	printf("Offset of 1st relocation item: %u\n", exehead.relocoff);
	printf("Overlay number: %d\n", exehead.overlay);
	return 0;
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.