99 from qiling .os .memory import QlMemoryManager
1010
1111
12+ class FsMappedStream (io .BytesIO ):
13+ """Wrap stream objects to make them look like a QlFsMappedObject.
14+ """
15+
16+ def __init__ (self , fname : str , * args ) -> None :
17+ super ().__init__ (* args )
18+
19+ self .name = fname
20+
21+
1222class QlProcFS :
1323
1424 @staticmethod
@@ -28,14 +38,14 @@ def self_auxv(os: 'QlOsLinux') -> QlFsMappedObject:
2838 auxv_data .extend (os .ql .mem .read (auxv_addr , nbytes ))
2939 auxv_addr += nbytes
3040
31- return io . BytesIO ( bytes ( auxv_data ) )
41+ return FsMappedStream ( r'/proc/self/auxv' , auxv_data )
3242
3343 @staticmethod
3444 def self_cmdline (os : 'QlOsLinux' ) -> QlFsMappedObject :
3545 entries = (arg .encode ('utf-8' ) for arg in os .ql .argv )
3646 cmdline = b'\x00 ' .join (entries ) + b'\x00 '
3747
38- return io . BytesIO ( cmdline )
48+ return FsMappedStream ( r'/proc/self/cmdline' , cmdline )
3949
4050 @staticmethod
4151 def self_environ (os : 'QlOsLinux' ) -> QlFsMappedObject :
@@ -48,14 +58,14 @@ def __to_bytes(s: AnyStr) -> bytes:
4858 entries = (b'=' .join ((__to_bytes (k ), __to_bytes (v ))) for k , v in os .ql .env .items ())
4959 environ = b'\x00 ' .join (entries ) + b'\x00 '
5060
51- return io . BytesIO ( environ )
61+ return FsMappedStream ( r'/proc/self/environ' , environ )
5262
5363 @staticmethod
5464 def self_exe (os : 'QlOsLinux' ) -> QlFsMappedObject :
5565 with open (os .ql .path , 'rb' ) as exefile :
5666 content = exefile .read ()
5767
58- return io . BytesIO ( content )
68+ return FsMappedStream ( r'/proc/self/exe' , content )
5969
6070 @staticmethod
6171 def self_map (mem : 'QlMemoryManager' ) -> QlFsMappedObject :
@@ -65,4 +75,4 @@ def self_map(mem: 'QlMemoryManager') -> QlFsMappedObject:
6575 for lbound , ubound , perms , label , container in mapinfo :
6676 content += f"{ lbound :x} -{ ubound :x} \t { perms } p\t 0\t 00:00\t 0\t { container if container else label } \n " .encode ("utf-8" )
6777
68- return io . BytesIO ( bytes ( content ) )
78+ return FsMappedStream ( r'/proc/self/map' , content )
0 commit comments