Module: Pwnlib::Util::Getdents
- Defined in:
- lib/pwnlib/util/getdents.rb
Overview
Helper methods related to getdents syscall.
Defined Under Namespace
Classes: Dirent
Constant Summary collapse
- DT_TYPE_INVERSE =
For inverse mapping of linux_dirent#d_type. man getdents to see more information.
{ 0 => 'UNKNOWN', 1 => 'FIFO', 2 => 'CHR', 4 => 'DIR', 6 => 'BLK', 8 => 'REG', 10 => 'LNK', 12 => 'SOCK' }.freeze
Class Method Summary collapse
-
.parse(binstr) ⇒ String
Parse the output of getdents syscall.
Class Method Details
.parse(binstr) ⇒ String
Parse the output of getdents syscall. For users to handle the shit-like output by shellcraft.ls
(e.g. Shellcraft::Generators::X86::Linux#ls).
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pwnlib/util/getdents.rb', line 69 def parse(binstr) str = StringIO.new(binstr) result = StringIO.new until str.eof? ent = Dirent.new(endian: context.endian.to_sym) ent.bits = context.bits ent.read(str) # NOTE: d_name might contains garbage after first "\x00", so we use gsub(/\x00.*/) instead of delete("\x00"). result.puts("#{DT_TYPE_INVERSE[ent.d_type]} #{ent.d_name.gsub(/\x00.*/, '')}") end result.string end |