home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / MISC / IMPEXP.TXT < prev    next >
Text File  |  1995-10-29  |  4KB  |  162 lines

  1. 3P Import/Export format
  2. =======================
  3.  
  4. I've added 3 entries to the main header to support imports and exports so the new header (strucs.inc)
  5. has the entries NewExports, NewImports & NewImportModCnt. NewExports is the length of the export
  6. section, NewImports the length of the import section and NewImportModCnt the number of modules being
  7. imported from.
  8.  
  9.  
  10. The IMPORT details follow the EXPORT details which come after the relocation entries. So the order is
  11. now main header, segment definitions, relocation table, exports, imports and then the program.
  12.  
  13.  
  14.  
  15. The export section is the following format:
  16.  
  17. dword - number of entries
  18.  
  19. followed by number of entries+1 of:
  20.  
  21. dword - offset of export record.
  22.  
  23. Each export record has the following format:
  24.  
  25. dword - offset value
  26. word - segment number.
  27. byte - name string length.
  28.  
  29. then name string length bytes of the symbol name.
  30.  
  31. The first export entry should always be the modules name and have zero's in the segment & offset
  32. fields. eg,
  33.  
  34.     org 0
  35.  
  36.     dd 2    ;2 entries (not counting module name)
  37.  
  38.     dd ModName    ;offset of module name entry
  39.     dd Export1    ;offset of first real export entry
  40.     dd Export2    ;offset of second export entry.
  41.  
  42. ModName:
  43.     dd 0    ;dummy offset value.
  44.     dw 0    ;dummy segment value.
  45.     db 4    ;name string length.
  46.     db "TEST"
  47.  
  48. Export1:
  49.     dd ?    ;offset of exported value within its segment
  50.     dw ?    ;segment of exported value.
  51.     db 7
  52.     db "EXPORT1"
  53.  
  54. Export2:
  55.     dd ?    ;offset of exported value within its segment
  56.     dw ?    ;segment of exported value
  57.     db 7
  58.     db "EXPORT2"
  59.  
  60.  
  61. The above would export EXPORT1 & EXPORT2 in a module called TEST. As far as I can remember case IS
  62. significant to the loader so generally it's a good idea to upper case things.
  63.  
  64.  
  65.  
  66. The import section has the following format:
  67.  
  68. dword - offset of module name table.
  69. dword - offset of function name table.
  70. dword - offset of import fixup data.
  71.  
  72.  
  73. The module name table is as follows:
  74.  
  75. dword - number of entries
  76.  
  77. then number of entries dwords of name string offsets.
  78.  
  79. Module names must allow 4 bytes of space even if not required by the name. The loader needs a
  80. guarentee that 4 bytes are available so the name can be converted to a pointer and stored in the
  81. same place.
  82.  
  83.  
  84. The function name table is as follows:
  85.  
  86. dword - number of entries
  87.  
  88. then number of entries dwords of name string offsets.
  89.  
  90.  
  91.  
  92. The import fixup data is as follows:
  93.  
  94. dword - number of entries
  95.  
  96. then variable length number of entries.
  97.  
  98. byte - fixup type
  99.  bit 7  is the ordinal/name flag. SET means function number is an ordinal.
  100.  bit 6  is the self relative flag. SET means fixup is self relative.
  101.  bits 5-0 are the fixup type.
  102.   0 - 16-bit offset.
  103.   1 - 32-bit offset.
  104.   2 - 16-bit seg:offset pointer.
  105.   3 - 32-bit seg:offset pointer.
  106.   4 - 16-bit seg only.
  107. dword - fixup lengths / offset
  108.  bits 31&30 are module number length in bytes.
  109.  bits 29&28 are function number length in bytes.
  110.  bits 27-0 are fixup offset within program image same as a normal fixup.
  111.  
  112.  
  113. eg,
  114.  
  115.     org 0
  116.  
  117.     dd ModNames            ;offset of list of module names imported.
  118.     dd FuncNames        ;offset of list of function names imported.
  119.     dd Fixups            ;offset of fixup data.
  120.  
  121. ModNames:
  122.     dd 1                    ;number of module names.
  123.     dd Module1            ;offset of name string.
  124.  
  125. Module1:
  126.     db 4                    ;name string length.
  127.     db "TEST"            ;name of module to IMPORT from.
  128.  
  129. FuncNames:
  130.     dd 2                    ;number of function names.
  131.     dd Function1        ;offset of name string.
  132.     dd Function2        ;offset of name string.
  133.  
  134. Function1:
  135.     db 9                    ;name string length.
  136.     db "FUNCTION1"        ;name of function to import.
  137.  
  138. Function2:
  139.     db 9                    ;name string length.
  140.     db "FUNCTION2"        ;name of function to import.
  141.  
  142. Fixups:
  143.     dd 2                    ;number of fixup entries.
  144.  
  145.     db 1+64                        ;32-bit offset, self relative.
  146.     dd ?+(1<<28)+(1<<30)        ;function number only needs 1 byte and module number only needs 1 byte.
  147.     db 0                            ;module name number.
  148.     db 0                            ;function name number (FUNCTION1)
  149.  
  150.     db 1+64                        ;32-bit offset, self relative.
  151.     dd ?+(1<<28)+(1<<30)        ;function number only needs 1 byte and module number only needs 1 byte.
  152.     db 0                            ;module name number.
  153.     db 1                            ;function name number (FUNCTION2)
  154.  
  155.  
  156.  
  157. Remember to make sure you leave room for at least 4 bytes of module name includeing the length byte
  158. for internal use even if the string only requires 2 bytes.
  159.  
  160. Modules can have imports without exports and exports without imports.
  161.  
  162.