Cleanups and cruft removal.
This commit is contained in:
+28
-64
@@ -25,11 +25,9 @@
|
||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __UPX_UTIL_H
|
||||
#define __UPX_UTIL_H 1
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
// misc. support functions
|
||||
**************************************************************************/
|
||||
@@ -37,19 +35,17 @@
|
||||
char *fn_basename(const char *name);
|
||||
int fn_strcmp(const char *n1, const char *n2);
|
||||
char *fn_strlwr(char *n);
|
||||
bool fn_has_ext(const char *name, const char *ext, bool ignore_case=true);
|
||||
bool fn_has_ext(const char *name, const char *ext, bool ignore_case = true);
|
||||
|
||||
bool file_exists(const char *name);
|
||||
bool maketempname(char *ofilename, size_t size,
|
||||
const char *ifilename, const char *ext, bool force=true);
|
||||
bool makebakname(char *ofilename, size_t size,
|
||||
const char *ifilename, bool force=true);
|
||||
bool maketempname(char *ofilename, size_t size, const char *ifilename, const char *ext,
|
||||
bool force = true);
|
||||
bool makebakname(char *ofilename, size_t size, const char *ifilename, bool force = true);
|
||||
|
||||
unsigned get_ratio(unsigned u_len, unsigned c_len);
|
||||
bool set_method_name(char *buf, size_t size, int method, int level);
|
||||
void center_string(char *buf, size_t size, const char *s);
|
||||
|
||||
|
||||
int find(const void *b, int blen, const void *what, int wlen);
|
||||
int find_be16(const void *b, int blen, unsigned what);
|
||||
int find_be32(const void *b, int blen, unsigned what);
|
||||
@@ -60,74 +56,42 @@ int find_le64(const void *b, int blen, upx_uint64_t what);
|
||||
|
||||
int mem_replace(void *b, int blen, const void *what, int wlen, const void *r);
|
||||
|
||||
/*************************************************************************
|
||||
// protect against integer overflows and malicious header fields
|
||||
**************************************************************************/
|
||||
|
||||
#if (ACC_CC_BORLANDC && (__BORLANDC__ < 0x0530))
|
||||
#elif (ACC_CC_DMC && (__DMC__ < 0x830))
|
||||
#elif (ACC_CC_MSC && (_MSC_VER < 1310))
|
||||
#else
|
||||
template <class T>
|
||||
inline int ptr_diff(const T *p1, const T *p2)
|
||||
{
|
||||
COMPILE_TIME_ASSERT(sizeof(T) == 1)
|
||||
assert(p1 != NULL); assert(p2 != NULL);
|
||||
ptrdiff_t d = (const char*) p1 - (const char*) p2;
|
||||
assert((int)d == d);
|
||||
return (int) d;
|
||||
}
|
||||
#endif
|
||||
inline int ptr_diff(const void *p1, const void *p2)
|
||||
{
|
||||
assert(p1 != NULL); assert(p2 != NULL);
|
||||
ptrdiff_t d = (const char*) p1 - (const char*) p2;
|
||||
assert((int)d == d);
|
||||
return (int) d;
|
||||
size_t mem_size(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0);
|
||||
size_t mem_size_get_n(upx_uint64_t element_size, upx_uint64_t n);
|
||||
|
||||
bool mem_size_valid(upx_uint64_t element_size, upx_uint64_t n, upx_uint64_t extra = 0);
|
||||
bool mem_size_valid_bytes(upx_uint64_t bytes);
|
||||
|
||||
#define New(type, n) new type[mem_size_get_n(sizeof(type), n)]
|
||||
|
||||
int ptr_diff(const char *p1, const char *p2);
|
||||
|
||||
inline int ptr_diff(const unsigned char *p1, const unsigned char *p2) {
|
||||
return ptr_diff((const char *) p1, (const char *) p2);
|
||||
}
|
||||
|
||||
inline int ptr_diff(const void *p1, const void *p2) {
|
||||
return ptr_diff((const char *) p1, (const char *) p2);
|
||||
}
|
||||
|
||||
/*************************************************************************
|
||||
// some unsigned char string support functions
|
||||
**************************************************************************/
|
||||
|
||||
inline char *strcpy(unsigned char *s1,const unsigned char *s2)
|
||||
{
|
||||
return strcpy((char*) s1,(const char*) s2);
|
||||
inline char *strcpy(unsigned char *s1, const unsigned char *s2) {
|
||||
return strcpy((char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
inline int strcasecmp(const unsigned char *s1,const unsigned char *s2)
|
||||
{
|
||||
return strcasecmp((const char*) s1,(const char*) s2);
|
||||
inline int strcasecmp(const unsigned char *s1, const unsigned char *s2) {
|
||||
return strcasecmp((const char *) s1, (const char *) s2);
|
||||
}
|
||||
|
||||
inline size_t strlen(const unsigned char *s)
|
||||
{
|
||||
return strlen((const char*) s);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
**************************************************************************/
|
||||
|
||||
#if 0
|
||||
bool upx_isdigit(int c);
|
||||
bool upx_islower(int c);
|
||||
bool upx_isspace(int c);
|
||||
int upx_tolower(int c);
|
||||
#undef isdigit
|
||||
#undef islower
|
||||
#undef isspace
|
||||
#undef tolower
|
||||
#define isdigit upx_isdigit
|
||||
#define islower upx_islower
|
||||
#define isspace upx_isspace
|
||||
#define tolower upx_tolower
|
||||
#endif
|
||||
|
||||
inline size_t strlen(const unsigned char *s) { return strlen((const char *) s); }
|
||||
|
||||
#endif /* already included */
|
||||
|
||||
|
||||
/*
|
||||
vi:ts=4:et
|
||||
*/
|
||||
|
||||
/* vim:set ts=4 sw=4 et: */
|
||||
|
||||
Reference in New Issue
Block a user