Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. const
  3. BufferSize = 1024;
  4.  
  5. var
  6. Buffer: PChar;
  7. BytesRead: DWORD;
  8. BytesInPipe: DWORD;
  9. BytesToRead: DWORD;
  10. PipeName: String;
  11. PipeHandle: THandle;
  12. SecAttrs: SECURITY_ATTRIBUTES;
  13. SecDescr: SECURITY_DESCRIPTOR;
  14.  
  15. begin
  16. InitializeSecurityDescriptor(@SecDescr, SECURITY_DESCRIPTOR_REVISION);
  17. SetSecurityDescriptorDacl(@SecDescr, True, nil, False);
  18. SecAttrs.lpSecurityDescriptor := @SecDescr;
  19. SecAttrs.nLength := SizeOf(SECURITY_ATTRIBUTES);
  20. SecAttrs.bInheritHandle := True;
  21.  
  22. PipeName := '\.pipecom_1';
  23.  
  24. PipeHandle := CreateFile(PChar(PipeName), GENERIC_READ or GENERIC_WRITE, 0, @SecAttrs, OPEN_EXISTING, 0, 0);
  25. Memo1.Lines.Add('CreateFile; PipeHandle = '+IntToStr(PipeHandle));
  26.  
  27. Buffer := AllocMem(BufferSize + 1);
  28.  
  29. repeat
  30. repeat
  31. PeekNamedPipe(PipeHandle, nil, 0, nil, @BytesInPipe, nil);
  32. BytesToRead := Min(BufferSize, BytesInPipe);
  33.  
  34. if BytesToRead > 0 then
  35. begin
  36. BytesRead := 0;
  37. Memo1.Lines.Add('PeekNamedPipe; BytesInPipe = '+IntToStr(BytesInPipe)+'; BytesToRead = '+IntToStr(BytesToRead));
  38.  
  39. if ReadFile(PipeHandle, Buffer[0], BytesToRead, BytesRead, nil) then
  40. begin
  41. Buffer[BufferSize] := #0;
  42. // OemToAnsi(Buffer, Buffer); // without this line I'm getting the following log
  43.  
  44. Memo1.Lines.Add('ReadFile; BytesToRead = '+IntToStr(BytesToRead)+'; BytesRead = '+IntToStr(BytesRead));
  45. Memo1.Lines.Add('ReadFile; Buffer = '+String(Buffer));
  46. end;
  47. end;
  48. until
  49. (BytesToRead = 0);
  50.  
  51. Application.ProcessMessages;
  52. until
  53. (Tag = 1);
  54. end;
  55.  
  56. CreateFile; PipeHandle = 240
  57. PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
  58. ReadFile; BytesToRead = 1; BytesRead = 1
  59. ReadFile; Buffer = 0
  60. PeekNamedPipe; BytesInPipe = 16; BytesToRead = 16
  61. ReadFile; BytesToRead = 16; BytesRead = 16
  62. ReadFile; Buffer = 000
  63. PeekNamedPipe; BytesInPipe = 169; BytesToRead = 169
  64. ReadFile; BytesToRead = 169; BytesRead = 169
  65. ReadFile; Buffer = 0
  66. PeekNamedPipe; BytesInPipe = 74; BytesToRead = 74
  67. ReadFile; BytesToRead = 74; BytesRead = 74
  68. ReadFile; Buffer =
  69. PeekNamedPipe; BytesInPipe = 28; BytesToRead = 28
  70. ReadFile; BytesToRead = 28; BytesRead = 28
  71. ReadFile; Buffer = DOWSsystem32ntkrnlpa.exe
  72. PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
  73. ReadFile; BytesToRead = 1; BytesRead = 1
  74. ReadFile; Buffer = 0OWSsystem32ntkrnlpa.exe
  75. PeekNamedPipe; BytesInPipe = 261; BytesToRead = 261
  76. ReadFile; BytesToRead = 261; BytesRead = 261
  77. ReadFile; Buffer = 000
  78. PeekNamedPipe; BytesInPipe = 26; BytesToRead = 26
  79. ReadFile; BytesToRead = 26; BytesRead = 26
  80. ReadFile; Buffer = WSsystem32ntkrnlpa.exe
  81. PeekNamedPipe; BytesInPipe = 288; BytesToRead = 288
  82. ReadFile; BytesToRead = 288; BytesRead = 288
  83. ReadFile; Buffer = 0000
  84. PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
  85. ReadFile; BytesToRead = 1; BytesRead = 1
  86. ReadFile; Buffer = 0000
  87. PeekNamedPipe; BytesInPipe = 218; BytesToRead = 218
  88. ReadFile; BytesToRead = 218; BytesRead = 218
  89. ReadFile; Buffer = 000
  90. PeekNamedPipe; BytesInPipe = 69; BytesToRead = 69
  91. ReadFile; BytesToRead = 69; BytesRead = 69
  92. ReadFile; Buffer =
  93. PeekNamedPipe; BytesInPipe = 1; BytesToRead = 1
  94. ReadFile; BytesToRead = 1; BytesRead = 1
  95. ReadFile; Buffer = 0Ì]Â
  96. PeekNamedPipe; BytesInPipe = 287; BytesToRead = 287
  97. ReadFile; BytesToRead = 287; BytesRead = 287
  98. ReadFile; Buffer = 000
Add Comment
Please, Sign In to add comment