home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / MachOViewer / Source / MachO2.m < prev    next >
Encoding:
Text File  |  1994-02-07  |  1.6 KB  |  91 lines

  1. #import <MachOFile.h>
  2. /*
  3.  * $Log:    MachO2.m,v $
  4. Revision 1.1  94/02/07  21:36:18  ediger
  5. Initial revision
  6.  
  7.  */
  8.  
  9. static char rcsident[] = "$Id: MachO2.m,v 1.1 94/02/07 21:36:18 ediger Exp Locker: ediger $";
  10.  
  11. void print_segments(id mach_o_file);
  12. void print_threads(id oFile);
  13.  
  14. extern struct mach_header _mh_execute_header;
  15.  
  16. int
  17. main(int ac, char **av)
  18. {
  19.     MachOFile *oFile;
  20.     char buf[256];
  21.  
  22.     puts("Hit return to continue...");
  23.     gets(buf);
  24.  
  25.     oFile = [[MachOFile alloc] init];
  26.  
  27.     [oFile considerMappedFiles];
  28.  
  29.     printf("address of header: 0x%x\n", &_mh_execute_header);
  30.     [oFile fillFromAddress:(char *)&_mh_execute_header];
  31.  
  32.     print_threads(oFile);
  33.  
  34.     print_segments(oFile);
  35.  
  36.     [oFile free];
  37.  
  38.     puts("Hit return to finish...");
  39.     gets(buf);
  40.  
  41.     return 0;
  42. }
  43.  
  44. void
  45. print_threads(oFile)
  46.     id oFile;
  47. {
  48.     int iThreads, iCC;
  49.  
  50.     iThreads = [oFile threads];
  51.  
  52.     for (iCC = 0; iCC < iThreads; ++iCC)
  53.     {    id            oThread = [oFile thread:iCC];
  54.         unsigned long ulAddr = [oThread pc];
  55.  
  56.         printf("Thread's pc: 0x%lx\n", ulAddr);
  57.     }
  58. }
  59.  
  60. void
  61. print_segments(oFile)
  62.     id oFile;
  63. {
  64.     int iSegments, iCC;
  65.  
  66.     iSegments = [oFile mappedSegments];
  67.  
  68.     for (iCC = 0; iCC < iSegments; ++iCC)
  69.     {    id              oSegment = [oFile mappedSegment:iCC];
  70.         int             iSections;
  71.  
  72.         if ((iSections = [oSegment numberOfSections]) > 0)
  73.         {    int             iC;
  74.  
  75.             for (iC = 0; iC < iSections; ++iC)
  76.             {    struct section *sect = [oSegment getSection:iC];
  77.                 printf("\t%s in seg %s - 0x%lx, %lu bytes\n",
  78.                     sect->sectname, sect->segname,
  79.                     sect->addr, sect->size);
  80.             }
  81.         }
  82.  
  83.         printf("Segment 0x%lx => 0x%lx named \"%s\"\n",
  84.             [oSegment getBaseAddress],
  85.             [oSegment getUpperAddress],
  86.             [oSegment commandName]);
  87.     }
  88.  
  89.     return;
  90. }
  91.