------------------------------------求指点一个思路------------------------------------

vqt2prt12 2014-08-11 04:28:24
一个exe文件 别人的 我不能控制
它在dos下 会长时间不停的有内容输出

要把 它输出的内容实时的过滤
再重新输出

求思路
怎么获取CreateProcess 的内容
...全文
245 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
vqt2prt12 2014-08-14
  • 打赏
  • 举报
回复
我自己顶下了
vqt2prt12 2014-08-12
  • 打赏
  • 举报
回复
输出到文件 再读取 没别的方法了
707wk 2014-08-11
  • 打赏
  • 举报
回复
引用 11 楼 zhao4zhong1 的回复:
[quote=引用 10 楼 zhao4zhong1 的回复:] Hook INT10H
这是纯DOS下的思路。 Windows下参考下面:
#pragma comment(lib,"user32")
#include <stdio.h>
#include <windows.h>
int main() {
    SECURITY_ATTRIBUTES sa          = {0};
    STARTUPINFO         si          = {0};
    PROCESS_INFORMATION pi          = {0};
    HANDLE              hPipeOutputRead  = NULL;
    HANDLE              hPipeOutputWrite = NULL;
    HANDLE              hPipeInputRead   = NULL;
    HANDLE              hPipeInputWrite  = NULL;
    BOOL                bTest = 0;
    DWORD               dwNumberOfBytesRead = 0;
    DWORD               dwNumberOfBytesWrite = 0;
    CHAR                szMsg[100];
    CHAR                szBuffer[256];

    sa.nLength = sizeof(sa);
    sa.bInheritHandle = TRUE;
    sa.lpSecurityDescriptor = NULL;

    // Create pipe for standard output redirection.
    CreatePipe(&hPipeOutputRead,  // read handle
            &hPipeOutputWrite, // write handle
            &sa,      // security attributes
            0      // number of bytes reserved for pipe - 0 default
            );

    // Create pipe for standard input redirection.
    CreatePipe(&hPipeInputRead,  // read handle
            &hPipeInputWrite, // write handle
            &sa,      // security attributes
            0      // number of bytes reserved for pipe - 0 default
            );

    // Make child process use hPipeOutputWrite as standard out,
    // and make sure it does not show on screen.
    si.cb = sizeof(si);
    si.dwFlags     = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    si.wShowWindow = SW_HIDE;
    si.hStdInput   = hPipeInputRead;
    si.hStdOutput  = hPipeOutputWrite;
    si.hStdError   = hPipeOutputWrite;

    CreateProcess (
          NULL, "cmd.exe",
          NULL, NULL,
          TRUE, 0,
          NULL, NULL,
          &si, &pi);

    // Now that handles have been inherited, close it to be safe.
    // You don't want to read or write to them accidentally.
    CloseHandle(hPipeOutputWrite);
    CloseHandle(hPipeInputRead);

    // Now test to capture DOS application output by reading
    // hPipeOutputRead.  Could also write to DOS application
    // standard input by writing to hPipeInputWrite.
    sprintf(szMsg, "dir *.txt /b\nexit\n");
    WriteFile(
          hPipeInputWrite,      // handle of the write end of our pipe
          &szMsg,               // address of buffer that send data
          18,                   // number of bytes to write
          &dwNumberOfBytesWrite,// address of number of bytes read
          NULL                  // non-overlapped.
          );

    while(TRUE)
    {
       bTest=ReadFile(
          hPipeOutputRead,      // handle of the read end of our pipe
          &szBuffer,            // address of buffer that receives data
          256,                  // number of bytes to read
          &dwNumberOfBytesRead, // address of number of bytes read
          NULL                  // non-overlapped.
          );

      if (!bTest){
          sprintf(szMsg, "Error #%d reading pipe.",GetLastError());
          MessageBox(NULL, szMsg, "WinPipe", MB_OK);
          break;
      }

      // do something with data.
      szBuffer[dwNumberOfBytesRead] = 0;  // null terminate
      MessageBox(NULL, szBuffer, "WinPipe", MB_OK);
    }

    // Wait for CONSPAWN to finish.
    WaitForSingleObject (pi.hProcess, INFINITE);

    // Close all remaining handles
    CloseHandle (pi.hProcess);
    CloseHandle (hPipeOutputRead);
    CloseHandle (hPipeInputWrite);

    return 0;
}
[/quote]不明觉厉
赵4老师 2014-08-11
  • 打赏
  • 举报
回复
引用 10 楼 zhao4zhong1 的回复:
Hook INT10H
这是纯DOS下的思路。 Windows下参考下面:
#pragma comment(lib,"user32")
#include <stdio.h>
#include <windows.h>
int main() {
    SECURITY_ATTRIBUTES sa          = {0};
    STARTUPINFO         si          = {0};
    PROCESS_INFORMATION pi          = {0};
    HANDLE              hPipeOutputRead  = NULL;
    HANDLE              hPipeOutputWrite = NULL;
    HANDLE              hPipeInputRead   = NULL;
    HANDLE              hPipeInputWrite  = NULL;
    BOOL                bTest = 0;
    DWORD               dwNumberOfBytesRead = 0;
    DWORD               dwNumberOfBytesWrite = 0;
    CHAR                szMsg[100];
    CHAR                szBuffer[256];

    sa.nLength = sizeof(sa);
    sa.bInheritHandle = TRUE;
    sa.lpSecurityDescriptor = NULL;

    // Create pipe for standard output redirection.
    CreatePipe(&hPipeOutputRead,  // read handle
            &hPipeOutputWrite, // write handle
            &sa,      // security attributes
            0      // number of bytes reserved for pipe - 0 default
            );

    // Create pipe for standard input redirection.
    CreatePipe(&hPipeInputRead,  // read handle
            &hPipeInputWrite, // write handle
            &sa,      // security attributes
            0      // number of bytes reserved for pipe - 0 default
            );

    // Make child process use hPipeOutputWrite as standard out,
    // and make sure it does not show on screen.
    si.cb = sizeof(si);
    si.dwFlags     = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
    si.wShowWindow = SW_HIDE;
    si.hStdInput   = hPipeInputRead;
    si.hStdOutput  = hPipeOutputWrite;
    si.hStdError   = hPipeOutputWrite;

    CreateProcess (
          NULL, "cmd.exe",
          NULL, NULL,
          TRUE, 0,
          NULL, NULL,
          &si, &pi);

    // Now that handles have been inherited, close it to be safe.
    // You don't want to read or write to them accidentally.
    CloseHandle(hPipeOutputWrite);
    CloseHandle(hPipeInputRead);

    // Now test to capture DOS application output by reading
    // hPipeOutputRead.  Could also write to DOS application
    // standard input by writing to hPipeInputWrite.
    sprintf(szMsg, "dir *.txt /b\nexit\n");
    WriteFile(
          hPipeInputWrite,      // handle of the write end of our pipe
          &szMsg,               // address of buffer that send data
          18,                   // number of bytes to write
          &dwNumberOfBytesWrite,// address of number of bytes read
          NULL                  // non-overlapped.
          );

    while(TRUE)
    {
       bTest=ReadFile(
          hPipeOutputRead,      // handle of the read end of our pipe
          &szBuffer,            // address of buffer that receives data
          256,                  // number of bytes to read
          &dwNumberOfBytesRead, // address of number of bytes read
          NULL                  // non-overlapped.
          );

      if (!bTest){
          sprintf(szMsg, "Error #%d reading pipe.",GetLastError());
          MessageBox(NULL, szMsg, "WinPipe", MB_OK);
          break;
      }

      // do something with data.
      szBuffer[dwNumberOfBytesRead] = 0;  // null terminate
      MessageBox(NULL, szBuffer, "WinPipe", MB_OK);
    }

    // Wait for CONSPAWN to finish.
    WaitForSingleObject (pi.hProcess, INFINITE);

    // Close all remaining handles
    CloseHandle (pi.hProcess);
    CloseHandle (hPipeOutputRead);
    CloseHandle (hPipeInputWrite);

    return 0;
}
赵4老师 2014-08-11
  • 打赏
  • 举报
回复
Hook INT10H
vqt2prt12 2014-08-11
  • 打赏
  • 举报
回复
谢谢楼上了 我试试啊
liweiiewil 2014-08-11
  • 打赏
  • 举报
回复
给你查了一下:
在启动cmd时,用如下的命令:
cmd /k "mode 50,10"
或者启动cmd后用mode 50,10设置一下
此时缓冲区只有250个字符,之后用管道试一下。如果250个字符你还不认为是实时,那我这里没啥好办法了...
vqt2prt12 2014-08-11
  • 打赏
  • 举报
回复
不想输出到文件 能不能直接在内存里面处理 搜到用管道 继续求思路中.......
勤奋的小游侠 2014-08-11
  • 打赏
  • 举报
回复
引用 1 楼 ouyh12345 的回复:
试试重定向,再过滤
楼主要可以试下重定向。将程序输出到一个文件处理。
liweiiewil 2014-08-11
  • 打赏
  • 举报
回复
回复#4楼:
我的理解是:不会等程序完全输出完了你的程序再处理。程序一般有个buffer,buffer满了之后再输出到屏幕上。如果你输出的信息足够多,不用担心这个问题吧。
vqt2prt12 2014-08-11
  • 打赏
  • 举报
回复
2楼 liweiiewil 你这方法可以是可以 就是要等别的程序完全输出完了 我的程序才能再去处理 不能实时
leleyjg 2014-08-11
  • 打赏
  • 举报
回复
挺有挑战性的 等大家分享吧。。
liweiiewil 2014-08-11
  • 打赏
  • 举报
回复
它会输出到哪呢?
如果输出到屏幕上,那么就可以用管道的方法作为你的文件的输入。比如这个程序叫c:\a.exe,那么可以这么写:

c:\a.exe | b.exe

b.exe是你写的程序,在其内部可以用cin获取a.exe的输出,进行过滤后再输出即可。
ouyh12345 2014-08-11
  • 打赏
  • 举报
回复
试试重定向,再过滤

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧