dwindows.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:24k
- /*
- * dwindows.cxx
- *
- * Resource compiler, MS-Windows binary resource decompiler.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: dwindows.cxx,v $
- * Revision 1.19 2000/06/21 02:05:45 robertj
- * Fixed problems in decompile of .ICO file with multiple icons
- *
- * Revision 1.18 1999/10/18 04:41:09 robertj
- * Added decompile of .BMP and .ICO files and fixed ability to have 64x64 icons
- *
- * Revision 1.17 1999/01/21 05:23:24 robertj
- * Fixed build environment problems.
- *
- * Revision 1.16 1998/09/26 01:24:04 robertj
- * Added open source license
- *
- * Revision 1.15 1997/12/12 08:44:24 robertj
- * Update to currect version of PWLIB
- *
- * Revision 1.14 1995/12/10 12:11:59 robertj
- * Changes to support graphical resource file editor.
- *
- * Revision 1.13 1994/07/02 03:25:39 robertj
- * Fixed bug.
- *
- * Revision 1.12 1994/06/25 12:16:28 robertj
- * Synchonsiation with unix implementation.
- *
- * Revision 1.11 1994/04/03 08:37:00 robertj
- * *** empty log message ***
- *
- * Revision 1.10 1994/04/01 14:29:16 robertj
- * New format PRC file
- *
- * Revision 1.9 1994/01/03 04:34:30 robertj
- * Changed scan lines in internal structure to top to bottom.
- *
- * Revision 1.8 1993/12/31 07:05:07 robertj
- * Changed pixmap images for one pixel one number in PRC file.
- *
- * Revision 1.7 1993/12/14 18:54:42 robertj
- * WIN32 port.
- *
- * Revision 1.6 1993/11/30 18:39:11 robertj
- * Standard container macro changed.
- *
- * Revision 1.5 1993/08/21 04:42:42 robertj
- * Clone() function made optional and removed.
- *
- * Revision 1.4 1993/07/19 14:14:52 robertj
- * Fixed major bugs in ICON and CURSOR decompiling.
- *
- * Revision 1.3 1993/07/17 02:57:00 robertj
- * Further implementation
- *
- * Revision 1.2 1993/07/16 14:52:23 robertj
- * Further implementation.
- *
- * Revision 1.1 1993/07/16 12:53:12 robertj
- * Initial revision
- *
- */
- #include <ptlib.h>
- #ifndef WIN32
- #undef NEAR
- #endif
- #include <windows.h>
- #include "pwrc.h"
- #include "....includepwlibstdresid.h"
- #include <ctype.h>
- #include <fcntl.h>
- #include <iomanip.h>
- ///////////////////////////////////////////////////////////////
- //
- // Decompiler
- //
- PDECLARE_CLASS(WinResource, PObject)
- public:
- WinResource(short tn, PString ts, short i, PINDEX l, off_t p)
- : typeNum(tn), typeStr(ts), ID(i), len(l), pos(p) { }
-
- short typeNum;
- PString typeStr;
- short ID;
- PINDEX len;
- off_t pos;
- protected:
- Comparison Compare(const PObject & obj) const
- { return typeNum == ((const WinResource &)obj).typeNum ? EqualTo : GreaterThan; }
- };
- PLIST(WinResourceList, WinResource);
- static WinResourceList WinResources;
- short ReadWord(PFile & in)
- {
- short s;
- in.Read(&s, sizeof(s));
- return s;
- }
- long ReadLong(PFile & in)
- {
- long l;
- in.Read(&l, sizeof(l));
- return l;
- }
- PString ReadStr(PFile & in)
- {
- PString s;
- PINDEX count = 256;
- char * p = s.GetPointer(count+1);
- while (count > 0 && in.Read(p, 1) && *p++ != ' ')
- count--;
- s.MakeMinimumSize();
- return s;
- }
- short ReadTypeOrID(PFile & in, PString & str)
- {
- BYTE c;
- if (in.Read(&c, 1) && c == 0xff) {
- str = "";
- return ReadWord(in);
- }
- str = PString(c) + ReadStr(in);
- return 0;
- }
- short ReadResHeader(PFile & in, short & ID, long & resLen)
- {
- PString resTypeStr, resIDStr;
- short resType = ReadTypeOrID(in, resTypeStr);
- ID = ReadTypeOrID(in, resIDStr);
- if (!resIDStr.IsEmpty()) // Named resources not supported
- resType = 0;
- in.SetPosition(2, PFile::Current); // Skip load options
- resLen = ReadLong(in);
- return resType;
- }
- void ScanResources(PFile & in)
- {
- in.SetPosition(0);
- while (in.GetPosition() < in.GetLength()) {
- const char * warn = NULL;
- PString resTypeStr, resIDStr;
- short resType = ReadTypeOrID(in, resTypeStr);
- if (resTypeStr != "DIALOGSTRINGS" &&
- resTypeStr.GetLength() != 4 &&
- (resType < 1 || resType > 6) &&
- resType != 9 && resType != 10 && resType != 12 && resType != 14)
- warn = "Usupported resource";
- short resID = ReadTypeOrID(in, resIDStr);
- if (!resIDStr.IsEmpty())
- warn = "Named resources are unsupported";
- if (ReadWord(in) != 0x1030) {
- cerr << "Warning: Unsupported load options in resource, type=";
- if (resTypeStr.IsEmpty())
- cerr << resType;
- else
- cerr << resTypeStr.ToLiteral();
- cerr << " ID=";
- if (resIDStr.IsEmpty())
- cerr << resID;
- else
- cerr << resIDStr.ToLiteral();
- }
- long resLen = ReadLong(in);
- if (warn == NULL)
- WinResources.Append(new WinResource(resType,
- resTypeStr, resID, (PINDEX)resLen, in.GetPosition()));
- else {
- cerr << "Warning: " << warn << ", type=";
- if (resTypeStr.IsEmpty())
- cerr << resType;
- else
- cerr << resTypeStr.ToLiteral();
- cerr << " ID=";
- if (resIDStr.IsEmpty())
- cerr << resID;
- else
- cerr << resIDStr.ToLiteral();
- cerr << " - ignoring.n";
- }
- in.SetPosition(resLen, PFile::Current);
- }
- }
- void DecompileStrings(PFile & in, PTextFile & out, const WinResource & res)
- {
- for (PINDEX i = 0; i < 16; i++) {
- char len;
- in.Read(&len, 1);
- if (len != 0) {
- PString s;
- in.Read(s.GetPointer(len+1), len);
- out << "String " << (((res.ID-1)<<4)|i) << ", " << s.ToLiteral() << ";n";
- }
- }
- }
- void DecompileSubMenu(PFile & in, PTextFile & out, const PString & indent)
- {
- PString title = ReadStr(in);
- out << indent << "Menu " << title.ToLiteral() << "{n";
- short menuFlags;
- do {
- menuFlags = ReadWord(in);
- if ((menuFlags&MF_POPUP) != 0)
- DecompileSubMenu(in, out, indent+" ");
- else {
- unsigned short id = (unsigned short)ReadWord(in);
- title = ReadStr(in);
- if (title.IsEmpty())
- out << indent << " Separator;n";
- else {
- int tab = title.Find('t');
- if (tab > 0)
- title = title(0, tab-1);
- out << indent << " Item ";
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << "MenuItem";
- out << id << " {n"
- << indent << " Title " << title.ToLiteral() << ";n"
- << indent << " }n";
- }
- }
- } while ((menuFlags&MF_END) == 0);
- out << indent << "}n";
- }
- void DecompileMenuBar(PFile & in, PTextFile & out, const WinResource & res)
- {
- out << "nnnMenuBar ";
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << "@MenuBar";
- out << res.ID << "n{n";
- short menuFlags;
- do {
- menuFlags = ReadWord(in);
- if ((menuFlags&MF_POPUP) != 0)
- DecompileSubMenu(in, out, " ");
- } while ((menuFlags&MF_END) == 0);
- out << "}n";
- }
- void DecompileDialog(PFile & in, PTextFile & out, const WinResource & res)
- {
- for (PINDEX strRes = 0; strRes < WinResources.GetSize(); strRes++) {
- if (WinResources[strRes].ID == res.ID &&
- WinResources[strRes].typeStr == "DIALOGSTRINGS")
- break;
- }
- long style = ReadLong(in);
- if (style != (WS_POPUP|WS_CAPTION|WS_SYSMENU|DS_MODALFRAME|DS_SETFONT))
- cerr << "Warning: Unsupported style for dialog " << res.ID << endl;
- char numItems;
- in.Read(&numItems, 1);
- short pos_x = ReadWord(in);
- short pos_y = ReadWord(in);
- short dim_x = ReadWord(in);
- short dim_y = ReadWord(in);
- if (in.ReadChar() != 0) {
- cerr << "Warning: Unsupported menu in dialog " << res.ID << endl;
- ReadStr(in);
- }
- if (in.ReadChar() != 0) {
- cerr << "Warning: Unsupported class for dialog " << res.ID << endl;
- ReadStr(in);
- }
- PString s = ReadStr(in);
- out << "nnnDialog ";
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << "@Dialog";
- out << res.ID << "n{n"
- " Title " << s.ToLiteral() << ";n";
- if (pos_x != -10000 || pos_y != -10000)
- out << " Position " << pos_x << ',' << pos_y << ";n";
- if (dim_x > 0 || dim_y > 0)
- out << " Dimensions " << dim_x << ',' << dim_y << ";n";
- short fontSize = ReadWord(in);
- s = ReadStr(in);
- if (s != "MS Sans Serif" || fontSize != 8)
- out << " Font " << s.ToLiteral() << ", " << fontSize << endl;
- out << endl;
- for (PINDEX i = 0; i < numItems; i++) {
- pos_x = ReadWord(in);
- pos_y = ReadWord(in);
- dim_x = ReadWord(in);
- dim_y = ReadWord(in);
- short id = ReadWord(in);
- style = ReadLong(in);
- BYTE type = (BYTE)in.ReadChar();
- int iconID = 0;
- if (type == 0x82 && (style&15) == SS_ICON) {
- if (in.ReadChar() == 0xff) {
- iconID = ReadWord(in);
- in.SetPosition(1, PFile::Current); // Skip the extra null
- }
- else {
- ReadStr(in);
- cerr << "Warning: Unsupported icon name in item " << i+1
- << " (ID=" << id << ") in dialog " << res.ID << endl;
- in.SetPosition(2, PFile::Current); // Skip the terminating nulls
- }
- }
- else {
- s = ReadStr(in);
- in.SetPosition(1, PFile::Current); // Skip the extra null
- }
- char * keyword = "??Control";
- BOOL hasName = TRUE;
- BOOL styleWarning = FALSE;
- switch (type) {
- case 0x80 :
- switch (style & 15) {
- case BS_PUSHBUTTON :
- case BS_DEFPUSHBUTTON :
- keyword = "PushButton";
- break;
-
- case BS_AUTOCHECKBOX :
- case BS_CHECKBOX :
- keyword = "CheckBox";
- break;
-
- case BS_AUTO3STATE :
- case BS_3STATE :
- keyword = "Check3Way";
- break;
-
- case BS_AUTORADIOBUTTON :
- case BS_RADIOBUTTON :
- keyword = "RadioButton";
- break;
- case BS_GROUPBOX :
- keyword = "StaticBox";
- break;
- default:
- styleWarning = TRUE;
- }
- break;
- case 0x81 :
- if ((style&ES_MULTILINE) != 0)
- keyword = "TextEditor";
- else if (s == "INTEDITBOX")
- keyword = "IntEdit";
- else if (s == "REALEDITBOX")
- keyword = "RealEdit";
- else
- keyword = "EditBox";
- hasName = FALSE;
- break;
- case 0x82 :
- switch (style & 15) {
- case SS_LEFT :
- case SS_SIMPLE :
- keyword = "LeftText";
- break;
-
- case SS_CENTER :
- keyword = "CentreText";
- break;
-
- case SS_RIGHT :
- keyword = "RightText";
- break;
-
- case SS_ICON :
- keyword = "StaticIcon";
- hasName = FALSE;
- break;
- default:
- styleWarning = TRUE;
- }
- break;
- case 0x83 :
- keyword = "ListBox";
- hasName = FALSE;
- break;
- case 0x84 :
- keyword = (style&1) == SBS_HORZ ? "HScrollBar" : "VScrollBar";
- hasName = FALSE;
- break;
- case 0x85 :
- switch (style & 15) {
- case CBS_DROPDOWN :
- keyword = "ComboBox";
- break;
- case CBS_DROPDOWNLIST :
- keyword = "ChoiceBox";
- break;
- default:
- styleWarning = TRUE;
- }
- hasName = FALSE;
- break;
- }
- if (styleWarning)
- cerr << "Warning: Unsupported style for item " << i+1
- << " (ID=" << id << ") in dialog " << res.ID << endl;
- out << " " << keyword << " {n";
- if (hasName)
- out << " Title " << s.ToLiteral() << ";n";
- else if (type == 0x82 && (style&15) == SS_ICON)
- out << " Icon " << iconID << ";n";
- if (PProcess::Current().GetArguments().HasOption('i'))
- out << " Id " << id << ";n";
- out << " Position " << pos_x << ", " << pos_y << ";n"
- " Dimensions " << dim_x << ", " << dim_y << ";n";
- PString options;
- switch (type) {
- case 0x83 :
- if ((style&LBS_SORT) != 0)
- options = "Sorted ";
- if ((style&LBS_EXTENDEDSEL) != 0)
- options += "MultiSelect ";
- if ((style&LBS_MULTICOLUMN) != 0)
- options += "MultiColumn";
- break;
- case 0x85 :
- if ((style&CBS_SORT) != 0)
- options = "Sorted";
- break;
- case 0x80 :
- switch (style & 15) {
- case BS_DEFPUSHBUTTON :
- case BS_PUSHBUTTON :
- switch (id) {
- case 1 :
- options = "Ok";
- break;
- case 2 :
- options = "Cancel";
- break;
- case 3 :
- options = "Help";
- break;
- }
- if ((style & 15) == BS_DEFPUSHBUTTON)
- options += " Default";
- }
- }
- if (!options.IsEmpty())
- out << " Options " << options << ";n";
- if (strRes < WinResources.GetSize()) {
- off_t remember = in.GetPosition();
- in.SetPosition(WinResources[strRes].pos);
- while (in.GetPosition() < in.GetLength()) {
- short strID = ReadWord(in);
- short strLen = ReadWord(in);
- short strCount = ReadWord(in);
- if (strCount == 0)
- break;
- if (strID == id) {
- out << " String {n";
- while (--strCount > 0)
- out << " " << ReadStr(in).ToLiteral() << ",n";
- out << " " << ReadStr(in).ToLiteral() << "n"
- " }n";
- break;
- }
- in.SetPosition(strLen, PFile::Current);
- }
- in.SetPosition(remember);
- }
- out << " }n";
- }
- out << "}n";
- }
- void DecompileClut(PFile & in, PTextFile & out, PINDEX bitCount)
- {
- if (bitCount == 24)
- return;
- out << " Colours {n";
- PINDEX colours = (1 << bitCount)-1;
- for (PINDEX c = 0; c <= colours; c++) {
- RGBQUAD rgb;
- in.Read(&rgb, sizeof(rgb));
- out << " " << setw(3) << (rgb.rgbRed&0xff)
- << ", " << setw(3) << (rgb.rgbGreen&0xff)
- << ", " << setw(3) << (rgb.rgbBlue&0xff)
- << (c != colours ? ",n" : "n");
- }
- out << " }n";
- }
- void DecompilePixels(PFile & in, PTextFile & out,
- const char * keyword, PINDEX lines, PINDEX lineWidth, PINDEX bitsPerPixel)
- {
- off_t pixbase = in.GetPosition();
- PINDEX lineBytes = ((lineWidth*bitsPerPixel+31)/32)*4;
- out << " " << keyword << " {n ";
- for (int l = lines-1; l >= 0; l--) {
- in.SetPosition(pixbase+l*lineBytes);
- if (bitsPerPixel > 8) {
- for (PINDEX byteInLine = 0; byteInLine < lineBytes; byteInLine++)
- out << in.ReadChar() << ' ';
- }
- else {
- PINDEX outWidth = bitsPerPixel > 6 ? 4 : bitsPerPixel > 3 ? 3 : 2;
- PINDEX byteInLine = 0;
- PINDEX pixelsPerByte = 8/bitsPerPixel;
- PINDEX bitsPerPixelMask = (1 << bitsPerPixel)-1;
- PINDEX bitShift = 8 - bitsPerPixel;
- PINDEX pixelInByte = pixelsPerByte;
- PINDEX byte = 0;
- for (PINDEX pix = 0; pix < lineWidth; pix++) {
- if (++pixelInByte >= pixelsPerByte) {
- byte = in.ReadChar();
- byteInLine++;
- pixelInByte = 0;
- }
- out << setw(outWidth) << ((byte >> bitShift)&bitsPerPixelMask);
- byte <<= bitsPerPixel;
- }
- }
- if (l > 0)
- out << "n ";
- }
- out << "n }n";
- in.SetPosition(pixbase+lines*lineBytes);
- }
- BOOL ReadBitmapHeader(PFile & in, BITMAPINFOHEADER & bm)
- {
- in.Read(&bm, sizeof(bm));
- if (bm.biPlanes == 1 && bm.biSizeImage < 65536L)
- return TRUE;
- cerr << "Warning: Unsupported image bitmap typen";
- return FALSE;
- }
- BOOL DecompileIconCursorImage(PFile & in, PTextFile & out)
- {
- BITMAPINFOHEADER bm;
- if (!ReadBitmapHeader(in, bm))
- return FALSE;
- bm.biHeight /= 2;
- out << " Dimensions " << bm.biWidth << ','
- << bm.biHeight << ',' << bm.biBitCount << ";n";
- DecompileClut(in, out, bm.biBitCount);
- DecompilePixels(in, out, "Pixels",
- (PINDEX)bm.biHeight, (PINDEX)bm.biWidth, (PINDEX)bm.biBitCount);
- DecompilePixels(in, out, "AndMask",
- (PINDEX)bm.biHeight, (PINDEX)bm.biWidth, 1);
- return TRUE;
- }
- void DecompileIconCursor(PFile & in, PTextFile & out, const WinResource & res,
- const char * keyword, short checkCode, short imgResType, BOOL hasHotspot)
- {
- out << "nnn" << keyword << ' ';
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << '@' << keyword;
- out << res.ID << "n{n";
- in.SetPosition(2, PFile::Current);
- if (ReadWord(in) != checkCode)
- cerr << "Warning: Invalid " << keyword << " directory resource.n";
- int biLevelID = -1;
- int colourID = -1;
- short count = ReadWord(in);
- while (count-- > 0) {
- in.SetPosition(4, PFile::Current);
- if (ReadWord(in) != 1) {
- cerr << "Warning: Multi plane " << keyword << " in resource.n";
- in.SetPosition(8, PFile::Current);
- }
- else {
- short bits = ReadWord(in);
- in.SetPosition(4, PFile::Current);
- if (bits == 1)
- biLevelID = ReadWord(in);
- else if (colourID < 0)
- colourID = ReadWord(in);
- else {
- cerr << "Warning: Only one colour " << keyword << " supported in resource.n";
- in.SetPosition(2, PFile::Current);
- }
- }
- }
- if (colourID >= 0) {
- for (PINDEX colourRes=0; colourRes < WinResources.GetSize(); colourRes++) {
- if (WinResources[colourRes].typeNum == imgResType &&
- WinResources[colourRes].ID == colourID)
- break;
- }
- if (colourRes >= WinResources.GetSize())
- cerr << "Warning: Missing " << keyword << " resource.n";
- else {
- off_t remember = in.GetPosition();
- in.SetPosition(WinResources[colourRes].pos);
-
- if (hasHotspot)
- out << " HOTSPOT "
- << ReadWord(in) << ',' << ReadWord(in) << ";n";
-
- DecompileIconCursorImage(in, out);
- in.SetPosition(remember);
- }
- }
- if (biLevelID >= 0) {
- for (PINDEX biLevelRes=0; biLevelRes<WinResources.GetSize(); biLevelRes++){
- if (WinResources[biLevelRes].typeNum == imgResType &&
- WinResources[biLevelRes].ID == biLevelID)
- break;
- }
- if (biLevelRes >= WinResources.GetSize())
- cerr << "Warning: Missing " << keyword << " resource.n";
- else {
- off_t remember = in.GetPosition();
- in.SetPosition(WinResources[biLevelRes].pos);
-
- if (hasHotspot) {
- if (colourID < 0)
- out << " HOTSPOT "
- << ReadWord(in) << ',' << ReadWord(in) << ";n";
- else
- in.SetPosition(4, PFile::Current);
- }
- BITMAPINFOHEADER bm;
- ReadBitmapHeader(in, bm);
- bm.biHeight /= 2;
-
- if (colourID < 0)
- out << " Dimensions " << bm.biWidth << ','
- << bm.biHeight << ',' << bm.biBitCount << ";n";
- in.SetPosition(2*sizeof(RGBQUAD), PFile::Current);
- DecompilePixels(in, out, "XorMask",
- (PINDEX)bm.biHeight, (PINDEX)bm.biWidth, 1);
- if (colourID < 0)
- DecompilePixels(in, out, "AndMask",
- (PINDEX)bm.biHeight, (PINDEX)bm.biWidth, 1);
- in.SetPosition(remember);
- }
- }
- out << "}n";
- }
- void DecompileIcon(PFile & in, PTextFile & out, const WinResource & res)
- {
- DecompileIconCursor(in, out, res, "Icon", 1, 3, FALSE);
- }
- void DecompileCursor(PFile & in, PTextFile & out, const WinResource & res)
- {
- DecompileIconCursor(in, out, res, "Cursor", 2, 1, TRUE);
- }
- void DecompileImage(PFile & in, PTextFile & out, const WinResource & res)
- {
- BITMAPINFOHEADER bm;
- ReadBitmapHeader(in, bm);
- out << "nnnIMAGE " << res.ID << "n{n Dimensions "
- << bm.biWidth << ',' << bm.biHeight << ',' << bm.biBitCount << ";n";
- DecompileClut(in, out, bm.biBitCount);
- DecompilePixels(in, out, "Pixels",
- (PINDEX)bm.biHeight, (PINDEX)bm.biWidth, (PINDEX)bm.biBitCount);
- out << "}n";
- }
- void DecompileDataBlock(PFile & in, PTextFile & out, PINDEX len)
- {
- out << "n{n ";
- int lineOutput = 16;
- for (PINDEX i = 0; i < len-1; i++) {
- out << in.ReadChar();
- if (--lineOutput != 0)
- out << ", ";
- else {
- out << ",n ";
- lineOutput = 16;
- }
- }
- out << in.ReadChar() << "n}n";
- }
- void DecompileData(PFile & in, PTextFile & out, const WinResource & res)
- {
- out << "nnnResource ";
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << "@Resource";
- out << res.ID;
- DecompileDataBlock(in, out, res.len);
- }
- void DecompileCustom(PFile & in, PTextFile & out)
- {
- for (PINDEX res = 0; res < WinResources.GetSize(); res++) {
- if (WinResources[res].typeStr.GetLength() == 4) {
- in.SetPosition(WinResources[res].pos);
- out << "nnnResource ";
- if (!PProcess::Current().GetArguments().HasOption('i'))
- out << "@Resource";
- out << WinResources[res].ID << ", "
- << WinResources[res].typeStr.ToLiteral();
- DecompileDataBlock(in, out, WinResources[res].len);
- }
- }
- }
- void DecompileResources(PFile & in, PTextFile & out, short type,
- void (*decompiler)(PFile &, PTextFile &, const WinResource &))
- {
- for (PINDEX res = 0; res < WinResources.GetSize(); res++) {
- if (WinResources[res].typeNum == type) {
- in.SetPosition(WinResources[res].pos);
- decompiler(in, out, WinResources[res]);
- }
- }
- }
- void Decompile(PFile & in, PTextFile & out)
- {
- out << "// Portable Windows Library Resource Decompiler Generated File.nn";
- _setmode(in.GetHandle(), _O_BINARY);
- if (in.GetFilePath().GetType() == ".bmp") {
- WinResource res(2, "", 1, 0, 0);
- BITMAPFILEHEADER bmfh;
- in.Read(&bmfh, sizeof(bmfh));
- if (bmfh.bfType != 'MB')
- cerr << "Resource file is not a .BMP file!n";
- else
- DecompileImage(in, out, res);
- }
- else if (in.GetFilePath().GetType() == ".ico") {
- if (ReadWord(in) != 0 || ReadWord(in) != 1)
- cerr << "Resource file is not a .ICO file!n";
- else {
- PINDEX count = ReadWord(in);
- in.SetPosition(16*count, PFile::Current);
- for (PINDEX i = 1; i <= count; i++) {
- out << "nnnICON " << i << "n{n";
- if (!DecompileIconCursorImage(in, out))
- break;
- out << "}n";
- }
- }
- }
- else {
- #ifdef WIN32
- cerr << "Warning!!! The decompile facility is not available on Windows NT platforms.n"
- "This will only decompile Windows 3.1 Resource files.nn";
- #endif
- ScanResources(in);
- DecompileResources(in, out, 6, DecompileStrings);
- DecompileResources(in, out, 4, DecompileMenuBar);
- DecompileResources(in, out, 5, DecompileDialog);
- DecompileResources(in, out, 14, DecompileIcon);
- DecompileResources(in, out, 12, DecompileCursor);
- DecompileResources(in, out, 2, DecompileImage);
- DecompileResources(in, out, 10, DecompileData);
- DecompileCustom(in, out);
- }
- out << "nnn// End Resources.n";
- }