|
|
|
@ -155,54 +155,50 @@
|
|
|
|
|
* Misc terminal codes *
|
|
|
|
|
***********************/
|
|
|
|
|
|
|
|
|
|
#define TERM_HOME "\x1b[H"
|
|
|
|
|
#define TERM_CLEAR TERM_HOME "\x1b[2J"
|
|
|
|
|
#define cEOL "\x1b[0K"
|
|
|
|
|
#define CURSOR_HIDE "\x1b[?25l"
|
|
|
|
|
#define CURSOR_SHOW "\x1b[?25h"
|
|
|
|
|
// 定义一些额外的终端控制代码
|
|
|
|
|
#define TERM_HOME "\x1b[H" // 移动光标到终端左上角
|
|
|
|
|
#define TERM_CLEAR TERM_HOME "\x1b[2J" // 清除终端屏幕
|
|
|
|
|
#define cEOL "\x1b[0K" // 清除当前行从光标位置到行尾的内容
|
|
|
|
|
#define CURSOR_HIDE "\x1b[?25l" // 隐藏光标
|
|
|
|
|
#define CURSOR_SHOW "\x1b[?25h" // 显示光标
|
|
|
|
|
|
|
|
|
|
/************************
|
|
|
|
|
* Debug & error macros *
|
|
|
|
|
************************/
|
|
|
|
|
|
|
|
|
|
/* Just print stuff to the appropriate stream. */
|
|
|
|
|
|
|
|
|
|
// 定义一些宏用于调试和错误处理
|
|
|
|
|
// 如果配置中定义了MESSAGES_TO_STDOUT,则使用printf,否则使用fprintf(stderr, ...)
|
|
|
|
|
#ifdef MESSAGES_TO_STDOUT
|
|
|
|
|
# define SAYF(x...) printf(x)
|
|
|
|
|
#else
|
|
|
|
|
# define SAYF(x...) fprintf(stderr, x)
|
|
|
|
|
#endif /* ^MESSAGES_TO_STDOUT */
|
|
|
|
|
|
|
|
|
|
/* Show a prefixed warning. */
|
|
|
|
|
|
|
|
|
|
// 显示带前缀的警告信息
|
|
|
|
|
#define WARNF(x...) do { \
|
|
|
|
|
SAYF(cYEL "[!] " cBRI "WARNING: " cRST x); \
|
|
|
|
|
SAYF(cRST "\n"); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Show a prefixed "doing something" message. */
|
|
|
|
|
|
|
|
|
|
// 显示带前缀的“正在执行”信息
|
|
|
|
|
#define ACTF(x...) do { \
|
|
|
|
|
SAYF(cLBL "[*] " cRST x); \
|
|
|
|
|
SAYF(cRST "\n"); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Show a prefixed "success" message. */
|
|
|
|
|
|
|
|
|
|
// 显示带前缀的成功信息
|
|
|
|
|
#define OKF(x...) do { \
|
|
|
|
|
SAYF(cLGN "[+] " cRST x); \
|
|
|
|
|
SAYF(cRST "\n"); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Show a prefixed fatal error message (not used in afl). */
|
|
|
|
|
|
|
|
|
|
// 显示带前缀的严重错误信息(不在afl中使用)
|
|
|
|
|
#define BADF(x...) do { \
|
|
|
|
|
SAYF(cLRD "\n[-] " cRST x); \
|
|
|
|
|
SAYF(cRST "\n"); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Die with a verbose non-OS fatal error message. */
|
|
|
|
|
|
|
|
|
|
// 以详细非操作系统致命错误消息退出程序
|
|
|
|
|
#define FATAL(x...) do { \
|
|
|
|
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \
|
|
|
|
|
cBRI x); \
|
|
|
|
@ -211,8 +207,7 @@
|
|
|
|
|
exit(1); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Die by calling abort() to provide a core dump. */
|
|
|
|
|
|
|
|
|
|
// 通过调用abort()退出程序,以便提供core dump
|
|
|
|
|
#define ABORT(x...) do { \
|
|
|
|
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] PROGRAM ABORT : " \
|
|
|
|
|
cBRI x); \
|
|
|
|
@ -221,8 +216,7 @@
|
|
|
|
|
abort(); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Die while also including the output of perror(). */
|
|
|
|
|
|
|
|
|
|
// 以包含perror()输出的方式退出程序
|
|
|
|
|
#define PFATAL(x...) do { \
|
|
|
|
|
fflush(stdout); \
|
|
|
|
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD "\n[-] SYSTEM ERROR : " \
|
|
|
|
@ -233,16 +227,12 @@
|
|
|
|
|
exit(1); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Die with FAULT() or PFAULT() depending on the value of res (used to
|
|
|
|
|
interpret different failure modes for read(), write(), etc). */
|
|
|
|
|
|
|
|
|
|
// 根据res的值调用FAULT()或PFAULT(),用于解释read()、write()等的不同失败模式
|
|
|
|
|
#define RPFATAL(res, x...) do { \
|
|
|
|
|
if (res < 0) PFATAL(x); else FATAL(x); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
/* Error-checking versions of read() and write() that call RPFATAL() as
|
|
|
|
|
appropriate. */
|
|
|
|
|
|
|
|
|
|
// 定义ck_write和ck_read宏,用于检查write和read操作是否成功,并在失败时调用RPFATAL
|
|
|
|
|
#define ck_write(fd, buf, len, fn) do { \
|
|
|
|
|
u32 _len = (len); \
|
|
|
|
|
s32 _res = write(fd, buf, _len); \
|
|
|
|
@ -255,4 +245,4 @@
|
|
|
|
|
if (_res != _len) RPFATAL(_res, "Short read from %s", fn); \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#endif /* ! _HAVE_DEBUG_H */
|
|
|
|
|
#endif /* !_HAVE_DEBUG_H */
|