Re: man-in-the-middle translation of input



In article <eapvt1$4fui8$1@xxxxxxxxxxxxxx>,
Daniel Franke <franke@xxxxxxxxxxxxxxx> wrote:

Hi there.

I would like to ease my life with an interactive console based program
(source not available). This program (a MUD like game, actually) takes a
couple of commands. For some of its puzzles, it's tiring to retype the same
command sequences over and over again. Therefore I decided to write a small
program that spawns the game, forwards its output to stdout, reads my input
at stdin, checks for keywords and either forwards the command as-is or
replaces my input by a series of valid game commands. To achieve this, I
tried a combination of pipe(), fork(), dup2(), execve(), select(), read()
and write() but failed. While I can easily permit the spawned child to
write to stdout, I couldn't find a way to read from stdin, preprocess the
input and feed it through a pipe to the child (invalid seek).

You need TWO pipes, one for the child's stdin, and the other for its
stdout/stderr. Your MITM program should read from its stdin, preprocess
this, and write to its end of the child's stdin pipe. It should also
read from its end of the child's stdout pipe and write this to its own
stdout.

Actually, you may not need the second pipe. If you don't need to modify
the child's output, you can simply let it inherit your stdout and write
to it directly.

Which program is reporting the invalid seek, the child or your MITM?
I'm not sure why the MUD would be trying to seek, since you can't seek
on a terminal device, which is presumably its normal stdin.

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • Re: Check Pop3 or IMAP4
    ... I read somewhere that telnet does not support stdin and stdout. ... to send commands to the port 110. ... This works only if the server doesn't require the encoding of the password, ...
    (microsoft.public.scripting.vbscript)
  • Re: How to redirect stdout to stdin?
    ... stdout of nc to its stdin. ... If you could connect the output of a command to its input, ... Use a pair of pipes, at least one of which must be a named pipe ...
    (comp.unix.shell)
  • Re: how to split STDOUT into 2 or more output streams
    ... >>I want to log a process and its children's output into a log file, ... >>printing the output on STDOUT. ... dup STDOUT and STDERR from pipe; ... close STDIN ...
    (comp.unix.programmer)
  • Running pipes
    ... if (fork() == 0) ... close STDIN; close STDOUT; close STDERR ... less complex pipe, and it needed to close the STDIN and STDOUT ...
    (comp.lang.perl.moderated)
  • feed stdin of cmd.exe
    ... My windows program creates two named pipes, ... the StartupInfo parm to pass the pipe handles as the StdInput, ... that::ReadFile from stdin and::WriteFile to stdout. ... But I cant get it to read what I feed on stdin. ...
    (microsoft.public.win32.programmer.kernel)