Posts

    Thursday, 30 October 2014

    How to mount NTFS External Disk in write mode in OS X Yosemite

    This works for Mavericks also :)

    It is not possible by default to mount a NTFS External Drive in write mode on OS X since Mavericks. There is a complex way to do this. In order to make it simple for you, I wrote a script which does it.

    First you need to install Xcode and Homebrew. Google how to install them :P

    Download this script


    Then do this:
    chmod +x ntfs_write_mode_enabler
    ./ntfs_write_mode_enabler

    Now connect the driveIn Mavericks you will get a warning “Kernel extension is not from an identified developer”. You are good to go if you click OK. However, if you are using Yosemite, you have to restart your system to load the kernel extension. For more on that read this.

    In Yosemite you might get the following error if you are updating old osxfuse. As we have enabled developer mode which allows you to run unsigned kext, it will not be a problem.

    osxfuse: OS X Mavericks or older is required for this package.

    OS X Yosemite introduced a strict unsigned kext ban which breaks this package.You should remove this package from your system and attempt to find upstream binaries to use instead.

    Uninstalling


    Execute the following command to replace the modified NTFS mounter with the original one

    sudo mv /sbin/mount_ntfs.old /sbin/mount_ntfs

    Loading unsigned kernel extensions on Yosemite

    Since Mavericks, OS X started checking signatures of kernel extensions. However unlike in Mavericks, loading unsigned code to kernel is disabled in Yosemite (in Mavericks only a warning, “Kernel extension is not from an identified developer” was displayed). It is required to sign kernel extensions using the Developer ID obtained after enrolling in Mac Developer program. With Yosemite still in beta, it is hard to find signed kernel extensions other than the ones officially released by Apple. 

    You will get this error when you try to load unsigned kext:

    Diagnostics for [unsigned kext]:
    Code Signing Failure: not code signed
    ERROR: invalid signature for [unsigned kext], will not load

    This being said, it is possible to sign all unsigned kext by doing this:

    sudo nvram boot-args="kext-dev-mode=1"
    Restart to get all the kext running!

    Wednesday, 29 October 2014

    Porting from Eclipse to Android Studio on mac

    First download android studio from here.

    Install Android studio from the .dmg file as usual

    Now, before opening Android studio, open the terminal and delete the sdk which comes with it.

    cd /Applications/Android\ Studio.app
    rm -rf sdk

    Now create a link of your old sdk in that folder

    ln -s [absolute path to old sdk]  /Applications/Android\ Studio.app/sdk

    Now open Android studio like any other app and open your existing project. You are good to go!


    Or follow this to migrate your eclipse project to gradle!

    Monday, 6 October 2014

    How to fix blurry windows on retina display on mac

    You might've observed that some third party apps have blurry windows on mac. This is due to the fact that those apps are not making use of the retina display introduced by Apple sometime back. I found a simple way to fix this using an app called Retinizer. Simply drag and drop the app (.app file from Applications folder) to its window to "Retinize" the app!

    DOWNLOAD: http://retinizer.mikelpr.com/


    Sunday, 5 October 2014

    The curious case of deleting .nomedia file

    Deleting .nomedia file not enough to make a folder visible in android gallery

    TL;DR: After removing .nomedia file, add/delete some file in that folder.

    You might probably know that if you want to hide a folder from gallery all you have to do is create an empty file called .nomedia. This will make sure that the media scanner will skip that folder.

    Sometime back I did this when I wanted to hide the Whatsapp folder from gallery. Now I changed my mind and want Whatsapp folder to show up in the gallery. So I did like any other guy would do -- I deleted .nomedia file from that folder. But this didn't work.

    If I had any android version prior to Kitkat, I could've just run media scanner from some app. Unfortunately after Kitkat this wouldn't work (They changed how media scanner works to save battery).

    Then I tried renaming the folder (after deleting .nomedia file). Magically, all the images started displaying in the gallery. However, I couldn't afford changing the name of the folder.

    I realized that post jellybean, media scanner updates the media index only when there is a change in the folder. So, I just added a new image to that folder manually. It worked like a charm!

    NOTE: If the folder is on sdcard, you can just remove the sdcard and put it back (after removing .nomedia file) to run media scanner.

    Tuesday, 30 September 2014

    How to open apps from terminal on mac

    I switched to mac from ubuntu recently. I noticed that apps installed from .dmg files are not accessible from terminal. In ubuntu to open say, gvim (MacVim in mac) I used to simply type gvim in the terminal. This doesn't work on mac :(

    After doing some analysis on how apps are maintained, I noticed that each application (.app) is stored in /Applications folder. And .app file is simply a directory holding contents of the app. Say I open firefox, the executable which launches the app (firefox), stored in /Applications/Firefox.app/Contents/MacOS is executed.

    So if I execute:
    /Applications/Firefox.app/Contents/MacOS/firefox
    from terminal, firefox is launched!

    However I do not want to type this huge path every time I want to launch firefox nor do I want to alias each and every app I install nor do I want to add all of them to $PATH. So I wrote a simple script to automatically open any app I want to.

    Step1


    Download this gist

    Step2


    Make it executable and move it to /usr/bin. You are done!

    $ chmod +x app

    $ sudo mv app /usr/bin/


    How to use it?


    Say you want to open chrome from terminal to open a html file

    $ app chrome index.html

    Say you want to launch vlc from terminal to open a file

    $ app vlc file.mp4

    Say you want to open MacVim from terminal and open a file. Note that it is case insensitive.

    $ app macvim file

    Thursday, 25 September 2014

    ShellShock: Largest security bug ever in the computing world

    ​'Bigger than Heartbleed': Bash bug could leave IT systems in shellshock
    - CNET

    Shell Shock: Bash bug labelled largest ever to hit the internet
    - Sydney herald

    You might have heard about "ShellShock" bug in bash shell that everyone is talking about. You might ask what is the big deal about it? and say that you don't even use bash. It might astound you if I say that this bug exists in so many systems from your fancy smart watches to android phones to Macbooks to powerful web/email/DHCP servers. Basically, bash shell is used everywhere!
    "Heatbleed" bug, a vulnerability in OpenSSL servers, created a huge fuss few months back. Experts think that ShellShock is much more serious than that considering the number of systems being affected. Lot of military and government organizations are at risk.


    So what is Shell Shock?

    It is a vulnerability present in bash till 4.3. Because of this lot of applications using bash are not safe. This 22 yr old bug exists because of the way bash handles environment variables. It is common to assign a function to an environment variable in shell scripts. However it was noticed that the trailing code in the function definition is also executed. Hence it is possible to remotely execute malicious code in many websites by just injecting it at the end of function definition.

    To give more detail consider:

    env X="() { pwd; ls;}; echo hacked" bash -c "echo done"

    The result is:
    hacked
    done

    After function definition, malicious code echo hacked was also executed!

    Am I safe?

    Open terminal and execute this:

    env X="() { pwd; ls;}; echo hacked" bash -c "echo done"

    You have to worry if the result is:
    hacked
    done

    instead of
    done

    In action!

    There are three files in the folder:
    DO_NOT_DELETE_THIS.txt
    IMPORTANT.txt
    I_WILL_GET_FIRED_IF_I_LOSE_THIS_FILE.txt

    after executing this all files get deleted!:

    env X="() { :;}; rm -rf *" bash -c "echo completed"

    Note that rm -rf * is injected (Here I have just typed :P) and it wipes the folder clean



    How to fix this?

    Considering the amount of legacy code which can't be modified, we need a patch in bash itself. Fortunately, a workaround is provided by RedHat here.
    Sysadmins make sure that you apply this patch if you don't want to get fired :P

    Worth Reading


    Bash 'shellshock' bug is wormable

    ​'Bigger than Heartbleed': Bash bug could leave IT systems in shellshock



    Wednesday, 17 September 2014

    42.zip - Zip Bomb!

    I was reading online sometime back and I came across this really interesting thing called 42.zip also known as Zip Bomb, Zip of Death, Peta bomb or decompression bomb.

    The file is only 42,374 bytes (42KB). When unzipped it becomes 4,503,599,626,321,920 bytes (4.5 Peta Bytes)!!!

    The main use of it is to render useless the host reading the file, usually to disable antivirus. When you unzip it, the antivirus will be busy scanning the unzipped files, sucking up all the available resources and a malicious program injected can execute itself undetected!

    How it works?
    42.zip has 16 zipped files.
    Each of these 16 have 16 zipped files.
    Each of these have 16 zipped files.
    Each of these have 16 zipped files.
    Each of these have 16 zipped files.
    Each of these have 1 file, with the size 4.3GB

    Still. How is this level of compression achieved??
    It relies on repetition of identical files!! Think of it as same file being unzipped over and over again.
    Awesome isn't it?!



    Also read Fork Bomb.

    Tuesday, 2 September 2014

    Convert Little-endian UTF-16 to ascii

    I took a csv export from mssql. I had to read this file in python. However there was a problem. Python was reading it in binary format.

    file.readlines read it like this:

    '\xff\xfe2\x000\x001\x003\x00-\x001\x000\x00-\x001\x000\x00 \x000\x000\x00:\x000\x002\x00:\x000\x000\x00,\x00i\x00n\x00s\x00t\x00a\x00l\x00l\x00 \x002\x000\x001\x003\x00,\x00t\x00o\x00o\x00k\x00 \x00r\x00a\x00\r\x00\n'

    When i used file command on that file I got:

    Little-endian UTF-16 Unicode text, with very long lines, with CRLF, CR line terminators

    When I tried to use dos2unix command I got this error:

    dos2unix: Binary symbol 0x000B found at line 9419305
    dos2unix: Skipping binary file calls.csv

    So I tried iconv command to convert the file to urf-8

    iconv -f utf-16 -t utf-8 input_file > output_file

    And it worked! Now python reads it properly.


    Open file in existing gvim in new tab

    We know that gvim -p can be used to open multiple files together in different tabs in gvim. However if you want to open a file in a new tab in the existing gvim session "gvim -p" wont do any good. For that we can use client server concept available in gvim. Add the following line in "~/.bashrc" file and you are good to go!

    alias gvim='gvim --servername gViM --remote-tab'

    Now you can simply give gvim [file(s)] to open in new tab in the existing gvim session!