Created
July 7, 2020 13:47
-
-
Save dmitrodem/ad547bbb75e750663714f08f33b13e94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from ctypes import * | |
libc = CDLL("libc.so.6") | |
class dirent(Structure): | |
_fields_ = [ | |
('d_ino', c_long), | |
('d_off', c_long), | |
('d_reclen', c_ushort), | |
('d_type', c_ubyte), | |
('d_name', c_char * 256)] | |
libc.opendir.restype = c_void_p | |
libc.opendir.argtypes = [c_char_p] | |
libc.readdir.restype = c_void_p | |
libc.readdir.argtypes = [c_void_p] | |
libc.closedir.restype = c_int | |
libc.closedir.argtypes = [c_void_p] | |
DIR = libc.opendir(b"/") | |
ent = libc.readdir(DIR) | |
content = {} | |
while(ent): | |
u = cast(ent, POINTER(dirent))[0] | |
content[u.d_name.decode('ascii')] = u.d_ino | |
ent = libc.readdir(DIR) | |
libc.closedir(DIR) | |
print(content["."]) | |
print(content[".."]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment