Friday, July 14, 2023

building ".so" file i.e. shared library for getch, getche , clrscr & gotoxy, for command prompt ( terminal )

 "clrscr-getch.h" header and shared library file : "libclrscr-getch.so" to getch, getche , clrscr & gotoxy for terminal in C++ in centos 7 linux. :-
-----------------------------------------------------------------------

first open codeblocks IDE-> new project -> shared library -> next -> C++ :-

1. project title   : clrscr-getch
2. folder project : /opt/so-file/clrscr-getch
3. project name   : clrscr-getch
4. resulting file name : automated by IDE
 

This "so" file name will be same as name of "project title ".

Now :-
------

1. remove main.cpp
2. Project -> Build options ->  Position Independent Code(-fPIC) -> right tick on it.
3. Have g++ follow the coming C++1y (aka C++14) ISO C++ language standard -> right tick on it.
4. Target x86_64 (64bit) -> right tick on it.
5. new file :-
important point : do not add new class to this project because if you do this,
resultant "so" file header will not be able to added in calling cpp project, for example if you build a so file as "so-file.so" and header file "so-file.h" to call its functionalities. Now you add this shared object and header files in your "so-file.so" calling CPP project. In place where we add header file via "#include" directive, intellisense does not recognize it's header file here "so-file.h" will not be added.
    To get it recognized, you need to add as this :-
1. new -> file -> C/C++ header -> next ->
   i. file name with full path :- "clrscr-getch.h"
   ii. Header guard will be generated automatically.
   iii. add file to active project : right tick on both Debug and Release
   
2. new -> file -> C/C++ source -> next -> C++ ->
    i. file name with full path : "clrscr-getch.cpp" - be sure name should be same as header file but extension is ".cpp".
    ii. Add file to active project : right tick on both Debug and Release -> finish.
3. project -> properties -> bin/Debug/libclrscr-getch.so
                            bin/Release/libclrscr-getch.so
    here "libclrscr-getch.so" name by default will be "liblibclrscr-getch.so"
    you need to change it to from double "liblib..." to single "lib..."
    as from "liblibclrscr-getch.so" to "libclrscr-getch.so".
    this "so" file name will be same as name of project name. As here mine project name is : "clrscr-getch".
-------------------------------------------------------------------------

Code :-
----------

add header file : "clrscr-getch.h" :-
----------------------------------------

#ifndef CLRSCRGETCH_H_INCLUDED
#define CLRSCRGETCH_H_INCLUDED

#include <iostream>
#include <sys/ioctl.h>
#include <unistd.h>

#include <termios.h>
#include <cstdio>
#include <iomanip>

static struct termios oldterm, newterm;

class CClrscrGetch
{
public:
    CClrscrGetch();
    virtual ~CClrscrGetch();

    void gotoxy(int x, int y);
    void clrscr();
    void clrscr(int x1, int y1, int x2, int y2);


    char getch();
    char getche();

protected:

private:

    void initTermios(bool echo);
    void resetTermios();
    char getch_(bool echo);
};

#endif //CLRSCRGETCH_H_INCLUDED

---------------------------------------

add source File : "clrscr-getch.cpp" :-
--------------------------------------------------------
#include "clrscr-getch.h"
#include <cstdio>


using std::cin;
using std::cout;

CClrscrGetch::CClrscrGetch()
{
    //ctor
}

CClrscrGetch::~CClrscrGetch()
{
    //dtor
}

void CClrscrGetch::gotoxy(int x, int y)
{
    printf("%c[%d;%df", 0x1B, y, x);
}

void CClrscrGetch::initTermios(bool echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void CClrscrGetch::resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char CClrscrGetch::getch_(bool echo)
{
    char ch;
    initTermios(echo);
    ch = getchar();
    resetTermios();

    return ch;
}

char CClrscrGetch::getch()
{
    char ch = getch_(false);
    return ch;
}

char CClrscrGetch::getche()
{
    char ch = getch_(true);
    return ch;
}

void CClrscrGetch::clrscr()
{
    gotoxy(0, 0);
    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);

    for( int i = 0; i < w.ws_row; i++)
    {
        for(int j = 0; j < w.ws_col; j++)
        {
            cout << " ";
        }
    }
    gotoxy(0, 0);
}

void CClrscrGetch::clrscr(int x1, int y1, int x2, int y2)
{    

    int k = y1;
    gotoxy(x1, y1);

    for( int i = 0; i < x2; i++)
    {
        for(int j = 0; j < y2; j++)
        {
            cout << " ";
        }

        gotoxy(x1, ++k);
    }
    gotoxy(x1, y1);
}
----------------------------------------------------------
resultant "so" will be generated in folder "Debug" or "Release" with "so" extension.

To get it to include in all projects, this file to be recognized locally (under account of its own user) or globally (for all users account). To do that you can do this :-
    i. add it to local user : gedit -> open -> or "home/<user>/.bash_profile".
        add this : "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path to your so file>"
    ii. add it for all users (globally) :
        1. login as root user
        2. gedit -> open -> /etc/profile" and add following (for example) :-
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/so-file/clrscr-getch
 
 here "/opt/so-file/clrscr-getch" is path of shared object file path to shared as globally.
         3. or you can also put in "/usr/lib" or "/usr/lib64/" or "/usr/local/lib/" or "/usr/local/lib64/"
         this will look this file as globally for all applications.
         But may be name clashing happen, so it is convenient to create folder as named "clrscr-getch" then paste shared library. 

        4. For "header file" - "clrscr-getch.h" put this in "/usr/include/clrscr-getch/", or where you are convenient to add header file that is easier to understand or search in your calling project by compiler. As I added here "/opt/so-files/include/headers/".
----------------------------------------------

Now we will call this shared object file in our CPP project :-
--------------------------------------------------------------

1. new -> project -> Console application -> next -> C++ ->
    i. Project title : test-ops
    ii. Folder to create project in : give path to project location
    iii. project name and resultant file name : manage it by self.
    iv. finish.
2. Project -> build options ->     
    i. Have g++ follow the coming C++1y (aka C++14) ISO C++ language standard -> right tick on it.
    ii. Target x86_64 (64bit) -> right tick on it.
3. linker settings : add -> clrscr-getch
    here IDE will add this shared object file as : "-lclrscr-getch"
    you do not need to add full name - with extension.
4. search directories ->
    i. Compiler -> add ->/opt/so-file/clrscr-getch
        path to header file : in my case path of "clrscr-getch.h" .
        you can give here as either absolute or relative path.
    ii. Linker -> add -> /opt/so-file/clrscr-getch
        path to shared object ".so" file :  in may case path of "libclrscr-getch.so"
5. add using include directive of header file :    <clrscr-getch.h>
    if it is not in intellisense "Reparse this project" as : right click on project name and select "Reparse this project". Then try again.

6. While you are in terminal and there is problem of can not find shared library of given name. Then run following command to reload global profile ( /etc/profile) or local profile (~/.bash_profile ) :-

# source /etc/profile ( press enter  )

$ ./test-so ( press enter ) ( mine "so" file test project )
 

// example file : project : test-ops :-
---------------------------------------
#include <iostream>
#include <clrscr-getch.h>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;

    CClrscrGetch *get = new CClrscrGetch;

    get->gotoxy(2, 4);

    cout << "Hello i am here";

    get->getch();

    get->clrscr();

    get->getch();

    get->gotoxy(3, 9);

    cout << "I am Here";

    get->getch();
    get->gotoxy(4, 60);
    cout << "enter char : ";
    char ch = get->getche();

    get->gotoxy(23, 12);

    cout <<"you entered : " << ch;

    get->getch();

    get->clrscr();

    return 0;
}

---------------------------------------------
Now you can add this "clrscr-getch.h" header and shared library file : "libclrscr-getch.so" into different projects and declare an object or pointer to object of class "CClrscrGetch" and initialize it. then using it you can access functions : "gotoxy(int x, int y), clrscr(), clrscr(int x1, int y1, int x2, int  y2) for clearing a rectangle in terminal, getch() and getche()"
  
    NOW THIS IS COMPLETE
------------------------------------------------------------------

Wednesday, July 12, 2023

shared library (".so") file in C++ in Centos 7 Linux

 ".so" file - "shared object file" i.e. "shared library file" creation in C++ in centos 7 linux. :-
----------------------------------------------------------------------------------------------------

before building ".so" library, build your C++ project for that library, so that we can test working of targeted library file. After successfully testing and seeing proper output and functionality checking, build  library. This way is easier than  directly building ".so" file, because we can not test functionality of ".so" lib file in shared library project. It needs runnable program to test. So first test than build library.


first open codeblocks IDE-> new project -> shared library -> next -> C++ :-

1. prject title   : so-file
2. folder project : /opt/projects/so-file
3. project name   : so-file
4. resulting file name : automated by IDE

This "so" file name will be same as name of "project title ".

Now :-
------

1. remove main.cpp
2. Project -> Build options -> tick on Position Independent Code(-fPIC) -> right tick on it.
3. Have g++ follow the coming C++1y (aka C++14) ISO C++ language standard -> right tick on it.
4. Target x86_64 (64bit) -> right tick on it.
5. new file :-
important point : do not add new class to this project because if you do this,
resultant "so" file header will not be able to added in calling cpp project. For example if you build a so file as "so-file.so" and header file "so-file.h" to call its functionalities. Now you add this shared object and header files in your "so-file.so" calling CPP project. In place where we add header file via "#include" directive, intellisense does not recognize it's header file e.g. "so-file.h" will not be added.
    To get it recognized you need to add as this :-
1. new -> file -> C/C++ header -> next ->
   i. file name with full path :- "so-build-w-class.h"
   ii. Header guard will be generated automatically.
   iii. add file to active project : right tick on both Debug and Release
   
2. new -> file -> C/C++ source -> next -> C++ ->
    i. file name with full path : "so-build-w-class.cpp" - be sure name should be same as header file but extension is ".cpp".
    ii. Add file to active project : right tick on both Debug and Release
    -> finish.
3. project -> properties -> bin/Debug/lib01-so-test-h-s.so
                            bin/Release/lib01-so-test-h-s.so
    here "lib01-so-test-h-s.so" name by default will be "liblib01-so-test-h-s.so"
    you need to change it to from double "liblib..." to single "lib..."
    as from "liblib01-so-test-h-s.so" to "lib01-so-test-h-s.so".
    this "so" file name will be same as name of project name. As here mine project name is : "01-so-test-h-s".
-------------------------------------------------------------------------
Example :-
----------

file : "so-build-w-class.h" :-
------------------------------

#ifndef SO-BUILD-W-CLASS_INCLUDED
#define SO-BUILD-W-CLASS_INCLUDED

class print_one
{
public:
    print_one();
    virtual ~print_one();

    void print();
    void read();

protected:

private:

    int i, j;

};

#endif // SO-BUILD-W-CLASS_INCLUDED
---------------------------------------

File : "so-build-w-class.cpp" :-
--------------------------------
#include "so-build-w-class.h"
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

print_one::print_one()
{
    //ctor
    i = j = 5;
}

print_one::~print_one()
{
    //dtor
}

void print_one::print()
{
    cout << "i = " << i << endl;
    cout << "j = " << j << endl;
}

void print_one::read()
{
    cout << "i = ";
    cin  >> i;
    cout << "j = ";
    cin  >> j;
}


resultant "so" will be generated in folder "Debug" or "Release" with "so" extension.

To get it to include in all projects, this file to be recognized locally (under account of its own user) or globally (for all users account). To do that you can do this :-
    i. add it to local user : gedit -> open -> or "home/<user>/.bash_profile".
        add this : "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path to your so file>"
    ii. add it for all users (globally) :
        1. login as root user
        2. gedit -> open -> /etc/profile" and add following (for example) :-
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/oracle/instantclient_11_2:/opt/project/lpi/lpi_headers:/opt/so-files:/opt/so-files/so-file-test-without-class/so-files-wc
 
 here "/opt/so-files/so-file-test-without-class/so-files-wc" is path of shared object file path to shared as globally.
         3. or you can also put in "/usr/lib" or "/usr/lib64/" or "/usr/local/lib/" or "/usr/local/lib64/"

        4. or you can make directory "/usr/lib64/your_dir" and paste it your "so" file.


         this will look this file as globally for all applications.
         But may be name clashing happen.
----------------------------------------------

Now we will call this shared object file in our CPP project :-
--------------------------------------------------------------

1. new -> project -> Console application -> next -> C++ ->
    i. Project title : Calling-CPP-project
    ii. Folder to create project in : give path to project location
    iii. project name and resultant file name : manage it by self.
    iv. finish.
2. Project -> build options ->     
    i. Have g++ follow the coming C++1y (aka C++14) ISO C++ language standard -> right tick on it.
    ii. Target x86_64 (64bit) -> right tick on it.
3. linker settings : add -> 01-so-test-h-s
    here IDE will add this shared object file as : "-l01-so-test-h-s"
    you do not need to add full name - with extension.
4. search directories ->
    i. Compiler -> add -> /opt/so-files/so-file-test-without-class/so-files-wc
        path to header file : in may case path of "so-build-w-class.h".
        you can give here as either absolute or relative path.
    ii. Linker -> add -> /opt/so-files/so-file-test-without-class/so-files-wc
        path to shared object ".so" file :  in may case path of "lib01-so-test-h-s.so"
5. add using include directive of header file :    <so-build-w-class.h>
    if it is not in intellisense "Reparse this project" as : right click on project name and select "Reparse this project". Then try again.
 

// example file : project : calling-cpp :-
------------------------------------------
#include <iostream>

#include <so-build-w-class.h>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;

    print_one p;

    p.print();

    cout << "Ente i and j : " << endl;

    p.read();

    cout << endl;

    p.print();

    return 0;
}
 

output :-


[rahul@C-Client Debug]$ ./calling-cpp
Hello world!
i = 5
j = 5
Ente i and j :
i = 3
j = 4

i = 3
j = 4
[rahul@C-Client Debug]$
   
    NOW THIS IS COMPLETE
------------------------------------------------------------------

Friday, June 16, 2023

showing bits of int as it is saved as in memory in C

#include <stdio.h>
#include <stdlib.h>

void showBits(int s)
{
    int status, i, j, k, result, sz, bitStatus;
    int ibits[64]; // size of int in 64 bit OS is 64 bits = 8 bytes.
    char *pchi, jbit, chi;

    result = s;
    sz = sizeof(result);
    pchi = (char*)(&result);

    for(i = 0; i < sz; i++)
    {
        jbit = 0x01;
        chi = *pchi;

        for(j = 0; j < 8; j++)
        {
            bitStatus = (chi & jbit);
            chi = chi >> 1;
            ibits[(i * 8) + j] = bitStatus;
        }
        pchi++;
    }

    for(k = 63; k >= 0; k--)
    {
        printf("%d", ibits[k]);
    }
}

int main(int argc, char ** argv)
{
    int i, status, result, num;

    if( argc != 2)
    {
        printf("--Help \nshowBits int_value\n");
        return 0;
    }
    num = atoi(argv[1]);

    printf("\n");
    showBits(num);

    printf("\n");

//    printf("\n");
//    showBits(0);
//
//    printf("\n");
//    showBits(-1);
//
//    printf("\n");

    return 0;
}

/*

output :-
---------
[rahul@C-Client Debug]$ ./showBits 1

00000000000000000000000000000001
[rahul@C-Client Debug]$ ./showBits 0

00000000000000000000000000000000
[rahul@C-Client Debug]$ ./showBits -1

11111111111111111111111111111111
[rahul@C-Client Debug]$ ./showBits -2

11111111111111111111111111111110
[rahul@C-Client Debug]$

Note : negative numbers are stored in memory in two's complements.
so "-1" = all 1s : 11111111111111111111111111111111

*/

Monday, May 15, 2023

VLC media player installation in Centos 7 Linux

 how to install VLC player :-
------------------------------------------

here firstly you must connected to internet.


first download and install following repo : 

 epel-release-7-11.noarch.rpm 

# rpm -ivh --force epel-release-7-11.noarch.rpm

to get hands on linux search RHCSA video tutorial for centos 7 linux in youtube.

then login as root user and run yum command :

# cd /opt
# mkdir vlc-rpms
# cd vlc-rpms
# yum install vlc --downloaddir=.

this command will download all rpms in  directory '/opt/vlc-rpms".

now run following command to install all rpms at once :

# rpm -ivh --force *.rpm

here you must be inside dir where all rpms are downloaded.

OR install separately download following rpms  from "pkgs.org" web site and download individually. Install via above command for "*.rpm"

aalib-libs-1.4.0-0.22.rc5.el7.x86_64.rpm
crystalhd-firmware-3.10.0-11.el7.noarch.rpm
epel-release-7-11.noarch.rpm
faad2-libs-2.7-5.el7.nux.x86_64.rpm
faad2-libs-2.7-9.el7.x86_64.rpm
fdk-aac-0.1.4-1.x86_64.rpm
ffmpeg-libs-2.8.15-2.el7.nux.x86_64.rpm
ffmpeg-libs-3.4.8-1.el7.x86_64.rpm
fluidsynth-libs-2.1.8-4.el7.x86_64.rpm
fribidi-1.0.2-1.el7.x86_64.rpm
ftgl-2.1.3-0.8.rc5.el7.x86_64.rpm
game-music-emu-0.6.2-1.el7.x86_64.rpm
gnome-vfs2-2.24.4-14.el7.x86_64.rpm
jack-audio-connection-kit-1.9.9.5-6.el7.x86_64.rpm
lame-libs-3.100-1.el7.x86_64.rpm
liba52-0.7.4-27.el7.x86_64.rpm
libaom-3.1.1-1.el7.x86_64.rpm
libass-0.13.4-6.el7.x86_64.rpm
libcaca-0.99-0.17.beta17.el7.x86_64.rpm
libcddb-1.3.2-12.el7.nux.x86_64.rpm
libcddb-1.3.2-12.el7.x86_64.rpm
libchromaprint-1.0-1.el7.x86_64.rpm
libcrystalhd-3.10.0-11.el7.x86_64.rpm
libdav1d-0.5.2-2.el7.x86_64.rpm
libdc1394-2.2.2-3.el7.x86_64.rpm
libdca-0.0.5-7.el7.nux.x86_64.rpm
libdca-0.0.5-9.el7.x86_64.rpm
libdvbpsi-1.3.3-1.el7.x86_64.rpm
libebml-1.3.9-1.el7.x86_64.rpm
libffado-2.1.0-4.el7.x86_64.rpm
libGLEW-1.10.0-5.el7.x86_64.rpm
libkate-0.4.1-5.el7.x86_64.rpm
libmad-0.15.1b-26.el7.x86_64.rpm
libmatroska-1.5.2-1.el7.x86_64.rpm
libmfx-1.21-2.el7.x86_64.rpm
libmicrodns-0.1.2-1.el7.x86_64.rpm
libmodplug-0.8.9.0-9.el7.x86_64.rpm
libmpeg2-0.5.1-10.el7.nux.x86_64.rpm
libmpeg2-0.5.1-15.el7.x86_64.rpm
libplacebo-0.4.0-2.el7.x86_64.rpm
libprojectM-2.1.0-2.el7.x86_64.rpm
libspatialaudio-3.1-1.20200406gitd926a2e.el7.x86_64.rpm
libtiger-0.3.4-7.el7.x86_64.rpm
libupnp-1.6.25-1.el7.x86_64.rpm
libusb-0.1.4-3.el7.x86_64.rpm
libvdpau-1.1.1-3.el7.x86_64.rpm
libxml++-2.37.1-1.el7.x86_64.rpm
lirc-libs-0.10.0-16.el7.x86_64.rpm
live555-2013.11.26-1.el7.nux.x86_64.rpm
live555-2020.07.31-1.el7.x86_64.rpm
minizip-1.2.7-18.el7.x86_64.rpm
ocl-icd-2.2.12-1.el7.x86_64.rpm
opencore-amr-0.1.3-3.el7.nux.x86_64.rpm
opencore-amr-0.1.5-6.el7.x86_64.rpm
openjpeg2-2.3.1-3.el7_7.x86_64.rpm
protobuf-lite-2.5.0-8.el7.x86_64.rpm
rpmfusion-free-release-7.noarch.rpm
schroedinger-1.0.11-4.el7.x86_64.rpm
SDL_image-1.2.12-11.el7.x86_64.rpm
soxr-0.1.2-1.el7.x86_64.rpm
srt-libs-1.2.3-2.el7.x86_64.rpm
twolame-libs-0.3.13-12.el7.x86_64.rpm
vid.stab-1.1-4.20170830gitafc8ea9.el7.x86_64.rpm
vlc-2.2.8-1.el7.nux.x86_64.rpm
vlc-3.0.16-1.el7.x86_64.rpm
vlc-core-2.2.8-1.el7.nux.x86_64.rpm
vlc-core-3.0.16-1.el7.x86_64.rpm
vo-amrwbenc-0.1.2-1.el7.nux.x86_64.rpm
vo-amrwbenc-0.1.3-1.el7.x86_64.rpm
vulkan-1.1.97.0-1.el7.x86_64.rpm
vulkan-filesystem-1.1.97.0-1.el7.noarch.rpm
x264-libs-0.142-11.20141221git6a301b6.el7.nux.x86_64.rpm
x264-libs-0.148-24.20170521gitaaa9aa8.el7.x86_64.rpm
x265-libs-1.9-1.el7.nux.x86_64.rpm
x265-libs-2.9-3.el7.x86_64.rpm
xvidcore-1.3.2-5.el7.nux.x86_64.rpm
xvidcore-1.3.4-2.el7.x86_64.rpm
zlib-1.2.7-18.el7.x86_64.rpm
zlib-devel-1.2.7-18.el7.x86_64.rpm
zvbi-0.2.35-1.el7.x86_64.rpm
 

Here you may be get library file errors, then you must resolve all as :-

copy name of library name which is ".so.version" file. search on google for rpm of that "so" file. you may suffix with centos. It most probably get link of "pkgs.org". Now download rpm for that library file. Do that for all library files. now run rpm command for as given above for all rpms. It may display again lib errors. Again download rpm for libs. Repeat until get no library dependencies. Then rpm command will install VLC. This method works for all type of software installing from rpm.

Monday, May 8, 2023

Actual Reverse Engineering in Software Industries

 
 It is possible to convert machine code of software, to source code in high level language in which that software is written. From starting of softwares all over the world level even all scientists assumed that source code (i.e. programs or softwares written in high level language such as c, c++, java, vc#.net etc.) is converted into machine code by compiler is not possible to convert binary machine language back into high level language source code, but I say this is possible. Now here is that compiler first find errors mostly in starting, of syntax errors and others. Than error free from bugs source code is converted to object code and then linker and loader attaches library, that makes this object code to executable code ( i.e. machine language, that is understands only 0s and 1s or in other words numbers). Our scientists believed that this executable machine code can not be converted to reverse in source code that is in high level language in which this software (converted machine code) is written.

  But I say that this is possible. I termed this as "Reverse Engineering".
From machine code to high level language source code.

    I get it from here :- When I was in college in a subject  "Micro processors", we did our practicals in 8085 micro processors programming. There was in big box 8085 was fixed, aside of this there was Hexa decimal number display for two digits of hexa code. And there is also a Hexa decimal keybords, labeled  ( 0 1 2 3 4 5 6 7 8 9 A B C D E F ). Now to program in 8085 which understands only numbers, we need first build program in paper hard copy in assembly language. And in order to enter or type program in 8085 we enters hexa decimal code equivalent to that assembly language program. for example :-
    
    machine code -- assembly code
    8F                MOVE A, AC         (MOVE CONTENT OF REGISTER A TO ACCUMULATOR )
    54                ADD AC, B        ( ADD ACCUMULATOR VALUE TO CONTENT OF REGISTER B)
    .
    .
    .
    .
    F6               MOVE AC, D        ( MOVE ACCUMULATOR TO REGISTER D, Let it is answer that is received by end user).
    
    If you remember a book "TSR through C" by kanentkar, and other deeply discovered and delved enough kanetkar's books for c programmers. There was some functions that works and operates with CPU registers, correct.
    
    Now then compiler converts source code into object code.
    
    I remember once I was working in visual studio in college, program displayed a message for some errors. And there was option for debugging in vc++ or something like that. I didn't understand that message and hit for debugging. That IDE moved me to file in editor have some columns, some for some non-understandable numbers and one for assembly commands. I asked one of my friend Rudra Rup Mitra, What are these dude. He said I don't know much about that, this is assembly language code, some numbers but didn't get delve into this. Because of that window I thought it may be that there is assembly language code and there equivalent machine code.
    
    Now as in above listing, it is clear that machine code is equivalent to assembly code. i.e. we can write equivalent assembly code from its executable machine code. And from that we can convert from assembly code to high level source code. That is "Reverse Engineering". and for that there is "Decompiler".

Tuesday, April 25, 2023

installing NVIDIA graphics card in Centos 7-6 linux

First download NVIDIA driver from official website.

Now blacklist "nouveau" driver shipped with Linux OS which is responsible for graphical display.  Disable it to install NVIDIA graphics card software. 

because "nouveau" is default driver for graphics card and is shipped with OS, it necessary to disable it. Otherwise OS does not allow to install our graphics card driver. In CentOS 6, to disable "nouveau" graphics driver, just change name of "nouveau.ko" to your choosen name as mine is "nouveau.ko.original.backup"

Path to "nouveau.ko"  graphics driver in Centos 6 is :-

dir : "/lib/modules/2.6.32-754.el6.x86_64/kernel/drivers/gpu/drm/nouveau/"

# mv nouveau.ko nouveau.ko.original.backup

You do not need to blacklist, because if you rename it, at boot time OS can not find it by its original name. After renaming that, run "dracut" command as given below. Without it if you restart OS then OS will not boot even in emergency mode. So do as follows.

run following commands as root user :-

# dracut /boot/initramfs-$(uname -r).img $(uname -r) --force 

in centos 7 do only this to disable nouveau.ko

add "rdblacklist=nouveau" at last after "rhgb quiet" in grub.cfg.

as in this :-

linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=UUID=0ec7e49f-5f1c-43db-be98-7f0d008a8514 ro crashkernel=auto rhgb quiet rdblacklist=nouveau


then run following commands :-

# dracut /boot/initramfs-$(uname -r).img $(uname -r) --force

then

# reboot 

boot in runlevel 3 mode, to do that :-

in boot menu highlight Linux 7 boot option then press "e", go down and add "3" after "rhgb quiet rdblacklist=nouveau" 

as :-


linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=UUID=0ec7e49f-5f1c-43db-be98-7f0d008a8514 ro crashkernel=auto rhgb quiet rdblacklist=nouveau 3

and boot by pressing keys : Ctrl + X

 after getting command prompt login  as root then go to directory where NVIDIA driver is stored and run following command for driver :-

# ./NVIDIA-Linux-x86_64-352.30.run

here above is driver of your nvidia graphics card downloaded from internet.

# reboot

and NVIDIA-Linux is installed.

following command

 $ nvidia-xconfig 

will opens management window of NVIDIA card.

Most probably it may work.

you may add NVIDIA command in Main menu. This is I given already in previous blog.

You can add "nvidia.desktop" file in "/usr/share/applications/" folder to add nvidia shortcut in man menu. How to that I said it in one of previous blog search it.

Thursday, April 6, 2023

How to make iso to bootable usb & vise-versa in Centos 7 Linux

 if you are in linux you need to run following command to create bootable USB Stick from ISO of CEntOS.
In rpm linux run following commands :
in root account :-


1 # lsblk 

this will show you name, ..., size,...,..., MountPoint.
note down name of filwsystem from first collumn NAME. e.g. sde1
 

2 # umount /dev/sdx1
e.g. # umount /dev/sde1
 

3. The last step is to flash the CentOS ISO image to the USB drive. Make sure you replace /dev/sdx with your drive and do not append the partition number. Also, replace /path/to/CentOS-7-x86_64-DVD-1810.iso with the path to the ISO file. If you downloaded the file using a web browser , then it should be stored in the Downloads folder located in your user account. for ease of work you may copy ISO in /opt or /software folder or filesystem.
run command :-
 

# dd bs=4M if=/path/to/Centos7-Everthing.iso of=/dev/sde status=progress oflag=sync
 

here in "of=/dev/sde" name of "sde" is NAME of filesystem that we noted earlier as "sde1", also note that here we given "sde" not "sde1".
now you have bootable USB from ISO of Centos Linux.

You can build bootable USB from any bootable iso of any softrware. For example from redo-rescue-4.3.iso downloaded from internet. i.e. if iso is bootable  image then usb stick build will be bootable.

To build ISO from USB stick, Run following command  :-

# dd if=/dev/sdx1 of=/path/to/iso-file.iso 

this will create complete usb image to iso file. Here sdx1 in /dev/sdx1 is usb drive file system name and also here we given "sdx1" not "sdx" as for command for ISO to USB "dd" command. If USB stick is bootable, then iso build as above will also be bootable.

Tuesday, April 4, 2023

gotoxy(int x, int y); and clrscr() in linux terminal (command prompt)

 

#include <sys/ioctl.h>
#include <unistd.h>
 

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

} 

-----------------------------------------------------------------------------

use above code to place cursor  any where in terminal e.g gotoxy(4, 10);

places (x, y) co-ordinate as (4, 10). 4th column and 10th row.

 example :-

#include <iostream>

#include <sys/ioctl.h>
#include <unistd.h>
  

using std::cout;

using std::cin;

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

}

int main()

{

    gotoxy(5, 10);

    cout << "Here is Cursur : " ;

    cin >> x;

    return 0;

}

----------------------------------------------------------------------

example :-

#include <iostream>

#include <sys/ioctl.h>
#include <unistd.h>

#include <termio.h>
#include <cstdio>
#include <iomanip>



using std::cout;

using std::cin;

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);

}

static termios oldterm, newterm;
 void clrscr()
{
        gotoxy(0,0);

        struct winsize w;
        ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);

        for (int x = 0; x < w.ws_row; x++)
        {
            for(int y = 0; y < w.ws_col; y++)
            {
                cout << " ";
            }
        }
        gotoxy(0, 0);
}

void initTermios(bool echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char getch_(bool echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char getch()
{
    return getch_(false);
}

char getche()
{
    return getch_(true);
}

int main()

{

    char x;
     clrscr();
    gotoxy(5, 10);

    cout << "Here is Cursur : " ;

    cin >> x;

    gotoxy(5, 11);
    cout << "you entered : " << x;


    getch();
    getch();
    clrscr();

    return 0;

}



getch and getche in Linux in both C++ and C

In C++ language :-

-----------------------------

 file : ClassGetch.h
-------------------------------

#ifndef ClassGetch_H
#define ClassGetch_H

#include <termio.h>
#include <cstdio>

#include <iostream>
#include <iomanip>
#include <unistd.h>

static struct termios oldterm, newterm;

class ClassGetch
{
public:
    ClassGetch();
    virtual ~ClassGetch();

    char getch();
    char getche();
    void initTermios(bool echo);
    void resetTermios(void);



protected:

private:

    termios   oldterm;
    termios   newterm;
    char getch_(bool echo);

};

#endif // ClassGetch_H

---------------------------------------------------------------
// file :- ClassGetch.cpp

-------------------------------------------------
#include "ClassGetch.h"

ClassGetch::ClassGetch()
{
    //ctor
}

ClassGetch::~ClassGetch()
{
    //dtor
}

void ClassGetch::initTermios(bool echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void ClassGetch::resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char ClassGetch::getch_(bool echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char ClassGetch::getch()
{
    return getch_(false);
}

char ClassGetch::getche()
{
    return getch_(true);
}

-----------------------------------------------------------------------------------

Include class and write above code then use getche() and getch() as where you want in your program.

getche() wait for echo of char i.e. prints a character and then returns, while getch() doesn't wait for echo of char and returns without print of char.

 -----------------------------------------------------------------------------------
file : main.cpp
-----------------------
#include "ClassGetChoice.h"
#include <iostream>


using std::cout;
using std::endl;

int main()
{
    char c;

    ClassGetch * cg = new ClassGetch;

    cout << "getche() example : " << endl;
    cout << "Enter any character : ";
 

    c = cg->getche();

    cout << "\nyou entered : " << c <<endl;

    cout << "getch() Example : "<< endl;
    cout << "Enter any character : ";
 

    c = cg->getch();


    cout << "\nYou entered : " << c << endl;

    return 0;
}

/* 

output :-

-------------

[rahul@C-Client Debug]$ ./getche-getch
getche() example :
Enter any character : w
you entered : w
getch() Example :
Enter any character :
You entered : w
[rahul@C-Client Debug]$
*/
----------------------------------------------------------------------------

In C language : -

-------------------------

file : getche-getc.h :-
-----------------------

#ifndef GETCHE-GETCH_H_INCLUDED
#define GETCHE-GETCH_H_INCLUDED

#include <stdio.h>
#include <termios.h>
#include <unistd.h>

struct termios   oldterm;
struct termios   newterm;

void initTermios(int echo);

void resetTermios();

char getch_(int echo);

char getch();

char getche();

#endif // GETCHE-GETCH_H_INCLUDED
------------------------------------------

file : getche-get.c :-
----------------------
#include "getche-getch.h"

void initTermios(int echo)
{
    tcgetattr(0, &oldterm);
    newterm = oldterm;
    newterm.c_lflag &= ~ICANON;
    newterm.c_lflag &= echo ? ECHO : ~ECHO;
    tcsetattr(0, TCSANOW, &newterm);
}

void resetTermios()
{
    tcsetattr(0, TCSANOW, &oldterm);
}

char getch_(int echo)
{
     char ch;
     initTermios(echo);
     ch = getchar();
     resetTermios();
     return ch;
}


char getch()
{
    return getch_(0);
}

char getche()
{
    getch_(1);
}
-----------------------------------------------
file : main.c :-
----------------
#include <stdio.h>
#include <stdlib.h>
#include "getche-getch.h"


int main(void)
{
    char c;
    printf("(getche example) please type a letter: ");


    c = getche();
 

    printf("\nYou typed: %c\n", c);

    printf("(getch example) please type a letter...");
 

    c = getch();
 

    printf("\nYou typed: %c\n", c);
    return 0;
}
-------------------------------------------------
/*
output :-
---------
[rahul@C-Client Debug]$ ./getch-getche-c
(getche example) please type a letter: w
You typed: w
(getch example) please type a letter...
You typed: w
[rahul@C-Client Debug]$
*/

----------------------------------------------------


Wednesday, March 22, 2023

CPP program to get exactely - yes (y) or no(n) option

 Program to get options (Y/y) for  yes or  ( N/n) for no. Neither will be accepted other  than those.

#include <iostream>
#include <string>

using std::string;
using std::cin;
using std::cout;
using std::endl;

char charExtract(string str)
{
    string::iterator istr;

    char ch;

    istr = str.begin();
    ch = *istr;

    if(str.length() == 1)
        return ch;
    else
        return 0;
}

bool yesno()
{
    string str;
    char ch;

    int i;

    while(1)
    {
        cout << "Enter y(yes) or n(no) : ";

        getline(cin, str);

        if(str.length() == 0 )
            continue;
        else
        {
             ch = charExtract(str);

            if(ch == 'Y' || ch == 'y')
            {
                return true;
            }

            else if(ch == 'N' || ch == 'n')
            {
                return false;
            }

            else
            {
                cout << "\nEnter only Y(yes) or N(No)"  << endl;
            }
        }
    }
}

int main()
{

    bool yn = yesno();

    if(yn == true)
    {
        cout << "true" << endl;
    }
    else if( yn == false)
    {
        cout << "false" << endl;
    }


    return 0;
}
/*
output :-
-------------
[rahul@C-Client Release]$ ./yes-no
Enter y(yes) or n(no) : YES

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : NO

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : Nu

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : 123

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : 1

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : 0

Enter only Y(yes) or N(No)
Enter y(yes) or n(no) : Y
true
[rahul@C-Client Release]$ ./yes-no
Enter y(yes) or n(no) : y
true
[rahul@C-Client Release]$ ./yes-no
Enter y(yes) or n(no) : N
false
[rahul@C-Client Release]$ ./yes-no
Enter y(yes) or n(no) : n
false
[rahul@C-Client Release]$
*/

Saturday, March 18, 2023

How to set menu item of software in main menu in centos 7 linux.

 for example we are setting menu for firefox-108.92. First extract it as I did in "/opt/firefox"
then write as following in gedit and name this file as : "firefox.desktop". This is menu shortcut in Linux. If you double click this file firefox web browser will be oppened. To edit it open in gedit.

firefox.desktop:-
-----------------
[Desktop Entry]
Version=198.92
Type=Application
Terminal=false
Exec=/opt/firefox/firefox
Name=Firefox
Comment=Internet Web Browser
Categories=Network;WebBrowser;
---------------------------------

Here file name in "Exec" entry last "firefox" is executable file in folder "/opt/firefox". Remember we extracted firefox.tar.gz here in path : "\op\firefox". You can also set "Icon" by giviing full path name of "Icon File".

Now Save it to path folder : "/usr/share/application" as: "/usr/share/application/firefox.desktop". After you saved file in "application" folder, file name will be displayed as given "Name" item in ".desktop" file, here in our "firefox.desktop" file in "Name" entry is "Firefox". So in "application" folder file name will be shown  : "Firefox". This will add in menu as Universal access menu. If you want to add in "user account", or local menu entry, save ".desktop" file in path : "/home/user-name/.local/share/applications", as mine path is : "/home/rahul/.local/share/applications". That will add in local menu. That will add in local menu.

To put in internet category, you should add "Categories=Network". To know what "Category"  is, for perticular ".desktop" file for it's application, you should check in "/usr/share/application" and search nearest application desktop file. To do that see for example in our case i saw in menu near is "Ekiga Softphone". Now in "/usr/share/application" search for "Ekiga Softphone", open it in gedit and search for "Categories" tag and copy all tags following "=", and paste in our ".desktop" file in "Categories" tag. This "Categories" sets our menu item in place whre it should be shown. In our case "Apllication->Internet->Firefox" menu.

That's all.

Tuesday, February 28, 2023

How to install gcc in centos 7, online and offline both

 how to install gcc in centos 7. First you need internet connection to install it i.e. online installation. To install offline i.e. without internet connection, read up to last

1. download gcc. I've gcc-9.3.0.tar.gz and extract it somewhere, with taking care of "no space" in path of gcc extracted folder as mine : "/opt/gcc-9.3.0"

2. run following command ( run shell script located in contrib/download_prerequisites, this is a file) like this:-

# ./contrib/download_prerequisites ( press Enter )
  here you need to be in main directory of gcc ( i.e. gcc-9.3.0 ), you can not run it in its own directory i.e. in "contrib" dir.
  this file will download all supporting softwares needed to gcc.

As I did here :-

[root@kaljayi gcc-9.3.0]# ./contrib/download_prerequisites
18:25:27 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
18:25:32 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [1]
18:25:36 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [1]
18:25:41 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291] -> "./isl-0.18.tar.bz2" [1]
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.
[root@kaljayi gcc-9.3.0]#

make a directory parallel to gcc-9.3.0 as named "objdir".

then do this :-

2. # cd  ../objdir/

3. # ./../gcc-9.3.0/configure --disable-multilib ( to install only 64 bit library )

4. # make 

5. # make install

this installation will take minimum 3-4 hour.

thats it all.
 

Save gcc tar ball to install it for future use without internet connection i.e offline installation, so do this :-

after running ./contrib/download-prerequisites compress gcc folder by right clicking on gcc folder and select "compress" as tar.gz. This will create tar ball as gcc-9.3.0.tar.gz with all prerequisites inside it. For installing it without internet connection, extract it by right cilicking it select exract here. Then goto inside it and run command :

# ./countrib/download_prerequisites ( press enter )

this will setup links as it is done as with internet connection, then install gcc. It will be installed fairly.

Tuesday, December 20, 2022

installing .NET Fx 3.5 in Windows server 2016 - 2019

 mount setup DVD, and run following command in power shell ( run as administrator ):-

 

prompt > dism /online /enable-feature /featurename:NetFX3 /All /Source:E:\sources\sxs /LimitAccess

where "E:" is "DVD drive" where setup DVD is mounted.

Now .NetFx3 is installed