/* Windows Help File Internal Records Pete Davis & Ron Burk - 05/93 */ #include /* Since some targets, notably older AIX compilers, do not understand #pragma pack, * offer use of the GNU C extension to control struct packing */ #ifdef __GNUC__ # define PACKED __attribute__((packed)) #elif !defined(PACKED) # define PACKED #endif #pragma pack(1) /*typedef unsigned long DWORD; typedef unsigned short WORD; typedef unsigned char BYTE; typedef unsigned int UINT;*/ /* Define WHIFS Page Size and Page size for other B-Trees */ // #define WHIFSPageSize 1024L #define BTreePageSize 2048L /* Define the size of a Topic Block 4k - sizeof(TOPICLINK) */ // #define TopicBlockSize 4084L // Win 3.0 : 0x800-sizeof... #define GotoWHIFSPage(DestPage) \ fseek(HelpFile, FirstPageLoc+(DestPage * leword(WHIFSHeader.PageSize)), SEEK_SET) #define GotoPage(DestPage) \ fseek(HelpFile, FirstPageLoc+(DestPage * BTreePageSize), SEEK_SET) #ifndef RGB # define RGB(r,g,b) ((DWORD)(b*65536) + (DWORD)(g*256) + (DWORD) (r)) #endif /* Help file Header record */ typedef struct HELPHEADER { LEDWORD MagicNumber; /* 0x00035F3F */ LEDWORD DirectoryFileOffset;/* Pointer to WHIFS header */ LONG Negative1; LEDWORD FileSize; /* Size of entire .HLP File */ } PACKED HELPHEADER; /* File Header for WHIFS files */ typedef struct FILEHEADER { LEDWORD FilePlusHeader; /* File size including this header */ LEDWORD FileSize; /* File size not including header */ char TermNull; } PACKED FILEHEADER; /* Help Directory BTREE */ typedef struct WHIFSBTREEHEADER { // char Unknown1[22]; char Unknown1[4]; LEWORD PageSize; /* Size of a Page in Bytes (WinHelp 3.1 always 0x800 = 2048, HCW sometimes 0x1000 */ char Unknown2[16]; LEWORD MustBeZero; /* Probably shows up when Help > ~40 megs */ LEWORD NSplits; /* Number of page split Btree has suffered */ LEWORD RootPage; /* Page # of root page */ LEWORD MustBeNegOne; /* Probably shows up when B-Tree is HUGE!! */ LEWORD TotalPages; /* total # to 2Kb pages in Btree */ LEWORD NLevels; /* Number of levels in this Btree */ LEDWORD TotalWHIFSEntries; } PACKED WHIFSBTREEHEADER; /* Keyword & TTL BTREE Headers - Slightly different than WHIFS B-tree Header. Both WHIFS and Keyword B-Trees use same leaf and index node headers. */ typedef struct BTREEHEADER { // char Unknown1[22]; char Unknown1[4]; LEWORD PageSize; /* Size of a Page in Bytes (WinHelp 3.1 always 0x800 = 2048, HCW sometimes 0x1000 */ char Unknown2[16]; LEWORD MustBeZero1; LEWORD NSplits; /* # of page splits Btree has suffered */ LEWORD RootPage; /* page #of root page */ LEWORD MustBeNegOne1; LEWORD TotalPages; /* total # of 2Kb pages in Btree */ LEWORD NLevels; /* # of levels in this Btree */ LEDWORD TotalBtreeEntries; } PACKED BTREEHEADER; /* Modified B-Tree Node header to handle a pointer to the page */ typedef struct BTREENODEHEADER { LEWORD Signature; /* Signature byte */ LEWORD NEntries; /* Number of entries */ LEWORD PreviousPage; /* Index of Previous Page */ LEWORD NextPage; /* Index of Next Page */ } PACKED BTREENODEHEADER; /* Modified B-Tree Index header to handle a pointer to the page */ typedef struct BTREEINDEXHEADER { LEWORD Signature; /* Signature byte */ LEWORD NEntries; /* Number of entries in node */ } PACKED BTREEINDEXHEADER; /* Phrase header In uncompressed, last field is empty */ typedef struct PHRASEHDR { LEWORD NumPhrases; /* Number of phrases in table */ LEWORD OneHundred; /* 0x0100 */ LEDWORD PhrasesSize; /* Amount of space uncompressed phrases requires. */ } PACKED PHRASEHDR; /* Header for |FONT file */ typedef struct FONTHEADER { LEWORD NumFonts; /* Number of fonts in Font List */ LEWORD NumDescriptors; /* Number of font descriptors */ LEWORD DefDescriptor; /* Default font descriptor */ LEWORD DescriptorsOffset; /* Offset to descriptor list */ } PACKED FONTHEADER; typedef struct FONTDESCRIPTOR { BYTE Attributes; /* Font Attributes See values below */ BYTE HalfPoints; /* PointSize * 2 */ BYTE FontFamily; /* Font Family. See values below */ BYTE FontName; /* Number of font in Font List */ BYTE Unknown; BYTE FGRGB[3]; /* RGB values of foreground */ BYTE BGRGB[3]; /* background RGB Values (?? Not sure */ } PACKED FONTDESCRIPTOR; typedef struct { /* Long Version of FONTDESCRIPTOR: Used by MVCC13... */ LEDWORD FontName; /* Number of font in Font List */ char unknown1[2]; BYTE FGRGB[3]; /* RGB values of foreground */ BYTE BGRGB[3]; /* background RGB Values (?? Not sure */ LEDWORD NegHalfPoints; char unknown2[12]; LEDWORD lfWeight; /* Weight-Value */ DWORD lfItalic; /* BOOL: True if Italic */ char unknown3[3]; BYTE FontFamily; char unknowne[42-4-2-3-3-4-12-4-4-4]; } PACKED LONGFONTDESCRIPTOR; /* Font Attributes */ #define FONT_NORM 0x00 /* Normal */ #define FONT_BOLD 0x01 /* Bold */ #define FONT_ITAL 0x02 /* Italics */ #define FONT_UNDR 0x04 /* Underline */ #define FONT_STRK 0x08 /* Strike Through */ #define FONT_DBUN 0x10 /* Dbl Underline */ #define FONT_SMCP 0x20 /* Small Caps */ /* Font Families */ #define FAM_MODERN 0x01 #define FAM_ROMAN 0x02 #define FAM_SWISS 0x03 #define FAM_TECH 0x03 #define FAM_NIL 0x03 #define FAM_SCRIPT 0x04 #define FAM_DECOR 0x05 /* Header for |SYSTEM file */ typedef struct SYSTEMHEADER { BYTE Magic; /* 0x6C */ BYTE Version; /* Version # */ BYTE Revision; /* Revision code */ BYTE Always0; /* Unknown */ LEWORD Always1; /* Always 0x0001 */ time_t GenDate; /* Date/Time that the help file was generated */ LEWORD Flags; /* Values seen: 0x0000 0x0004, 0x0008, 0x000A */ } PACKED SYSTEMHEADER; /* Flags for |SYSTEM header Flags field below */ #define NO_COMPRESSION_310 0x0000 #define COMPRESSION_310 0x0004 #define COMPRESSION_UNKN 0x0008 #define SYSFLAG_300 0x000A /* Help Compiler 3.1 System record. Multiple records possible */ typedef struct SYSTEMREC { LEWORD RecordType; /* Type of Data in record */ LEWORD DataSize; /* Size of RData */ char *RData; /* Raw data (Icon, title, etc) */ } PACKED SYSTEMREC; /* Types for SYSTEMREC RecordType below */ #define HPJ_TITLE 0x0001 /* Title from .HPJ file */ #define HPJ_COPYRIGHT 0x0002 /* Copyright notice from .HPJ file */ #define HPJ_CONTENTS 0x0003 /* Contents=??? from .HPJ */ #define HPJ_MACRO_DATA 0x0004 /* SData = 4 nulls if no macros */ #define HPJ_ICON_DATA 0x0005 #define HPJ_SECWINDOWS 0x0006 /* Secondary window info in .HPJ */ #define HPJ_CITATION 0x0008 /* CITATION= under [OPTIONS] */ #define HPJ_GROUPDEF 0x000d /* Secondary Window Record following type 0x0006 System Record */ typedef struct SECWINDOW { LEWORD Flags; /* Flags (See Below) */ BYTE Type[10]; /* Type of window */ BYTE Name[9]; /* Window name */ BYTE Caption[51]; /* Caption for window */ LEWORD X; /* X coordinate to start at */ LEWORD Y; /* Y coordinate to start at */ LEWORD Width; /* Width to create for */ LEWORD Height; /* Height to create for */ LEWORD Maximize; /* Maximize flag */ BYTE Rgb[3]; BYTE Unknown1; BYTE RgbNsr[3]; /* RGB for non scrollable region */ BYTE Unknown2; } PACKED SECWINDOW; /** Values for Flags **/ #define WSYSFLAG_TYPE 0x0001 /* Type is valid */ #define WSYSFLAG_NAME 0x0002 /* Name is valid */ #define WSYSFLAG_CAPTION 0x0004 /* Ccaption is valid */ #define WSYSFLAG_X 0x0008 /* X is valid */ #define WSYSFLAG_Y 0x0010 /* Y is valid */ #define WSYSFLAG_WIDTH 0x0020 /* Width is valid */ #define WSYSFLAG_HEIGHT 0x0040 /* Height is valid */ #define WSYSFLAG_MAXIMIZE 0x0080 /* Maximize is valid */ #define WSYSFLAG_RGB 0x0100 /* Rgb is valid */ #define WSYSFLAG_RGBNSR 0x0200 /* RgbNsr is valid */ #define WSYSFLAG_TOP 0x0400 /* On top was set in HPJ file */ /* Header for |TOMAP file */ typedef struct TOMAPHEADER { LEDWORD IndexTopic; /* Index topic for help file */ LEDWORD Reserved[15]; LEWORD ToMapLen; /* Number of topic pointers */ LEDWORD *TopicPtr; /* Pointer to all the topics */ } PACKED TOMAPHEADER; /* Keyword Map Record */ typedef struct KWMAPREC { LEDWORD FirstRec; /* Index number of first keyword on leaf page */ LEWORD PageNum; /* Page number that keywords are associated with */ } PACKED KWMAPREC; /* |TOPIC Block header - Header for a block of topic data. If uncompressed, there's only one of these at the beginning of the file. If the help file is compressed, then these occur in 4k increments. (e.g. 0x0000, 0x1000, 0x2000, 0x3000, 0x4000, etc. ) */ typedef struct TOPICBLOCKHEADER { LEDWORD LastTopicLink; /* Offset of last topic link in previous block */ LEDWORD TopicData; /* Offset of topic data start */ LEDWORD LastTopicHeader; /* Offset of last topic header in previous block */ } PACKED TOPICBLOCKHEADER; /* Linked list record for |TOPIC file */ typedef struct TOPICLINK { LEDWORD BlockSize; /* Size of this link + Data */ LEDWORD DataLen2; /* Length of LinkData2 */ LEDWORD PrevBlock; /* Relative to first byte of |TOPIC */ LEDWORD NextBlock; /* Relative to first byte of |TOPIC */ LEDWORD DataLen1; /* Len(LinkData1 + 11(hdr size)) */ BYTE RecordType; /* See below */ BYTE *LinkData1; /* Data associated with this link */ BYTE *LinkData2; /* Second set of data */ } PACKED TOPICLINK; /* Known record types for topic link */ #define TL_DISPLAY30 0x01 /* WinHelp 3.0 TopicLink with Text */ #define TL_TOPICHDR 0x02 /* Topic header information */ #define TL_DISPLAY 0x20 /* Displayable information */ #define TL_TABLE 0x23 /* WinHelp Table */ /* Topic header. Starts inside LinkData of a type 0x02 record */ typedef struct TOPICHEADER { LEDWORD BlockSize; /* Size of topic, including internal topic links */ LEDWORD BrowseBck; /* Topic offset for prev topic in Browse sequence */ LEDWORD BrowseFor; /* Topic offset for next topic in Browse sequence */ DWORD TopicNum; /* Topic Number(?) */ LEDWORD NonScroll; /* Start of Non-Scroll Region */ LEDWORD Scroll; /* Start of Scrolling Region of text. */ LEDWORD NextTopic; /* Start of next Type 0x02 record */ } PACKED TOPICHEADER; /* Record from |CTXOMAP file. Created from the [MAP] section of .HPJ file */ typedef struct CTXOMAPREC { LEDWORD MapID; LEDWORD TopicOffset; } PACKED CTXOMAPREC; /* Record from |CONTEXT file */ typedef struct CONTEXTREC { LEDWORD HashValue; /* Hash value of a phrase */ LEDWORD TopicOffset; /* Topic offset of the phrase */ } PACKED CONTEXTREC; /* Record for the |KWBTREE file */ typedef struct KWBTREEREC { char Keyword[8000]; /* Variable Length Keyword */ LEWORD Count; /* Count of Keywords occurances */ LEDWORD KWDataOffset; /* Offset into |KWDATA file */ } PACKED KWBTREEREC; #pragma pack()