home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / rsyssrc.lha / RSysCheckOffsets.c < prev    next >
C/C++ Source or Header  |  1993-09-20  |  6KB  |  339 lines

  1. /*
  2. ***************************************************************************
  3. *
  4. * Datei:
  5. *      RSysCheckOffsets.c
  6. *
  7. * Inhalt:
  8. *
  9. *      --- Globale Routinen ---
  10. *
  11. *    void PrintDevOffsets ( LIBRARY *lib );
  12. *    void PrintLibOffsets ( LIBRARY *lib );
  13. *    void SysCheckOffs ( void );
  14. *
  15. *      --- Lokale  Routinen ---
  16. *
  17. *    static void KillMemory ( int kill );
  18. *    static void makeblank ( void );
  19. *    static void makeentry ( ULONG adr , FUNCTION *func );
  20. *    static void makehead ( char *title );
  21. *    static void makeinfo ( struct Library *library , struct List *list );
  22. *    static void makerominfo ( UBYTE *title , ULONG num );
  23. *    static void makeromsizeinfo ( UBYTE *title , ULONG num );
  24. *    static void makesummary ( int count );
  25. *
  26. * Bemerkungen:
  27. *      Ermittlung der gepatchten Libraries und Devices im ROM.
  28. *
  29. * Erstellungsdatum:
  30. *      07-Jul-93     Rolf Böhme
  31. *
  32. * Änderungen:
  33. *      07-Jul-93     Rolf Böhme      Erstellung
  34. *
  35. ***************************************************************************
  36. */
  37.  
  38. #include "RSys.h"
  39.  
  40. static struct func
  41. {
  42.     UWORD jmp;                          /* Assembler-Befehl jmp */
  43.     ULONG adr;                          /* Sprungadresse */
  44. };
  45.  
  46. struct Remember *FKey = NULL;
  47. struct List FuncList;
  48.  
  49. static ULONG kickromstart;
  50.  
  51. static void
  52. KillMemory(int kill)
  53. {
  54.     FREEF(TRUE);
  55.  
  56.     if(kill) ErrorHandle("Library offset memory", MEMORY_ERR, ALLOC_FAIL, KILL);
  57.  
  58.     return;
  59. }
  60.  
  61. static void
  62. makeblank(void)
  63. {
  64.     struct Node *blanknode = ALLOCF(sizeof(*blanknode));
  65.  
  66.     if(blanknode)
  67.     {
  68.         AddTail(&FuncList,blanknode);
  69.         return;
  70.     }
  71.  
  72.     KillMemory(KILL);
  73.  
  74.    return;
  75. }
  76.  
  77. static void
  78. makehead(char *title)
  79. {
  80.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  81.  
  82.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  83.     {
  84.         sprintf(newnode->ln_Name,"---- %s", title);
  85.         AddTail(&FuncList, newnode);
  86.  
  87.         return;
  88.     }
  89.  
  90.     KillMemory(KILL);
  91.  
  92.    return;
  93. }
  94.  
  95. static void
  96. makerominfo(UBYTE *title, ULONG num)
  97. {
  98.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  99.  
  100.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  101.     {
  102.         sprintf(newnode->ln_Name,"%s : 0x%08lx",(char *)title, num);
  103.         AddTail(&FuncList,newnode);
  104.  
  105.         return;
  106.     }
  107.  
  108.     KillMemory(KILL);
  109.  
  110.    return;
  111. }
  112.  
  113. static void
  114. makeromsizeinfo(UBYTE *title, ULONG num)
  115. {
  116.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  117.  
  118.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  119.     {
  120.         sprintf(newnode->ln_Name,"%s : %lD Bytes",(char *)title, num);
  121.         AddTail(&FuncList,newnode);
  122.  
  123.         return;
  124.     }
  125.  
  126.     KillMemory(KILL);
  127.  
  128.    return;
  129. }
  130.  
  131. static void
  132. makeinfo(struct Library *library, struct List *list)
  133. {
  134.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  135.  
  136.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  137.     {
  138.         sprintf(newnode->ln_Name,"(%ld funcs [%ld FDs] at 0x%08lx)",
  139.                  (library->lib_NegSize / 6), CountNodes(list), library);
  140.  
  141.         AddTail(&FuncList,newnode);
  142.  
  143.         return;
  144.     }
  145.  
  146.     KillMemory(KILL);
  147.  
  148.    return;
  149. }
  150.  
  151. static void
  152. makeentry(ULONG adr, FUNCTION *func)
  153. {
  154.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  155.  
  156.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  157.     {
  158.           sprintf(newnode->ln_Name,EntryAttr[LIBRARYOFFS].ea_dataformat,
  159.               func->f_bias, adr, func->f_public ? "pub" : "prv", func->f_name);
  160.  
  161.         AddTail(&FuncList,newnode);
  162.  
  163.         return;
  164.     }
  165.  
  166.     KillMemory(KILL);
  167.  
  168.    return;
  169. }
  170.  
  171. static void
  172. makesummary(int count)
  173. {
  174.     struct Node *newnode = ALLOCF(sizeof(*newnode));
  175.  
  176.     if(newnode && (newnode->ln_Name = ALLOCF(BUFSIZE)))
  177.     {
  178.         sprintf(newnode->ln_Name,"-> %4ld patched offsets found", count);
  179.  
  180.         AddTail(&FuncList,newnode);
  181.  
  182.         return;
  183.     }
  184.  
  185.     KillMemory(KILL);
  186.  
  187.    return;
  188. }
  189.  
  190. void
  191. PrintLibOffsets(LIBRARY *lib)
  192. {
  193.    FUNCTION *func;
  194.     struct func *funcptr;
  195.    struct Node *fnode;
  196.    struct Library *library;
  197.     int j = 0;
  198.  
  199.     makehead(lib->l_name);
  200.  
  201.     library = OpenLibrary((STRPTR)lib->l_name, 0L);
  202.     if (library)
  203.     {
  204.         makeinfo(library, &(lib->l_functions));
  205.  
  206.         Forbid();
  207.  
  208.       for(fnode = lib->l_functions.lh_Head; fnode->ln_Succ; fnode = fnode->ln_Succ)
  209.         {
  210.          func = (FUNCTION *)fnode;
  211.          funcptr = (struct func *)((ULONG)library - (ULONG)func->f_bias);
  212.  
  213.             if ((funcptr->adr < kickromstart) || (funcptr->adr > MAGIC_ROM_END))
  214.             {
  215.                 makeentry(funcptr->adr, func);
  216.                 j++;
  217.             }
  218.         }
  219.  
  220.         Permit();
  221.  
  222.         CloseLibrary(library);
  223.  
  224.         makesummary(j);
  225.     }
  226.     else makehead("Can't open library!");
  227.  
  228.     makeblank();
  229.  
  230.     return;
  231. }
  232.  
  233. void
  234. PrintDevOffsets(LIBRARY *lib)
  235. {
  236.    FUNCTION *func;
  237.     struct func *funcptr;
  238.    struct Node *fnode;
  239.    struct Library *library;
  240.     struct IORequest ioreq;
  241.    int unit = 0;
  242.     int    j = 0, err;
  243.  
  244.     makehead(lib->l_name);
  245.  
  246.     memset(&ioreq,0,sizeof(struct IORequest));
  247.  
  248.    if(!strcmp(lib->l_name,"console.device")) unit = -1;
  249.  
  250.     err = OpenDevice((STRPTR)lib->l_name, unit, &ioreq, (ULONG)unit);
  251.     if (!err)
  252.     {
  253.         library = &(ioreq.io_Device->dd_Library);
  254.  
  255.         makeinfo(library, &lib->l_functions);
  256.  
  257.         Forbid();
  258.  
  259.       for(fnode = lib->l_functions.lh_Head; fnode->ln_Succ; fnode = fnode->ln_Succ)
  260.         {
  261.          func = (FUNCTION *)fnode;
  262.          funcptr = (struct func *)((ULONG)library - (ULONG)func->f_bias);
  263.  
  264.             if ((funcptr->adr < kickromstart) || (funcptr->adr > MAGIC_ROM_END))
  265.             {
  266.                 makeentry(funcptr->adr, func);
  267.                 j++;
  268.             }
  269.         }
  270.  
  271.         Permit();
  272.  
  273.         CloseDevice(&ioreq);
  274.  
  275.         makesummary(j);
  276.     }
  277.     else makehead("Can't open device!");
  278.  
  279.     makeblank();
  280.  
  281.     return;
  282. }
  283.  
  284.  
  285. void
  286. SysCheckOffs(void)
  287. {
  288.     register int i;
  289.     struct Node *node;
  290.     LIBRARY *lib;
  291.  
  292.    HandleHelp(MN_SysCheckOffs);
  293.  
  294.     PrintHeader(LIBRARYOFFS, NULL);
  295.  
  296.     EmptyListView();
  297.  
  298.     NewList(&FuncList);
  299.  
  300.     kickromstart = MAGIC_ROM_END - MAGIC_ROM_SIZE;
  301.  
  302.     makehead("Kick-ROM Info");
  303.     makerominfo((UBYTE *)"ROM Start ", kickromstart);
  304.     makeromsizeinfo((UBYTE *)"ROM Size  ", MAGIC_ROM_SIZE);
  305.     makeblank();
  306.  
  307.    if(Flags.dummy2)
  308.       for(node = Libraries.lh_Head; node->ln_Succ; node = node->ln_Succ)
  309.       {
  310.          lib = (LIBRARY *)node;
  311.          if(lib->l_typ) PrintLibOffsets(lib);
  312.          else
  313.             PrintDevOffsets(lib);
  314.       }
  315.    else
  316.    {
  317.       makeblank();
  318.       makehead((char *)field[NO_FD_FIELD]);
  319.    }
  320.  
  321.     countentries = CountNodes(&FuncList);
  322.  
  323.     Entries = AllocScrollEntries(countentries);
  324.  
  325.     for (i = 0, node = FuncList.lh_Head; i < countentries; i++, node = node->ln_Succ)
  326.     {
  327.         strcpy(Entries[i].se_Entry,node->ln_Name);
  328.  
  329.         AddNodeToList(i, NO_SORT, 0);
  330.     }
  331.  
  332.     KillMemory(NO_KILL);
  333.  
  334.     PrintStatistics();
  335.  
  336.     return;
  337. }
  338.  
  339.