Category: Operating Systems

Uninstallation script for GIT on Mac

if [ ! -r “/usr/local/git” ]; then echo “Git doesn’t appear to be installed via this installer. Aborting” exit 1fiecho “This will uninstall git by removing /usr/local/git/**/*, /etc/paths.d/git, /etc/manpaths.d/git”printf “Type ‘yes’ if you sure you wish to continue: “read responseif [ “$response” == “yes” ]; then sudo rm -rf /usr/local/git/ sudo rm /etc/paths.d/git sudo rm

Continue Reading →

Fixing warning: Permissions 0644 for '/Users/darshan/.ssh/id_rsa' are too open.

Davids-Mac:work darshan$ git clone [email protected]:Local/foo Cloning into ‘foo’… @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for ‘/Users/darshan/.ssh/id_rsa’ are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. bad permissions: ignore key: /Users/darshan/.ssh/id_rsa [email protected]’s password: Permission denied, please try again.

Continue Reading →

XOR facts

If you XOR a number even times by itself, you will end up with zero but if you do it odd times, you will be getting the number itself. This logic can be used in many different problems, e.g. finding the odd and even number of times a number occurs and so on.

Continue Reading →

vs2005: fatal error C1083: Cannot open include file: 'Mscat.h': No such file or directory

add the following code: extern “C” { typedef HANDLE HCATADMIN; typedef HANDLE HCATINFO; typedef struct CATALOG_INFO_ { DWORD cbStruct; WCHAR wszCatalogFile[MAX_PATH]; } CATALOG_INFO; BOOL WINAPI IsCatalogFile( HANDLE hFile, WCHAR* pwszFileName ); BOOL WINAPI CryptCATAdminAcquireContext( HCATADMIN* phCatAdmin, const GUID* pgSubsystem, DWORD dwFlags ); BOOL WINAPI CryptCATAdminCalcHashFromFileHandle( HANDLE hFile, DWORD* pcbHash, BYTE* pbHash, DWORD dwFlags ); HCATINFO

Continue Reading →

Iterate through all the tabs in Internet Explorer Windows

I found this code useful when you want to go through each tab and then look into their URLs and so on. You can also quit each tab individually. [sourcecode lang=”cpp”] // Implementation #include #include typedef BOOL (CALLBACK * IEENUMPROC)(HWND hwnd, LPVOID pif, LPARAM lParam); static BOOL CALLBACK EnumIEChildWindows(HWND hwnd, LPARAM lParam) { TCHAR szClassName[100];

Continue Reading →

IHTMLCollection iterating through HTML frames / GUI manipulation

LRESULT lResult; UINT nMsg = ::RegisterWindowMessage( _T(“WM_HTML_GETOBJECT”) ); ::SendMessageTimeout( handleToInternetExplorerWindow, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lResult); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, “ObjectFromLresult” ); HRESULT hr; CComPtr htmlDoc2; hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument2, 0, (void**)&htmlDoc2); if ( SUCCEEDED(hr) ) { IHTMLFramesCollection2 *p; htmlDoc2->get_frames(&p); long lLen; p->get_length(&lLen); for (long i = 0; i < lLen; i++) {

Continue Reading →

_SECURE_SCL issues

Be careful when using _SECURE_SCL option when integrating your DLLs with DLLs you received from someone else. If you have compiled your dlls with this option but the dlls you use havent, you are most likely going to get a runtime application compatibility error. To fix this just remove this option. When secure SCL is

Continue Reading →

Unicode

I got this from joel on software. I pasted it here for my reference: Wednesday, October 08, 2003 Ever wonder about that mysterious Content-Type tag? You know, the one you’re supposed to put in HTML and you never quite know what it should be? Did you ever get an email from your friends in Bulgaria

Continue Reading →

Getting the parent id of a process

Below is the code to return the parent id of a process, given a process id. This can be helpful in circumstances when we have to scan all the running processes to find out the spawned processes from another process. [code language=”cpp”] // change this method signature according to your requirements BOOL GetParentPID( DWORD dwParentId,

Continue Reading →

Using Virtual Box COM APIs to list the Virtual machine snapshots

int Helper_ReturnVms(IVirtualBox *virtualBox) { HRESULT rc; bool bFound=false; /* * First we have to get a list of all registered VMs */ SAFEARRAY *machinesArray = NULL; rc = virtualBox->get_Machines(&machinesArray); if(FAILED(rc)) { SafeArrayDestroy (machinesArray); return -1; } IMachine **machines; rc = SafeArrayAccessData (machinesArray, (void **) &machines); if(FAILED(rc)) { SafeArrayUnaccessData (machinesArray); SafeArrayDestroy (machinesArray); return -1; } for

Continue Reading →

reading messages from message table

Sometimes data is also stored as message instead of resources. the easiest way to read this is as below: ofstream myfile; myfile.open (“example.txt”); HMODULE handle = LoadLibrary(“AgentRes.dll”); // dll for reading the file DWORD err=::GetLastError(); for(int i=0;i<10000;i++) { LPTSTR    lpMsgBuffer=NULL; DWORD dwRet=FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE, handle, i, // number of the corresponding message // you

Continue Reading →

Windows debugging using windbg

Sometimes or most times when you get a crash dump from your customer, its always good to know how to reproduce the crash and point out where the actual crash happens. Today I was debugging some bug with my lead, I found this very useful: Here are the steps: First of all open the windows

Continue Reading →

Hacking into DLLs [ COM ]

This is especially useful when you want to use someone else’s dlls. 1) Open the dll in windows dependency viewer: You should see the following, if its a COM dll. This basically is related to COM. If you go through COM tutorials you will know about this. 1)  next open the dll you need in

Continue Reading →

Using DebugBreak()

I learnt this from my manager. DebugBreak is powerful tool you can use when debugging applications. I had this scenario where I need to use a java app which was internally calling C++ methods, basically JNI functions. The error in question was in the C++ side, so not really an option to use debugger. Therefore

Continue Reading →

Virtual Store and UAC

As mentioned previously, many legacy Windows applications were created so you could access parts of the file system and registry that are now locked in Windows Vista, and many of these applications are not being immediately updated. However, Microsoft has devised an interesting solution within Windows Vista to provide backward compatibility so that legacy software

Continue Reading →

Step by step instructions on signing your android app [.apk] to get google maps api key

Paste this exactly to get your MD5 key: C:Program FilesJavajdk1.6.0_20bin>keytool.exe -list -alias androiddebugkey – keystore “C:Documents and Settingstest.androiddebug.keystore” -storepass android -keypass android Also there is a bug in eclipse, where in you will get a greyed out map with only tiles. Use this to correct that: The solution was to set the “Custom debug keystore”

Continue Reading →

SubVersion error: 1053: not able to create a service

When trying to run a subversion or svn service, we get this error stating the service is not running, this is because of the way you create the service: Below are the right and wrong way to create it: WRONG WAY: F:Program FilesSubversionbin>sc create svnserver binpath= “F:Program FilesS ubversionbinsvnserve.exe –service -r F:Dev FilesRepository” displayname= “S

Continue Reading →

Windows developer tools you need to have

Some tools which I really find helpful are: a. Multimon – Support for multiple monitors b. Process Monitor c. Process Explorer d. Desktops – Desktops allows you to organize your applications on up to four virtual desktops. e. OleView – For COM purposes f. Spy++ – For windows GUI handling g. Resource hunter – Reading

Continue Reading →

Displaying a background image in Android

Goto your res folder as shown in image below add a background image. After adding a background image, goto the main.xml and add the below text: <ImageView android:layout_height=”wrap_content” android:layout_width=”wrap_content” android:src=”@drawable/background” /> Note: Do not add the extn to the image name, it wont recognize the file and give an error. Next goto your main class

Continue Reading →

Detecting memory leaks in VC++

One of the simplest ways to detect a leak in your code would be to use debugCRT. Simple usage: a. Create you project in visual studio b. run the project in debug mode, then only you will find the memory leak dumps int main() { _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_ALLOC_MEM_DF); //below call will break where the leak

Continue Reading →

creating a new registry key in windows using VC++

Below is the code to create a registry key in VC++. I used visual studio 2008 for this(VC9) RegCreateKeyEx is the command to create the key. More documentation can be found [email protected] msdn. #include “stdafx.h” #include “Windows.h” int _tmain(int argc, _TCHAR* argv[]) { HKEY hOutKey; RegCreateKeyEx(HKEY_LOCAL_MACHINE,  L”SOFTWARE\ABC\Registration\addkey”, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hOutKey, NULL); return

Continue Reading →

Nokia N8 stolen and then reviewed

I recently came across this site where they have reviewed the much awaited nokia n8. What I am amazed is that these fools reviewed an unfinished and untested product and declared the phone worthless. Any sensible person would not review an untested and unreleased product. God save their readers. As for the stolen phone, it

Continue Reading →

comparing two systemtime variables using filetime in vc++

lets take a look at how to compare two systemtime variables but using Filetime to do so. We make use of the utility method CompareFiletime to do this. 1) store the systemtime in a variable 2) convert it into filetime. Use this method SystemTimeToFileTime(&systemtime1, &filetime1) SystemTimeToFileTime(&systemtime2, &filetime2) 3) Compare the filetimes using the method CompareFileTime(&filetime1,

Continue Reading →