<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>Ex nihilo nihil fit &#187; Microsoft</title> <atom:link href="http://victorhurdugaci.com/category/microsoft/feed/" rel="self" type="application/rss+xml" /><link>http://victorhurdugaci.com</link> <description>Victor Hurdugaci&#039;s playground</description> <lastBuildDate>Wed, 18 Apr 2012 16:29:21 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=</generator> <item><title>Default indexer and Reflection glitch</title><link>http://victorhurdugaci.com/default-indexer-and-reflection-glitch/</link> <comments>http://victorhurdugaci.com/default-indexer-and-reflection-glitch/#comments</comments> <pubDate>Fri, 22 Apr 2011 13:28:07 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Code]]></category> <category><![CDATA[Reflection]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2279</guid> <description><![CDATA[I was writing some C# unit tests that had to use Reflection in order to set properties on objects, when I got into an interesting problem. I will provide a simplified version of the code I wrote, first the version without reflection, then my reflection version that had an issue and, in the end, the [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">I was writing some C# unit tests that had to use Reflection in order to set properties on objects, when I got into an interesting problem. I will provide a simplified version of the code I wrote, first the version without reflection, then my reflection version that had an issue and, in the end, the correct version.</p><p
style="text-align: justify;"><em>TestClass </em>is a class that has a property of type <em>List&lt;int&gt;</em>:</p><pre class="brush: csharp; title: ; notranslate">
class TestClass
{
    public List&lt;int&gt; Value { get; set; }
}
</pre><p
style="text-align: justify;">Goal: create an instance of this class, set the property and print the second element in the list. Simple, huh? The code without reflection is:</p><pre class="brush: csharp; title: ; notranslate">
TestClass c = new TestClass();
c.Value = new List&lt;int&gt;() { 4, 5, 6 };
Console.WriteLine(c.Value[1]);
</pre><p
style="text-align: justify;">Seems straight forward to use reflection for this, right? Here is my attempt:</p><pre class="brush: csharp; title: ; notranslate">
//TestClass c = new TestClass();
object c = new TestClass();
//c.Value = new List&lt;int&gt;() { 4, 5, 6 };
Type t = c.GetType();
PropertyInfo prop = t.GetProperty(&quot;Value&quot;, BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(c, new List&lt;int&gt;() { 4, 5, 6 }, null);
//Console.WriteLine(c.Value[1]);
int valueToOutput = (int)prop.GetValue(c, new object[] { 1 });
Console.WriteLine(valueToOutput);
</pre><p
style="text-align: justify;">Can you see the glitch? I can tell you that line 10 throws <em>TargetParameterCountException</em>. You know why?</p><p><span
id="more-2279"></span></p><p
style="text-align: justify;">Looking at the IL disassembled code for the program without reflection gives the answer (I added some comments for clarity and removed unnecessary lines):</p><pre class="brush: plain; highlight: [12,13]; title: ; notranslate">
//TestClass c = new TestClass();
IL_0001:  newobj     instance void ConsoleApplication1.TestClass::.ctor()
//c.Value = new List&lt;int&gt;() { 4, 5, 6 };
IL_0008:  newobj     instance void class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;::.ctor()
IL_0010:  callvirt   instance void class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;::Add(!0)
IL_0018:  callvirt   instance void class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;::Add(!0)
IL_0020:  callvirt   instance void class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;::Add(!0)
IL_0027:  callvirt   instance void ConsoleApplication1.TestClass::set_Value(class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;)
//Console.WriteLine(c.Value[1]);
IL_002e:  callvirt   instance class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt; ConsoleApplication1.TestClass::get_Value()
IL_0034:  callvirt   instance !0 class [mscorlib]System.Collections.Generic.List`1&lt;int32&gt;::get_Item(int32)
IL_0039:  call       void [mscorlib]System.Console::WriteLine(int32)
</pre><p
style="text-align: justify;">Line 3 in the original program gets translated to a property get in order to obtain the <em>List&lt;nt&gt;</em> object and then, on that object, the <em>get_Item</em> method is called with the same arguments as the indexed property. This is where I was wrong, I was calling the property with the arguments that were supposed to be for method and, of course, not invoking the method. The correct approach is (changed lines are highlighted):</p><pre class="brush: csharp; highlight: [10,11,12]; title: ; notranslate">
//TestClass c = new TestClass();
object c = new TestClass();
//c.Value = new List&lt;int&gt;() { 4, 5, 6 };
Type t = c.GetType();
PropertyInfo prop = t.GetProperty(&quot;Value&quot;, BindingFlags.Public | BindingFlags.Instance);
prop.SetValue(c, new List&lt;int&gt;() { 4, 5, 6 }, null);
//Console.WriteLine(c.Value[1]);
object listObject = prop.GetValue(c, null);
MethodInfo mtd = listObject.GetType().GetMethod(&quot;get_Item&quot;, BindingFlags.Public | BindingFlags.Instance);
int valueToOutput = (int)mtd.Invoke(listObject, new object[] { 1 });
Console.WriteLine(valueToOutput);
</pre><p
style="text-align: justify;">In the end, two observations:</p><p
style="text-align: justify;">1. A method can&#8217;t have a default indexer and a method <em>get_Item</em> with the same argument. The following code will not compile because the method is defined twice.</p><pre class="brush: csharp; title: ; notranslate">
class TestClass
{
    public int this[int index]
    {
        get
        {
            return 0;
        }
    }
    public int get_Item(int index)
    {
        return 0;
    }
}
</pre><p
style="text-align: justify;">2. You can replace indices with calls to <em>get_Item</em>. This method is hidden by the Visual Studio Intellisense but it perfectly legal.</p><pre class="brush: csharp; title: ; notranslate">
TestClass c = new TestClass();
c.Value = new List&lt;int&gt;() { 4, 5, 6 };
//Equivalent with Console.WriteLine(c.Value[1]);
Console.WriteLine(c.Value.get_Item(1));
</pre>]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/default-indexer-and-reflection-glitch/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Fun with Batch files</title><link>http://victorhurdugaci.com/fun-with-batch-files/</link> <comments>http://victorhurdugaci.com/fun-with-batch-files/#comments</comments> <pubDate>Sat, 12 Feb 2011 09:24:06 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Script]]></category> <category><![CDATA[BAT]]></category> <category><![CDATA[Tricky]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2243</guid> <description><![CDATA[It goes like this: create a small script that will take the files from a folder (only the top folder, not the sub directories) and will copy them to Program Files (32 bit). How hard can it be? Well&#8230; If you have a programming background and you like to format the code then, such a [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">It goes like this: create a small script that will take the files from a folder (only the top folder, not the sub directories) and will copy them to Program Files (32 bit). How hard can it be?</p><p
style="text-align: justify;">Well&#8230; If you have a programming background and you like to format the code then, such a task takes 1 hour, otherwise&#8230; 5 minutes.</p><p
style="text-align: justify;">So, I wrote a batch file (just part of it displayed here):</p><pre class="brush: powershell; title: ; notranslate">
SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)
</pre><p
style="text-align: justify;">Which is incorrect. Can you spot the mistake?</p><p
style="text-align: justify;">I will highlight one of the lines for you, maybe you can spot it then.</p><pre class="brush: powershell; highlight: [6]; title: ; notranslate">
SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath = %ProgramFiles(x86)%
IF %config% == 1 (set drop = source\bin\x86\Debug)
IF %config% == 2 (set drop = bin\x86\Release)
</pre><p
style="text-align: justify;">Another hint: lines 5, 6 and 7 are incorrect.</p><p
style="text-align: justify;">Let me fix it and maybe you&#8217;ll see the problem.<br
/> <span
id="more-2243"></span></p><pre class="brush: powershell; title: ; notranslate">
SET /P config=Configuration to deploy (1 = Debug; 2 = Release):
ECHO Setting up folders...
SET instpath=%ProgramFiles(x86)%
IF %config% == 1 (set drop=source\bin\x86\Debug)
IF %config% == 2 (set drop=bin\x86\Release)
</pre><p
style="text-align: justify;">Can you see the difference now? Some of you might not&#8230;</p><p
style="text-align: justify;">In BAT files:</p><pre class="brush: powershell; light: true; title: ; notranslate">SET instpath=%ProgramFiles(x86)%</pre><p>and</p><pre class="brush: powershell; light: true; title: ; notranslate">SET instpath = %ProgramFiles(x86)%</pre><p
style="text-align: justify;">are not the same. The first one will set the variable, while the second one will fail (without warning/error). Apparently, there should be no space between the variable name and the equal sign when setting a value.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/fun-with-batch-files/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>OneNote Anywhere</title><link>http://victorhurdugaci.com/onenote-anywhere/</link> <comments>http://victorhurdugaci.com/onenote-anywhere/#comments</comments> <pubDate>Mon, 08 Nov 2010 21:19:51 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Office Live]]></category> <category><![CDATA[OneNote]]></category> <category><![CDATA[Sync]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2177</guid> <description><![CDATA[I like OneNote. I use it to store different code snippets and links to tech pages with useful information. It is not the ideal tool for doing this &#8211; IMO there is no tool, yet, that can replace a physical notebook &#8211; but I got used to it. Especially I enjoy the search feature because [...]]]></description> <content:encoded><![CDATA[<div
class="alignright" style="margin-left: 5px;"><p><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep2.jpg"><img
class="size-medium wp-image-2179" title="OneNoteLiveStep2" src="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep2-300x204.jpg" alt="" width="300" height="204" /></a></p><p><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep3.jpg"><img
class="size-medium wp-image-2180" title="OneNoteLiveStep3" src="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep3-300x204.jpg" alt="" width="300" height="204" /></a></p><p><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep4.jpg"><img
class="size-medium wp-image-2181" title="OneNoteLiveStep4" src="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep4-300x159.jpg" alt="" width="300" height="159" /></a></p></div><p
style="text-align: justify;">I like OneNote. I use it to store different code snippets and links to tech pages with useful information. It is not the ideal tool for doing this &#8211; IMO there is no tool, yet, that can replace a physical notebook &#8211; but I got used to it. Especially I enjoy the search feature because is impossible to do it on paper.</p><p
style="text-align: justify;">Until a few months ago, a solution for sharing the notebook between PCs was Mesh (or DropBox, or similar services), solution about which I wrote <a
href="http://victorhurdugaci.com/tip-3-shared-onenote-notebooks-with-live-mesh/" target="_blank">here</a>. Since Office Live, this task was simplified &#8211; not that it was complicated before. With Office Live you can now save the notebooks online and edit them directly. Moreover, it allows sharing notebooks between computers connected to the Internet.</p><p><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep1.jpg"></a><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep1.jpg"><img
class="size-full wp-image-2178 aligncenter" title="OneNoteLiveStep1" src="http://victorhurdugaci.com/wp-content/uploads/2010/11/OneNoteLiveStep1.jpg" alt="" width="430" height="178" /></a></p><p
style="text-align: justify;">To do this you need a <a
href="http://skydrive.live.com/" target="_blank">SkyDrive </a>account (actually a LiveID). Then you can go on the website and create a new notebook. Give it a name and add information in it;do (almost) whatever you were doing in the OneNote client.</p><p
style="text-align: justify;">Now, if you choose Open in OneNote it will add that notebook to the application and&#8230; the best part&#8230; it will keep it synchronized with the live version.  You still have a local copy but if you lose it, only the changes since the last sync are gone &#8211; if  you are connected to the Internet then the last sync is, probably, 2 minutes ago. If you change the notebook in one place (on the website or in the local application), the changes will be reflected everywhere.</p><p
style="text-align: justify;">You can open the notebook on two or more computers and it will be updated on all of them. Even if one of them is offline, the changes are stored on the Internet and when you connect, you get the updated version.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/onenote-anywhere/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Modifying .NET binaries – Part 2</title><link>http://victorhurdugaci.com/modifying-net-binaries-part-2/</link> <comments>http://victorhurdugaci.com/modifying-net-binaries-part-2/#comments</comments> <pubDate>Wed, 21 Jul 2010 11:16:39 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[.NET Framework]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Expert]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[Advanced]]></category> <category><![CDATA[CFF Explorer]]></category> <category><![CDATA[Cracking]]></category> <category><![CDATA[IL]]></category> <category><![CDATA[WinDbg]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2122</guid> <description><![CDATA[Description Objective Remove the &#8216;Trial protection&#8217; from an obfuscated .NET application Tools WinDbg CFF Explorer Target audience Advanced users The second part of the article discusses how to modify binaries that are obfuscated. For simplicity and clarity, I will not use obfuscated binaries. Doing this, allows the reader to understand what is actually happening. In [...]]]></description> <content:encoded><![CDATA[<table
class="tutorial-description" border="1" cellspacing="0"><tbody><tr><th
colspan="2">Description</th></tr><tr><td
class="header-column">Objective</td><td>Remove the &#8216;Trial protection&#8217; from an obfuscated .NET application</td></tr><tr><td
class="header-column">Tools</td><td><ul><li>WinDbg</li><li>CFF Explorer</li></ul></td></tr><tr><td
class="header-column">Target audience</td><td>Advanced users</td></tr></tbody></table><p
style="text-align: justify;">The second part of the article discusses how to modify binaries that are obfuscated. For simplicity and clarity, I will not use obfuscated binaries. Doing this, allows the reader to understand what is actually happening. In the demo I will completely ignore the name of the methods or the actual, non-obfuscated, code.</p><p
style="text-align: justify;">I recommend reading the <a
href="http://victorhurdugaci.com/modifiying-net-binaries-part-1/" target="_blank">first part</a>, if you didn&#8217;t already. It provides some information that might be needed to understand theis second part.</p><p
style="text-align: justify;">The same &#8216;TrialApp.exe&#8217; binary is used. The current approach, as opposed the the former one, is:</p><ol
style="text-align: justify;"><li>Load the application in debugger and break the execution when the trial message is displayed.</li><li>Get the call stack</li><li>Find the address of the trial check method</li><li>Remove the call</li></ol><h4 style="text-align: justify;">1. Load the application in debugger and break the execution when the trial message is displayed</h4><p
style="text-align: justify;">WinDbg can be obtained for free from Windows SDK (see the Microsoft Downloads website). If you are running a 64 bit OS, make sure you start the 32bit version of WinDbg (should be in Program Files (x86)).</p><p
style="text-align: justify;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg01.jpg"><img
class="alignright size-thumbnail wp-image-2130" title="WinDbg01" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg01-150x101.jpg" alt="" width="150" height="101" /></a>Load &#8216;TrialApp.exe&#8217; in WinDbg by clicking File -&gt; Load Executable. In order to run it you have 3 options:</p><ol
style="text-align: justify;"><li>Type &#8216;g&#8217; and press ENTER</li><li>Press F5</li><li>Click Debug -&gt; Go</li></ol><p
style="text-align: justify;">The application will start and the execution will stop when the message box is displayed. Is actually waiting for the user to click OK. At this point break the execution by pressing Debug -&gt; Break.</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg02.jpg"><img
class="aligncenter size-large wp-image-2131" title="WinDbg02" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg02-1024x689.jpg" alt="" width="717" height="482" /></a></p><p
style="text-align: justify;">Before being able to debug the .NET application, 2 DLLs needs to be loaded. They help the debugger &#8216;understand&#8217; the .NET internals. The actual paths might differ on your configuration. Anyway, make sure you load the 32 bit version of these files (the 64 bit version are in the <em>Framework64 </em>folder). The <em>.load</em> command loads external libraries.</p><pre class="brush: plain; light: true; title: ; notranslate">.load c:\Windows\Microsoft.NET\Framework\v4.0.30319\SOS.dll
.load c:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll</pre><h4><span
id="more-2122"></span>2. Get the call stack</h4><p
style="text-align: justify;">A call stack is associated with a thread. Before getting the stack we need to figure out which is the thread for which we want it. Execute the following command and inspect the output&#8230;</p><pre class="brush: plain; light: true; title: ; notranslate">!threads</pre><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg03.jpg"><img
class="size-large wp-image-2132  aligncenter" title="WinDbg03" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg03-1024x689.jpg" alt="" width="717" height="482" /></a></p><p
style="text-align: justify;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg03.jpg"></a>There are two thread having IDs 0 and 2. Is quite easy to decide which is the main thread since just one of them is Single Thread Apartment (STA). Switch to the main thread and display the CLR stack using the following commands:</p><pre class="brush: plain; light: true; title: ; notranslate">~0s
!clrstack</pre><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg04.jpg"><img
class="aligncenter size-large wp-image-2133" title="WinDbg04" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg04-1024x689.jpg" alt="" width="717" height="482" /></a></p><h4>3. Find the address of the trial check method</h4><p
style="text-align: justify;">OK! You&#8217;re still with me? If yes, then take a look at the result of the last command. It displays the call stack of the main thread. Notice that OnCreateControl calls OnLoad, OnLoad calls From1_Load, etc. In the case of obfuscated code, the name would probably be strange and you would have to analyze each method in depth. Because the code was JIT compiled the call to the trial check was inlined.</p><p
style="text-align: justify;">Let&#8217;s take a look at the IL code for Form1_Load. To do this, first we need the address description of the MethodDesc structure of method. The <em>ip2md</em> command returns the structure. The argument is the IP address of the method. After this, just dump the IL for the address specified in MethodDesc. I want to make on observation here: if you look at the MethodDesc structure you can see the <em>mdToken</em> field. This field specified the table and the row in the table for the this method (the row corresponding to this method is the 6<sup>th</sup>, because the index starts at 0).</p><pre class="brush: plain; light: true; title: ; notranslate">!ip2md 003f01f9
!dumpil 00176304</pre><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg05_details.jpg"><img
class="aligncenter size-large wp-image-2135" title="WinDbg05_details" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/WinDbg05_details-1024x689.jpg" alt="" width="717" height="482" /></a></p><p
style="text-align: justify;">In case of obfuscated code, you would probably see just a call instruction to some cryptic method. It makes no difference. We can see that at IL_0001 (relative to the start of the method) we have a call and this instruction uses 5 bytes in the file (0006-0001 = 0005; in hex)).</p><p
style="text-align: justify;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/CFF01.jpg"><img
class="alignright size-thumbnail wp-image-2126" title="CFF01" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/CFF01-150x101.jpg" alt="" width="150" height="101" /></a>Having the size of the instruction, its position and the row of the method in the <a
href="http://msdn.microsoft.com/en-us/magazine/cc163791.aspx#S8" target="blank">methods table</a> we can proceed further. Open CFF Explorer and load the assembly.</p><p
style="text-align: justify;">Navigate to .NET Directory -&gt; MetaData Streams -&gt; #~ -&gt; Tables. Look for the Method table in the new tree and select the entry with number 5. Copy its RVA value.</p><h4>4. Remove the call</h4><p
style="text-align: justify;">With the RVA in hand (on clipboard :-) ), remove the call just like in the first part of the article. Replace the call bytes with zeros. One observation: we must also remove the instruction before the call (ldarg_0; opcode 02; no arguments). So, zero 6 bytes starting at the first in the method.</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/07/CFF02.jpg"><img
class="aligncenter size-large wp-image-2127" title="CFF02" src="http://victorhurdugaci.com/wp-content/uploads/2010/07/CFF02-1024x692.jpg" alt="" width="717" height="484" /></a></p><p
style="text-align: justify;">In other words, replace:</p><pre class="brush: plain; light: true; title: ; notranslate">00 00 0A 02 28 08 00 00 06 2A 1E 02 28 06 00 00
06 2A 66 02 7B 02 00 00 04 2C 10 72 01 00 00 00</pre><p>with</p><pre class="brush: plain; light: true; title: ; notranslate">00 00 0A 02 28 08 00 00 06 2A 1E 00 00 00 00 00
00 2A 66 02 7B 02 00 00 04 2C 10 72 01 00 00 00</pre><p
style="text-align: justify;">Run the application. The trial check is gone.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/modifying-net-binaries-part-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>They finally merge</title><link>http://victorhurdugaci.com/they-finally-merge/</link> <comments>http://victorhurdugaci.com/they-finally-merge/#comments</comments> <pubDate>Sat, 26 Jun 2010 21:54:22 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Microsoft]]></category> <category><![CDATA[News]]></category> <category><![CDATA[Dreams]]></category> <category><![CDATA[Integration]]></category> <category><![CDATA[Live Mesh]]></category> <category><![CDATA[Office Live]]></category> <category><![CDATA[SkyDrive]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2110</guid> <description><![CDATA[Online software is nice because it allows you to have your documents (of any form) available anywhere is Internet access. However, you end up being forced to use a lot of services and, the worst part, they never interact. For example: I was using Microsoft Live Mesh in order to synchronize and backup my files [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">Online software is nice because it allows you to have your documents (of any form) available anywhere is Internet access. However, you end up being forced to use a lot of services and, the worst part, they never interact.</p><p
style="text-align: justify;">For example: I was using Microsoft Live Mesh in order to synchronize and backup my files with the cloud. But MS also offered the Office Workspaces where you could store documents. So, I was using 2 services but it was impossible to edit/view a document from Mesh in the SharePoint workspace.</p><p
style="text-align: justify;">Another example is SkyDrive, with the new feature for editing documents (Office Live Apps). A nice addition, but my documents were in Mesh, not in SkyDrive. So, again, I had everything except the interaction between applications.</p><p
style="text-align: justify;">I am really excited to say it: they finally (started to) merge all the services! Seems that SkyDrive will the place where everything goes merged:</p><ul
style="text-align: justify;"><li>SkyDrive offers 25 GB for storage</li><li>Live Mesh will be replaced by Live Sync, which will upload the files on SkyDrive (just 2 out of 25 GB storage limit &#8211; strange)</li><li>Office 2010 supports loading and saving from and to SkyDrive</li><li>Office Live Apps are on SkyDrive <span
style="text-decoration: line-through;">and documents uploaded through Sync can be edited there </span>Seems that synced files cannot be edited :(</li><li>Live Workspace will be replaced (integrated?) by Office Live Apps</li></ul><p
style="text-align: justify;">With the Outlook connector I can keep my calendar, contacts and e-mail synchronized with the same cloud. Hopefully a feature for synchronizing tasks will be added soon. Also, mobile synchronization is a must &#8211; for my WM phone.</p><p
style="text-align: justify;">Is really nice that MS is doing a homogeneous environment where everything can be accessed from everywhere. However, the integration is not complete and it would be nice if they could integrate everything from My Phone to Messenger and social networks. Just imagine a single place from where you can do everything without being forced to use many services&#8230; [I'm dreaming, right?]</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/they-finally-merge/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Modifying .NET binaries &#8211; Part 1</title><link>http://victorhurdugaci.com/modifiying-net-binaries-part-1/</link> <comments>http://victorhurdugaci.com/modifiying-net-binaries-part-1/#comments</comments> <pubDate>Sun, 30 May 2010 17:11:00 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[.NET Framework]]></category> <category><![CDATA[C#]]></category> <category><![CDATA[Expert]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[.NET]]></category> <category><![CDATA[Advanced]]></category> <category><![CDATA[CFF Explorer]]></category> <category><![CDATA[Cracking]]></category> <category><![CDATA[IL]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2076</guid> <description><![CDATA[The content of this post can be used for good and bad purposes. Modifying the source code to bypass trial/license checks is what crackers do in order to get paid software for free. Be advised that the purpose of this article is not to teach you how to steal. My target for this article are [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">The content of this post can be used for good and bad purposes. Modifying the source code to bypass trial/license checks is what crackers do in order to get paid software for free. Be advised that the purpose of this article is not to teach you how to steal. My target for this article are the .NET developers who should understand what a cracker will (try to) do in order to get access to paid features.</p><p
style="text-align: justify;">Before reading any further you should understand that each protection measure (as long as the cracker can access the source code) is useless. Is just a matter of time, for a motivated person, before she will bypass any protection.</p><p
style="text-align: justify;">For the demo, we are going to use a very simple Windows Forms Application that will display a message box with a trial message and will exit after that. The goal is to show a few techniques that will prevent the application from exiting (and will remove the trial message).</p><p
style="text-align: justify;">The code for the &#8216;trial&#8217; application is kept in just one class. There is just one variable for checking the trial and we&#8217;ll consider that is always true &#8211; it makes no difference if there was a function call to determine if the trial has expired.</p><pre class="brush: csharp; title: ; notranslate">
public partial class Form1 : Form
{
    bool hasExpired = true;
    public Form1()
    {
        InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        CheckTrialApp();
    }
    private void CheckTrialApp()
    {
        if (hasExpired)
        {
            MessageBox.Show(&quot;Trial has expired&quot;);
            Application.Exit();
        }
    }
}
</pre><p
style="text-align: justify;">The binary used was compiled on the x86 Release configuration with VS2010 having .NET 4.0 as target framework. The IL Disassembler from VS2010 and a free application called <a
href="http://www.ntcore.com/exsuite.php" target="blank">CFF Explorer</a> are used to view and edit the binary.</p><p
style="text-align: justify;"><span
id="more-2076"></span></p><p
style="text-align: justify;">Opening the &#8216;TrialApp.exe&#8217; file (the target binary) in IL Dissasembler will reveal all the statements from each method. This is important but, more important is the <a
href="http://stackoverflow.com/questions/2170843/va-virutual-adress-rva-relative-virtual-address" target="blank">RVA</a> of the method containing the trial check, the bytes for each statement and their position relative to the RVA.</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/05/BytesExplained.jpg"><img
class="aligncenter size-full wp-image-2087" title="BytesExplained" src="http://victorhurdugaci.com/wp-content/uploads/2010/05/BytesExplained.jpg" alt="" width="708" height="408" /></a></p><p
style="text-align: justify;">By knowing the RVA you are able to navigate to that address using CFF explorer and locate the bytes for the calls. Even without seeing the actual bytes, one is able to locate the calls (and their length) by looking at the offsets (ie: the byte 2C is located 0006 bytes from the beginning of the implementation) &#8211; more on this in Part2.</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/05/ILMapping.jpg"><img
class="aligncenter size-large wp-image-2090" title="ILMapping" src="http://victorhurdugaci.com/wp-content/uploads/2010/05/ILMapping-1024x433.jpg" alt="" width="717" height="303" /></a></p><p
style="text-align: justify;">Having access to all this information gives not one but many possibilities of bypassing the trial check:</p><ol
style="text-align: justify;"><li>Remove the two calls to <em>Application.Exit</em> and <em>MessageBox.Show.</em></li><li>Change the <em>if</em> check.</li><li>Remove the &#8216;CheckTrialApp&#8217; call from &#8216;Form1_Load&#8217;.</li></ol><p
style="text-align: justify;">This post will cover just the first two possibilities, since the third is similar to the first.</p><h3>1. Remove the calls to <em>Exit </em>and <em>Show</em></h3><p
style="text-align: justify;">The bytes from the method implementation:</p><pre class="brush: csharp; light: true; title: ; notranslate">
         02 7B 02 00 00 04 2C 10 72 01 00 00 70
28 16 00 00 0A 26 28 17 00 00 0A 2A
</pre><p
style="text-align: justify;">A call to a method has the opcode 28. The next 4 bytes following the opcode represent the location of the method in the methods table (you can see this table using CFF explorer).</p><p
style="text-align: justify;">Now here comes the magic: in order to remove the calls to <em>Exit </em>and <em>Show, </em>one must  replace with NOP, all the bytes associated with these methods. Basically we are going the introduce a NOP byte (00) for each byte in the call.</p><pre class="brush: csharp; light: true; title: ; notranslate">
         02 7B 02 00 00 04 2C 10 72 01 00 00 70
00 00 00 00 00 26 00 00 00 00 00 2A
</pre><p>That&#8217;s all. Save the file and the trial is bypassed.</p><h3>2. Change the <em>if</em> check</h3><p
style="text-align: justify;">If you look in the disassembled IL you can see that at offset 0&#215;6 we have a <em>brfalse.s</em> opcode. This is a branch instruction that will branch to offset 0&#215;18 (IL_0018) if false. However, in the case of &#8216;TrialApp&#8217;, since <em>hasExpired</em> is always true, the branch will never take place and the code following it will be executed.</p><p
style="text-align: justify;">In order to change the meaning of the code &#8211; in other words &#8220;give the trial message if the application has NOT expired&#8221; &#8211; the check will be changed. Currently, is checking against <em>false</em> using the instruction <em>brfalse.s</em>, having the opcode 2C. By looking on MSDN, the opcode for <em>brtrue.s</em> can be found: 2D. Replacing 2C with 2D will make the branch happen always.</p><p
style="text-align: justify;">The method inside the binary, after replacing the <em>brfalse.s</em> opcode:</p><pre class="brush: csharp; light: true; title: ; notranslate">
         02 7B 02 00 00 04 2D 10 72 01 00 00 70
28 16 00 00 0A 26 28 17 00 00 0A 2A
</pre><p
style="text-align: justify;">That&#8217;s all. The message box will not be displayed since the body of the <em>if</em> statement is no longer executed.</p><p
style="text-align: justify;">There are some techniques that will make cracking difficult. Obfuscating the code is one of them. However, part 2 of this article will cover the modification of obfuscated binaries.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/modifiying-net-binaries-part-1/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Expression evaluation</title><link>http://victorhurdugaci.com/expression-evaluation/</link> <comments>http://victorhurdugaci.com/expression-evaluation/#comments</comments> <pubDate>Thu, 27 May 2010 17:44:33 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Tips]]></category> <category><![CDATA[Bug]]></category> <category><![CDATA[Coding]]></category> <category><![CDATA[Evaluation]]></category> <category><![CDATA[Expression]]></category> <category><![CDATA[Java]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=2035</guid> <description><![CDATA[Let&#8217;s start with a simple quiz: 7/2 = &#8230; . Of course is 3.5 but is this also true for code? If you somehow use a non-fractional data type for storing the result, you will always get the result 3. And that should not surprise you. However, if you choose to use a fractional data [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">Let&#8217;s start with a simple quiz: 7/2 = &#8230; . Of course is 3.5 but is this also true for code?</p><p
style="text-align: justify;">If you somehow use a non-fractional data type for storing the result, you will always get the result 3. And that should not surprise you.</p><pre class="brush: csharp; light: true; title: ; notranslate">
int result = 7/2; //expression is 3
</pre><p
style="text-align: justify;">However, if you choose to use a fractional data type, things will change &#8230;</p><pre class="brush: csharp; light: true; title: ; notranslate">
double result = 7/2;
</pre><p
style="text-align: justify;">&#8230; or not. The value stored in the variable <em>result</em> is still 3 (actually 3.0 or something really close to 3.0 &#8211; since floating point data types store the approximation of a number).</p><p
style="text-align: justify;">Why is this happening?<br
/> <span
id="more-2035"></span><br
/> Let&#8217;s take a look at the expression, <em>result = 7/2</em>. There are two operators: / and =. Based on their precedence, the first evaluated is the division operator; it is a binary operator so, it has two operands. The general definition of the / operator in C# is:</p><pre class="brush: csharp; light: true; title: ; notranslate">
public static TYPE1 operator /(TYPE2 op1, TYPE3 op2)
</pre><p
style="text-align: justify;">In our case 7 and 2 need to be matched to TYPE2 and TYPE3. In most languages, the operators for primitive types are defined only for the same type of operands (TYPE2 = TYPE3). In this way, for <em>n</em> types <em>n</em> operator overloads have to be defined, otherwise it could go up to <em>n<sup>2</sup></em> overloads.</p><p
style="text-align: justify;">The compiler will try to match the operands with one of the operator signatures. In our case, both operands are integer so, it will call <em>operator / (int, int)</em> which returns <em>int</em> (!!). The expression on the right hand side (RHS) of = is evaluated as an <em>int</em>.</p><p
style="text-align: justify;">After that, the = operator will be evaluated. Because its RHS operand is an <em>int</em>, a conversion will be performed to <em>double</em>, in order to match the type of the left hand side of the operator. At this point, is to late to get the fractional part because it was already disposed. The final result will be an integer represented as a double.</p><p
style="text-align: justify;">The following drawing shows the abstract syntax tree and its evaluation for the previously mentioned expression.</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/05/AST1.jpg"><img
class="aligncenter size-large wp-image-2047" title="AST1" src="http://victorhurdugaci.com/wp-content/uploads/2010/05/AST1-1024x581.jpg" alt="" width="740" height="430" /></a></p><p
style="text-align: justify;">In order to fix the problem, you need to explicitly state that a certain part of the expression must be evaluated as double. The best way to do this is to make one of the operands double. For example:</p><pre class="brush: csharp; light: true; title: ; notranslate">
double r1 = 7.0/2;
double r2 = 7/2.0;
double r3 = 7.0/2.0;
double r4 = 7d/2d;
double r5 = ((double)5)/2; //This is not recommended but will work
</pre><p
style="text-align: justify;">In this above cases, the conversion node will be evaluated sooner, before any precision is lost, hence allowing you to get the expected result. The next image shows the AST for the expression <em>double result = 7 / 3.0</em>.</p><p><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/05/AST2.jpg"><img
src="http://victorhurdugaci.com/wp-content/uploads/2010/05/AST2-1024x593.jpg" alt="" title="AST2" width="740" height="430" class="aligncenter size-large wp-image-2053" /></a></p><p
style="text-align: justify;">Understanding how an expression is evaluated is very important because non trivial statement can make your life harder. Take a look at the following examples and try to guess the results (r4 is similar to a bug we encountered).</p><pre class="brush: csharp; light: true; title: ; notranslate">
double r1 = 7 / 2;
double r2 = 6.0 + 7 / 2;
double r3 = 5 / 2 + 7 / 2;
double r4 = DateTime.Now.Millisecond * (1000 / 3600);
double r5 = 6.5 / (1 / 2);
double r6 = 10.0 * (1 / 2);
double r7 = 11.0 * 1 / 2;
</pre>]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/expression-evaluation/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>My Interview with Microsoft</title><link>http://victorhurdugaci.com/my-interview-with-microsoft/</link> <comments>http://victorhurdugaci.com/my-interview-with-microsoft/#comments</comments> <pubDate>Sat, 13 Mar 2010 16:59:46 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Personal/Blog]]></category> <category><![CDATA[Denmark]]></category> <category><![CDATA[Interview]]></category> <category><![CDATA[MDCC]]></category> <category><![CDATA[Question]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=1837</guid> <description><![CDATA[This post is for those who want to apply or have already applied (but not finished the interview) for a Microsoft Job. The recruitment process is quite similar for everyone and consists of a few steps. Application E-Mail Interview Phone Interview On Site Interview I will tell you my story and how I went through [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">This post is for those who want to apply or have already applied (but not finished the interview) for a Microsoft Job. The recruitment process is quite similar for everyone and consists of a few steps.</p><ol
style="text-align: justify;"><li>Application</li><li>E-Mail Interview</li><li>Phone Interview</li><li>On Site Interview</li></ol><p
style="text-align: justify;">I will tell you my story and how I went through the four phases.</p><h3 style="text-align: justify;">1. Application</h3><p
style="text-align: justify;">My blog&#8217;s title (Ex Nihilo Nihil Fit) means &#8220;Nothing Comes Out of Nothing&#8221;. You can&#8217;t get a job at Microsoft by not doing anything &#8211; this is true for anything else. The first step you need to complete is the application process.</p><p
style="text-align: justify;">For this, many options are available. You can&#8230;</p><ul
style="text-align: justify;"><li>&#8230; apply online on Microsoft&#8217;s Careers website as I did</li><li>&#8230; send your CV to different e-mail addresses (there are some dedicated e-mails for different positions)</li><li>&#8230; apply through some 3rd party organization (job shop, campus recruitment, job agency, etc)</li></ul><p
style="text-align: justify;">On MS Careers you just have to post your CV and choose the job you want. That&#8217;s all! No recommendation letter, no cover letter, no nothing. Of course, not every CV passes the selection process. Here are some tips for improving your resume (worked for me):</p><ol
style="text-align: justify;"><li><strong>Don&#8217;t write it just before applying!</strong> Write a draft version, wait a few days and then review it. This way you will find a lot of mistakes and stupid things you wrote initially. If you review it immediately after writing, your mind will not be criticism oriented and will just ignore mistakes. Repeat the write-wait-review process as many times as necessary, until you find that the review revealed no mistakes.</li><li>After you did the final review and the CV is bullet-proof, <strong>ask others to review it.</strong> They will definitely find inconsistencies and mistakes and this will make you feel stupid. This is good because will open your eyes will make you go into an &#8216;I want to improve&#8217; mode. You&#8217;ll try to correct everything. After you come up with a modified version go again through steps 1 and 2. Repeat this as many times as necessary. [Special thanks to Lucian Sasu, Nadia Comanici, Andrei Ciobanu, Monica Balan and Lavinia Tanase for reviewing my CV!]</li><li><strong>Make it short and give only relevant facts.</strong> Initially, I come up with a 5 pages CV because I wrote every single technology with which I worked. There were a lot irrelevant things, I wrote Windows Workflow Foundation just because I played with it for a few days. I added extensive descriptions for every project, made a personal details section (name, birth date, address, etc) of 1/2 page. Others suggested to cut everything that was not necessary. You don&#8217;t need to give extensive descriptions, just add a few words. For example, I wrote &#8220;VS Image Visualizer &#8211; Visual Studio 2008 debug visualizer for images&#8221; and added a link to the project&#8217;s page &#8211; you submit formatted andcan embed links.</li><li><strong>Add something that makes it different. </strong>I don&#8217;t know if this makes a difference, but I added some lines to separate items just like in the picture below. Definitely Microsoft gets thousands of CVs per day. You need something special.<br
/> <a
href="http://victorhurdugaci.com/wp-content/uploads/2010/03/CV.png"><img
class="alignnone size-large wp-image-1838" src="http://victorhurdugaci.com/wp-content/uploads/2010/03/CV-1024x237.png" alt="" width="655" height="152" /></a></li><li><strong>Don&#8217;t lie!</strong> Tell exactly what you did and what is the proficiency level of your skills. For example, don&#8217;t write &#8220;Advanced&#8221; for UML if you don&#8217;t know the difference between composition and aggregation. Be realistic and don&#8217;t under/over estimate yourself.</li><li><strong>Use the spell</strong> <strong><em>chick</em>.</strong> Make sure everything is written in correct English and there are no grammar/spelling mistakes. <em>Noddy </em>likes a <em>WC </em>with grammar <em>mi takes. </em>You <em>mght </em>fail just because of that.</li></ol><p
style="text-align: justify;">Once you completed your CV, choose the job that suits best your needs, apply and wait&#8230; The waiting is a problem because all these big companies like Microsoft, Google, Mozilla, Apple, etc. will contact you only if they find something interesting in your application. If you&#8217;re not suitable, then no rejection is sent.</p><p
style="text-align: justify;">I applied for an Intern Software Development Engineer position at Microsoft Redmond. I cannot apply for a full time position because I want to finish the master program on time, in the next summer &#8211; an internship is just what I need.</p><h3 style="text-align: justify;">2. E-Mail Interview</h3><p
style="text-align: justify;">January 20, 2010. Two months since I submitted the CV. I wasn&#8217;t hoping anymore that MS will contact me, when I got an e-mail titled: &#8220;Victor Hurdugaci ES DK&#8221; from Holly Peterson saying:</p><blockquote><p>Hi there,<br
/> My name is Holly and I work with the Microsoft International Internship recruitment program.<br
/> We recently received your CV and would like to consider you for one of our technical internship positions in Denmark in 2010.<br
/> [...]<br
/> Please respond by the end of the day if possible<br
/> [...]</p></blockquote><p
style="text-align: justify;">Wow! Now this was a good news. The possible bad side was that the internship was going to take 12 months. This might be a problem. However, it solved really well after talking to my professors. They understood the value of this internship and considered that will be possible to go for 12 months in Denmark and do my thesis there.</p><p
style="text-align: justify;">The e-mail also contained a set of 15 questions that I was supposed to answer when sending the response. The topic of the questions was not the same. Some asked HR questions like:</p><ul
style="text-align: justify;"><li>In what city/country will you be residing in June 2010?</li><li>Describe your ideal job</li><li>Have you interviewed with Microsoft before?</li></ul><p
style="text-align: justify;">Others were a little tricky and technical:</p><ul
style="text-align: justify;"><li>How many lines of code would you estimate you personally have written in the last year?</li><li>How would you test a function that is supposed to calculate the factorial up to 1000?</li></ul><p
style="text-align: justify;">I tried to be as specific as possible, but still give exhaustive answers, trying to cover all possible uncertainties present in the question&#8217;s text. By the way, you can&#8217;t send an e-mail back to ask for more details or clarifications. I don&#8217;t think I am allowed to post my answers to questions. I will just  leave them as homework for you.</p><p
style="text-align: justify;">Replied the same day (actually the next day at 00:20 in the morning) and I waited again. Now was better because they are going inform me about the decision, no matter if is positive or negative. It was just a matter of time.</p><p
style="text-align: justify;">You might have more than one e-mail interview. I met someone who had two with less questions.</p><p
style="text-align: justify;">Few days later, another e-mail arrived. They continue to consider me as a candidate. Someone from Microsoft Development Center Copenhagen (MDCC) will contact me to schedule a phone interview.</p><h3 style="text-align: justify;">3. Phone Interview</h3><p
style="text-align: justify;">This is where it gets interesting. Until now everything was asynchronous and for all questions I had time to think. During a phone interview you have to come up with (almost) instant solutions.</p><p
style="text-align: justify;"><span
id="more-1837"></span></p><p
style="text-align: justify;">I was contacted by Mario Lucich who proposed an interview on March 5<sup>th</sup> at 10:00. That time was not convenient for me and I asked to postpone the call. The new time, 13:00, was good. If you get to the phone interview and the proposed time-slot is not good for you, don&#8217;t be afraid to ask for changes.</p><p
style="text-align: justify;">March 5th, around: 12:30. I was preparing for the interview: a piece of paper, a pencil, a glass of water and I was really cool with this.</p><p
style="text-align: justify;">March 5th, around 12:50. I was nervous, I felt like I wasn&#8217;t ready for this and I was expecting for a bad interview.</p><p
style="text-align: justify;">March 5th, around 13:00. Mario calls on Live Meeting (we decided to use this application instead of phone &#8211; is more convenient).</p><p
style="text-align: justify;">The start of the interview was a relief because we both had problems with the headset and there was a period with &#8220;Can you hear me? No? Click-click. How about now? No? Click click &#8230; &#8220;. This showed that the interview was not going to be formal. Good!</p><p
style="text-align: justify;">After we solved the headset problems and went through the usual &#8220;Hello. How are you? Fine. How about you?&#8221;, we got straight into questions.</p><p
style="text-align: justify;">From what I read on the Internet, each phone interview is different. Each individual got a different set of questions. Again, no answers will be provided. I was asked:</p><ol
style="text-align: justify;"><li>Suppose &lt;some name&gt; will give you 1M dollars. What project would you start?</li><li>You are supposed to hire an assistant. For what qualities are you looking? [HINT: short skirt, big boobs, etc. are not good answers]</li><li>If you wouldn&#8217;t work in software development for what other job would you look?</li></ol><p
style="text-align: justify;">An interview, usually, lasts  for 30-45 minutes. After 10 minutes, the interviewer, dropped a bomb: &#8220;Victor, I&#8217;ll say this directly. I don&#8217;t think we should go any further with this interview&#8221;. Ups&#8230; I got upset and I said to myself: &#8220;Victor, you are so stupid. You provided the worst answers possible and now you missed your change&#8221;. And then he said: &#8220;&#8230; because you convinced me and you will be invited for another interview at MDCC&#8221;. I was completely amazed! After just 10-15 minutes the interview was over and it was a success.</p><p
style="text-align: justify;">I was expecting to technical questions. Other had quite a lot of them, but I got no technical question. The only technical part was when I talked about expert systems &#8211; my Bachelor thesis.</p><p
style="text-align: justify;">Again &#8220;someone will contact you in order to schedule the interview and all the details&#8221;.</p><p
style="text-align: justify;">Tips for interview:</p><ol
style="text-align: justify;"><li><strong>Don&#8217;t lie!</strong> Tell the truth even if it might sound silly. They want to know how are you and not how you pretend to be.</li><li><strong>If you need time to think, ask for it.</strong> Don&#8217;t say &#8220;I don&#8217;t know&#8221;. Take your time to think and say the best solution you come up. Express your thoughts and say what you think.</li><li><strong>Try to be calm, wait</strong> for the interviewer to finish each question before coming up with an answer.</li><li><strong>Stay in a quiet place and don&#8217;t be tired.</strong> Try to maximize the chances of coming up with good answers.</li><li><strong>Don&#8217;t search for answers on Internet! Don&#8217;t type at computer!</strong> Usually, if the interviews hears this, is bad. Use just your mind (and eventually pen/paper).</li><li><strong>Take notes.</strong> You might even want to write down the question you are supposed to answer.</li></ol><h3 style="text-align: justify;">4. On Site Interview</h3><p
style="text-align: justify;">As agreed, I was contacted by someone to schedule the date of the on site interview. I was supposed to fly on March 4th to Copenhagen, sleep that night at Raddison Blu Scandinavia hotel and have the interview in the next morning. This is how it happened.</p><p
style="text-align: justify;">The flight with KLM was really nice! I am quite afraid of flight, but I enjoyed this one. The plane was not full so I had 3 seats to seat on :) The same thing happened when I was returning to Holland (with a minor difference. More on this below).</p><p
style="text-align: center;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/03/IMG_5898.jpg"><img
class="size-full wp-image-1890  aligncenter" title="IMG_5898" src="http://victorhurdugaci.com/wp-content/uploads/2010/03/IMG_5898.jpg" alt="" width="698" height="138" /></a></p><p
style="text-align: justify;">The plane ticket was prepaid by Microsoft. The same thing didn&#8217;t happen with the hotel room. I had to pay it and money will be reimbursed.  Be careful that Raddison Blu Scandinavia is not accepting Maestro cards! I was really lucky to have a VISA card with me.</p><p
style="text-align: justify;">So, after a good sleep and a delicious breakfast I took the taxi to MDCC. The taxi driver said he knows where are we going and after a few minutes started to look on the map for the location. He didn&#8217;t know where we were supposed to go. I used my phone to find the location and I think he made a huge detour because I had to pay twice as much as others. The good side is that this expense will be reimbursed.</p><p
style="text-align: justify;">I arrived at MDCC 1 hour before the schedule. The interview was scheduled at 10:30 and I arrived at 9:30. I was hoping to take a walk through the campus, but it was too cold to stay outside. The lady at the front desk invited me to wait there, on a couch. I read some brochures and had some water.</p><p
style="text-align: justify;">At 10:30 I met Scott Simmons, the person who was going to be my guide in that day. He took me to another room with other interviewees (~10 . They were coming from Romania, Austria, Germany, Russia, Moldavia and Finland) and a table full of snacks and drinks. Whooo party! In that room was also a Microsoft Surface with which we played during the day &#8211; unfortunately is not as impressive as in commercials.</p><p
style="text-align: justify;">Near our room, was another full of interviewers. They were coming out when someone was supposed to be interviewed and they were going back in when the interview finished. After 10 minutes, one interviewer asked for me. We went to another room, in another building and the interview day started.</p><p
style="text-align: justify;">The first interview was really direct. I was expecting an introduction or something, but went straight to the blackboard and said: &#8220;You are given two arrays: <strong>before</strong>: {3, 3, 5, 8, 1} and <strong>after</strong>: {5, 3, 2, 4}. Determine what numbers were removed/added from/to the &#8216;before&#8217; array in order to obtain &#8216;after&#8217;.&#8221; I had to write code on blackboard. I choose to write C# code and I implemented the solution using a dictionary. After this, I was asked about the complexity of the algorithm and the discussion went really deep in the implementation and complexity of dictionary (hash table) &#8211; &#8220;What elements to you add to a dictionary in order to make the Contains method run, always, in O(n), where n is the number of  KeyValuePairs in dictionary?&#8221;. After a few hints, I was able to come up with the solution, which is not really simple even after knowing it. Can you figure it out?</p><p
style="text-align: justify;">After that he explained me what is his role at Microsoft and how the development process works &#8211; he was a developer team lead. We had a chat on our way the waiting room, in the other building. Drinks, Surface, chat with the other for another few minutes.</p><p
style="text-align: justify;">My second interviewer comes out from &#8216;The Room&#8217; and we are going to a room in the same building. This was great because outside was really, really cold. It was the interview I enjoyed the most. After each of us telling his story &#8211; he told me about his life at Microsoft, I told him how I got to Netherlands and what I like to do &#8211; he told me to design a Tetris game, on blackboard. This wasn&#8217;t hard &#8211; I did some UML diagrams, explained each design decision and in the end had to write some code that will show a design pattern which can be applied to that design. I implemented a pseudo observer pattern and quite messed it up, but seems it wasn&#8217;t so bad after all. The interview ended with me asking for feedback about my design.</p><p
style="text-align: justify;">The third interview, thinking back now, was supposed to be the easiest. I had to design a function that takes a string as argument and reverses the order of the words, preserving spaces. Imagine that I spent 1 hour and I managed to come with a crappy implementation. First I tried something with regular expressions which didn&#8217;t worked eventually ending up by manually splitting the phrase in words and groups of spaces. What disoriented me was, that between words, you can have multiple spaces or tabs. After arriving home I found the solution in 1-2 minutes. I really performed bad in that interview and I don&#8217;t think the interviewer was impressed at all.</p><p
style="text-align: justify;">The last interview session was not really technical. I talked with one product manager who wanted to know what I want to do there and I think he was trying to understand on which position &#8211; tester or developer &#8211; I fit better. The discussion was awesome because I found some more information about the development and shipping process of Microsoft products.</p><p
style="text-align: justify;">I was getting tired, nervous and anxious after the four interviews. In the waiting room there was just me and a guy from Austria. The person responsible for me comes out of the room and asks me if I am someone else. He apologies and after a few minutes comes back again. We were still waiting. We gather around a table and he tells us that we both are going to get a job at Microsoft! None of us knew how to react. Then, he gave us some more details about the internship program and how are we going to proceed further.</p><p
style="text-align: justify;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2010/03/IMG_5957.jpg"><img
class="alignright size-medium wp-image-1893" title="IMG_5957" src="http://victorhurdugaci.com/wp-content/uploads/2010/03/IMG_5957-225x300.jpg" alt="" width="225" height="300" /></a>After four hours of interviews, everything ended up with success. Me and the Austrian went to the train station, waited for a train which was more that one hour behind the schedule and finally arrived to the airport. We had dinner and a beer (duh!!) and each of us went to his plane &#8211; we&#8217;ll meet again in summer. There is an cool commercial in Kastrup Airport (after you pass the security check) &#8211; see the picture on right.</p><p
style="text-align: justify;">The flight back to Netherlands was quite good. We had some turbulence before landing, but otherwise it was OK. There were some lousy guys in the plane which amused me.</p><p
style="text-align: justify;">My tips for the on-site interview (you can find many others on Internet):</p><ol
style="text-align: justify;"><li><strong>Take time and think. </strong>Don&#8217;t go straight into coding. Take a few minutes, simulate different solutions in your head and implement the best one.</li><li><strong>Be goal oriented!</strong> If you need to choose between a crappy implementation that will work and not doing anything, go for the former. A working solution is better than none. You can say, as I did, that the implementation is not the best but you cannot see a better one now.</li><li><strong>Sleep before the interview. </strong>Try to maximize you chances as much as possible. Not being tired gives you a good boost.</li><li><strong>Don&#8217;t eat to much in the morning. </strong>Might sound silly but have a light breakfast even is you are tempted by all the good meals at the hotel&#8217;s restaurant. The last thing you want is to have problems with your stomach.</li><li><strong>Don&#8217;t think you have to be perfect.</strong> The interviewer are aware that everyone mistakes and they will not kill you :) Think loud, explain your solution, try to prove its correct and don&#8217;t panic if you find mistakes (or the interviewer points some). Correct what you can and that&#8217;s it.</li><li><strong>Socialize with the other candidates. </strong>No matter if you are competing or not with the others for the job don&#8217;t forget to be nice and socialize. Is good to have connections all over the world.</li></ol><p
style="text-align: justify;">Yesterday, March 12<sup>th</sup>, I received my employment contract which will start in summer and will last 12 months. Finally, I&#8217;ll go where I always dreamed.</p><h3 style="text-align: justify;"><strong>Resources</strong></h3><p
style="text-align: justify;">When you are preparing for the interview you are searching for as many information as possible. I will make your job a little easier and share the best resources I used (in random order):</p><ul
style="text-align: justify;"><li>Kristian Kristensen on <a
rel="bookmark" href="http://zianet.dk/blog/2007/02/21/my-job-interview-at-microsoft-development-center-copenhagen-mdcc/">My Job Interview at Microsoft Development Center  Copenhagen (MDCC)</a></li><li><a
href="http://channel9.msdn.com/posts/TheChannel9Team/Gary-Daniels-and-Evan-Goldring-Mock-whiteboard-problem/">Gary  Daniels and Evan Goldring &#8211; Mock whiteboard problem</a> &#8211; &#8220;Here&#8217;s a mock whiteboard session to see what an interviewer looks for during that stage of the interview.&#8221;</li><li><a
href="http://channel9.msdn.com/posts/Dan/Get-Hired-at-Microsoft-Episode-1-Write-a-Killer-Resume/">Get  Hired @ Microsoft, Episode 1: Write a Killer Resume</a></li><li><a
href="http://channel9.msdn.com/posts/Dan/Get-Hired--Microsoft-Episode-2-Partner-with-your-Recruiter/">Get  Hired @ Microsoft, Episode 2: Partner with your Recruiter</a></li><li><a
href="http://channel9.msdn.com/shows/WM_IN/Zoe-Goldring-and-Gretchen-Ledgard-What-is-it-like-to-interview-at-Microsoft/">Zoe  Goldring and Gretchen Ledgard &#8211; What is it like to interview at  Microsoft?</a></li><li
style="text-align: justify;"><a
href="http://channel9.msdn.com/posts/TheChannel9Team/Zoe-Goldring-and-Gretchen-Ledgard-Riding-the-Recruiting-Shuttle/">Zoe  Goldring and Gretchen Ledgard &#8211; Riding the Recruiting Shuttle</a></li></ul> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/my-interview-with-microsoft/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>Using UAC with C# – Part 3</title><link>http://victorhurdugaci.com/using-uac-with-c-part-3/</link> <comments>http://victorhurdugaci.com/using-uac-with-c-part-3/#comments</comments> <pubDate>Wed, 06 Jan 2010 22:02:28 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[C#]]></category> <category><![CDATA[Intermediate]]></category> <category><![CDATA[Microsoft]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[UAC]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=1716</guid> <description><![CDATA[After a long period since I wrote part 2 of this article I decided to add some extra information. There is one thing that was missed by the previous two articles: the design of UAC enabled applications. If you use Windows Vista/7 then you know that buttons and links which elevate privileges are preceded by [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: justify;">After a long period since I wrote <a
href="http://victorhurdugaci.com/using-uac-with-c-part-2/" target="_blank">part 2</a> of this article I decided to add some extra information. There is one thing that was missed by the previous two articles: the design of UAC enabled applications.</p><p
style="text-align: justify;">If you use Windows Vista/7 then you know that buttons and links which elevate privileges are preceded by a shield icon. This is the way Microsoft decided to inform the user about the effect of clicking that control.</p><p
style="text-align: justify;">The first idea that might pop up is the reinvention of the wheel (or shield). In other words you could draw the shield on a button. This is OK except that:</p><ol
style="text-align: justify;"><li>Is not easy</li><li>Will require you to recompile the interface if Microsoft decides to change the icon</li><li>You need the icon in many sizes 16&#215;16, 24&#215;24, 32&#215;32, etc. (extract it from MS&#8217; DLLs)</li><li>Will create a lot of overhead with layout (position icon relative to text size/position)</li></ol><p
style="text-align: justify;">The second method is easier, safer and recommended by MS. All you need to do is send a specific message (<em>BCM_SETSHIELD</em>) to the button if the user has limited privileges and pressing that button will trigger the UAC window. Actually there is a second, tricky, thing that must be done: the style of the button must be &#8220;System&#8221; (in C# &#8220;<a
href="http://msdn.microsoft.com/en-us/library/system.windows.forms.flatstyle.aspx" target="_blank">System.Windows.FlatStyle</a>.System&#8221;). Without this you will not be able to see the shield.</p><p
style="text-align: justify;">The code provided in <a
href="http://victorhurdugaci.com/using-uac-with-c-part-1/" target="_blank">part 1</a> of this article will be modified in order to display the shield on the two buttons. Moreover, the shield will be displayed only when the user runs under an account with limited privileges or non-elevated administrator.</p><p
style="text-align: center;"><img
title="UACShield" src="http://victorhurdugaci.com/wp-content/uploads/2010/01/UACShield.png" alt="" width="700" height="280" /></p><p
style="text-align: justify;">In order to display the shield one needs to send the <em>BCM_SETSHIELD </em>(=<em>0x0000160C)</em> message to the button. This can be done by using the <a
href="http://msdn.microsoft.com/en-us/library/ms644950%28VS.85%29.aspx">SendMessage function from user32.dll</a>. This article will not cover what is and how to use SendMessage, if you need more information about it follow the previous link.</p><p
style="text-align: justify;">To set the shield of the &#8220;Elevate this application&#8221; button one needs to send the message in the following way:</p><div
class="wp_codebox"><table><tr
id="p17164"><td
class="code" id="p1716code4"><pre class="csharp" style="font-family:monospace;">SendMessage<span style="color: #008000;">&#40;</span>btnElevate<span style="color: #008000;">.</span><span style="color: #0000FF;">Handle</span>, BCM_SETSHIELD, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div><p
style="text-align: justify;">The first parameter is the handle of the button, the second one is the message, the third one is not used and must be &#8217;0&#8242; and the last argument must be non-zero in order to draw the shield, zero otherwise.</p><p
style="text-align: justify;">If you try this it will not work :) Remember the &#8216;tricky&#8217; thing told before? This is the full code to display the shield for <em>btnElevate</em>:</p><div
class="wp_codebox"><table><tr
id="p17165"><td
class="code" id="p1716code5"><pre class="csharp" style="font-family:monospace;">btnElevate<span style="color: #008000;">.</span><span style="color: #0000FF;">FlatStyle</span> <span style="color: #008000;">=</span> FlatStyle<span style="color: #008000;">.</span><span style="color: #000000;">System</span><span style="color: #008000;">;</span>
SendMessage<span style="color: #008000;">&#40;</span>btnElevate<span style="color: #008000;">.</span><span style="color: #0000FF;">Handle</span>, BCM_SETSHIELD, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div><p
style="text-align: justify;">There is only one thing that must be done in order to work properly. Remove the shield if the user has elevated privileges. I don&#8217;t know if this is against MS&#8217; recommendation but in my opinion one must not be shown information that cannot be used in that context; in our case don&#8217;t show the elevate shield if there is nothing to elevate.</p><p
style="text-align: justify;">Part 1 described how to check if a user has full rights. Now we are just using that boolean variable:</p><div
class="wp_codebox"><table><tr
id="p17166"><td
class="code" id="p1716code6"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>hasAdministrativeRight<span style="color: #008000;">&#41;</span>
    SetUACShields<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div><p
style="text-align: justify;">Where <em>SetUACShields</em> will send the message to all buttons that require the shield drawn.</p><p
style="text-align: justify;">The full updated code from Part 1: <a
href="http://victorhurdugaci.com/download/uacapp3.zip"><img
src="http://victorhurdugaci.com/img/download-icon.jpg" alt="Download Icon" width="24" height="24" />UAC Code 3 (10.13 KB)</a></p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/using-uac-with-c-part-3/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>1, 2, 3, 7!</title><link>http://victorhurdugaci.com/1-2-3-7/</link> <comments>http://victorhurdugaci.com/1-2-3-7/#comments</comments> <pubDate>Thu, 22 Oct 2009 08:57:06 +0000</pubDate> <dc:creator>Victor</dc:creator> <category><![CDATA[Microsoft]]></category> <category><![CDATA[News]]></category> <category><![CDATA[Funny]]></category> <category><![CDATA[Price]]></category> <category><![CDATA[Release]]></category> <category><![CDATA[Windows 7]]></category> <guid
isPermaLink="false">http://victorhurdugaci.com/?p=1471</guid> <description><![CDATA[Today is a big day for Windows fans. The final milestone in Windows 7 development process has been reached and the new operating system is general available. Just two years passed since the release of Vista and many say that Windows 7 should be just a &#8220;super-service pack&#8221; for Vista. If you are not a [...]]]></description> <content:encoded><![CDATA[<p
style="text-align: center;"><img
class="aligncenter size-full wp-image-1472" title="Win7_01" src="http://victorhurdugaci.com/wp-content/uploads/2009/10/Win7_01.png" alt="Win7_01" width="706" height="277" /></p><p
style="text-align: justify;"><a
href="http://victorhurdugaci.com/wp-content/uploads/2009/10/Win7_02.jpg"><img
class="alignright size-medium wp-image-1475" title="Win7_02" src="http://victorhurdugaci.com/wp-content/uploads/2009/10/Win7_02-225x300.jpg" alt="Win7_02" width="203" height="270" /></a>Today is a big day for Windows fans. The final milestone in Windows 7 development process has been reached and the new operating system is general available.</p><p
style="text-align: justify;">Just two years passed since the release of Vista and many say that Windows 7 should be just a &#8220;super-service pack&#8221; for Vista.</p><p
style="text-align: justify;">If you are not a MS Partner and you don&#8217;t have a MSDN/TechNet Subscription then this is the first time you can get Windows 7 non-trial. Many shops already started to sale and deliver copies of W7 &#8211; got few mail in the morning with special offers.</p><p
style="text-align: justify;">The prices on Amazon are:</p><ul
style="text-align: justify;"><li>Windows 7 Home Premium (Retail/Upgrade): $199.99/$119.99</li><li>Windows 7 Professional (Retail/Upgrade): $299.99/$199.99</li><li>Windows 7 Ultimate (Retail/Upgrade): $319.99/$219.99</li></ul><p
style="text-align: justify;">And now two funny things: on Amazon you have &#8220;2 Used and new&#8221; copies of Windows 7. I wonder who has a used copy of W7 that has just been released :)</p><p
style="text-align: justify;">The image on the right I found it on <a
href="http://blogs.msdn.com/larryosterman/archive/2009/10/21/win7-whoppers.aspx" target="_blank">Larry Osterman&#8217;s blog</a>.</p> ]]></content:encoded> <wfw:commentRss>http://victorhurdugaci.com/1-2-3-7/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
