diff --git a/logger/logger.cpp b/logger/logger.cpp index d25dd7f..1477dd1 100644 --- a/logger/logger.cpp +++ b/logger/logger.cpp @@ -10,7 +10,7 @@ char *get_current_time_str() { static char buffer[30]; struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, nullptr); struct tm *local = localtime(&tv.tv_sec); diff --git a/main.cpp b/main.cpp index a0b6e65..c72e542 100644 --- a/main.cpp +++ b/main.cpp @@ -12,8 +12,8 @@ #define MAIN_TAG "main" -static const char *outputFileName = NULL; -static const char *sourceFileName = NULL; +static const char *outputFileName = nullptr; +static const char *sourceFileName = nullptr; static Arch targetArch = ARCH_ARM64; static Platform targetPlatform = PLATFORM_LINUX; static int optimizationLevel = -1; diff --git a/wrapper/elf.cpp b/wrapper/elf.cpp index 73600eb..afdb5ad 100644 --- a/wrapper/elf.cpp +++ b/wrapper/elf.cpp @@ -5,7 +5,6 @@ #include "elf.h" #include "file.h" #include "mspace.h" -#include #include "assembler.h" #include "logger.h" @@ -26,9 +25,9 @@ Elf64_Ehdr *createElfHeader(uint16_t type, Elf64_Ehdr *ehdr = (Elf64_Ehdr *) malloc(sizeof(Elf64_Ehdr)); // 检查分配是否成功 - if (ehdr == NULL) { + if (ehdr == nullptr) { printf("Memory allocation failed\n"); - return NULL; + return nullptr; } // 填充 e_ident 魔术字节和标识信息 @@ -107,9 +106,9 @@ Elf64_Shdr *createSectionHeader(uint32_t name, Elf64_Shdr *shdr = (Elf64_Shdr *) malloc(sizeof(Elf64_Shdr)); // 检查分配是否成功 - if (shdr == NULL) { - fprintf(stderr, "Error: memory allocation failed\n"); - return NULL; + if (shdr == nullptr) { + loge(ELF_TAG, "Error: memory allocation failed\n"); + return nullptr; } // 填充节头字段 diff --git a/wrapper/macho.cpp b/wrapper/macho.cpp index 1ad806f..6f8b606 100644 --- a/wrapper/macho.cpp +++ b/wrapper/macho.cpp @@ -21,9 +21,9 @@ mach_header_64 *createMachHeader64(uint32_t cputype, mach_header_64 *header = (mach_header_64 *) malloc(sizeof(mach_header_64)); // 检查分配是否成功 - if (header == NULL) { + if (header == nullptr) { printf("Memory allocation failed\n"); - return NULL; + return nullptr; } // 填充 Mach-O 头部字段 @@ -52,9 +52,9 @@ segment_command_64 *createSegmentCommand64(const char *segname, segment_command_64 *segment = (segment_command_64 *) malloc(sizeof(segment_command_64)); // 检查分配是否成功 - if (segment == NULL) { + if (segment == nullptr) { printf("Memory allocation failed\n"); - return NULL; + return nullptr; } // 填充段命令字段 @@ -81,9 +81,9 @@ symtab_command *createSymtabCommand(uint32_t symoff, symtab_command *symtab = (symtab_command *) malloc(sizeof(symtab_command)); // 检查分配是否成功 - if (symtab == NULL) { + if (symtab == nullptr) { printf("Memory allocation failed\n"); - return NULL; + return nullptr; } // 填充符号表命令字段 @@ -110,9 +110,9 @@ section_64 *createSection64(const char *sectname, section_64 *section = (section_64 *) malloc(sizeof(section_64)); // 检查分配是否成功 - if (section == NULL) { + if (section == nullptr) { printf("Memory allocation failed\n"); - return NULL; + return nullptr; } // 填充区块字段 diff --git a/wrapper/pe.cpp b/wrapper/pe.cpp index d030a32..b4a5656 100644 --- a/wrapper/pe.cpp +++ b/wrapper/pe.cpp @@ -42,9 +42,9 @@ OptionalHeader *createOptionalHeader(uint16_t numberOfSections, uint32_t fileAlignment) { // 分配可选头内存 OptionalHeader *optionalHeader = (OptionalHeader *) malloc(sizeof(OptionalHeader)); - if (optionalHeader == NULL) { + if (optionalHeader == nullptr) { loge(PE_TAG, "Memory allocation for Optional header failed\n"); - return NULL; + return nullptr; } // 填充可选头 @@ -153,9 +153,9 @@ SectionHeader *createSectionHeader(const char *name, SectionHeader *sectionheader = (SectionHeader *) malloc(sizeof(SectionHeader)); // 检查分配是否成功 - if (sectionheader == NULL) { - fprintf(stderr, "Error: memory allocation failed\n"); - return NULL; + if (sectionheader == nullptr) { + loge(PE_TAG, "Error: memory allocation failed\n"); + return nullptr; } // 填充节头字段 @@ -186,9 +186,9 @@ ProgramSegment *createProgramSegment(uint32_t type, ProgramSegment *segment = (ProgramSegment *) malloc(sizeof(ProgramSegment)); // 检查分配是否成功 - if (segment == NULL) { - fprintf(stderr, "Error: memory allocation failed\n"); - return NULL; + if (segment == nullptr) { + loge(PE_TAG, "Error: memory allocation failed\n"); + return nullptr; } // 填充段信息字段