HpSomBinaryFile.h

Go to the documentation of this file.
00001 /* * Copyright (C) 2000-2001, The University of Queensland
00002  *
00003  * See the file "LICENSE.TERMS" for information on usage and
00004  * redistribution of this file, and for a DISCLAIMER OF ALL
00005  * WARRANTIES.
00006  *
00007  */
00008 
00009 /* File: HpSomBinaryFile.h
00010  * Desc: This file contains the definition of the class HpSomBinaryFile.
00011 */
00012 
00013 /* $Revision: 1.8 $
00014  *
00015  * 22 Jun 00 - Mike: Initial revision
00016  * 09 May 01 - Mike: Read the imports table so can identify library functions
00017  * 14 May 01 - Mike: Added GetAddressByName()
00018  * 01 Aug 01 - Mike: GetGlobalPointerInfo() returns unsigned ints now
00019  * 03 Aug 01 - Mike: Added a few useful structs
00020  * 10 Aug 01 - Mike: Added GetDynamicGlobalMap()
00021  * 12 Jul 05 - Mike: Use new double map SymTab class
00022 */
00023 
00024 #ifndef __HPSOMBINARYFILE_H__
00025 #define __HPSOMBINARYFILE_H__
00026 
00027 /*==============================================================================
00028  * Dependencies.
00029  *============================================================================*/
00030 
00031 #include "BinaryFile.h"
00032 #include "SymTab.h"
00033 #include <set>
00034 
00035 struct import_entry {
00036     int         name;
00037     short       reserved2;
00038     Byte        type;
00039     Byte        reserved1;
00040 };
00041 
00042 struct export_entry {
00043     int         next;
00044     int         name;
00045     int         value;
00046     int         size;       // Also misc_info
00047     Byte        type;
00048     char        reserved1;
00049     short       module_index;
00050 };
00051 
00052 struct space_dictionary_record {
00053     unsigned    name;
00054     unsigned    flags;
00055     int         space_number;
00056     int         subspace_index;
00057     unsigned    subspace_quantity;
00058     int         loader_fix_index;
00059     unsigned    loader_fix_quantity;
00060     int         init_pointer_index;
00061     unsigned    init_pointer_quantity;
00062 };
00063 
00064 struct subspace_dictionary_record {
00065     int         space_index;
00066     unsigned    flags;
00067     int         file_loc_init_value;
00068     unsigned    initialization_length;
00069     unsigned    subspace_start;
00070     unsigned    subspace_length;
00071     unsigned    alignment;
00072     unsigned    name;
00073     int         fixup_request_index;
00074     int         fixup_request_quantity;
00075 };
00076 
00077 struct plt_record {
00078     ADDRESS     value;                      // Address in the library
00079     ADDRESS     r19value;                   // r19 value needed
00080 };
00081 
00082 struct symElem {
00083     const char* name;                       // Simple symbol table entry
00084     ADDRESS     value;
00085 };
00086 
00087 class HpSomBinaryFile : public BinaryFile
00088 {
00089 public:
00090                     HpSomBinaryFile();          // Constructor
00091 virtual             ~HpSomBinaryFile();
00092 virtual void        UnLoad();                   // Unload the image
00093 virtual bool        Open(const char* sName);    // Open the file for r/w; pv
00094 virtual void        Close();                    // Close file opened with Open()
00095 virtual bool        PostLoad(void* handle);     // For archive files only
00096 virtual LOAD_FMT    GetFormat() const;       // Get format i.e. LOADFMT_PALM
00097 virtual MACHINE     GetMachine() const;       // Get format i.e. MACHINE_HPRISC
00098 virtual const char  *getFilename() const { return m_pFileName; }
00099 
00100 virtual bool        isLibrary() const;
00101 virtual std::list<const char *> getDependencyList();
00102 virtual ADDRESS     getImageBase();
00103 virtual size_t      getImageSize();
00104 
00105         // Get a symbol given an address
00106 virtual const char* SymbolByAddress(ADDRESS dwAddr);
00107         // Lookup the name, return the address
00108 virtual ADDRESS     GetAddressByName(char* pName, bool bNoTypeOK = false);
00109         // Return true if the address matches the convention for A-line system calls
00110         bool        IsDynamicLinkedProc(ADDRESS uNative);
00111 
00112         // Specific to BinaryFile objects that implement a "global pointer"
00113         // Gets a pair of unsigned integers representing the address of %agp (first)
00114         // and the value for GLOBALOFFSET (unused for pa-risc)
00115 virtual std::pair<unsigned,unsigned> GetGlobalPointerInfo();
00116 
00117     // Get a map from ADDRESS to const char*. This map contains the native
00118     // addresses and symbolic names of global data items (if any) which are
00119     // shared with dynamically linked libraries. Example: __iob (basis for
00120     // stdout).The ADDRESS is the native address of a pointer to the real dynamic data object.
00121 virtual std::map<ADDRESS, const char*>* GetDynamicGlobalMap();
00122 
00123 //
00124 //  --  --  --  --  --  --  --  --  --  --  --
00125 //
00126 // Internal information
00127 // Dump headers, etc
00128 //virtual bool    DisplayDetails(const char* fileName, FILE* f = stdout);
00129 
00130 
00131     // Analysis functions
00132 virtual std::list<SectionInfo*>& GetEntryPoints(const char* pEntry = "main");
00133 virtual ADDRESS     GetMainEntryPoint();
00134 virtual ADDRESS     GetEntryPoint();
00135 
00136 //      bool        IsDynamicLinkedProc(ADDRESS wNative);
00137 //      ADDRESS     NativeToHostAddress(ADDRESS uNative);
00138 protected:
00139 virtual bool        RealLoad(const char* sName); // Load the file; pure virtual
00140 
00141     
00142 private:
00143         // Private method to get the start and length of a given subspace
00144         std::pair<ADDRESS, int> getSubspaceInfo(const char* ssname);
00145 
00146         unsigned char* m_pImage;                    // Points to loaded image
00147         SymTab      symbols;                    // Symbol table object
00148 //      ADDRESS     mainExport;                 // Export entry for "main"
00149         std::set<ADDRESS> imports;              // Set of imported proc addr's
00150         const char *m_pFileName;
00151 };
00152 
00153 #endif      // #ifndef __HPSOMBINARYFILE_H__

Generated on Tue Sep 19 21:18:24 2006 for Boomerang by  doxygen 1.4.6