Closed Thread
Results 1 to 4 of 4

Thread: Sending output to a device driver

  1. #1
    DarkLordoftheMonkeys's Avatar
    DarkLordoftheMonkeys is offline Programming Professional
    Join Date
    Oct 2009
    Location
    Massachussets
    Posts
    255
    Blog Entries
    56
    Rep Power
    11

    Sending output to a device driver

    What would happen if you typed something like:

    Code:
    $ cat text.txt > /dev/console
    Would it overwrite the content of the device driver, or would it tell the device to do something, like say, display the contents of text.txt on the terminal? I want to explore this, because I think I could write some pretty powerful applications by sending output to device drivers, but I'm afraid I'll mess them up (if I have permission on them).
    Life's too short to be cool. Be a nerd.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    TimVim is offline Newbie
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Re: Sending output to a device driver

    I was bold enough to type your trojan into my console and apparently it doesn't do anything.

    Code:
    LimpPimp:~ timvim$ cat text.txt > /dev/console
    cat: text.txt: No such file or directory
    LimpPimp:~ timvim$

  4. #3
    saeras's Avatar
    saeras is offline Learning Programmer
    Join Date
    Jan 2010
    Location
    Sweden
    Posts
    67
    Rep Power
    8

    Re: Sending output to a device driver

    Cat('s) always strike when you least expect it. :3

  5. #4
    ETShost is offline Learning Programmer
    Join Date
    Nov 2009
    Location
    Flint, Michigan USA
    Posts
    48
    Rep Power
    0

    Re: Sending output to a device driver

    When writing to a device file, what happens depends on the device and how the driver is written.
    For example, writing to your sound device will actually play sound(of course that sound would have to be uncompressed first, otherwise it wouldn't sound very great). Writing to a modem's device file will give it instructions to dial a number(if you know what commands to write to it).

    Also in your example, writing to someones console device would cause the text you wrote to appear on their screen. However instead of writing to /dev/console you would write to their pseudo-terminal(AKA a pty). You can usually find out which pty a terminal device a session is attached to using the who command. You can open up multiple terminals a output text to different ones to see for yourself.

    Code:
    zpowers@zpowers-devel:~$ who
    zpowers  tty7         2010-02-16 09:43 (:0)
    zpowers  pts/0        2010-02-18 11:33 (:0.0)
    zpowers  pts/2        2010-02-18 12:57 (:0.0)
    zpowers  pts/3        2010-02-18 12:59 (:0.0)
    zpowers@zpowers-devel:~$ w
    10:59:36 up 3 days,  1:16,  4 users,  load average: 0.06, 0.01, 0.00
    USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
    zpowers  tty7     :0               Tue09    3days 43:12   0.28s gnome-session
    zpowers  pts/0    :0.0             Thu11   19:01   5.75s  5.65s ssh acm.umflint.edu
    zpowers  pts/2    :0.0             Thu12    1:29m  0.11s  0.11s bash
    zpowers  pts/3    :0.0             Thu12    0.00s  0.10s  0.01s w
    
    zpowers@zpowers-devel:~$ ls -l /dev/pts
    total 0
    crw--w---- 1 zpowers tty  136, 0 2010-02-19 10:59 0
    crw--w---- 1 zpowers tty  136, 1 2010-02-16 10:01 1
    crw--w---- 1 zpowers tty  136, 2 2010-02-19 09:34 2
    crw--w---- 1 zpowers tty  136, 3 2010-02-19 10:59 3
    c--------- 1 root    root   5, 2 2010-02-16 09:45 ptmx
    zpowers@zpowers-devel:~$ echo Hi! > /dev/pts/3
    Hi!
    zpowers@zpowers-devel:~$
    In this particular case I was using pseudo-terminal session number 3, and writing to the device caused text to appear in my terminal.

    Generally I wouldn't write to just any device without knowing what you are doing, or what will happen when you write to it. Bad things can happen(like if you were write directly to your RAM or worst cause more permanent damage by writing to your hard drive).
    ETShost .com - Exceeding Innovation
    Dedicated ServersVPS • Web Hosting
    24/7 Support | 1-866-259-2934

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. my device driver is dropping characters
    By onus in forum C and C++
    Replies: 10
    Last Post: 09-26-2010, 09:29 AM
  2. Replies: 0
    Last Post: 06-25-2010, 01:45 AM
  3. USB device driver in linux
    By B-80 in forum C and C++
    Replies: 5
    Last Post: 06-02-2010, 04:21 AM
  4. Replies: 6
    Last Post: 07-02-2009, 05:13 PM
  5. Sending AT commands to device connected to USB
    By susotest in forum C and C++
    Replies: 3
    Last Post: 01-21-2008, 03:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts