Monday, September 8, 2014

Connecting Samsung S3 with Ubuntu 12.04

There are lots of issues in connecting your Samsung S3 with Ubuntu machine. I have tried lot of methods and not satisfied with all of  them because of simply you need more time to configure and get the things done . For example You can get file access to your phone's internal storage (/mnt/sdcard) or your external SD card (/mnt/extSdCard/) using gMTP 

You'll need to install libmtp and gMTP.  But , I would not recommend to use this method because of frequent crashes and mtp implementation is not much stable at current moment. 

The main issue here was Samsung S3's MTP protocol is not compatible with Ubuntu 12.04 existing implementation. Hope we will get updated version from Ubuntu community soon.

So, the most reliable solution is to install "ES File Explorer File Manager" from Google play in your mobile phone. This application provides various options to establish the connection with your PC such FTP, private hot spot, cloud etc.  Once you  installed the application , you will have to follow these steps in your machine if you haven't installed Samba yet :)

PC configuration 

1) Samba is not installed by default, so just type the following command in your       terminal 


2) Open the Samba configuration by typing 
   


    Go to the  “Authentication” section and remove "#"
     security = user

    Do the following changes as well

    We are almost done, now save the file and exit.

3) Let's add yourself in to Samba user list
   
    
4)  Restart the Samba 
   sudo restart smbd 
  
   Now you should be able to access one computer from another computer or mobile devices.


  Mobile side configuration 

  1) Open ES file manager and go to LAN section , here you will find your computer name , in my case it was emdc

  
2) If you hold your computer name for a second ( not clicking) then you will find edit server section where you will have add your username and password
                              
 
3) In the edit server menu , un-tick Anonymous authentication and type your user name and password

    
We are done !!!!!!! . Now, you can copy or move files from your shared folder to SD card/internal storage and vice verse.
Enjoy !!!!!!!!!!!!!!!!!!!

Friday, September 5, 2014


Configuring KTH VPN in Ubuntu 12.04

The purpose of this post to demonstrate how to connect eduroam network which is widely been using by all European universities. Though you are outside the eduroam network you can still access the university network through VPN. Most of the universities having this VPN access by providing public interface.
The following information you might need to setup your VPN connection

1) Cisco AnyConnect Secure Mobility Client
2) Your user name 
3) eduroam password
4) We need the root certificate ( we can download KTH certificate from following link (http://certauth.ug.kth.se/  )


So, lets first install the Cisco AnyConnect Secure Mobility Client, go to this link and choose your version 32 bit or 64 bit ( http://www.lan.kth.se/vpn/vpn.html

unzip in to your preferred location 
execute the chmod +x vpn_install.sh to give the execution access , now we are ready to run vpn_install.sh 

Once it has been installed ,  click the application from launch bar ( if it is not there just search Cisco AnyConnect  Secure Mbility Client) 
Click connect !!!!!!!!!. Now you can access your campus private network  :) 
 

Wednesday, September 12, 2012

C++ FIX message validate

Since most of the financial institutions have been following FIX messages as a standard communication mechanism in between their products, today I want to share how we can create a simple FIX message in C++ and validate that message. Further I will be giving some FIX message basics to understand the whole picture of FIX. 

The following details explaining what FIX protocol is.

  • Acronym for Financial Information eXchange Protocol (not to be confused with IPFIX, the Internet Protocol Flow Information Export).
  • Open standard which defines a message format as well as a communication model.
  • This standard has been created by an industry consortium consisting of banks, independent vendors etc.
  • The intended audience consists of financial institutions like banks, brokers, dealers, exchanges etc.
  • FIX is the defacto standard in financial information exchange today.
  • FIX is platform independent (concerning systems and networks).
  • Central point for all information about FIX is http://www.fixprotocol.org. 
There are three types of main user groups involves in using FIX Protocol.
Buy-side firms: Communication with sell-side firms by means of pre-trade, trade and post-trade messages.

Sell-side firms: Communictaion with buy-side firms via pre-trade, trade and post-trade messages. In addition to that communication with exchanges and OTC markets in general.

Exchanges: Receiving trades from their members, sending execution reports etc. back to them. Currently a wide variety of product classes are suported ranging from equities to fixed income products, derivatives and the like.

A typical FIX setup shown below. 


FIX message structure and fields 
Although FIX messages always have a similar structure, the number and type of possible fields depends strongly on the version of the FIX Protocol which is used. At the time of this writing the latest version is FIX 5.0 although most current production systems use older versions 4.x (4.4 being
the last).
FIX messages are grouped into two categories:
  1. Admin messages: Connection establishment and termination, heartbeat messages etc. (logon, logoff, heartbeat,test request, resend request, reject, sequence reset,. . )
  2. Application messages: Business related message transferring trade data etc. (advertisement, indication of interest, news, execution report, order cancel, new order,quote and many, many more)
Every FIX message is built according to the following structure: 

Message header: Contains the message type, length,sender/receiver name, sequence number, time stamp..etc

Message body: Contains session/application specific data.

Message trailer: Contains a message checksum and an optional signature.

The message consists of so called FIX fields which look like this: <tag>=<value><delimiter> The tag is a numerical identifier, the value is a string (which must be of correct type and length for this particular tag) and the delimiter is SOH (Start of header – ASCII 0x01) which is written as ^ in printed messages.

Although FIX supports literally hundreds of predefined tags, there is room for custom defined tags (field numbers 5000 to 9999).

The following example of a New Order Single message 
8=FIX.4.1^9=0235^35=D^34=10^43=N^49=VENDOR^50=CUSTOMER^56=BROKER^52=19980930-09:25:58^1=XQCCFUND^11=10^21=1^ 55=EK^48=277461109^22=1^54=1^38=10000^40=2^44=76.750000^59=0^10=165

Header: 8 (version), 9 (body length), 35 (MsgType), 34 (MsgSeqNum), 43 (PossDupFlag), 49
(SenderCompID), 115 (OnBehalfOfCompID), 56 (TargetCompID), 52 (time stamp)

Body: 1 (Account), 11 (ClOrdID), 21 (HandInst), 55(Symbol), 48 (SecurityID), 22 (IDSource), 54 (Side),
38 (OrderQty), 49 (OrdType), 44 (Price), 59 (TimeInForce)

Trailer: 10 (Checksum)

Note : This checksum value is for demonstrated purpose .

The FIX Protocol supports many different message types – some of these are shown in the following:
0: Heartbeat
1: Test request
2: Resend request
3: Reject
4: Sequence reset
5: Logout
6: Indication of interest
7: Advertisement
8: Execution report
9: Order cancel reject
A: Logon
B: News
C: Email
D: Order single
E: Order list

As a programmer we need to know the ASCII value of FIX delimiter which is 1 ( \001). For example lets assume we have FIX message like following. 

8=FIX.4.2<SOH>9=97<SOH>35=6<SOH>49=BKR<SOH>56=IM<SOH>34=14<SOH>52=2010020409:18:42<SOH>23=115685<SOH>28=N<SOH>55=SPMI.MI<SOH>54=2<SOH>44=2200.75<SOH>27=S<SOH>25=H<SOH>10=248<SOH> 

Tag                  Field                  Value                          Description
8                  BeginString           FIX.4.2
9                  BodyLength           97
35                  MsgType                   6                                 Indication of Interest
49                  SenderCompID    BKR
56                  TargetCompID   IM
34                  MsgSeqNum           14
52                  SendingTime           20100204-09:18:42
23                  IOIid                   115685
28                  IOITransType           N                                 New
55                  Symbol                    SPMI.MI
54                  Side                           2                                 Sell
44                  Price                   2200.75
27                  IOIShares           S                                 Small
25                  IOIQltyInd           H                                 High
10                  CheckSum           248

We used to validate FIX message by using check sum value which will be at trailer. Every single FIX message from tcp socket has to be identified using this method in order to extract single FIX message. 

#include <iostream>  
 #include <numeric>  
 #include <stdio.h>  
 #include <string.h>  
 #include <sstream>  
 #define BUFFER_LENGTH 400  
 using namespace std;  
 int main()  
 {  
 stringstream ss;  
 char fixChkSum[4];  
 unsigned int actualChkSum = 0;  
 int claimedChkSum = 0;  
 ss<<"8=";  
 ss<<"FIX.4.2";  
 ss<<"\0019=";  
 ss<<"97";  
 ss<<"\00135=";  
 ss<<"6";  
 ss<<"\00149=";  
 ss<<"BKR";  
 ss<<"\00156=";  
 ss<<"IM";  
 ss<<"\00134=";  
 ss<<"14";  
 ss<<"\00152=";  
 ss<<"20100204-09:18:42";  
 ss<<"\00123=";  
 ss<<"115685";  
 ss<<"\00128=";  
 ss<<"N";  
 ss<<"\00155=";  
 ss<<"SPMI.MI";  
 ss<<"\00154=";  
 ss<<"2";  
 ss<<"\00144=";  
 ss<<"2200.75";  
 ss<<"\00127=";  
 ss<<"S";  
 ss<<"\00125=";  
 ss<<"H";  
 ss<<"\00110=";  
 ss<<"248";  
 ss<<"\001";  
 int length = strlen(ss.str().c_str());  
 const char * fixin = new char[BUFFER_LENGTH];  
 memset ( (char*)fixin, 0, BUFFER_LENGTH);  
 strcpy((char*)fixin , (char*)ss.str().c_str());  
 int len = (int)strlen(fixin) - 7;  
 cout <<"Input fix mesasge length="<<len<<endl;  
 actualChkSum = accumulate(fixin, fixin+len, 0)% 256 ;  
 memcpy(fixChkSum, fixin+len+3, 3);  
 fixChkSum[3] = 0;  
 claimedChkSum = atoi(fixChkSum);  
 if( actualChkSum == claimedChkSum )  
       cout <<"Valid FIX message"<<endl;  
 else  
    cout <<"FIX message is not valid"<<endl;  
 return 0;  
 }  

The output will be like this ..:)



Tuesday, August 7, 2012

Decompiler to C# programs

This post,I would like to introduce decompiler tool which we will really useful for developers who are doing reverse engineering . The term decompiler is most commonly applied to a program which translates executable programs (the output from a compiler) into source code in a (relatively) high level language which, when compiled, will produce an executable whose behavior is the same as the original executable program. By comparison, a disassembler translates an executable program into assembly language (and an assembler could be used to assemble it back into an executable program).

Basically,  Decompilers can be thought of as composed of a series of phases each of which contributes specific aspects of the overall decompilation process. 

Even-though there are so many sophisticated decompiler tools are available in the internet , I would suggest ILSpy decompiler which is very easy to use and very comprehensive. 

Here are some features about ILSpy

  • assembly browsing
  • IL Disassembly
  • Decompilation to C#
  • Shows XML documentation
  • Hyperlink-based type/method/property navigation
  • Find usage of field/method
  • Extensible via plugins (MEF)
  • Assembly Lists

Step by step procedure to run this tool 

1. Go to this link and download later version binaries (ex: 2.1)
                      http://wiki.sharpdevelop.net/ILSpy.ashx
2. Store *.zip file in to your hard disk or the place where you want to place 
3. unzip the file and run ILSpy.exe.
4. Open up *.exe file which you want to explore. :) 

Finally you will end up like this interface. . Enjoy your reverse engineering ..!   

Tuesday, July 3, 2012

CppUnit configuration in VS 2008

I hope this post would be helpful those who are going to use C++ unit testing frame work. Even though  so many unit testing frame works are available out there, As far as I know CppUnit is better among them because of following functionality.

  • XML output with hooks for additional data (XSL format avaliable in release 1.10.2 needs some FiXing)
  • Compiler-like text output to integrate with an IDE
  • Helper macros for easier test suite declaration
  • Hierarchical test fixture support
  • Test registry to reduce recompilation need
  • Test plug-in for faster compile/test cycle (self testable dynamic library)
  • Protector to encapsulate test execution (allow capture of exception not derived from std::exception)

Configuration steps 


1) Download latest CppUnit framework from this website 
http://sourceforge.net/projects/cppunit/files/cppunit/1.12.1/


2) Create any folder (ex: CPPUNIT) at any directory and copy your downloaded 


3) If you are using Visual Studio 2005 or 2008, it wont compile out of the box.
Fix For Visual studio 2005 and 2008
Open file MsDevCallerListCtrl.cpp in the folder srcmsvc6testrunner.
Find the following line
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0")
 raw_interfaces_only named_guids
and change the version("7.0") to:
version("8.0") for VS 2005
version("9.0") for VS 2008
Now do a batch build for all configurations.
Dont worry about errors yet.
Go and look into the lib directory in the cppunit directory.
if you have cppunit.lib, cppunit_dll.lib and cppunit_dll.dll, then you are ready to go.
Adding the include and lib paths to Visual Studio environment

open Tools->Options.
Choose Projects and Solutions -> VC++ Directories
from the dropdown for "Show directories for" choose "Include Files"
and add(by clicking in the blank space on the bottom) -> <cppunit directory>include
for "Library files"
Add-> <cppunit directory>lib 


Now you have finished your configuration part . Follow CppUnit example program to run your test cases .:) 

Wednesday, April 4, 2012

Using Log4cxx in your C++ program

This post is actually from my current experience , because  i have spent lots of time to compile and configure log4cxx along with my program. Previous versions of log4xx having so many issues with visual stdio 2008. End of this post I have included compiled log4cxx lib and dll files. You have to be very careful before using log4cxx in your program, because some debugging version dll and libraries will not work in release version.  So , if you are going to compile your program in release mode, use release dll and release library.

This is my sample configuration file which is more important for log4cxx.


#Log4cxx configuration file .
#Author - Sri  4/4/2012
----------------------------------------------------------------------------------------------------
log4j.rootLogger=DEBUG, DT

log4j.appender.DT=org.apache.log4j.RollingFileAppender
log4j.appender.DT.File=.\\log\\log.log
log4j.appender.DT.MaxFileSize=100KB
log4j.appender.DT.MaxBackupIndex=1
log4j.appender.DT.layout=org.apache.log4j.PatternLayout
log4j.appender.DT.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.DT.rollingPolicy.FileNamePattern=.\\log\\log-%d.log.zip
log4j.appender.DT.rollingPolicy=org.apache.log4j.TimeBasedRollingPolicy



log4j.appender.RawAppender=org.apache.log4j.RollingFileAppender
log4j.appender.RawAppender.File=.\\log\\RawData.log
log4j.appender.RawAppender.MaxFileSize=100KB
log4j.appender.RawAppender.MaxBackupIndex=1
log4j.appender.RawAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RawAppender.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.RawAppender.rollingPolicy.FileNamePattern=.\\log\\RawData-%d.log.zip
log4j.appender.RawAppender.rollingPolicy=org.apache.log4j.TimeBasedRollingPolicy


# Set options for appender named 'ErrorAppender'
# ErrorAppender's layout is TTCC, using the
# ISO8061 date format with context printing enabled.

log4j.appender.ErrorAppender=org.apache.log4j.RollingFileAppender
log4j.appender.ErrorAppender.File=.\\log\\Error.log
log4j.appender.ErrorAppender.MaxFileSize=100KB
log4j.appender.ErrorAppender.MaxBackupIndex=1
log4j.appender.ErrorAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.ErrorAppender.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.OMSRawAppender.rollingPolicy.FileNamePattern=.\\log\\Error-%d.log.zip
log4j.appender.OMSRawAppender.rollingPolicy=org.apache.log4j.TimeBasedRollingPolicy




# Set options for appender named 'ErrorAppender'
# ErrorAppender's layout is TTCC, using the
# ISO8061 date format with context printing enabled.


log4j.appender.FatalAppender=org.apache.log4j.RollingFileAppender
log4j.appender.FatalAppender.File=.\\log\\Fatal.log
log4j.appender.FatalAppender.MaxFileSize=100KB
log4j.appender.FatalAppender.MaxBackupIndex=1
log4j.appender.FatalAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.FatalAppender.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.OMSRawAppender.rollingPolicy.FileNamePattern=.\\log\\Fatal-%d.log.zip
log4j.appender.OMSRawAppender.rollingPolicy=org.apache.log4j.TimeBasedRollingPolicy

# The logger 'DTRawData' inherits its level from the
# logger hierarchy. Output will go to the appender's of the root
# logger, DT in this case.

log4j.logger.DTRawData=INHERIT,RawAppender
log4j.additivity.DTRawData=false



# The logger 'DTError' inherits its level from the
# logger hierarchy. Output will go to the appender's of the root
# logger, DT in this case.

log4j.logger.DTError=INHERIT,ErrorAppender
log4j.logger.DTFatal=INHERIT,FatalAppender
----------------------------------------------------------------------------------------------------

Hope this sample proprieties file will help you guys to use in your program. Next post I will give an introduction of every proprieties in detail and sample program.  :)



Tuesday, March 20, 2012

CSV or Txt file merger

After long time I am posting this article due to some busy works. Recently my friend has encountered a problem which was about file merging. If we have two or 3 files then we can simply merge in to one . For example , Lets assume in your directory you have 3 files (all are having extension .csv or .txt) , Simplest way to do this, 
 C:\<your file directory> copy *.csv targetfilename.csv  ( pretty simple right  ?) 
If you have more than 100 or 1000 files you can use above command to append or merge . Now my friend's requirement was can we merge files by column. Because above command only append next file in to end of previous file. 

I have written a C++ program to achieve this very fast column wise merging. Enjoy it . 
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <map>
#include <Windows.h>
using namespace std;


typedef map<int , char*> MAPFILES;

int main(int argc , char **argv)
{
cout <<"****************** CSV files merging program**************"<<endl;
cout <<"Written by vampire."<<endl;
cout<< "Date:20/3/2012"<<endl;
cout<<"Usage of this program..  program name  input.csv  output.csv "<<endl;
cout<<"***********************************************************"<<endl;
if(argc==1 || argc ==2)
{
cout <<"Wrong arg types. please contact vampire"<<endl;

}
else
{
ofstream myFile(argv[2], ios::out | ios::binary);
MAPFILES mapFile[40];
ifstream maininput;
int l_line=-1;
int l_realline =0;
int l_maxLine = 0;
maininput.open(argv[1]);

if(maininput.is_open())
{

while(maininput.good())
{
string line ;
char *zBuffer=new char[100];
memset(zBuffer,0, 100);
getline(maininput, line);
++l_realline;
int iFound =line.find_last_of("Timestamp");
if(iFound  != -1)
{
++l_line;
l_realline=0;
}

if(l_line ==-1)
cout <<"This is not a proper csv file. please contact to vampire"<<endl;
else
{
const  char *ptr = line.c_str();
int ip=0;
for(int i =0 ; i < line.size(); ++i)
{
if(i%2!=0)
{
zBuffer[ip] = ptr[i];
++ip;
}
}
mapFile[l_line].insert(make_pair<int,char *>(l_realline, zBuffer));
}
}
}
maininput.close();
cout <<"No of section found "<<l_line<<endl;
Sleep(10000);
/********************************************************************************/

int imin = 0;
for ( int i =0 ; i< l_line; ++i)
{
imin= mapFile[0].size();
if(imin > mapFile[l_line].size())
imin= mapFile[l_line].size();

}
map<int , char*>::iterator itr;
map<int , char*>::iterator itr1;

int iCount =0;
bool bfalse= false;

for(itr = mapFile[0].begin(); itr != mapFile[0].end(); ++itr)
{
if(iCount<imin)
{
char zBuff[1024];
memset(zBuff, 0, sizeof(zBuff));

char * ptr  =itr->second;
int iintiallength  =strlen(itr->second);
memcpy(zBuff,itr->second,iintiallength);

zBuff[iintiallength-1]=',';
zBuff[iintiallength]=0;

for(int j =1 ; j<=l_line; ++j)
{
itr1 = mapFile[j].find(iCount);
if(itr1 !=mapFile[j].end())
{
int iLen = strlen(mapFile[j].find(iCount)->second);
memcpy(zBuff+iintiallength,mapFile[j].find(iCount)->second,iLen);

iintiallength +=iLen;
zBuff[iintiallength-1]=',';
zBuff[iintiallength+iLen]=0;
bfalse =true;
}
else
{
bfalse = false;
}
}

if(bfalse)
myFile<<zBuff<<endl;
++iCount;
}
}

}
}