Unusual Features You Would Not Expect From a Terminal Emulator
Who doesn't wish they could work with Legos all day? Maybe it's time to bring the Lego-concept into the workplace, and begin building our software like our favorite, colorful bricks.
Join the DZone community and get the full member experience.Join For Free
i don’t know about you, but i love lego, i really do. back when i was a kid i actually didn’t have the original lego set; my father was a fan of more advanced construction toys like meccano and erector, where you had to screw parts together with nuts and bolts. however, being a programmer—and i am one—you get to appreciate the beauty of the lego concept.
building complex devices or systems by connecting simple blocks together is the essence of engineering, and you will be hard-pressed to find a better example of “complex from simple” than that offered by lego. all the blocks are compatible, all the blocks connect to other blocks easily, you don’t need any nuts, bolts or tools, and only your imagination is the limit for what you can build. and boy, have you ever tried to break * a lego brick? i dare you to accomplish this!
when we design software, this has got to be our ultimate goal. we want it to be like lego. we want it to be built with small building blocks, each one as simple and robust as a lego brick, each one interchangeable and easily interconnectable with other blocks.
unfortunately, it is not always possible to achieve this goal, and even when it is, we often find excuses for not going all the way in lego-izing our projects. after all, our customers (and most employers) usually only care about the end product, not the bricks it is built of.
i will argue, however, that investing time, money, and creative thinking into lego-izing your software product may reward you with unanticipated product strengths and features. in support of this statement, allow me to present exhibit a.
the case in point is our software called io ninja. here is a link to my introductory article covering the origins of ninja. to make the long story short, once upon a time we were looking for binary-enabled io terminals and sniffers for a specific set of transports and protocols. after not being satisfied with what we found (check the link above to find out why), we ended up creating our own all-in-one low-level io debugger. somewhere along the way we’ve got a crazy idea of making it programmable, so our users could write their own protocol analyzers and testing scripts. this is the preamble to what i want to tell you.
these two design goals—to build an all-in-one product and to make it programmable—have essentially forced a lego-like architecture upon us. so, this wasn’t even a choice; we couldn’t get away with the usual “the end product is what matters” mantra. in our case, the end product had to look a lot like lego!
here is what we ended up with: io ninja software consists of two large parts—the binary part and the script part. the binary part provides a framework of lego bricks: sockets, serial ports, sniffers, buttons, combo boxes and so on. scripts glue our lego bricks into specialized io sessions.
now comes the interesting part: after creating a lego-like design, we discovered that io ninja naturally has a plethora or interesting, useful, and unexpected features that were not anticipated even by us—the builders of this product!
ability to redirect anything-to-anything
users of unix-like systems are well-aware of the possibility of redirecting the output of one program to the input of another. session linking in io ninja provides similar functionality. the difference is this: instead of unidirectional data cascade of unix pipes, session linking shorts the tx stream of one session onto the rx stream of another, and vice versa. after this shorting, io ninja keeps passing the data back and forth between the two sessions. that turns io ninja into a universal redirector.
let’s say you have a device attached to your pc via a serial port, and you want to be able to connect to this device over tcp. that’s right. connect to a serial device over tcp.
launch io ninja and start a new serial session. open and configure your serial port. next, open a tcp listener session, choose a tcp port to listen on, and start listening.
now all is ready for you to reap the fruits of io ninja’s lego-like architecture! go menu->session->link sessions. voila! you can now connect to your serial device via tcp (notice the chain links on session tabs):
you can use the same approach for redirecting tcp-to-udp, udp-to-ssh, named pipe-to-tcp, and so on. as an extra bonus, all passing data will also be logged in the process, turning your setup into a universal man-in-the-middle sniffer.
searching for devices using udp broadcasts
a common way of auto-discovering devices on a local network segment is by broadcasting a udp request packet and collecting replies from participating devices. this is how tibbo’s software discovers our devices.
with io ninja’s modular architecture, we were able to take a lego brick of udp socket and plug it into a dedicated session specifically designed to handle one-to-many communications.
to try it, open a udp socket session, set the remote address to 255.255.255.255 (or to a subnet broadcast address like 192.168.1.255), then send an echo broadcast packet. as a result, you will see the list of devices connected to your local network segment. now choose one of these devices, copy-paste its ip address and start communicating with this particular device!
check out the compass button. when working with the udp protocol, you often need to reuse the source address from which the most recent packet has arrived (after all, udp is a connectionless protocol). of course, nothing prevents you from copying an address from the log and pasting it into the remote address combo box, yet why do something manually when you can automate the task? press the compass button, and the udp socket session will automatically readjust the remote address to the address from which the most recent packet was received.
sniffing tcp data using a tcp proxy
io ninja includes a network sniffer session. this is a pcap-based plugin for monitoring network protocols. when running it, io ninja behaves much like the wireshark software. despite the prevalence of pcap-based software tools, the reality is that the pcap-based approach is not the only way to eavesdrop on network communications. in some situations, using a pcap-based sniffer is simply not possible, and in some situations, there are much better ways to tap into the data stream.
in addition to the traditional pcap-based sniffer, io ninja provides the second kind of a tcp sniffer called a tcp proxy. it is a combination of two tcp sockets—a client one and a server one—passing data between each other.
here is the benefit of this approach: instead of a packet-based log (with disjoint chunks of data you must mentally piece together), your tcp proxy session provides a clean log of data streams, just like you would see in a tcp connection session. also, unlike with the pcap-based sniffing, which is only applicable to local networks, tcp proxy sessions allow you to monitor tcp links in all situations, as long as you can position yourself to be the man-in-the-middle.
here is a screenshot of an ftp session being monitored with the tcp proxy plugin:
debugging named pipes in windows
io ninja can be used to debug a very common ipc (inter-process communication) method in windows called named pipes . for example, all tibbo kernel-mode drivers use this method to communicate with user-mode services and configuration utilities.
unfortunately, debugging named pipes can be pretty tough due to the lack of named pipe terminals and monitors. before io ninja, you could not even send a packet over a named pipe without having to write a test application! naturally, we were determined to fix that. io ninja can work as both the client- and the server-side terminal for windows named pipe communications.
to use io ninja on the server side (the one that calls the connectnamedpipe function), launch the named pipe listener session. this plugin allows you to accept named pipe connections originating from your application, driver, or service, much like the tcp listener plugin accepts incoming tcp connections. after accepting a connection, you can communicate with a client and analyze the log of received commands.
for emulating the other side of named pipe communications, use the generic file session.
for monitoring named pipe communications you can employ the man-in-the-middle approach described earlier. to do so, start a named pipe listener session, link it to a generic file session and redirect your named pipe client to io ninja. in the future, we are planning to provide a dedicated standalone filesystem filter-based plugin for sniffing windows named pipes. for the time being, the man-in-the-middle approach will suffice for most debugging scenarios.
described above are just some of the many cool features stemming from the lego-like architecture of io ninja. allow me to repeat this: we haven’t even planned to implement some of those features, they simply appeared as a result of having a well-planned modular architecture. make no mistake, applying this lego principle to your project is a hard job. it requires a massive investment of time and effort, take my word on that. still, going down this path is well worth considering. who knows, maybe you will also discover a few unexpected and useful features magically appearing as a result of your lego-like approach.
so, let’s lego-ize!
originally published at: blog.tibbo.com
Opinions expressed by DZone contributors are their own.