I use a program (upx.exe) that compresses and extracts packed executables. When I decompress an executable the only option is to write a file. I dont want the extracted code to touch the hard drive.
So I thought about writing a python wrapper that starts the executable and reads the decompressed code from a named pipe.
I wanted to
- create a named pipe in python,
- let the external program use that pipe as an output file and
- read the content that has been written to that pipe into a string.
I tried the following:
import win32pipe, win32file
import win32file
p = win32pipe.CreateNamedPipe(r'\\.\pipe\upx',
win32pipe.PIPE_ACCESS_DUPLEX,
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
1, 65536, 65536,300,None)
os.system("upx -d -o\\\\.\\pipe\\upx nbtscan-1.0.35.exe")
win32pipe.ConnectNamedPipe(p, None)
fileHandle = win32file.CreateFile(r'\\.\pipe\upx',
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
0, None,
win32file.OPEN_EXISTING,
0, None)
data = win32file.ReadFile(fileHandle, 4096)
print data
This is what happens:
I have no experience with named pipes and feel very desperate right now.
Perhaps you have an idea or a tutorial to give me some example. (The MSDN reference did not help me very much)
My code is based on this code, but when I use the "ConnectNamedPipe" function before the "system" call, the program just hangs and waits or some action on that pipe.
Please help.