56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
# python windows namepipe serve
|
|
|
|
import win32pipe, win32file
|
|
import json
|
|
import threading
|
|
import sys
|
|
import ctypes
|
|
|
|
# 连接到命名管道
|
|
pipe_name = r"\\.\pipe\botext"
|
|
pipe_access = win32pipe.PIPE_ACCESS_DUPLEX
|
|
pipe_type = win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT
|
|
pipe_mode = 1
|
|
max_instances = 65536
|
|
out_buffer_size = 65536
|
|
default_time_out = 0
|
|
security_attributes = None
|
|
|
|
pipe = win32pipe.CreateNamedPipe(
|
|
pipe_name,
|
|
win32pipe.PIPE_ACCESS_DUPLEX,
|
|
win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT | win32pipe.PIPE_READMODE_MESSAGE,
|
|
win32pipe.PIPE_UNLIMITED_INSTANCES,
|
|
65535,
|
|
65535,
|
|
0,
|
|
None,
|
|
)
|
|
|
|
|
|
def namepipe_server(pipe):
|
|
try:
|
|
while True:
|
|
win32pipe.ConnectNamedPipe(pipe, None)
|
|
_, data = win32file.ReadFile(pipe, 4096)
|
|
if data == b'close':
|
|
sys.exit(0)
|
|
print(data)
|
|
ctypes.windll.user32.MessageBoxW(0, "hi", "BotExt", 0)
|
|
win32pipe.DisconnectNamedPipe(pipe)
|
|
except Exception as e:
|
|
win32pipe.DisconnectNamedPipe(pipe)
|
|
finally:
|
|
win32file.CloseHandle(pipe)
|
|
|
|
def namepipe_server_forver(pipe):
|
|
while True:
|
|
namepipe_server(pipe)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
task = threading.Thread(target=namepipe_server, args=(pipe,))
|
|
task.daemon = True
|
|
task.start()
|
|
task.join()
|