Existe um programa que pode contar a ocorrência de uma certa string em um arquivo binário?

4

Eu tenho um arquivo binário e preciso contar ocorrências de determinada string neste arquivo ou até mesmo listar com offsets. No Windows ou Linux - para esta tarefa eu uso o Fedora 12 e o Windows 2000.

    
por IvanH 15.05.2012 / 16:29

3 respostas

7

No Linux com GNU grep :

grep -F --text -o --byte-offset mystring binaryfile

Exemplo:

$ grep -F --text -o --byte-offset option /bin/tar
226542:option
237529:option
237612:option
...

Explicação dos parâmetros:

-F, --fixed-strings
      Interpret PATTERN as a list of fixed strings, separated by newlines,
      any of which is to be matched.  (-F is specified by POSIX.)

-a, --text
      Process  a binary file as if it were text; this is equivalent to the
      --binary-files=text option.

-o, --only-matching
      Print  only the matched (non-empty) parts of a matching line, with
      each such part on a separate output line.

-b, --byte-offset
      Print the 0-based byte offset within the input file before each line
      of output. If -o (--only-matching) is specified, print the offset of
      the matching part itself

Para contar as ocorrências, adicione | wc -l à linha de comando.

    
por 15.05.2012 / 17:13
2

Agent Ransack - Utilitário de busca de arquivos grátis

  • Immediate results Found text is shown with highlighted keywords so you don't need to waste time opening each file looking for the
    right information.

  • Boolean expressions Combine search terms using the familiar Boolean operators AND, OR, NOT.

  • Office formats Support for popular Office formats including Office 2007 and OpenOffice.
  • Perl regex Support for Perl compatible regular expressions.
  • 64-bit Version Natively compiled 64-bit version for improved compatibility.
  • Fast searching Highly efficient search algorithms mean that you spend less time waiting for results.
  • Printing and Exporting Results can be shared with others through printing and exporting.

    
por 16.05.2012 / 05:47
1

No Linux, você pode usar strings -a [filename] | grep [string] | wc -l

No Windows, você pode usar o strings * | findstr /i [string] , com o utilitário de strings da Sysinternals.

    
por 15.05.2012 / 17:05