Friday, 28 March 2014

[python] google developers tutorial

https://developers.google.com/edu/python/

readable and comprehensive

[tutorialspoint] Python Extension Programming with C

http://www.tutorialspoint.com/python/python_further_extensions.htm


For your first look at a Python extension module, you'll be grouping your code into four parts:
  • The header file Python.h.
  • The C functions you want to expose as the interface from your module.
  • A table mapping the names of your functions as Python developers will see them to C functions inside the extension module.
  • An initialization function

Structure
#include <Python.h>

static PyObject *module_func(PyObject *self, PyObject *args) {
   /* Do your stuff here. */
   Py_RETURN_NONE;
}

static PyMethodDef module_methods[] = {
   { "func", (PyCFunction)module_func, METH_NOARGS, NULL },
   { NULL, NULL, 0, NULL }
};

PyMODINIT_FUNC initModule() {
   Py_InitModule3(func, module_methods, "docstring...");
}
 

Example
#include <Python.h>

static PyObject* helloworld(PyObject* self)
{
    return Py_BuildValue("s", "Hello, Python extensions!!");
}

static char helloworld_docs[] =
    "helloworld( ): Any message you want to put here!!\n";

static PyMethodDef helloworld_funcs[] = {
    {"helloworld", (PyCFunction)helloworld, 
     METH_NOARGS, helloworld_docs},
    {NULL}
};

void inithelloworld(void)
{
    Py_InitModule3("helloworld", helloworld_funcs,
                   "Extension module example!");
}
 
 
Usage
setup.py

from distutils.core import setup, Extension
setup(name='helloworld', version='1.0',  \
      ext_modules=[Extension('helloworld', ['hello.c'])])

$ python setup.py install

Usage II
#!/usr/bin/python
import helloworld

print helloworld.helloworld()

Wednesday, 26 March 2014

Raspberry pi using SPI

http://www.brianhensley.net/2012/07/getting-spi-working-on-raspberry-pi.html

Original post guides through enabling RPi to connect to a micro controller.

He uses wheezy, but this works fine in nOS 2.2 as of March 2014.

I am only saving the commands required to enable it and test.

Background of SPI available at original link.

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install git

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update
sudo chmod +x /usr/bin/rpi-update
sudo rpi-update

sudo shutdown -h now

 #After reboot, check spidev0.0 is in fact available
ls /dev/

wget http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git\;a=blob_plain\;f=Documentation/spi/spidev_test.c -O spidev_test.c

#Original link command did not have escape letter, which did not work on my pi connection through SSH, so this one includes two escapes for ;

nano spidev_test.c
#change the device to spidev0.0
gcc spidev_test.c
sudo ./a.out

#if it does not work it will print 00s
#if it does work it will print FF 40 00 95 DE AD BE EF BA AD F0 0D
#MISO and  MOSI pins needs to be connected (GPIO 9 and GPIO 10)
#Positioning PI's HDMI port towards me, SD slot on the left, USB on the right, GPIO count begins from left bottom pin [1], incrementing to right up to GPIO 13.
#Then the top row left [14], to top right [26]


Raspberry pi backup SD card using linux

I use raspberry pi model B.

Due to my unstable power supply RPi had gone through many freeze/crashes.

This sudden change in voltage can corrupt SD card easily.

Restoring SD image and pop it back in, and save some downtime.

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=91&t=46911

    sudo dd if=/dev/mmcblk0 bs=4M | gzip > /home/your_username/image.gz

    gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/sdb

--

for me

sudo fdisk -l
#Showed sdcard as /dev/mmcblk0
sudo dd if=/dev/mmcblk0 bs=4M | gzip >/media/my/RPIbackup'date +%y%m%d'.gz

#To restore
sudo fdisk -l
gzip -dc /home/your_username/image.gz | sudo dd bs=4M of=/dev/mmcblk0

Thursday, 13 March 2014

How to start metasploit framework in kali linux

http://docs.kali.org/general-use/starting-metasploit-framework-in-kali

http://www.fastandeasyhacking.com/manual

start the db
service postgresql start
 
check for 5432 port
ss -ant

service metasploit start

launch console
mfsconsole

launch db and metasploit on boot
update-rc.d postgresql enable
update-rc.d metasploit enable

Debian wheezy kali linux installing jdk 7 by apt-get repository

http://stackoverflow.com/questions/15543603/installing-java-7-oracle-in-debian-via-apt-get

http://www.webupd8.org/2012/06/how-to-install-oracle-java-7-in-debian.html

su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
 
above can be simply typed/appended into /etc/apt/sources.list 
 
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
exit

Phoronix-Thread: PERFORMANCE OF FILESYSTEMS COMPARED (includes Reiser4 and Ext4).

http://phoronix.com/forums/showthread.php?1765-PERFORMANCE-OF-FILESYSTEMS-COMPARED-%28includes-Reiser4-and-Ext4%29

http://www.tech-analyser.com/2011/10/understanding-file-systemsntfs-fat.html



Use EXT2/3/4 format in External SD Card in Android

http://www.hackan.com.ar/2013/05/use-ext234-format-in-external-sd-card-in-android/#.Uxv7P8OycYx

In searching which file system gives best performance on SD card, above links showed up from google search