From db7086b5e69e917a9cbd4dd0598f639077f1d7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Moln=C3=A1r?= Date: Tue, 4 Jul 2006 14:11:56 +0200 Subject: [PATCH] pe: ignore duplicated relocation records --- src/p_armpe.cpp | 23 +++++++++++++++++++++-- src/p_w32pe.cpp | 23 +++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index 248dee0a..e7f48fb9 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -505,12 +505,31 @@ void PackArmPe::processRelocs() // pass1 { if (pos >= ih.imagesize) continue; // skip out-of-bounds record - if (type == 3) - set_le32(ibuf + pos,get_le32(ibuf + pos) - ih.imagebase - rvamin); if (type < 4) fix[type][xcounts[type]++] = pos - rvamin; } + // remove duplicated records + for (ic = 1; ic <= 3; ic++) + { + qsort(fix[ic], xcounts[ic], 4, le32_compare); + unsigned prev = ~0; + unsigned jc = 0; + for (unsigned kc = 0; kc < xcounts[ic]; kc++) + if (fix[ic][kc] != prev) + prev = fix[ic][jc++] = fix[ic][kc]; + + //printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc); + xcounts[ic] = jc; + } + + // preprocess "type 3" relocation records + for (ic = 0; ic < xcounts[3]; ic++) + { + pos = fix[3][ic] + rvamin; + set_le32(ibuf + pos, get_le32(ibuf + pos) - ih.imagebase - rvamin); + } + ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL); orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3], xcounts[3], diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index bee1e016..8009fa92 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -512,12 +512,31 @@ void PackW32Pe::processRelocs() // pass1 { if (pos >= ih.imagesize) continue; // skip out-of-bounds record - if (type == 3) - set_le32(ibuf + pos,get_le32(ibuf + pos) - ih.imagebase - rvamin); if (type < 4) fix[type][xcounts[type]++] = pos - rvamin; } + // remove duplicated records + for (ic = 1; ic <= 3; ic++) + { + qsort(fix[ic], xcounts[ic], 4, le32_compare); + unsigned prev = ~0; + unsigned jc = 0; + for (unsigned kc = 0; kc < xcounts[ic]; kc++) + if (fix[ic][kc] != prev) + prev = fix[ic][jc++] = fix[ic][kc]; + + //printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc); + xcounts[ic] = jc; + } + + // preprocess "type 3" relocation records + for (ic = 0; ic < xcounts[3]; ic++) + { + pos = fix[3][ic] + rvamin; + set_le32(ibuf + pos, get_le32(ibuf + pos) - ih.imagebase - rvamin); + } + ibuf.fill(IDADDR(PEDIR_RELOC), IDSIZE(PEDIR_RELOC), FILLVAL); orelocs = new upx_byte [rnum * 4 + 1024]; // 1024 - safety sorelocs = ptr_diff(optimizeReloc32((upx_byte*) fix[3], xcounts[3],