Fun with USB RS232

http://www.loganpsychology.com.au/big/163.html Yes i am alive, pirated butter fish didn’t kill me.

купить кодеин Ломоносов Recently, in my great pile of E-Junk, i found a usb to rs232 converter that wasn’t in use. I decided to do something with it. with a little bit of reading, i made this:

синтез винта

Initially, i hooked up the motor to the txd and gnd pins of the rs232 port and hoped that it worked – it didn’t. It turns out that it doesn’t have enough current to drive the motor (it lit up LEDs though, I didn’t mess around with LEDs much as my LEDs might die from it :/). i figure i need some sort of external power supply, this is where the N-MOSFET comes in.

Anyways… this is what you need to make your own

Circuit Diagram

Assemble your board according to the diagram

 

You can then connect the positive and negative cables to any battery powered device you have lying around (i happened to have a spare propeller), for the battery, i used a standard 9v battery.

 

Mine turned out like this:

Connecting to Rs232 port

Connect the Gate pin of the mosfet to the RS232’s Txd  and Connecting GND pin to the source pin.

On the computer…

All you need to now is to send something to the port,

In *nix based systems(Linux, Mac, etc):
$ echo 1 > /dev/tty(WHATEVER)

Windows
C:\> echo 1 > COM(WHATEVER)

Notice that the more data you send to the port the longer the your powered device stays powered up. To keep your device powered for a longer time, you might want to write a scrip to loop trough it.

Here’s an idea…

Hook this up with twitter and a battery powered nerf gun and everytime someone mention you in twitter, your nerf gun will fire!

Share/Bookmark

ADBFS a FUSE Filesystem for Android Debug Bridge

Android Debugging Bridge in action

Android Debug Bridge(ADB) is usually used for debugging android devices. I personally use it to move files arround because mounting your sdcard can sometimes be a bitch. moving files around in command line isn’t fun too imagine typing the following:

adb push bla /sdcard/ultRa\ Long\ Directory/AnOther\ Long\Directory/bla

not fun…. so to solve this problem i wrote ADBFS. With adbfs, i can simply drag and drop files as usual.

Requirements

  • *nix Os (or any os that support FUSE – i think windows has a port.. not sure)
  • FUSE ( macfuse for mac users – windows, i don’t know.)
  • android sdk from  Android developers site
  • git

Installation

git clone git@github.com:isieo/adbFS.git .
cd adbFS
make
mv adbfs <location of android sdk>/tools/adbfs

Usage

mkdir ~/mounted-adb
adbfs mounted-adb

done! enjoy drag and drop without needing to “mount” your sdcard to your machine.

Note: adbfs can be very very slow at times, this is because your file manager is trying to access all the files to get data from it. ADB was never designed to do this so its not fast. Also this program is a proof-of-concept if anyone have a better implementation, please suggest.

License

/*
 *      Redistribution and use in source and binary forms, with or without
 *      modification, are permitted provided that the following conditions are
 *      met:
 *      
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following disclaimer
 *        in the documentation and/or other materials provided with the
 *        distribution.
 *      * Neither the name of the  nor the names of its
 *        contributors may be used to endorse or promote products derived from
 *        this software without specific prior written permission.
 *      
 *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

Warning

Very experimental =P its usable though i use this regularly to modify my playlist file.

Android Debugger Bridge Filesystem

Preventing CSRF in Kohana

Recently I found myself a neat CSRF module for kohana:

http://github.com/synapsestudios/kohana-csrf

I liked its simple design, you generate a token for your form then validate the token when its submitted. Unfortunately, I can’t use this solely for my project. The first issue with this module is that It will require me to manually add support for every single form and be very careful when adding AJAX and regular forms together. So i forked it.

http://github.com/isieo/kohana-csrf

What i did was i add a controller that returns the token as JSON and included a “fake javascript” file. My javascript is simple, its a simple jQuery script that injects a hidden field containing the token that was requested via AJAX, the token is then validated by the the controller automatically which upon success un-assign the token element from the $_POST array and reject if invalid. With that, CSRF tokens are transparent to your front end designers(if you are working with one) and all you need to tell your javascript programmer to do is call getCSRFToken() and post it in every Ajax Call.

Example usage for normal forms:

<!DOCTYPE html>
<html>
    <head>
        ...
        <script src="jquery-goes-here.js" />
        <script src="<?=url::site('/csrf/javascript/csrf.js');?>" />
    </head>
    <body>
        ...
        <form action="" method="post">
            <input type="email" name="emailaddress" />
            <input type="submit" value="submit">
        </form>
    </body>
</html>

that will work out of the box! no including pesky <input type=”hidden”> crap in your form.

Example using an AJAX call in jQuery:

$.post("<?=url::site('/email/add');?>", 
         { 
           'email':'someone@example.com',
           'csrf-token' : getCSRFToken() 
         }
       );

All you need to do is to add the ‘csrf-token’ : getCSRFToken()  into the ajax request. simple, no need to do callbacks for ajax calls that doesn’t require them.

Security in using JSON for getting token. Some of you might argue that serving tokens in JSON isn’t secure but if you read about JSONP (yes JSON with a P), you will notice that JSON doesn’t work well cross domain.  I am no security expert but hey, Accodring to: robubu.com there are no current vulnerabilities in using “serialized object” JSON (php’s json_encode function returns that by default).

So there you go a simple and nice module to prevent CSRF in kohana, coupled with jQuery Pouplate Plugin you get “pure html” forms that will make your frontend guy happy and not bug you for any assistant.

Update: As of 3 hours prior from this post, supports Namespaces to support multiple forms. but still.. its quite troublesome trying to keep track of token namespaces when you have many forms in a the same page which is going to make the frontend guy and you cry.. Its still a great module to use if you are working alone or you have an application that needs to be super-duper-uber-hacker-proof secure.