⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bdiff.c

📁 binary diff tool. scans input for matching patterns.
💻 C
字号:
/* (c) 2008 Petter Wahlman */#include <stdio.h>#include <unistd.h>#include <errno.h>#include <fcntl.h>#include <string.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>void print_usage(void){   fprintf(stderr, "usage: bdiff <file1> <file2> <offset1> <offset2> <val1> <val2>\n");   exit(1);}int main(int argc, char **argv){   int fd[2];   unsigned long val[2];   off_t offset[2];   int ret = 1;   if (argc != 7)      print_usage();   fd[0] = open(argv[1], O_RDONLY);   fd[1] = open(argv[2], O_RDONLY);   if ((-1 == fd[0]) || (-1 == fd[1]) ) {      fprintf(stderr, "can't open %s\n", fd[0] == -1 ? argv[1] : argv[2]);      goto out;   }   offset[0] = strtoul(argv[3], NULL, 0);   offset[1] = strtoul(argv[4], NULL, 0);   val[0] = strtoul(argv[5], NULL, 0);   val[1] = strtoul(argv[6], NULL, 0);   printf("bdiff:\n"          "   file 0: %s\n"          "   file 1: %s\n"          " offset 0: 0x%08lx\n"          " offset 1: 0x%08lx\n"          "   byte 0: 0x%x\n"          "   byte 1: 0x%x\n",            argv[1], argv[2],            offset[0], offset[1],            (unsigned char)val[0], (unsigned char)val[1]);   if(-1 == lseek(fd[0], offset[0], SEEK_SET)) {      fprintf(stderr, "unable to seek to offset: 0x%08lx in %s\n", offset[0], argv[1]);      goto out;   }   if(-1 == lseek(fd[1], offset[1], SEEK_SET)) {      fprintf(stderr, "unable to seek to offset: 0x%08lx in %s\n", offset[1], argv[2]);      goto out;   }   do {      unsigned char c[2];      int rc[2];      rc[0] = read(fd[0], &c[0], 1);      rc[1] = read(fd[1], &c[1], 1);      if ((-1 == rc[0]) || (-1 == rc[1])) {         fprintf(stderr, "%s %s\n", strerror(errno), rc[0] ? argv[1] : argv[2]);         goto out;      }      if (!(rc[0] || rc[1]))         break;      if ((val[0] == c[0]) && (val[1] == c[1]))         printf("match at both offsets: 0x%08lx - 0x%08lx\n", offset[0], offset[1]);       offset[0]++;      offset[1]++;   } while(1);   ret = 0;out:   close(fd[0]);   close(fd[1]);   return ret;}   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -