开发者

How to extract strings out of a binary file with ruby?

i want to extract string out of a memory dump. i'm using windows xp,ruby 1.9-mingw

the dump file is generated by a tool -- HiperDro开发者_如何学Cp.exe


This should be a good start:

str = IO.read('/path/to/file', :mode => 'rb')
printable_chars = %r{[A-Za-z0-9`~!@#%^&*()-_=+|'";:/?.>,< \t\$\{\}\[\]\\]{10,}}
str.scan(printable_chars).each do |match|
  puts match
end

Of course, change '/path/to/file' to the location of the memory dump. You can also change the 10 at the end of the 2nd line to be some other minimum string length.


I think sarnold above is right on the money. strings is a utility that's available in all *nix environments, and there are free equivalents available from Microsoft for Windows. Just call the program from Ruby and parse the output as you please.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜