diff options
-rw-r--r-- | common/winexe.cpp | 2 | ||||
-rw-r--r-- | common/winexe_ne.cpp | 32 | ||||
-rw-r--r-- | common/winexe_ne.h | 50 |
3 files changed, 46 insertions, 38 deletions
diff --git a/common/winexe.cpp b/common/winexe.cpp index 7cfc140452..877ab6baa1 100644 --- a/common/winexe.cpp +++ b/common/winexe.cpp @@ -73,7 +73,7 @@ String WinResourceID::toString() const { if (_idType == kIDTypeString) return _name; else if (_idType == kIDTypeNumerical) - return String::format("%08x", _id); + return String::format("0x%08x", _id); return ""; } diff --git a/common/winexe_ne.cpp b/common/winexe_ne.cpp index 8690f6795b..6bb40e0980 100644 --- a/common/winexe_ne.cpp +++ b/common/winexe_ne.cpp @@ -187,8 +187,8 @@ uint32 NEResources::getResourceTableOffset() { static const char *s_resTypeNames[] = { "", "cursor", "bitmap", "icon", "menu", "dialog", "string", "font_dir", "font", "accelerator", "rc_data", "msg_table", - "group_cursor", "group_icon", "version", "dlg_include", - "plug_play", "vxd", "ani_cursor", "ani_icon", "html", + "group_cursor", "group_icon", "", "", "version", "dlg_include", + "", "plug_play", "vxd", "ani_cursor", "ani_icon", "html", "manifest" }; @@ -200,9 +200,16 @@ bool NEResources::readResourceTable(uint32 offset) { return false; uint32 align = 1 << _exe->readUint16LE(); - uint16 typeID = _exe->readUint16LE(); + while (typeID != 0) { + // High bit of the type means integer type + WinResourceID type; + if (typeID & 0x8000) + type = typeID & 0x7FFF; + else + type = getResourceString(*_exe, offset + typeID); + uint16 resCount = _exe->readUint16LE(); _exe->skip(4); // reserved @@ -218,17 +225,18 @@ bool NEResources::readResourceTable(uint32 offset) { res.handle = _exe->readUint16LE(); res.usage = _exe->readUint16LE(); - res.type = typeID; + res.type = type; - if ((id & 0x8000) == 0) - res.id = getResourceString(*_exe, offset + id); - else + // High bit means integer type + if (id & 0x8000) res.id = id & 0x7FFF; + else + res.id = getResourceString(*_exe, offset + id); - if (typeID & 0x8000 && ((typeID & 0x7FFF) < ARRAYSIZE(s_resTypeNames))) + if (typeID & 0x8000 && ((typeID & 0x7FFF) < ARRAYSIZE(s_resTypeNames)) && s_resTypeNames[typeID & 0x7FFF][0] != 0) debug(2, "Found resource %s %s", s_resTypeNames[typeID & 0x7FFF], res.id.toString().c_str()); else - debug(2, "Found resource %04x %s", typeID, res.id.toString().c_str()); + debug(2, "Found resource %s %s", type.toString().c_str(), res.id.toString().c_str()); _resources.push_back(res); } @@ -257,7 +265,7 @@ String NEResources::getResourceString(SeekableReadStream &exe, uint32 offset) { return string; } -const NEResources::Resource *NEResources::findResource(uint16 type, WinResourceID id) const { +const NEResources::Resource *NEResources::findResource(const WinResourceID &type, const WinResourceID &id) const { for (List<Resource>::const_iterator it = _resources.begin(); it != _resources.end(); ++it) if (it->type == type && it->id == id) return &*it; @@ -265,7 +273,7 @@ const NEResources::Resource *NEResources::findResource(uint16 type, WinResourceI return 0; } -SeekableReadStream *NEResources::getResource(uint16 type, WinResourceID id) { +SeekableReadStream *NEResources::getResource(const WinResourceID &type, const WinResourceID &id) { const Resource *res = findResource(type, id); if (!res) @@ -275,7 +283,7 @@ SeekableReadStream *NEResources::getResource(uint16 type, WinResourceID id) { return _exe->readStream(res->size); } -const Array<WinResourceID> NEResources::getIDList(uint16 type) const { +const Array<WinResourceID> NEResources::getIDList(const WinResourceID &type) const { Array<WinResourceID> idArray; for (List<Resource>::const_iterator it = _resources.begin(); it != _resources.end(); ++it) diff --git a/common/winexe_ne.h b/common/winexe_ne.h index 4a1b2343df..f00941412f 100644 --- a/common/winexe_ne.h +++ b/common/winexe_ne.h @@ -34,27 +34,27 @@ class SeekableReadStream; /** The default Windows resources. */ enum NEResourceType { - kNECursor = 0x8001, - kNEBitmap = 0x8002, - kNEIcon = 0x8003, - kNEMenu = 0x8004, - kNEDialog = 0x8005, - kNEString = 0x8006, - kNEFontDir = 0x8007, - kNEFont = 0x8008, - kNEAccelerator = 0x8009, - kNERCData = 0x800A, - kNEMessageTable = 0x800B, - kNEGroupCursor = 0x800C, - kNEGroupIcon = 0x800D, - kNEVersion = 0x8010, - kNEDlgInclude = 0x8011, - kNEPlugPlay = 0x8013, - kNEVXD = 0x8014, - kNEAniCursor = 0x8015, - kNEAniIcon = 0x8016, - kNEHTML = 0x8017, - kNEManifest = 0x8018 + kNECursor = 0x01, + kNEBitmap = 0x02, + kNEIcon = 0x03, + kNEMenu = 0x04, + kNEDialog = 0x05, + kNEString = 0x06, + kNEFontDir = 0x07, + kNEFont = 0x08, + kNEAccelerator = 0x09, + kNERCData = 0x0A, + kNEMessageTable = 0x0B, + kNEGroupCursor = 0x0C, + kNEGroupIcon = 0x0D, + kNEVersion = 0x10, + kNEDlgInclude = 0x11, + kNEPlugPlay = 0x13, + kNEVXD = 0x14, + kNEAniCursor = 0x15, + kNEAniIcon = 0x16, + kNEHTML = 0x17, + kNEManifest = 0x18 }; /** @@ -81,17 +81,17 @@ public: bool loadFromEXE(SeekableReadStream *stream); /** Return a list of resources for a given type. */ - const Array<WinResourceID> getIDList(uint16 type) const; + const Array<WinResourceID> getIDList(const WinResourceID &type) const; /** Return a stream to the specified resource (or 0 if non-existent). */ - SeekableReadStream *getResource(uint16 type, WinResourceID id); + SeekableReadStream *getResource(const WinResourceID &type, const WinResourceID &id); private: /** A resource. */ struct Resource { WinResourceID id; - uint16 type; ///< Type of the resource. + WinResourceID type; ///< Type of the resource. uint32 offset; ///< Offset within the EXE. uint32 size; ///< Size of the data. @@ -112,7 +112,7 @@ private: bool readResourceTable(uint32 offset); /** Find a specific resource. */ - const Resource *findResource(uint16 type, WinResourceID id) const; + const Resource *findResource(const WinResourceID &type, const WinResourceID &id) const; /** Read a resource string. */ static String getResourceString(SeekableReadStream &exe, uint32 offset); |