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

📄 srch_strings.c

📁 linux下开发的针对所有磁盘的数据恢复的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
	  usage (stderr, 1);	default:	  if (string_min < 0)	    string_min = optc - '0';	  else	    string_min = string_min * 10 + optc - '0';	  break;	}    }  if (string_min < 0)    string_min = 4;  switch (encoding)    {    case 'S':    case 's':      encoding_bytes = 1;      break;    case 'b':    case 'l':      encoding_bytes = 2;      break;    case 'B':    case 'L':      encoding_bytes = 4;      break;    default:      usage (stderr, 1);    }  if (optind >= argc)    {#ifdef SET_BINARY      SET_BINARY (fileno (stdin));#endif      print_strings ("{standard input}", stdin, 0, 0, 0, (char *) NULL);      files_given = TRUE;    }  else    {      for (; optind < argc; ++optind)	{	      files_given = TRUE;	      exit_status |= strings_file (argv[optind]) == FALSE;	}    }  if (!files_given)    usage (stderr, 1);  return (exit_status);}/* Returns the size of the named file.  If the file does not   exist, or if it is not a real file, then a suitable non-fatal   error message is printed and zero is returned.  */off_tget_file_size (const char * file_name){  struct stat statbuf;  if (stat (file_name, &statbuf) < 0)    {      if (errno == ENOENT)        fprintf (stderr, "'%s': No such file", file_name);      else        fprintf (stderr, "Warning: could not locate '%s'.  reason: %s",                   file_name, strerror (errno));    }  else if (! S_ISREG (statbuf.st_mode)) {    fprintf(stderr, "Warning: '%s' is not an ordinary file", file_name);  }  else    return statbuf.st_size;  return 0;}/* Print the strings in FILE.  Return TRUE if ok, FALSE if an error occurs.  */static bfd_booleanstrings_file (char *file){  FILE *stream;  if (get_file_size (file) < 1)    return FALSE;      stream = file_open (file, "r");      if (stream == NULL)	{	  fprintf (stderr, "%s: ", program_name);	  perror (file);	  return FALSE;	}      print_strings (file, stream, (uint64_t) 0, 0, 0, (char *) 0);      if (fclose (stream) == EOF)	{	  fprintf (stderr, "%s: ", program_name);	  perror (file);	  return FALSE;	}  return TRUE;}/* Read the next character, return EOF if none available.   Assume that STREAM is positioned so that the next byte read   is at address ADDRESS in the file.   If STREAM is NULL, do not read from it.   The caller can supply a buffer of characters   to be processed before the data in STREAM.   MAGIC is the address of the buffer and   MAGICCOUNT is how many characters are in it.  */static longget_char (FILE *stream, uint64_t *address, int *magiccount, char **magic){  int c, i;  long r = EOF;  unsigned char buf[4];  for (i = 0; i < encoding_bytes; i++)    {      if (*magiccount)	{	  (*magiccount)--;	  c = *(*magic)++;	}      else	{	  if (stream == NULL)	    return EOF;#ifdef HAVE_GETC_UNLOCKED	  c = getc_unlocked (stream);#else	  c = getc (stream);#endif	  if (c == EOF)	    return EOF;	}      (*address)++;      buf[i] = c;    }  switch (encoding)    {    case 'S':    case 's':      r = buf[0];      break;    case 'b':      r = (buf[0] << 8) | buf[1];      break;    case 'l':      r = buf[0] | (buf[1] << 8);      break;    case 'B':      r = ((long) buf[0] << 24) | ((long) buf[1] << 16) |	((long) buf[2] << 8) | buf[3];      break;    case 'L':      r = buf[0] | ((long) buf[1] << 8) | ((long) buf[2] << 16) |	((long) buf[3] << 24);      break;    }  if (r == EOF)    return 0;  return r;}/* Find the strings in file FILENAME, read from STREAM.   Assume that STREAM is positioned so that the next byte read   is at address ADDRESS in the file.   Stop reading at address STOP_POINT in the file, if nonzero.   If STREAM is NULL, do not read from it.   The caller can supply a buffer of characters   to be processed before the data in STREAM.   MAGIC is the address of the buffer and   MAGICCOUNT is how many characters are in it.   Those characters come at address ADDRESS and the data in STREAM follow.  */static voidprint_strings (const char *filename, FILE *stream, uint64_t address,	       uint64_t stop_point, int magiccount, char *magic){  char *buf = (char *) malloc (sizeof (char) * (string_min + 1));  if (buf == NULL) {      fprintf(stderr, "Error allocating memory\n");      return;  }  while (1)    {      uint64_t start;      int i;      long c;      /* See if the next `string_min' chars are all graphic chars.  */    tryline:      if (stop_point && address >= stop_point)	break;      start = address;      for (i = 0; i < string_min; i++)	{	  c = get_char (stream, &address, &magiccount, &magic);	  if (c == EOF)	    return;	  if (! STRING_ISGRAPHIC (c))	    /* Found a non-graphic.  Try again starting with next char.  */	    goto tryline;	  buf[i] = c;	}      /* We found a run of `string_min' graphic characters.  Print up         to the next non-graphic character.  */      if (print_filenames)	printf ("%s: ", filename);      if (print_addresses)	switch (address_radix)	  {	  case 8:	      printf ("%10"PRIo64" ", start);	    break;	  case 10:	      printf ("%10"PRId64" ", start);	    break;	  case 16:	      printf ("%10"PRIx64" ", start);	    break;	  }      buf[i] = '\0';      fputs (buf, stdout);      while (1)	{	  c = get_char (stream, &address, &magiccount, &magic);	  if (c == EOF)	    break;	  if (! STRING_ISGRAPHIC (c))	    break;	  putchar (c);	}      putchar ('\n');    }}/* Parse string S as an integer, using decimal radix by default,   but allowing octal and hex numbers as in C.     Return 0 on error */static intinteger_arg (char *s){  int value;  int radix = 10;  char *p = s;  int c;  if (*p != '0')    radix = 10;  else if (*++p == 'x')    {      radix = 16;      p++;    }  else    radix = 8;  value = 0;  while (((c = *p++) >= '0' && c <= '9')	 || (radix == 16 && (c & ~40) >= 'A' && (c & ~40) <= 'Z'))    {      value *= radix;      if (c >= '0' && c <= '9')	value += c - '0';      else	value += (c & ~40) - 'A';    }  if (c == 'b')    value *= 512;  else if (c == 'B')    value *= 1024;  else    p--;  if (*p) {      fprintf(stderr, "invalid integer argument %s", s);      return 0;  }  return value;}static voidusage (FILE *stream, int status){  fprintf (stream, "Usage: %s [option(s)] [file(s)]\n", program_name);  fprintf (stream, " Display printable strings in [file(s)] (stdin by default)\n");  fprintf (stream, " The options are:\n\  -a -                 Scan the entire file, not just the data section\n\  -f       Print the name of the file before each string\n\  -n number       Locate & print any NUL-terminated sequence of at\n\  -<number>                 least [number] characters (default 4).\n\  -t {o,x,d}        Print the location of the string in base 8, 10 or 16\n\  -o                        An alias for --radix=o\n\  -e {s,S,b,l,B,L} Select character size and endianness:\n\                            s = 7-bit, S = 8-bit, {b,l} = 16-bit, {B,L} = 32-bit\n\  -h                  Display this information\n\  -v               Print the program's version number\n");  exit (status);}

⌨️ 快捷键说明

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