diff --git a/src/p_armpe.cpp b/src/p_armpe.cpp index cbfcfdfe..66b8f2ef 100644 --- a/src/p_armpe.cpp +++ b/src/p_armpe.cpp @@ -2508,16 +2508,20 @@ void PackArmPe::unpack(OutputFile *fo) // write decompressed file if (fo) { + unsigned ic; + for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++) + ; + ibuf.dealloc(); - ibuf.alloc(osection[0].rawdataptr); + ibuf.alloc(osection[ic].rawdataptr); ibuf.clear(); infoHeader("[Writing uncompressed file]"); // write loader + compressed file fo->write(&oh,sizeof(oh)); fo->write(osection,objs * sizeof(pe_section_t)); - fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); - for(unsigned ic = 0; ic < objs; ic++) + fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten()); + for (ic = 0; ic < objs; ic++) if (osection[ic].rawdataptr) fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); copyOverlay(fo, overlay, &obuf); diff --git a/src/p_w32pe.cpp b/src/p_w32pe.cpp index e86a7491..73157be3 100644 --- a/src/p_w32pe.cpp +++ b/src/p_w32pe.cpp @@ -2600,16 +2600,20 @@ void PackW32Pe::unpack(OutputFile *fo) // write decompressed file if (fo) { + unsigned ic; + for (ic = 0; ic < objs && osection[ic].rawdataptr == 0; ic++) + ; + ibuf.dealloc(); - ibuf.alloc(osection[0].rawdataptr); + ibuf.alloc(osection[ic].rawdataptr); ibuf.clear(); infoHeader("[Writing uncompressed file]"); // write loader + compressed file fo->write(&oh,sizeof(oh)); fo->write(osection,objs * sizeof(pe_section_t)); - fo->write(ibuf,osection[0].rawdataptr - fo->getBytesWritten()); - for(unsigned ic = 0; ic < objs; ic++) + fo->write(ibuf,osection[ic].rawdataptr - fo->getBytesWritten()); + for (ic = 0; ic < objs; ic++) if (osection[ic].rawdataptr) fo->write(obuf + osection[ic].vaddr - rvamin,ALIGN_UP(osection[ic].size,oh.filealign)); copyOverlay(fo, overlay, &obuf);