home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 418.lha / DumpsAmigaLoadFiles / dalf.rexx < prev    next >
OS/2 REXX Batch file  |  1990-07-26  |  10KB  |  326 lines

  1. /************************************************\
  2. *       dalf.rexx - Dumps Amiga Load Files.      *
  3. * C 1990 Mikael Karlsson (micke@slaka.sirius.se) *
  4. \************************************************/
  5.  
  6. parse arg file              /* File to examine */
  7.  
  8. signal on break_c           /* We want a nice clean break */
  9.  
  10. pl. = "s"                   /* This is how to handle plurals the ince way */
  11. pl.1 = ""
  12.  
  13. temp = '00'x
  14. flagtext.temp = ""
  15. temp = '40'x                /* Bit 30 means 'Load to CHIPMEM' */
  16. flagtext.temp = " (CHIP)"
  17. bits. = '00'x
  18.  
  19. type. = "Unknown"
  20.  
  21. /* These are the hunk types we know about (so far) */
  22.  
  23. Hunk_unit    = '03E7'x; type.Hunk_unit    = "Hunk_unit    "
  24. Hunk_name    = '03E8'x; type.Hunk_name    = "Hunk_name    "
  25. Hunk_code    = '03E9'x; type.Hunk_code    = "Hunk_code    "
  26. Hunk_data    = '03EA'x; type.Hunk_data    = "Hunk_data    "
  27. Hunk_bss     = '03EB'x; type.Hunk_bss     = "Hunk_bss     "
  28. Hunk_reloc32 = '03EC'x; type.Hunk_reloc32 = "Hunk_reloc32 "
  29. Hunk_reloc16 = '03ED'x; type.Hunk_reloc16 = "Hunk_reloc16 "
  30. Hunk_reloc8  = '03EE'x; type.Hunk_reloc8  = "Hunk_reloc8  "
  31. Hunk_ext     = '03EF'x; type.Hunk_ext     = "Hunk_ext     "
  32. Hunk_symbol  = '03F0'x; type.Hunk_symbol  = "Hunk_symbol  "
  33. Hunk_debug   = '03F1'x; type.Hunk_debug   = "Hunk_debug   "
  34. Hunk_end     = '03F2'x; type.Hunk_end     = "Hunk_end     "
  35. Hunk_header  = '03F3'x; type.Hunk_header  = "Hunk_header  "
  36. Hunk_overlay = '03F5'x; type.Hunk_overlay = "Hunk_overlay "
  37. Hunk_break   = '03F6'x; type.Hunk_break   = "Hunk_break   "
  38. Hunk_drel32  = '03F7'x; type.Hunk_drel32  = "Hunk_drel32  "
  39. Hunk_drel16  = '03F8'x; type.Hunk_drel16  = "Hunk_drel16  "
  40. Hunk_drel8   = '03F9'x; type.Hunk_drel8   = "Hunk_drel8   "
  41. Hunk_libhunk = '03FA'x; type.Hunk_libhunk = "Hunk_libhunk "
  42. Hunk_libindx = '03FB'x; type.Hunk_libindx = "Hunk_libindx "
  43.  
  44. /* These are subtypes in Hunk_ext */
  45.  
  46. Hunk_def     =   '01'x; type.Hunk_def     = "Hunk_def    "
  47. Hunk_abs     =   '02'x; type.Hunk_abs     = "Hunk_abs    "
  48. Hunk_res     =   '03'x; type.Hunk_res     = "Hunk_res    "
  49. Hunk_ext32   =   '81'x; type.Hunk_ext32   = "Hunk_ext32  "
  50. Hunk_ext16   =   '83'x; type.Hunk_ext16   = "Hunk_ext16  "
  51. Hunk_ext8    =   '84'x; type.Hunk_ext8    = "Hunk_ext8   "
  52. Hunk_dext32  =   '85'x; type.Hunk_dext32  = "Hunk_dext32 "
  53. Hunk_dext16  =   '86'x; type.Hunk_dext16  = "Hunk_dext16 "
  54. Hunk_dext8   =   '87'x; type.Hunk_dext8   = "Hunk_dext8  "
  55.  
  56. if ~open(lf, file, 'R') then do     /* Open load file */
  57.     say "Can't open" file
  58.     exit 10
  59. end
  60.  
  61. index = 0
  62. size. = 0
  63.  
  64. loop:
  65.     type = readch(lf, 4)            /* Read hunk type */
  66.     if type == "" then do           /* End of file */
  67.         signal done
  68.     end
  69.     bits.index = bitor(bits.index, left(type, 1))   /* Check flag bits */
  70.     type = right(type, 2)                           /* Remove flag bits */
  71.     if type.type = "Unknown"  then do
  72.         say "Unknown hunk type ("c2x(type)")"
  73.         exit 10
  74.     end
  75.     id = type.type "("c2x(type)")"
  76.     signal value trim(type.type)    /* Jump to hunk display routine */
  77.  
  78. Hunk_header:
  79.     say id
  80.     dummy = c2d(readch(lf, 4))         /* What's this? */
  81.     count = c2d(readch(lf, 4))
  82.     low   = c2d(readch(lf, 4))
  83.     high  = c2d(readch(lf, 4))
  84.     say "      "count "hunk"pl.count "("low "to" high")"
  85.     do i=low to high
  86.         size = readch(lf, 4)
  87.         bits.i = left(size, 1)
  88.         size.i = c2d(right(size, 3))*4
  89.         bits = bits.i
  90.         say "      Size hunk" i":" size.i "bytes" flagtext.bits
  91.     end
  92.     index = low
  93.     signal loop
  94.  
  95. Hunk_end:
  96.     say "    "id
  97.     signal loop
  98.  
  99. Hunk_code:
  100.     size = readch(lf, 4)
  101.     bits = bitor(bits.index, left(size, 1))
  102.     size = c2d(right(size, 3))*4
  103.     temp = right(index, 2)
  104.     temp = temp":" id
  105.     temp = temp "("size "bytes)"flagtext.bits
  106.     say temp
  107.     do while size>32768
  108.         data = readch(lf, 32768)
  109.         size = size-32768
  110.     end
  111.     data = readch(lf, size)
  112.     index = index+1
  113.     signal loop
  114.  
  115. Hunk_reloc32:
  116. Hunk_reloc16:
  117. Hunk_reloc8:
  118.     say "    "id
  119.     count = c2d(readch(lf, 4))
  120.     do while count~=0
  121.         ref = c2d(readch(lf, 4))
  122.         say "      "count "item"pl.count "for hunk" ref
  123.         refs = readch(lf, count*4)
  124.         count = c2d(readch(lf, 4))
  125.     end
  126.     signal loop
  127.  
  128. Hunk_ext:
  129.     say "    "id
  130.     sym_type = readch(lf, 1)
  131.     sym_length = c2d(readch(lf, 3))*4
  132.     do until sym_type == "00"x
  133.         symbol = strip(readch(lf, sym_length), 'T', '00'x)
  134.         select
  135.             when sym_type == hunk_def |,
  136.                  sym_type == hunk_abs |,
  137.                  sym_type == hunk_res then do
  138.                 offset = strip(c2x(readch(lf, 4)), 'T', '00'x)
  139.                 temp = "     " type.sym_type
  140.                 temp = temp left(symbol, 32)":" "0x"offset
  141.                 say temp
  142.             end
  143.             when sym_type == hunk_ext32  |,
  144.                  sym_type == hunk_ext16  |,
  145.                  sym_type == hunk_ext8   |,
  146.                  sym_type == hunk_dext32 |,
  147.                  sym_type == hunk_dext16 |,
  148.                  sym_type == hunk_dext8 then do
  149.                 count = c2d(readch(lf, 4))
  150.                 refs = readch(lf, count*4)
  151.                 temp = "     " type.sym_type
  152.                 temp = temp left(symbol, 32)":"
  153.                 temp = temp right(count, 2) "item"pl.count
  154.                 say temp
  155.             end
  156.             otherwise do
  157.                 say "      Unknown definition"
  158.             end
  159.         end
  160.         sym_type = readch(lf, 1)
  161.         sym_length = c2d(readch(lf, 3))*4
  162.     end
  163.     signal loop
  164.  
  165. Hunk_drel32:
  166. Hunk_drel16:
  167. Hunk_drel8:
  168.     say "    "id
  169.     count = c2d(readch(lf, 4))
  170.     do while count~=0
  171.         ref = c2d(readch(lf, 4))
  172.         say "      "count "item"pl.count "for hunk" ref
  173.         refs = readch(lf, count*4)
  174.         count = c2d(readch(lf, 4))
  175.     end
  176.     signal loop
  177.  
  178. Hunk_data:
  179.     size = readch(lf, 4)
  180.     bits = bitor(bits.index, left(size, 1))
  181.     size = c2d(right(size, 3))*4
  182.     temp = right(index, 2)
  183.     temp = temp":" id
  184.     temp = temp "("size "bytes"
  185.     if size.index-size>0 then do
  186.         temp = temp"," size.index-size "BSS"
  187.     end
  188.     temp = temp")"flagtext.bits
  189.     say temp
  190.     data = readch(lf, size)
  191.     index = index+1
  192.     signal loop
  193.  
  194. Hunk_bss:
  195.     size = readch(lf, 4)
  196.     bits = bitor(bits.index, left(size, 1))
  197.     size = c2d(right(size, 3))*4
  198.     temp = right(index, 2)
  199.     temp = temp":" id
  200.     temp = temp "("size "bytes)"flagtext.bits
  201.     say temp
  202.     index = index+1
  203.     signal loop
  204.  
  205. Hunk_unit:
  206. Hunk_name:
  207.     say right(index, 2)":"id
  208.     size = c2d(readch(lf, 4))*4
  209.     data = readch(lf, size)
  210.     say "    " type.type":" data
  211.     index = index+1
  212.     signal loop
  213.  
  214. Hunk_symbol:
  215.     say right(index, 2)":"id
  216.     size = c2d(readch(lf, 4))*4
  217.     do while size~=0
  218.         data = strip(readch(lf, size), 'T', '00'x)
  219.         say "    " left(data, 32)":" c2x(readch(lf, 4))
  220.         size = c2d(readch(lf, 4))*4
  221.     end
  222.     signal loop
  223.  
  224. Hunk_libhunk:
  225.     size = readch(lf, 4)
  226.     bits = bitor(bits.index, left(size, 1))
  227.     size = c2d(right(size, 3))*4
  228.     say "    "id "("size "bytes)"flagtext.bits
  229.     signal loop
  230.  
  231. Hunk_libindx:
  232.     size = c2d(readch(lf, 4))*4
  233.     say "    "id "("size "bytes)"
  234.     count = c2d(readch(lf, 2))
  235.     say "    " count "bytes in string block"
  236.     string = readch(lf, count)
  237.     do forever
  238.         nameoffset = c2d(readch(lf, 2))
  239.         if nameoffset=0 then leave
  240.         parse value substr(string, nameoffset+1) with name "00"x .
  241.         say "    PUNIT '"name"'"
  242.         unitoffset = c2d(readch(lf, 2))
  243.         say "     offset" unitoffset "longword"pl.unitoffset
  244.         hunkcount = c2d(readch(lf, 2))
  245.         say "    " hunkcount "hunk"pl.hunkcount
  246.         do for hunkcount
  247.             nameoffset = c2d(readch(lf, 2))
  248.             parse value substr(string, nameoffset+1) with name "00"x .
  249.             hunksize = c2d(readch(lf, 2))
  250.             hunktype = readch(lf, 2)
  251.             say "    " type.hunktype "'"name"' of" hunksize "longword"pl.hunksize
  252.             refcount = c2d(readch(lf, 2))
  253.             say "    " refcount "ref"pl.refcount":"
  254.             do for refcount
  255.                 nameoffset = c2d(readch(lf, 2))
  256.                 if substr(string, nameoffset+1, 1)="00"x then do
  257.                     nameoffset = nameoffset+1
  258.                     temp = "16"
  259.                 end
  260.                 else do
  261.                     temp = "32"
  262.                 end
  263.                 parse value substr(string, nameoffset+1) with name "00"x .
  264.                 say "      " temp"-bit ref '"name"'"
  265.             end
  266.             defcount = c2d(readch(lf, 2))
  267.             say "    " defcount "def"pl.defcount":"
  268.             do for defcount
  269.                 nameoffset = c2d(readch(lf, 2))
  270.                 parse value substr(string, nameoffset+1) with name "00"x .
  271.                 defoffset = readch(lf, 2)
  272.                 defdata = readch(lf, 2)
  273.                 deftype = c2d(right(defdata, 2))
  274.                 defdata = left(defdata, 2)
  275.                 select
  276.                     when deftype=1 then do
  277.                         say "       Define def '"name"' at" c2d(defoffset)
  278.                     end
  279.                     when deftype=2 then do
  280.                         defoffset = defdata || defoffset
  281.                         say "       Define abs '"name"' at" c2d(defoffset)
  282.                     end
  283.                     when deftype=3 then do
  284.                         say "       Define res '"name"' at" c2d(defoffset)
  285.                     end
  286.                     when deftype=66 then do
  287.                         defoffset = "FF"x || defdata || defoffset
  288.                         say "       Define abs '"name"' at" c2d(defoffset)
  289.                     end
  290.                     otherwise do
  291.                         say "Error in object file"
  292.                         exit 10
  293.                     end
  294.                 end
  295.             end
  296.         end
  297.     end
  298.     signal loop
  299.  
  300. Hunk_debug:
  301.     size = c2d(readch(lf, 4))*4
  302.     say "    "id "("size "bytes)"
  303.     say "       Offset:" c2d(readch(lf, 4))
  304.     say "       Type:  " readch(lf, 4)
  305.     data = readch(lf, size-8)
  306.     signal loop
  307.  
  308. Hunk_break:
  309.     size = c2d(readch(lf, 4))*4
  310.     say "    "id "("size "bytes)"
  311.     data = readch(lf, size)
  312.     index = index+1
  313.     signal loop
  314.  
  315. Hunk_overlay:
  316.     size = c2d(readch(lf, 4))*4
  317.     say "    "id "("size "bytes) - Not supported"
  318.     data = readch(lf, size)
  319.     index = index+1
  320.     signal loop
  321.  
  322.  
  323. break_c:
  324. done:
  325. exit 0
  326.