<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: messenger code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 21:20:20 GMT</pubDate>
    <description>DZone Snippets: messenger code</description>
    <item>
      <title>May fortune be my IM status.</title>
      <link>http://snippets.dzone.com/posts/show/5049</link>
      <description>// Tired of having others have cooler status on their IM clients,&lt;br /&gt;// I decided that I shall put an end to that.&lt;br /&gt;// Yet, I am no factory of coolness, but I figured my favorite buddy,&lt;br /&gt;// "fortune" will help me out a little.&lt;br /&gt;&lt;br /&gt;// By the way, this tool can definitely be done much better with regard&lt;br /&gt;// to the way it updates the MSN, but hey, I just wanted to play with&lt;br /&gt;// C#. My first time :P&lt;br /&gt;&lt;br /&gt;// BTW, the MSN thing works only if you have your MSN not minimized PLUS&lt;br /&gt;// the toolbar showing. (LAME! I know.)&lt;br /&gt;&lt;br /&gt;// If you really want to do it right, use http://www.xihsolutions.net/dotmsn/&lt;br /&gt;// and send me the code ;) bhtek@yahoo.com&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;using Microsoft.Win32;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Windows.Automation;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace ZenStatusUpdater&lt;br /&gt;{&lt;br /&gt;    class Program &lt;br /&gt;    {&lt;br /&gt;        [DllImport("USER32.DLL", EntryPoint = "FindWindowA", CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;        private static extern IntPtr FindWindow(string sClassName, string sWindowName);&lt;br /&gt;&lt;br /&gt;        [DllImport("USER32.DLL", EntryPoint = "PostMessageA", CallingConvention = CallingConvention.StdCall)]&lt;br /&gt;        private static extern bool PostMessage(IntPtr hWnd, uint iMsg, long wParam, long lParam); &lt;br /&gt;&lt;br /&gt;        static void exploreElement(AutomationElement sub)&lt;br /&gt;        {&lt;br /&gt;            foreach (AutomationProperty prop in sub.GetSupportedProperties())&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("\tProp[" + prop.ProgrammaticName + "]: " + sub.GetCurrentPropertyValue(prop));&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            foreach (AutomationPattern pat in sub.GetSupportedPatterns())&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("\tPat[" + pat.ProgrammaticName + "]");&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        static void explore(AutomationElement el)&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine("Self...");&lt;br /&gt;            exploreElement(el);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            foreach (AutomationElement sub in el.FindAll(TreeScope.Descendants, Condition.TrueCondition))&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine("Sub...");&lt;br /&gt;                exploreElement(sub);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        static void Main(string[] args)&lt;br /&gt;        {&lt;br /&gt;            String fortune = null;&lt;br /&gt;            int tries = 0;&lt;br /&gt;&lt;br /&gt;            do&lt;br /&gt;            {&lt;br /&gt;                fortune = GetFortune();&lt;br /&gt;                tries++;&lt;br /&gt;            } while (fortune.Length &gt; 130);&lt;br /&gt;&lt;br /&gt;            Console.WriteLine("Try #" + tries + ": " + fortune);&lt;br /&gt;&lt;br /&gt;            updateMsnStatus(fortune);&lt;br /&gt;            updateYahooStatus(fortune);&lt;br /&gt;&lt;br /&gt;            System.Threading.Thread.Sleep(5000);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected static void updateYahooStatus(String fortune)&lt;br /&gt;        {&lt;br /&gt;            // Get the current signed in user&lt;br /&gt;            //&lt;br /&gt;            string sUserName = "bhtek";&lt;br /&gt;            Console.WriteLine("The currently logged in user is " + sUserName);&lt;br /&gt;&lt;br /&gt;            // Now open the current user's profile and set the current status message, pass true to&lt;br /&gt;            // OpenSubKey to request write access&lt;br /&gt;&lt;br /&gt;            RegistryKey keyYahooCustomMessages = Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager\\profiles\\"&lt;br /&gt;            + sUserName + "\\Custom Msgs", true);&lt;br /&gt;&lt;br /&gt;            // Set the 5th message, seems like yahoo messenger has the functionality to move the newly set&lt;br /&gt;            // message up as the first one.&lt;br /&gt;            String status = fortune;&lt;br /&gt;            keyYahooCustomMessages.SetValue("5", status);&lt;br /&gt;            byte[] statusBin = (new ASCIIEncoding()).GetBytes(status);&lt;br /&gt;            keyYahooCustomMessages.SetValue("5_bin", (byte[])statusBin); &lt;br /&gt;            keyYahooCustomMessages.Close();&lt;br /&gt;                &lt;br /&gt;            // We are done setting the value in the registry. We now need to notify y! of this change&lt;br /&gt;            //&lt;br /&gt;&lt;br /&gt;            // Find the yahoo messenger window and sent it the notification&lt;br /&gt;            // 0x111: WM_COMMAND&lt;br /&gt;            // 0x188: Code 392&lt;br /&gt;&lt;br /&gt;            IntPtr hWndY = FindWindow("YahooBuddyMain", null);&lt;br /&gt;            System.Diagnostics.Debug.WriteLine("Find window got: " + hWndY.ToString());&lt;br /&gt;            PostMessage(hWndY, 0x111, 0x188, 0);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected static void updateMsnStatus(String fortune)&lt;br /&gt;        {&lt;br /&gt;            AutomationElementCollection msnWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MSBLWindowClass"));&lt;br /&gt;            if (msnWindows.Count &gt; 1)&lt;br /&gt;            {&lt;br /&gt;                foreach (AutomationElement potentialMsn in msnWindows)&lt;br /&gt;                {&lt;br /&gt;                    exploreElement(potentialMsn);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;                return;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            AutomationElement msn = msnWindows[0];&lt;br /&gt;            msn.SetFocus();&lt;br /&gt;&lt;br /&gt;            AutomationElement tools = msn.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AccessKeyProperty, "Alt+T"));&lt;br /&gt;            ExpandCollapsePattern toolsPat = (ExpandCollapsePattern)tools.GetCurrentPattern(ExpandCollapsePattern.Pattern);&lt;br /&gt;            toolsPat.Expand();&lt;br /&gt;&lt;br /&gt;            AutomationElement options = tools.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options..."));&lt;br /&gt;            InvokePattern optionsPat = (InvokePattern)options.GetCurrentPattern(InvokePattern.Pattern);&lt;br /&gt;            optionsPat.Invoke();&lt;br /&gt;&lt;br /&gt;            AutomationElement optionsWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options"));&lt;br /&gt;&lt;br /&gt;            AutomationElement personalMessage = optionsWindow.FindFirst(TreeScope.Descendants,&lt;br /&gt;                new AndCondition(&lt;br /&gt;                    new PropertyCondition(AutomationElement.ClassNameProperty, "RichEdit20W"),&lt;br /&gt;                    new PropertyCondition(AutomationElement.NameProperty, "Type a personal message for your contacts to see:")&lt;br /&gt;                    )&lt;br /&gt;            );&lt;br /&gt;            ValuePattern personalMessagePat = (ValuePattern)personalMessage.GetCurrentPattern(ValuePattern.Pattern);&lt;br /&gt;            personalMessagePat.SetValue(fortune);&lt;br /&gt;&lt;br /&gt;            AutomationElement ok = optionsWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "OK"));&lt;br /&gt;            InvokePattern okPat = (InvokePattern)ok.GetCurrentPattern(InvokePattern.Pattern);&lt;br /&gt;            okPat.Invoke();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private static String GetFortune()&lt;br /&gt;        {&lt;br /&gt;            System.Diagnostics.Process process = new System.Diagnostics.Process();&lt;br /&gt;            process.StartInfo.FileName = "c:\\cygwin\\bin\\fortune.exe";&lt;br /&gt;            process.StartInfo.RedirectStandardOutput = true;&lt;br /&gt;            process.StartInfo.UseShellExecute = false;&lt;br /&gt;            process.Start();&lt;br /&gt;            String fortune = process.StandardOutput.ReadToEnd();&lt;br /&gt;&lt;br /&gt;            fortune = System.Text.RegularExpressions.Regex.Replace(fortune, "\\s+", " ");&lt;br /&gt;            return fortune;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;       &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Jan 2008 11:54:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5049</guid>
      <author>bhtek (Boon Hian Tek)</author>
    </item>
    <item>
      <title>MSN Messenger Password Decrypter for Windows XP &amp; 2003</title>
      <link>http://snippets.dzone.com/posts/show/1007</link>
      <description>// MSN Messenger Password Decrypter for Windows XP &amp; 2003&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; /*&lt;br /&gt; *  MSN Messenger Password Decrypter for Windows XP &amp; 2003&lt;br /&gt; *  (Compiled-VC++ 7.0, tested on WinXP SP2, MSN Messenger 7.0)&lt;br /&gt; *      - Gregory R. Panakkal&lt;br /&gt; *        http://www.crapware.tk/&lt;br /&gt; *        http://www.infogreg.com/&lt;br /&gt; */&lt;br /&gt;&lt;br /&gt;#include &lt;windows.h&gt;&lt;br /&gt;#include &lt;wincrypt.h&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;&lt;br /&gt;#pragma comment(lib, "Crypt32.lib")&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;//Following definitions taken from wincred.h&lt;br /&gt;//[available only in Oct 2002 MS Platform SDK / LCC-Win32 Includes]&lt;br /&gt;&lt;br /&gt;typedef struct _CREDENTIAL_ATTRIBUTEA {&lt;br /&gt;    LPSTR Keyword;&lt;br /&gt;    DWORD Flags;&lt;br /&gt;    DWORD ValueSize;&lt;br /&gt;    LPBYTE Value;&lt;br /&gt;}&lt;br /&gt;CREDENTIAL_ATTRIBUTEA,*PCREDENTIAL_ATTRIBUTEA;&lt;br /&gt;&lt;br /&gt;typedef struct _CREDENTIALA {&lt;br /&gt;    DWORD Flags;&lt;br /&gt;    DWORD Type;&lt;br /&gt;    LPSTR TargetName;&lt;br /&gt;    LPSTR Comment;&lt;br /&gt;    FILETIME LastWritten;&lt;br /&gt;    DWORD CredentialBlobSize;&lt;br /&gt;    LPBYTE CredentialBlob;&lt;br /&gt;    DWORD Persist;&lt;br /&gt;    DWORD AttributeCount;&lt;br /&gt;    PCREDENTIAL_ATTRIBUTEA Attributes;&lt;br /&gt;    LPSTR TargetAlias;&lt;br /&gt;    LPSTR UserName;&lt;br /&gt;} CREDENTIALA,*PCREDENTIALA;&lt;br /&gt;&lt;br /&gt;typedef CREDENTIALA CREDENTIAL;&lt;br /&gt;typedef PCREDENTIALA PCREDENTIAL;&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;typedef BOOL (WINAPI *typeCredEnumerateA)(LPCTSTR, DWORD, DWORD *, PCREDENTIALA **);&lt;br /&gt;typedef BOOL (WINAPI *typeCredReadA)(LPCTSTR, DWORD, DWORD, PCREDENTIALA *);&lt;br /&gt;typedef VOID (WINAPI *typeCredFree)(PVOID);&lt;br /&gt;&lt;br /&gt;typeCredEnumerateA pfCredEnumerateA;&lt;br /&gt;typeCredReadA pfCredReadA;&lt;br /&gt;typeCredFree pfCredFree;&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////////////////////////////////&lt;br /&gt;&lt;br /&gt;void showBanner()&lt;br /&gt;{&lt;br /&gt;    printf("MSN Messenger Password Decrypter for Windows XP/2003\n");&lt;br /&gt;    printf("   - Gregory R. Panakkal, http://www.infogreg.com \n\n");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;////////////////////////////////////////////////////////////////////&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;    PCREDENTIAL *CredentialCollection = NULL;&lt;br /&gt;    DATA_BLOB blobCrypt, blobPlainText, blobEntropy;&lt;br /&gt;&lt;br /&gt;    //used for filling up blobEntropy&lt;br /&gt;    char szEntropyStringSeed[37] = "82BD0E67-9FEA-4748-8672-D5EFE5B779B0"; //credui.dll&lt;br /&gt;    short int EntropyData[37];&lt;br /&gt;    short int tmp;&lt;br /&gt;&lt;br /&gt;    HMODULE hDLL;&lt;br /&gt;    DWORD Count, i;&lt;br /&gt;&lt;br /&gt;    showBanner();&lt;br /&gt;&lt;br /&gt;    //Locate CredEnumerate, CredRead, CredFree from advapi32.dll&lt;br /&gt;    if( hDLL = LoadLibrary("advapi32.dll") )&lt;br /&gt;    {&lt;br /&gt;        pfCredEnumerateA = (typeCredEnumerateA)GetProcAddress(hDLL, "CredEnumerateA");&lt;br /&gt;        pfCredReadA = (typeCredReadA)GetProcAddress(hDLL, "CredReadA");&lt;br /&gt;        pfCredFree = (typeCredFree)GetProcAddress(hDLL, "CredFree");&lt;br /&gt;&lt;br /&gt;        if( pfCredEnumerateA == NULL||&lt;br /&gt;            pfCredReadA == NULL ||&lt;br /&gt;            pfCredFree == NULL )&lt;br /&gt;        {&lt;br /&gt;            printf("error!\n");&lt;br /&gt;            return -1;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;    //Get an array of 'credential', satisfying the filter&lt;br /&gt;    pfCredEnumerateA("Passport.Net\\*", 0, &amp;Count, &amp;CredentialCollection);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    if( Count ) //usually this value is only 1&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        //Calculate Entropy Data&lt;br /&gt;        for(i=0; i&lt;37; i++) // strlen(szEntropyStringSeed) = 37&lt;br /&gt;        {&lt;br /&gt;            tmp = (short int)szEntropyStringSeed[i];&lt;br /&gt;            tmp &lt;&lt;= 2;&lt;br /&gt;            EntropyData[i] = tmp;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        for(i=0; i&lt;Count; i++)&lt;br /&gt;        {&lt;br /&gt;            blobEntropy.pbData = (BYTE *)&amp;EntropyData;&lt;br /&gt;            blobEntropy.cbData = 74; //sizeof(EntropyData)&lt;br /&gt;&lt;br /&gt;            blobCrypt.pbData = CredentialCollection[i]-&gt;CredentialBlob;&lt;br /&gt;            blobCrypt.cbData = CredentialCollection[i]-&gt;CredentialBlobSize;&lt;br /&gt;&lt;br /&gt;            CryptUnprotectData(&amp;blobCrypt, NULL, &amp;blobEntropy, NULL, NULL, 1, &amp;blobPlainText);&lt;br /&gt;            &lt;br /&gt;            printf("Username : %s\n", CredentialCollection[i]-&gt;UserName);&lt;br /&gt;            printf("Password : %ls\n\n", blobPlainText.pbData);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    pfCredFree(CredentialCollection);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 22 Dec 2005 18:05:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1007</guid>
      <author>mornlee (mornlee)</author>
    </item>
  </channel>
</rss>
