src: pefile: try to work-around a scan-build warning
This commit is contained in:
+19
-19
@@ -330,7 +330,7 @@ bool PeFile::Reloc::next(unsigned &pos,unsigned &type)
|
|||||||
|
|
||||||
pos = rel->pagestart + (*rel1 & 0xfff);
|
pos = rel->pagestart + (*rel1 & 0xfff);
|
||||||
type = *rel1++ >> 12;
|
type = *rel1++ >> 12;
|
||||||
//printf("%x %d\n",pos,type);
|
NO_printf("%x %d\n",pos,type);
|
||||||
if (ptr_diff_bytes(rel1,rel) >= (int) rel->size)
|
if (ptr_diff_bytes(rel1,rel) >= (int) rel->size)
|
||||||
newRelocPos(rel1);
|
newRelocPos(rel1);
|
||||||
return type == 0 ? next(pos,type) : true;
|
return type == 0 ? next(pos,type) : true;
|
||||||
@@ -434,7 +434,7 @@ void PeFile32::processRelocs() // pass1
|
|||||||
if (fix[ic][kc] != prev)
|
if (fix[ic][kc] != prev)
|
||||||
prev = fix[ic][jc++] = fix[ic][kc];
|
prev = fix[ic][jc++] = fix[ic][kc];
|
||||||
|
|
||||||
//printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc);
|
NO_printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc);
|
||||||
xcounts[ic] = jc;
|
xcounts[ic] = jc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -539,7 +539,7 @@ void PeFile64::processRelocs() // pass1
|
|||||||
if (fix[ic][kc] != prev)
|
if (fix[ic][kc] != prev)
|
||||||
prev = fix[ic][jc++] = fix[ic][kc];
|
prev = fix[ic][jc++] = fix[ic][kc];
|
||||||
|
|
||||||
//printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc);
|
NO_printf("xcounts[%u] %u->%u\n", ic, xcounts[ic], jc);
|
||||||
xcounts[ic] = jc;
|
xcounts[ic] = jc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1495,7 +1495,7 @@ void PeFile::processLoadConf(Interval *iv) // pass 1
|
|||||||
if (pos >= lcaddr && pos < lcaddr + soloadconf)
|
if (pos >= lcaddr && pos < lcaddr + soloadconf)
|
||||||
{
|
{
|
||||||
iv->add(pos - lcaddr, type);
|
iv->add(pos - lcaddr, type);
|
||||||
// printf("loadconf reloc detected: %x\n", pos);
|
NO_printf("loadconf reloc detected: %x\n", pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
mb_oloadconf.alloc(soloadconf);
|
mb_oloadconf.alloc(soloadconf);
|
||||||
@@ -1511,8 +1511,8 @@ void PeFile::processLoadConf(Reloc *rel, const Interval *iv,
|
|||||||
for (unsigned ic = 0; ic < iv->ivnum; ic++)
|
for (unsigned ic = 0; ic < iv->ivnum; ic++)
|
||||||
{
|
{
|
||||||
rel->add(iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
rel->add(iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||||
//printf("loadconf reloc added: %x %d\n",
|
NO_printf("loadconf reloc added: %x %d\n",
|
||||||
// iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
iv->ivarr[ic].start + newaddr, iv->ivarr[ic].len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2068,7 +2068,7 @@ void PeFile::processResources(Resource *res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned PeFile::virta2objnum(unsigned addr,pe_section_t *sect,unsigned objs)
|
unsigned PeFile::virta2objnum(unsigned addr,SPAN_0(pe_section_t) sect,unsigned objs)
|
||||||
{
|
{
|
||||||
unsigned ic;
|
unsigned ic;
|
||||||
for (ic = 0; ic < objs; ic++)
|
for (ic = 0; ic < objs; ic++)
|
||||||
@@ -2087,7 +2087,7 @@ unsigned PeFile::tryremove (unsigned vaddr,unsigned objs)
|
|||||||
unsigned ic = virta2objnum(vaddr,isection,objs);
|
unsigned ic = virta2objnum(vaddr,isection,objs);
|
||||||
if (ic && ic == objs - 1)
|
if (ic && ic == objs - 1)
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"removed section: %d size: %lx\n",ic,(long)isection[ic].size);
|
NO_fprintf(stderr,"removed section: %d size: %lx\n",ic,(long)isection[ic].size);
|
||||||
info("removed section: %d size: 0x%lx",ic,(long)isection[ic].size);
|
info("removed section: %d size: 0x%lx",ic,(long)isection[ic].size);
|
||||||
objs--;
|
objs--;
|
||||||
}
|
}
|
||||||
@@ -2133,7 +2133,7 @@ void PeFile::readSectionHeaders(unsigned objs, unsigned sizeof_ih)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mb_isection.alloc(sizeof(pe_section_t) * objs);
|
mb_isection.alloc(sizeof(pe_section_t) * objs);
|
||||||
isection = (pe_section_t *)mb_isection.getVoidPtr();
|
isection = mb_isection; // => isection now is a SPAN_S
|
||||||
if (file_size_u < pe_offset + sizeof_ih + sizeof(pe_section_t)*objs) {
|
if (file_size_u < pe_offset + sizeof_ih + sizeof(pe_section_t)*objs) {
|
||||||
char buf[32]; snprintf(buf, sizeof(buf), "too many sections %d", objs);
|
char buf[32]; snprintf(buf, sizeof(buf), "too many sections %d", objs);
|
||||||
throwCantPack(buf);
|
throwCantPack(buf);
|
||||||
@@ -2251,8 +2251,9 @@ unsigned PeFile::readSections(unsigned objs, unsigned usize,
|
|||||||
ibuf.alloc(usize + xtrasize);
|
ibuf.alloc(usize + xtrasize);
|
||||||
|
|
||||||
// BOUND IMPORT support. FIXME: is this ok?
|
// BOUND IMPORT support. FIXME: is this ok?
|
||||||
|
ibufgood = isection[0].rawdataptr;
|
||||||
fi->seek(0,SEEK_SET);
|
fi->seek(0,SEEK_SET);
|
||||||
fi->readx(ibuf,ibufgood= isection[0].rawdataptr);
|
fi->readx(ibuf, ibufgood);
|
||||||
|
|
||||||
//Interval holes(ibuf);
|
//Interval holes(ibuf);
|
||||||
|
|
||||||
@@ -2423,7 +2424,7 @@ void PeFile::pack0(OutputFile *fo, ht &ih, ht &oh,
|
|||||||
// temporary solution:
|
// temporary solution:
|
||||||
unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1;
|
unsigned newvsize = (isection[objs-1].vaddr + isection[objs-1].vsize + oam1) &~ oam1;
|
||||||
|
|
||||||
//fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs);
|
NO_fprintf(stderr,"newvsize=%x objs=%d\n",newvsize,objs);
|
||||||
if (newvsize + soimport + sorelocs > ibuf.getSize())
|
if (newvsize + soimport + sorelocs > ibuf.getSize())
|
||||||
throwInternalError("buffer too small 2");
|
throwInternalError("buffer too small 2");
|
||||||
memcpy(ibuf+newvsize,oimport,soimport);
|
memcpy(ibuf+newvsize,oimport,soimport);
|
||||||
@@ -3134,21 +3135,20 @@ void PeFile::unpack0(OutputFile *fo, const ht &ih, ht &oh,
|
|||||||
ibuf.dealloc();
|
ibuf.dealloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
int PeFile::canUnpack0(unsigned max_sections, LE16 &ih_objects,
|
int PeFile::canUnpack0(unsigned max_sections, unsigned objs,
|
||||||
LE32 &ih_entry, unsigned ihsize)
|
unsigned ih_entry, unsigned ih_size)
|
||||||
{
|
{
|
||||||
if (!canPack())
|
if (!canPack())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
unsigned objs = ih_objects;
|
|
||||||
mb_isection.alloc(sizeof(pe_section_t) * objs);
|
mb_isection.alloc(sizeof(pe_section_t) * objs);
|
||||||
isection = (pe_section_t *)mb_isection.getVoidPtr();
|
isection = mb_isection; // => isection now is a SPAN_S
|
||||||
fi->seek(pe_offset + ihsize, SEEK_SET);
|
fi->seek(pe_offset + ih_size, SEEK_SET);
|
||||||
fi->readx(isection,sizeof(pe_section_t)*objs);
|
fi->readx(isection,sizeof(pe_section_t) * objs);
|
||||||
const unsigned min_sections = isefi ? 2 : 3;
|
const unsigned min_sections = isefi ? 2 : 3;
|
||||||
if (ih_objects < min_sections)
|
if (objs < min_sections)
|
||||||
return -1;
|
return -1;
|
||||||
bool is_packed = (ih_objects >= min_sections && ih_objects <= max_sections &&
|
bool is_packed = (objs >= min_sections && objs <= max_sections &&
|
||||||
(IDSIZE(15) || ih_entry > isection[1].vaddr));
|
(IDSIZE(15) || ih_entry > isection[1].vaddr));
|
||||||
bool found_ph = false;
|
bool found_ph = false;
|
||||||
if (memcmp(isection[0].name,"UPX",3) == 0)
|
if (memcmp(isection[0].name,"UPX",3) == 0)
|
||||||
|
|||||||
+4
-4
@@ -87,8 +87,8 @@ protected:
|
|||||||
virtual bool canUnpackVersion(int version) const override
|
virtual bool canUnpackVersion(int version) const override
|
||||||
{ return (version >= 12 && version <= 13); }
|
{ return (version >= 12 && version <= 13); }
|
||||||
|
|
||||||
int canUnpack0(unsigned max_sections, LE16 &ih_objects,
|
int canUnpack0(unsigned max_sections, unsigned objs,
|
||||||
LE32 &ih_entry, unsigned ihsize);
|
unsigned ih_entry, unsigned ih_size);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int readFileHeader();
|
virtual int readFileHeader();
|
||||||
@@ -209,7 +209,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
MemBuffer mb_isection;
|
MemBuffer mb_isection;
|
||||||
pe_section_t *isection;
|
SPAN_0(pe_section_t) isection = nullptr;
|
||||||
bool isdll;
|
bool isdll;
|
||||||
bool isrtm;
|
bool isrtm;
|
||||||
bool isefi;
|
bool isefi;
|
||||||
@@ -218,7 +218,7 @@ protected:
|
|||||||
bool use_stub_relocs;
|
bool use_stub_relocs;
|
||||||
|
|
||||||
|
|
||||||
static unsigned virta2objnum (unsigned, pe_section_t *, unsigned);
|
static unsigned virta2objnum (unsigned, SPAN_0(pe_section_t), unsigned);
|
||||||
unsigned tryremove (unsigned, unsigned);
|
unsigned tryremove (unsigned, unsigned);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
Reference in New Issue
Block a user