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

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