mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
More thorough use of O_BINARY.
This commit is contained in:
parent
42206364e5
commit
ed900b0476
|
@ -236,6 +236,11 @@ typedef unsigned char upx_byte;
|
||||||
#undef PAGE_MASK
|
#undef PAGE_MASK
|
||||||
#undef PAGE_SIZE
|
#undef PAGE_SIZE
|
||||||
|
|
||||||
|
#if !defined(O_BINARY) || (O_BINARY+0 == 0)
|
||||||
|
# if (ACC_OS_CYGWIN || ACC_OS_DOS16 || ACC_OS_DOS32 || ACC_OS_EMX || ACC_OS_OS2 || ACC_OS_OS216 || ACC_OS_WIN16 || ACC_OS_WIN32 || ACC_OS_WIN64)
|
||||||
|
# error "missing O_BINARY"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
#if !defined(O_BINARY)
|
#if !defined(O_BINARY)
|
||||||
# define O_BINARY 0
|
# define O_BINARY 0
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -429,7 +429,7 @@ off_t OutputFile::seek(upx_int64_t off64, int whence)
|
||||||
//{
|
//{
|
||||||
// fsync(_fd);
|
// fsync(_fd);
|
||||||
// InputFile infile;
|
// InputFile infile;
|
||||||
// infile.open(this->getName(), O_RDONLY);
|
// infile.open(this->getName(), O_RDONLY | O_BINARY);
|
||||||
// infile.seek(this->tell(), SEEK_SET);
|
// infile.seek(this->tell(), SEEK_SET);
|
||||||
// return infile.read(buf, len);
|
// return infile.read(buf, len);
|
||||||
//}
|
//}
|
||||||
|
@ -459,8 +459,8 @@ off_t OutputFile::unset_extent()
|
||||||
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
void OutputFile::dump(const char *name, const void *buf, int len, int flags)
|
||||||
{
|
{
|
||||||
if (flags < 0)
|
if (flags < 0)
|
||||||
flags = O_CREAT | O_BINARY | O_TRUNC;
|
flags = O_CREAT | O_TRUNC;
|
||||||
flags |= O_WRONLY;
|
flags |= O_WRONLY | O_BINARY;
|
||||||
OutputFile f;
|
OutputFile f;
|
||||||
f.open(name, flags, 0600);
|
f.open(name, flags, 0600);
|
||||||
f.write(buf, len);
|
f.write(buf, len);
|
||||||
|
|
|
@ -170,9 +170,9 @@ static void handle_allegropak(InputFile *fi, OutputFile *fo)
|
||||||
if (memcmp(buf, "slh+", 4) != 0)
|
if (memcmp(buf, "slh+", 4) != 0)
|
||||||
return;
|
return;
|
||||||
pfsize = get_be32_signed(buf+4);
|
pfsize = get_be32_signed(buf+4);
|
||||||
if (pfsize <= 8 || (off_t) pfsize >= (off_t) fi->st.st_size)
|
if (pfsize <= 8 || pfsize >= (off_t) fi->st.st_size)
|
||||||
return;
|
return;
|
||||||
fi->seek(-pfsize, SEEK_END);
|
fi->seek(-(off_t)pfsize, SEEK_END);
|
||||||
} catch (const IOException&) {
|
} catch (const IOException&) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,7 +512,7 @@ int PackUnix::canUnpack()
|
||||||
bufsize = fi->st_size();
|
bufsize = fi->st_size();
|
||||||
MemBuffer buf(bufsize);
|
MemBuffer buf(bufsize);
|
||||||
|
|
||||||
fi->seek(-bufsize, SEEK_END);
|
fi->seek(-(off_t)bufsize, SEEK_END);
|
||||||
fi->readx(buf, bufsize);
|
fi->readx(buf, bufsize);
|
||||||
int i = bufsize;
|
int i = bufsize;
|
||||||
while (i > small && 0 == buf[--i]) { }
|
while (i > small && 0 == buf[--i]) { }
|
||||||
|
|
|
@ -626,9 +626,9 @@ unsigned Packer::getRandomId() const
|
||||||
unsigned id = 0;
|
unsigned id = 0;
|
||||||
#if 0 && defined(__unix__)
|
#if 0 && defined(__unix__)
|
||||||
// Don't consume precious bytes from /dev/urandom.
|
// Don't consume precious bytes from /dev/urandom.
|
||||||
int fd = open("/dev/urandom", O_RDONLY);
|
int fd = open("/dev/urandom", O_RDONLY | O_BINARY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
fd = open("/dev/random", O_RDONLY);
|
fd = open("/dev/random", O_RDONLY | O_BINARY);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
if (read(fd, &id, 4) != 4)
|
if (read(fd, &id, 4) != 4)
|
||||||
|
|
|
@ -392,7 +392,7 @@ bool file_exists(const char *name)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
/* return true if we can open it */
|
/* return true if we can open it */
|
||||||
fd = open(name, O_RDONLY, 0);
|
fd = open(name, O_RDONLY | O_BINARY, 0);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
{
|
{
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user