home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05070a < prev    next >
Text File  |  1991-03-04  |  1KB  |  61 lines

  1.  
  2. #include <stdio.h>
  3. char EXEName[30] = "[d:\path\]exefile.exe";
  4. long DataPosition;
  5. FILE *EXEfile;
  6. char *DataErrors[6] =
  7. {
  8. "OK",
  9. "Unable to open EXE file",
  10. "Unable to read Header info",
  11. "Unable to read DataSeg",
  12. "Unable to write DataSeg",
  13. "Unable to close EXE file"
  14. };
  15. int SetDataPosition()
  16. {
  17. int Header[3];
  18.  
  19. if((EXEfile=fopen(EXEName, "r+b"))==NULL) /* Open the .EXE */
  20.      return 1;
  21.  
  22. if(fread(Header, sizeof(int), 3, EXEfile) != 3) /*Read*/
  23.      return 2; /* the first 3 integer of the Header */
  24.  
  25. DataPosition = 512*(Header[2]-1) + Header[1] + 1;
  26.      /* Compute the position of the Data */
  27.  
  28. fseek(EXEfile, DataPosition, SEEK_SET);
  29.  
  30. return 0;
  31.  }
  32. int ReadDataSeg(int Length, void *DataBuffer)
  33. {
  34. if(fread(DataBuffer, (size_t)Length, 1, EXEfile) !=1)
  35.      return 3; /*Read the data from the .EXE file */
  36.  
  37. return 0;
  38. }
  39. int WriteDataSeg(int Length, void *DataBuffer)
  40. {
  41. if(fwrite(DataBuffer, (size_t)Length, 1, EXEfile) != 1)
  42.      return 4; /* Write the data to the .EXE file*/
  43.  
  44. return 0;
  45. }
  46. void SeekDataSeg(long Offset)
  47.  {
  48. fseek(EXEfile, DataPosition+Offset, SEEK_SET);
  49. }         /* Seek a position in the DataSeg */
  50.  
  51. long TellDataSeg()
  52. {
  53. return ftell(EXEfile)-DataPosition;
  54. }         /* Tell the current position in the DataSeg */
  55. int CloseDataSeg()
  56. {
  57. if(fclose(EXEfile)) return 5;
  58. }    /* Close the EXE file */
  59.  
  60.  
  61.