00001
00002
00003
00004
00005
00006
00007
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #else
00011 #ifdef _MSC_VER
00012 #undef HAVE_UNISTD_H
00013 #define HAVE_DIRECT_H
00014 #define HAVE_WINDOWS_H
00015 #endif
00016 #endif
00017 #include "version.h"
00018
00019 #ifndef DEFINEH_H
00020 #define DEFINEH_H
00021
00022 #define DEBUG_MODE_GEN
00023 #define DEBUGPRINT
00024 #define DEBUG_MODE_WARN
00025 #define DEBUG_MODE_READ
00026 #define DEBUG_MODE_EMAIL
00027 #define DEBUG_MODE_MAIN
00028 #define DEBUG_MODE_INDEX
00029 #define DEBUG_MODE_CODE
00030 #define DEBUG_MODE_INFO
00031 #define DEBUG_MODE_HEXDUMP
00032 #define DEBUG_MODE_FUNC
00033
00034
00035 #define DEBUG_MAX_ITEMS 0
00036
00037 #define DEBUG_FILE_NO 1
00038 #define DEBUG_INDEX_NO 2
00039 #define DEBUG_EMAIL_NO 3
00040 #define DEBUG_WARN_NO 4
00041 #define DEBUG_READ_NO 5
00042 #define DEBUG_INFO_NO 6
00043 #define DEBUG_MAIN_NO 7
00044 #define DEBUG_DECRYPT_NO 8
00045 #define DEBUG_FUNCENT_NO 9
00046 #define DEBUG_FUNCRET_NO 10
00047 #define DEBUG_HEXDUMP_NO 11
00048
00049 #include <stdio.h>
00050 #include <stdlib.h>
00051 #include <stdarg.h>
00052 #include <time.h>
00053 #include <string.h>
00054 #include <ctype.h>
00055 #include <limits.h>
00056 #include <wchar.h>
00057 #include <signal.h>
00058 #include <errno.h>
00059
00060 #define PERM_DIRS 0777
00061
00062 #ifdef HAVE_UNISTD_H
00063 #include <unistd.h>
00064 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
00065 #else
00066 #include "XGetopt.h"
00067 #ifdef HAVE_DIRECT_H
00068 #include <direct.h>
00069 #define D_MKDIR(x) mkdir(x)
00070 #define chdir _chdir
00071 #endif
00072
00073 #ifdef HAVE_WINDOWS_H
00074 #include <windows.h>
00075 #endif
00076
00077 #ifdef _MSC_VER
00078 #define vsnprintf _vsnprintf
00079 #define snprintf _snprintf
00080 #define ftello _ftelli64
00081 #define fseeko _fseeki64
00082 #define strcasecmp _stricmp
00083 #define off_t __int64
00084 #define size_t __int64
00085 #define int64_t __int64
00086 #define uint64_t unsigned __int64
00087 #define int32_t __int32
00088 #define uint32_t unsigned int
00089 #define int16_t short int
00090 #define uint16_t unsigned short int
00091 #define int8_t signed char
00092 #define uint8_t unsigned char
00093 #define UINT64_MAX ((uint64_t)0xffffffffffffffff)
00094 int __cdecl _fseeki64(FILE *, __int64, int);
00095 __int64 __cdecl _ftelli64(FILE *);
00096 #endif
00097 #endif
00098
00099 #ifdef HAVE_SYS_STAT_H
00100 #include <sys/stat.h>
00101 #endif
00102
00103 #ifdef HAVE_SYS_TYPES_H
00104 #include <sys/types.h>
00105 #endif
00106
00107 #ifdef HAVE_DIRENT_H
00108 #include <dirent.h>
00109 #endif
00110
00111
00112 void pst_debug(const char *fmt, ...);
00113 void pst_debug_hexdumper(FILE* out, char* buf, size_t size, int col, int delta);
00114 void pst_debug_hexprint(char *data, int size);
00115
00116 void pst_debug_init(const char *fname);
00117 void pst_debug_msg_info (int line, const char *file, int type);
00118 void pst_debug_msg_text(const char* fmt, ...);
00119 void pst_debug_hexdump(char *x, size_t y, int cols, int delta);
00120 void pst_debug_func(const char *function);
00121 void pst_debug_func_ret();
00122 void pst_debug_close(void);
00123 void pst_debug_write();
00124 size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
00125
00126 void * xmalloc(size_t size);
00127
00128 #define MESSAGEPRINT(x,y) {pst_debug_msg_info(__LINE__,__FILE__,y);\
00129 pst_debug_msg_text x;}
00130
00131 #define LOGSTOP() {MESSAGESTOP();DEBUGSTOP();}
00132
00133 #define DIE(x) {\
00134 MESSAGEPRINT(x, 0);\
00135 printf x;\
00136 exit(EXIT_FAILURE);\
00137 }
00138 #define WARN(x) {\
00139 MESSAGEPRINT(x, 0);\
00140 printf x;\
00141 }
00142
00143 #ifdef DEBUGPRINT
00144 #define DEBUG_PRINT(x) pst_debug x;
00145 #else
00146 #define DEBUG_PRINT(x) {}
00147 #endif
00148
00149 #ifdef DEBUG_MODE_GEN
00150 #define DEBUG(x) {DEBUG_PRINT(x);}
00151 #else
00152 #define DEBUG(x) {}
00153 #endif
00154
00155 #ifdef DEBUG_MODE_INDEX
00156 #define DEBUG_INDEX(x) MESSAGEPRINT(x, DEBUG_INDEX_NO);
00157 #else
00158 #define DEBUG_INDEX(x) {}
00159 #endif
00160
00161 #ifdef DEBUG_MODE_EMAIL
00162 #define DEBUG_EMAIL(x) MESSAGEPRINT(x, DEBUG_EMAIL_NO);
00163 #define DEBUG_EMAIL_HEXPRINT(x,y) {pst_debug_msg_info(__LINE__, __FILE__, 11);\
00164 pst_debug_hexdump((char*)x, y, 0x10, 0);}
00165 #else
00166 #define DEBUG_EMAIL(x) {}
00167 #define DEBUG_EMAIL_HEXPRINT(x,y) {}
00168 #endif
00169
00170 #ifdef DEBUG_MODE_WARN
00171 #define DEBUG_WARN(x) MESSAGEPRINT(x, DEBUG_WARN_NO);
00172 #else
00173 #define DEBUG_WARN(x) {}
00174 #endif
00175
00176 #ifdef DEBUG_MODE_READ
00177 #define DEBUG_READ(x) MESSAGEPRINT(x, DEBUG_READ_NO);
00178 #else
00179 #define DEBUG_READ(x) {}
00180 #endif
00181
00182 #ifdef DEBUG_MODE_INFO
00183 #define DEBUG_INFO(x) MESSAGEPRINT(x, DEBUG_INFO_NO);
00184 #else
00185 #define DEBUG_INFO(x) {}
00186 #endif
00187
00188 #ifdef DEBUG_MODE_MAIN
00189 #define DEBUG_MAIN(x) MESSAGEPRINT(x, DEBUG_MAIN_NO);
00190 #else
00191 #define DEBUG_MAIN(x) {}
00192 #endif
00193
00194 #ifdef DEBUG_MODE_CODE
00195 #define DEBUG_CODE(x) {x}
00196 #else
00197 #define DEBUG_CODE(x) {}
00198 #endif
00199
00200 #ifdef DEBUG_MODE_DECRYPT
00201 #define DEBUG_DECRYPT(x) MESSAGEPRINT(x, DEBUG_DECRYPT_NO);
00202 #else
00203 #define DEBUG_DECRYPT(x) {}
00204 #endif
00205
00206 #ifdef DEBUG_MODE_HEXDUMP
00207 #define DEBUG_HEXDUMP(x, s)\
00208 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00209 pst_debug_hexdump((char*)x, s, 0x10, 0);}
00210 #define DEBUG_HEXDUMPC(x, s, c)\
00211 {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_HEXDUMP_NO);\
00212 pst_debug_hexdump((char*)x, s, c, 0);}
00213 #else
00214 #define DEBUG_HEXDUMP(x, s) {}
00215 #define DEBUG_HEXDUMPC(x, s, c) {}
00216 #endif
00217
00218 #define DEBUG_FILE(x) {pst_debug_msg_info(__LINE__, __FILE__, DEBUG_FILE_NO);\
00219 pst_debug_msg_text x;}
00220
00221 #ifdef DEBUG_MODE_FUNC
00222 # define DEBUG_ENT(x) \
00223 { \
00224 pst_debug_func(x); \
00225 MESSAGEPRINT(("Entering function %s\n",x),DEBUG_FUNCENT_NO); \
00226 }
00227 # define DEBUG_RET() \
00228 { \
00229 MESSAGEPRINT(("Leaving function\n"),DEBUG_FUNCRET_NO); \
00230 pst_debug_func_ret(); \
00231 }
00232 #else
00233 # define DEBUG_ENT(x) {}
00234 # define DEBUG_RET() {}
00235 #endif
00236
00237 #define DEBUG_INIT(fname) {pst_debug_init(fname);}
00238 #define DEBUG_CLOSE() {pst_debug_close();}
00239 #define DEBUG_REGISTER_CLOSE() {if(atexit(pst_debug_close)!=0) fprintf(stderr, "Error registering atexit function\n");}
00240
00241 #define RET_DERROR(res, ret_val, x)\
00242 if (res) { DIE(x);}
00243
00244 #define RET_ERROR(res, ret_val)\
00245 if (res) {return ret_val;}
00246
00247 #define DEBUG_VERSION 1
00248 struct pst_debug_file_rec_m {
00249 unsigned short int funcname;
00250 unsigned short int filename;
00251 unsigned short int text;
00252 unsigned short int end;
00253 unsigned int line;
00254 unsigned int type;
00255 };
00256
00257 struct pst_debug_file_rec_l {
00258 unsigned int funcname;
00259 unsigned int filename;
00260 unsigned int text;
00261 unsigned int end;
00262 unsigned int line;
00263 unsigned int type;
00264 };
00265
00266 #endif //DEFINEH_H