TObjFile - OMF Object File Generator

Fuente: source/classes/objfile.prg

TObjFile inherits from TFile and writes Intel OMF (Object Module Format) object files. OMF is the object file format used by Borland C/C++ and other x86 compilers. TObjFile provides methods to emit each record type: module header, compiler identification, segment/public/external definitions, logical segment data, group definitions, and module termination.

Inheritance

classDiagram TFile <|-- TObjFile class TObjFile { +THeadr(cModule) +Compiler(cName) +LNames(aNames) +SegDef(n, nClass, nLen, nAlign) +PubDef(cName, nSeg, nOff) +ExtDef(aNames) +LeData(cData, nSeg, nOff) +GrpDef(nName, aSegs) +ModEnd() }

Methods

MethodDescription
THeadr( cModule )Write THEADR record with module name
Compiler( cName )Write compiler identification string record
LNames( aNames )Write LNAMES records from an array of name strings
SegDef( n, nClass, nLen, nAlign )Define a logical segment with index, class index, length and alignment
PubDef( cName, nSeg, nOff )Define a public (exported) symbol, name, segment and offset
ExtDef( aNames )Define external (imported) symbols from an array of names
LeData( cData, nSeg, nOff )Write LEDATA record with binary data, segment index and offset
GrpDef( nName, aSegs )Define a segment group with name index and array of segment indices
ModEnd()Write MODEND record to terminate the object module

Example: Generate an OMF Object File

#include "FiveWin.ch"

function Main()

   local oObj := TObjFile():Create( "test.obj", 1 )

   oObj:THeadr( "TESTMODULE" )
   oObj:Compiler( "Harbour/FWH OMF Generator" )

   // Define segment names
   oObj:LNames( { "_TEXT", "CODE" } )

   // Define a code segment: index 1, class 1, length 256, para-align
   oObj:SegDef( 1, 1, 256, 4 )

   // Public symbol
   oObj:PubDef( "_TestFunc", 1, 0 )

   // External reference
   oObj:ExtDef( { "_printf" } )

   // Write code bytes
   oObj:LeData( Chr( 0xC3 ), 1, 0 )   // RET instruction at offset 0

   // Group definition
   oObj:GrpDef( 1, { 1 } )

   // End module
   oObj:ModEnd()

   oObj:Close()
   ? "Object file test.obj created"

return nil

Ver También