From f914cb6858da1fb691f658bef113eca12796ce4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Wed, 24 May 2006 17:14:09 +0200 Subject: [PATCH 1/2] pe: added support for empty resource section --- src/p_armpe.cpp | 13 +++++++------ src/p_w32pe.cpp | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index 7c870bdd..6041a121 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -1244,10 +1244,7 @@ void Resource::check(const res_dir *node,unsigned level) { int ic = node->identr + node->namedentr; if (ic == 0) - { - //throwCantPack("unsupported resource structure"); - throwCantPack("empty resource sections are not supported"); - } + return; for (const res_dir_entry *rde = node->entries; --ic >= 0; rde++) if (((rde->child & 0x80000000) == 0) ^ (level == 2)) throwCantPack("unsupported resource structure"); @@ -1273,10 +1270,14 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig } const res_dir *node = (const res_dir *) rnode; + int ic = node->identr + node->namedentr; + if (ic == 0) + return NULL; + upx_rbranch *branch = new upx_rbranch; branch->name = NULL; branch->parent = parent; - int ic = branch->nc = node->identr + node->namedentr; + branch->nc = ic; branch->children = new upx_rnode*[ic]; branch->data = *node; @@ -2401,7 +2402,7 @@ void PackArmPe::rebuildTls() void PackArmPe::rebuildResources(upx_byte *& extrainfo) { - if (ODSIZE(PEDIR_RESOURCE) == 0) + if (ODSIZE(PEDIR_RESOURCE) == 0 || IDSIZE(PEDIR_RESOURCE) == 0) return; icondir_count = get_le16(extrainfo); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 541ad255..63530a9e 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -1204,10 +1204,7 @@ void Resource::check(const res_dir *node,unsigned level) { int ic = node->identr + node->namedentr; if (ic == 0) - { - //throwCantPack("unsupported resource structure"); - throwCantPack("empty resource sections are not supported"); - } + return; for (const res_dir_entry *rde = node->entries; --ic >= 0; rde++) if (((rde->child & 0x80000000) == 0) ^ (level == 2)) throwCantPack("unsupported resource structure"); @@ -1233,10 +1230,14 @@ Resource::upx_rnode *Resource::convert(const void *rnode,upx_rnode *parent,unsig } const res_dir *node = (const res_dir *) rnode; + int ic = node->identr + node->namedentr; + if (ic == 0) + return NULL; + upx_rbranch *branch = new upx_rbranch; branch->name = NULL; branch->parent = parent; - int ic = branch->nc = node->identr + node->namedentr; + branch->nc = ic; branch->children = new upx_rnode*[ic]; branch->data = *node; @@ -2495,7 +2496,7 @@ void PackW32Pe::rebuildTls() void PackW32Pe::rebuildResources(upx_byte *& extrainfo) { - if (ODSIZE(PEDIR_RESOURCE) == 0) + if (ODSIZE(PEDIR_RESOURCE) == 0 || IDSIZE(PEDIR_RESOURCE) == 0) return; icondir_count = get_le16(extrainfo); From b7785b64cf1be1275ee8021418e78f9daf88b6d8 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Wed, 24 May 2006 19:21:26 +0200 Subject: [PATCH 2/2] Small cleanups to keep p_armpe & p_w32pe in sync. --- src/p_armpe.cpp | 7 ++++--- src/p_w32pe.cpp | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index 6041a121..cbfcfdfe 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -35,6 +35,7 @@ static const #include "stub/l_armpea.h" +static const #include "stub/l_armpet.h" #define IDSIZE(x) ih.ddirs[x].size @@ -245,6 +246,7 @@ void PackArmPe::createLinker(const void *pdata, int plen, int pinfo) linker = new ArmLinker(pdata, plen, pinfo); } + /************************************************************************* // util **************************************************************************/ @@ -1218,11 +1220,10 @@ public: bool clear(); void dump() const { dump(root,0); } - unsigned iname() const {return current->parent->id;} + unsigned iname() const {return current->parent->id;} const upx_byte *nname() const {return current->parent->name;} - /* - unsigned ilang() const {return current->id;} + unsigned ilang() const {return current->id;} const upx_byte *nlang() const {return current->name;} */ }; diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index 63530a9e..e86a7491 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -1178,11 +1178,10 @@ public: bool clear(); void dump() const { dump(root,0); } - - unsigned iname() const {return current->parent->id;} + unsigned iname() const {return current->parent->id;} const upx_byte *nname() const {return current->parent->name;} /* - unsigned ilang() const {return current->id;} + unsigned ilang() const {return current->id;} const upx_byte *nlang() const {return current->name;} */ };