pwnlib.util.getdents — Linux binary directory listing
- class pwnlib.util.getdents.linux_dirent(buf: bytes, is_dirent64: bool)[source]
Represent struct linux_dirent
struct linux_dirent { unsigned long d_ino; unsigned long d_off; unsigned short d_reclen; char d_name[]; }; // https://elixir.bootlin.com/linux/v6.14.4/source/fs/readdir.c#L244 // the 32version of linux_dirent stores d_type after d_name struct linux_dirent64 { u64 d_ino; s64 d_off; unsigned short d_reclen; unsigned char d_type; char d_name[]; }; // https://elixir.bootlin.com/linux/v6.14.4/source/include/linux/dirent.h#L5 enum { DT_UNKNOWN = 0, DT_FIFO = 1, DT_CHR = 2, DT_DIR = 4, DT_BLK = 6, DT_REG = 8, DT_LNK = 10, DT_SOCK = 12, DT_WHT = 14, DT_SUBVOL = 16 }; // https://elixir.bootlin.com/linux/v6.14.4/source/include/linux/fs_types.h#L42 // https://elixir.bootlin.com/linux/v6.14.4/source/fs/bcachefs/dirent_format.h#L37
- pwnlib.util.getdents.dirents(buf: bytes) list[linux_dirent]:[source]
Extracts data from a buffer emitted by getdents
- Parameters:
buf (bytes) – getdents result
- Returns:
A list of file names
Example
>>> with context.local(bytes = 4): ... buf = bytes.fromhex('5e843600c120fc1a1400746573742e63000000085f8436001f347e3010002e00be36ba040d002c00ffffff7f10002e2e00000004') ... print(dirents(buf)) ... [DT_REG test.c, DT_DIR ., DT_DIR ..]
- pwnlib.util.getdents.dirents64(buf: bytes) list[linux_dirent][source]
dirents(buf: bytes) -> list[linux_dirent]:
Extracts data from a buffer emitted by getdents64
- Parameters:
buf (bytes) – getdents64 result
- Returns:
A list of file names
Example
>>> with context.local(bytes = 8): ... buf = bytes.fromhex('223a2c0000000000786a631cc120fc1a200008746573742e63007464040000000d002c00000000004802ee451f347e301800042e0000000002002c0000000000ffffffffffffff7f1800042e2e000000') ... print(dirents64(buf)) ... [DT_REG test.c, DT_DIR ., DT_DIR ..]