Kirill K. Smirnov : winhelp: There are files without Phrases or Phrases40 compression, add support for them.

Alexandre Julliard julliard at winehq.org
Tue Dec 4 13:25:23 CST 2007


Module: wine
Branch: master
Commit: 7f2c72498a12f7811c7320e34ea3ba6c1e373fa6
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7f2c72498a12f7811c7320e34ea3ba6c1e373fa6

Author: Kirill K. Smirnov <lich at math.spbu.ru>
Date:   Tue Dec  4 03:22:05 2007 +0300

winhelp: There are files without Phrases or Phrases40 compression, add support for them.

---

 programs/winhelp/hlpfile.c |   56 +++++++++++++++++++++++--------------------
 programs/winhelp/hlpfile.h |    3 +-
 2 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/programs/winhelp/hlpfile.c b/programs/winhelp/hlpfile.c
index 7eeec1b..f9013e6 100644
--- a/programs/winhelp/hlpfile.c
+++ b/programs/winhelp/hlpfile.c
@@ -412,11 +412,13 @@ static BOOL HLPFILE_AddPage(HLPFILE *hlpfile, BYTE *buf, BYTE *end, unsigned off
 {
     HLPFILE_PAGE* page;
     BYTE*         title;
-    UINT          titlesize;
+    UINT          titlesize, blocksize, datalen;
     char*         ptr;
     HLPFILE_MACRO*macro;
 
-    title = buf + GET_UINT(buf, 0x10);
+    blocksize = GET_UINT(buf, 0);
+    datalen = GET_UINT(buf, 0x10);
+    title = buf + datalen;
     if (title > end) {WINE_WARN("page2\n"); return FALSE;};
 
     titlesize = GET_UINT(buf, 4);
@@ -424,23 +426,22 @@ static BOOL HLPFILE_AddPage(HLPFILE *hlpfile, BYTE *buf, BYTE *end, unsigned off
     if (!page) return FALSE;
     page->lpszTitle = (char*)page + sizeof(HLPFILE_PAGE);
 
-    if (hlpfile->hasPhrases)
+    if (titlesize > blocksize - datalen)
     {
-        HLPFILE_Uncompress2(title, end, (BYTE*)page->lpszTitle, (BYTE*)page->lpszTitle + titlesize);
-    }
-    else
-    {
-        if (GET_UINT(buf, 0x4) > GET_UINT(buf, 0) - GET_UINT(buf, 0x10))
-        {
-            /* need to decompress */
-            HLPFILE_Uncompress3(page->lpszTitle, page->lpszTitle + titlesize, 
-                                title, end);
-        }
+        /* need to decompress */
+        if (hlpfile->hasPhrases)
+            HLPFILE_Uncompress2(title, end, (BYTE*)page->lpszTitle, (BYTE*)page->lpszTitle + titlesize);
+        else if (hlpfile->hasPhrases40)
+            HLPFILE_Uncompress3(page->lpszTitle, page->lpszTitle + titlesize, title, end);
         else
         {
+            WINE_FIXME("Text size is too long, splitting\n");
+            titlesize = blocksize - datalen;
             memcpy(page->lpszTitle, title, titlesize);
         }
     }
+    else
+        memcpy(page->lpszTitle, title, titlesize);
 
     page->lpszTitle[titlesize] = '\0';
 
@@ -888,7 +889,7 @@ static BOOL HLPFILE_AddParagraph(HLPFILE *hlpfile, BYTE *buf, BYTE *end, unsigne
     UINT               textsize;
     BYTE              *format, *format_end;
     char              *text, *text_base, *text_end;
-    long               size;
+    long               size, blocksize, datalen;
     unsigned short     bits;
     unsigned           nc, ncol = 1;
 
@@ -900,25 +901,28 @@ static BOOL HLPFILE_AddParagraph(HLPFILE *hlpfile, BYTE *buf, BYTE *end, unsigne
 
     if (buf + 0x19 > end) {WINE_WARN("header too small\n"); return FALSE;};
 
+    blocksize = GET_UINT(buf, 0);
     size = GET_UINT(buf, 0x4);
+    datalen = GET_UINT(buf, 0x10);
     text = text_base = HeapAlloc(GetProcessHeap(), 0, size);
     if (!text) return FALSE;
-    if (hlpfile->hasPhrases)
+    if (size > blocksize - datalen)
     {
-        HLPFILE_Uncompress2(buf + GET_UINT(buf, 0x10), end, (BYTE*)text, (BYTE*)text + size);
-    }
-    else
-    {
-        if (GET_UINT(buf, 0x4) > GET_UINT(buf, 0) - GET_UINT(buf, 0x10))
-        {
-            /* block is compressed */
-            HLPFILE_Uncompress3(text, text + size, buf + GET_UINT(buf, 0x10), end);
-        }
+        /* need to decompress */
+        if (hlpfile->hasPhrases)
+            HLPFILE_Uncompress2(buf + datalen, end, (BYTE*)text, (BYTE*)text + size);
+        else if (hlpfile->hasPhrases40)
+            HLPFILE_Uncompress3(text, text + size, buf + datalen, end);
         else
         {
-            text = (char*)buf + GET_UINT(buf, 0x10);
+            WINE_FIXME("Text size is too long, splitting\n");
+            size = blocksize - datalen;
+            memcpy(text, buf + datalen, size);
         }
     }
+    else
+        memcpy(text, buf + datalen, size);
+
     text_end = text + size;
 
     format = buf + 0x15;
@@ -1694,7 +1698,7 @@ static BOOL HLPFILE_Uncompress_Phrases40(HLPFILE* hlpfile)
     else
         HLPFILE_UncompressLZ77(buf_phs + 9, end_phs, (BYTE*)phrases.buffer);
 
-    hlpfile->hasPhrases = FALSE;
+    hlpfile->hasPhrases40 = TRUE;
     return TRUE;
 }
 
diff --git a/programs/winhelp/hlpfile.h b/programs/winhelp/hlpfile.h
index 69cd604..c7e643e 100644
--- a/programs/winhelp/hlpfile.h
+++ b/programs/winhelp/hlpfile.h
@@ -137,7 +137,8 @@ typedef struct tagHlpFileFile
     unsigned short              tbsize;     /* topic block size */
     unsigned short              dsize;      /* decompress size */
     unsigned short              compressed;
-    unsigned                    hasPhrases; /* Phrases or PhrIndex/PhrImage */
+    unsigned                    hasPhrases;   /* file has |Phrases */
+    unsigned                    hasPhrases40; /* file has |PhrIndex/|PhrImage */
 
     unsigned                    numBmps;
     HBITMAP*                    bmps;




More information about the wine-cvs mailing list