Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm1.Button1Click(Sender: TObject);
- const
- BufferSize = 1024;
- var
- Buffer: PChar;
- BytesRead: DWORD;
- BytesInPipe: DWORD;
- BytesToRead: DWORD;
- PipeName: String;
- PipeHandle: THandle;
- SecAttrs: SECURITY_ATTRIBUTES;
- SecDescr: SECURITY_DESCRIPTOR;
- begin
- InitializeSecurityDescriptor(@SecDescr, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(@SecDescr, True, nil, False);
- SecAttrs.lpSecurityDescriptor := @SecDescr;
- SecAttrs.nLength := SizeOf(SECURITY_ATTRIBUTES);
- SecAttrs.bInheritHandle := True;
- PipeName := '\.pipecom_1';
- PipeHandle := CreateFile(PChar(PipeName), GENERIC_READ or GENERIC_WRITE, 0, @SecAttrs, OPEN_EXISTING, 0, 0);
- Memo1.Lines.Add('CreateFile; PipeHandle = '+IntToStr(PipeHandle));
- Buffer := AllocMem(BufferSize + 1);
- repeat
- repeat
- PeekNamedPipe(PipeHandle, nil, 0, nil, @BytesInPipe, nil);
- BytesToRead := Min(BufferSize, BytesInPipe);
- if BytesToRead > 0 then
- begin
- BytesRead := 0;
- Memo1.Lines.Add('PeekNamedPipe; BytesInPipe = '+IntToStr(BytesInPipe)+'; BytesToRead = '+IntToStr(BytesToRead));
- if ReadFile(PipeHandle, Buffer[0], BytesToRead, BytesRead, nil) then
- begin
- Buffer[BufferSize] := #0;
- // OemToAnsi(Buffer, Buffer); // without this line I'm getting the following log
- Memo1.Lines.Add('ReadFile; BytesToRead = '+IntToStr(BytesToRead)+'; BytesRead = '+IntToStr(BytesRead));
- Memo1.Lines.Add('ReadFile; Buffer = '+String(Buffer));
- end;
- end;
- until
- (BytesToRead = 0);
- Application.ProcessMessages;
- until
- (Tag = 1);
- end;
- CreateFile; PipeHandle = 240
- PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
- ReadFile; BytesToRead = 1; BytesRead = 1
- ReadFile; Buffer = 0
- PeekNamedPipe; BytesInPipe = 16; BytesToRead = 16
- ReadFile; BytesToRead = 16; BytesRead = 16
- ReadFile; Buffer = 000
- PeekNamedPipe; BytesInPipe = 169; BytesToRead = 169
- ReadFile; BytesToRead = 169; BytesRead = 169
- ReadFile; Buffer = 0
- PeekNamedPipe; BytesInPipe = 74; BytesToRead = 74
- ReadFile; BytesToRead = 74; BytesRead = 74
- ReadFile; Buffer =
- PeekNamedPipe; BytesInPipe = 28; BytesToRead = 28
- ReadFile; BytesToRead = 28; BytesRead = 28
- ReadFile; Buffer = DOWSsystem32ntkrnlpa.exe
- PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
- ReadFile; BytesToRead = 1; BytesRead = 1
- ReadFile; Buffer = 0OWSsystem32ntkrnlpa.exe
- PeekNamedPipe; BytesInPipe = 261; BytesToRead = 261
- ReadFile; BytesToRead = 261; BytesRead = 261
- ReadFile; Buffer = 000
- PeekNamedPipe; BytesInPipe = 26; BytesToRead = 26
- ReadFile; BytesToRead = 26; BytesRead = 26
- ReadFile; Buffer = WSsystem32ntkrnlpa.exe
- PeekNamedPipe; BytesInPipe = 288; BytesToRead = 288
- ReadFile; BytesToRead = 288; BytesRead = 288
- ReadFile; Buffer = 0000
- PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
- ReadFile; BytesToRead = 1; BytesRead = 1
- ReadFile; Buffer = 0000
- PeekNamedPipe; BytesInPipe = 218; BytesToRead = 218
- ReadFile; BytesToRead = 218; BytesRead = 218
- ReadFile; Buffer = 000
- PeekNamedPipe; BytesInPipe = 69; BytesToRead = 69
- ReadFile; BytesToRead = 69; BytesRead = 69
- ReadFile; Buffer =
- PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
- ReadFile; BytesToRead = 1; BytesRead = 1
- ReadFile; Buffer = 0Ì]Â
- PeekNamedPipe; BytesInPipe = 287; BytesToRead = 287
- ReadFile; BytesToRead = 287; BytesRead = 287
- ReadFile; Buffer = 000
Add Comment
Please, Sign In to add comment