EXEcutable file

This is a discussion on EXEcutable file within the C Programming forums, part of the General Programming Boards category; Can i? Can i edit a exe file via a code writeen in c? I just explore the file by ...

  1. #1
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002
    Posts
    92

    Question EXEcutable file

    Can i?
    Can i edit a exe file via a code writeen in c?
    I just explore the file by :
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    struct EXE{
    		char id[2];
    		unsigned last;
    		unsigned pages;
    		unsigned reloc_items;
    		unsigned headersize;
    		unsigned minpara;
    		unsigned maxpara;
    		unsigned ss;
    		unsigned sp;
    		unsigned chksum;
    		unsigned ip;
    		unsigned cs;
    		unsigned first_reloc;
    		unsigned ovr;
    		};
    
    void main(int argc,char *argv[])
    	{
    	FILE *fp;
    	struct EXE exe;
    	if((fp=fopen(argv[1],"rb"))==NULL)
    		{
    		puts("\n\nUsage: EXE exe_file_name\n");
    		exit(-1);
    		}
    	printf("abhinay shinde\n\n");
    	printf("Dept. of computer Science maharashtra.\n\n");
    	fread(&exe,sizeof(exe),1,fp);
    	printf("Id (usually MZ)........................%c%c\n",exe.id[0],exe.id[1]);
    	printf("Total bytes on the last sector.........%05u  %04x\n",exe.last,exe.last);
    	printf("Total sectors..........................%05u  %04x\n",exe.pages,exe.pages);
    	printf("No of reloc table items................%05u\n",exe.reloc_items);
    	printf("Header size in paras...................%05u\n",exe.headersize);
    	printf("Min paras required.....................%05u\n",exe.minpara);
    	printf("Max paras required.....................%05u\n",exe.maxpara);
    	printf("SS.....................................%05u  %04x\n",exe.ss,exe.ss);
    	printf("SP.....................................%05u  %04x\n",exe.sp,exe.sp);
    	printf("CheckSum...............................%05u\n",exe.chksum);
    	printf("IP.....................................%05u  %04x\n",exe.ip,exe.ip);
    	printf("CS.....................................%05u  %04x\n",exe.cs,exe.cs);
    	printf("Offset of the last reloc item..........%05u\n",exe.first_reloc);
    	printf("Overlay No.............................%d\n",exe.ovr);
    	}
    now i want to edit it .
    is it possible?

    &#91;code]&#91;/code]tagged by Salem
    AbHHinaay

  2. #2
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    Code:
    void main (int argc,char *argv[])
    is undefined - use:
    Code:
    int main (int argc,char *argv[])
    {
        ....
        ....
        return 0;
    }
    And if you declare 'int argc' you should use it to make sure that argv[1] you want to access actually exists!
    Code:
    e.g.:
    
    if(argc <= 0)
    {	
        fprintf(stderr, "command line error!");
        exit(1);
    }

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    u can modify a exe file but u need to know assembly

    i can use a dissembler to do it

    this is a code in asm that adds 2 number
    Code:
    mov al 5h
    mov dl 5h
    
    add al dl
    if i dump the exe file and veiw the content that does the same thing above this is what i c .If i need to change 5h which is 5 in decimal to say 10 then this is what i will do .I will open the exe or com file with a dissembler and modify the al 5h to
    Code:
    al ah             ;in decimal that is 10 it
    mosrt of the things are quite fimilair like SS means Segment stack, EC means extra segment u need to know assembly before attempting to write a dissembler ...
    Thats basically it ....
    Last edited by datainjector; 11-06-2002 at 02:54 PM.
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. using MAKE with makefile to create executable file
    By sballew in forum C Programming
    Replies: 1
    Last Post: 11-19-2001, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21