Extract a password from a saved .rdp file.

I choose complex passwords and I quickly forget them. I save them in rdp files so that I can just click the file and it will automatically log me into a remote desktop connection.

Recently I forgot a password and I really wanted it back. I googled.

Then with some knowledge, I made a stupid and ugly Windows Forms application which lets me extract the encoded password crypt from an rdp file, paste it into a TextBox and click a button to decrypt.

Ok, so the data is fake. All zeros does not decode and decrypt to “thisismypassword”. But it works 🙂

The interesting bits are very short after pulling together the p/invoke and hex encode library.


int discarded;
byte[] bytes =
Utility.HexEncoding.GetBytes( input.Text, out discarded );
System.Text.ASCIIEncoding acsciiencoding = new ASCIIEncoding();
System.Text.UnicodeEncoding lUnicodeEncoding = new UnicodeEncoding();

byte[] lDecryptedBytes = dataProtector.Decrypt( bytes, null );

string decrypted = Utility.HexEncoding.ToString( lDecryptedBytes );
output.Text = "decrypted:"+decrypted + Environment.NewLine +
"unicode:" + lUnicodeEncoding.GetString( lDecryptedBytes, 0, lDecryptedBytes.Length ) +
Environment.NewLine +
"ascii:" + acsciiencoding.GetString( lDecryptedBytes, 0, lDecryptedBytes.Length )
+ Environment.NewLine
;

I like it when things are simple.

its a week for great quotes

“you can build LINQ to NHibernate extensions and get all the goodness of
the LINQ language/compiler/intellisense work using NHibernate”
— Scott Guthrie http://elegantcode.com/?p=539

I don’t
like the implication that unit testing is a “team system” feature.
Whether you “test first” or “test later”, I think everybody pretty much
now agrees that you need to perform automated developer testing sometime, no matter what kind of work you’re doing. ”
— Scott McMaster http://softwaredevscott.spaces.live.com/Blog/cns!1A9E939F7373F3B7!332.entry

“TDD is cost effective when and if the effort you put into writing the
tests is less than the corresponding effort would have been for the
manual unit testing and additional debugging that you dodge by having
comprehensive unit test coverage. Add in the hard to quantify
advantage from the qualities of orthogonality that TDD all but requires
(testability design is mostly about creating orthogonality between the
pieces). ”
— Jeremy Miller http://codebetter.com/blogs/jeremy.miller/archive/2007/03/22/More-testing-code-than-production-code-is-typical_2C00_-but-don_2700_t-let-that-stop-you.aspx

Microsoft and Open Source

from Ayende and Hammit

http://elegantcode.com/?p=539

I don’t normally link things that are covered by others with far more reader than I have. This is so important to .NET developers everywhere. I feel I must spread the word however possible.

Take, for example, MSUnit. Boo. Hiss. That was a big miss. Can’t they be easier to run in the UI? Where are all of the baked in Asserts from NUnit?

Or take MSBuild. No please, take it. No out of the box task to Zip files? C’mon.

I hope all .NET Developers are aware of this trend and if they aren’t, they should question whether nor not they can call themselves developers.

with lots of unreadable code

When is Microsoft going to get off of this “without writing any code” kick? I am sick of sitting through Microsoft presentations where someone writes some XAML or ASP.NET and makes a bunch of changes and says “Look, we did all this without writing any code!” Should I try to coin a new term which is only 1 vowel different from the term which comes to mind? BILLSHIT!!!

XML is code. The Java world has known this for years. XML Hell is a very real thing in the Spring, Struts, Hibernate past of Java. Many of the new things in Java have been a move away from the XML hell of a few years ago.

So when I see a blog post about InfoPath saying “…without code!” that has a snippet like this…

[code]
concat(substring(concat((sum(../my:group1/my:group2/my:TotalMinutes) –
sum(../my:group1/my:group2/my:TotalMinutes) mod 60) div 60, “:”,
sum(../my:group1/my:group2/my:TotalMinutes) mod 60), 1,
(sum(../my:group1/my:group2/my:TotalMinutes) mod 60 > 9) *
string-length(concat((sum(../my:group1/my:group2/my:TotalMinutes) –
sum(../my:group1/my:group2/my:TotalMinutes) mod 60) div 60, “:”,
sum(../my:group1/my:group2/my:TotalMinutes) mod 60))),
substring(concat((sum(../my:group1/my:group2/my:TotalMinutes) –
sum(../my:group1/my:group2/my:TotalMinutes) mod 60) div 60, “:0”,
sum(../my:group1/my:group2/my:TotalMinutes) mod 60), 1,
(sum(../my:group1/my:group2/my:TotalMinutes) mod 60 < 10) *
string-length(concat((sum(../my:group1/my:group2/my:TotalMinutes) –
sum(../my:group1/my:group2/my:TotalMinutes) mod 60) div 60, “:0”,
sum(../my:group1/my:group2/my:TotalMinutes) mod 60))))
[/code]

…it makes me want to kill Microsoft employees and the idiot managers who buy into this BILLSHIT. It must be geared toward managers and inexperienced developers. It is all lies. Please stop the lies.

What is wrong with the above? Well, it looks like code to me. If it walks like a duck and talks like a duck… we get python duck typing. If it looks like code and smells like code (and yes, it is major code smell) … it must be code!

Why is this code smell? Well can I just look at that insane expression and know what it does? Nope. It is a fine example of dailywtf worthy unreadable code.

It is code. It is bad code.

Microsoft reinvents the wheel, again.

 

I am totally excited to see the wheel reinvented again. I’m so happy that
Microsoft has put their huge workforce of programmers to go and create
something which already exists.

The first blog post I read this morning is a link from Sam Gentile’s New
and Notable
on Entity
Client
. What an utter waste of time this is shaping up to me. I
get it. Microsoft wants LINQ to be awesome. Guess what? It
already is! So what is this Entity Client that has got me all worked
up? Well, in an nutshell, Microsoft REALLY likes NHibernate. But
NHibernate is OMG VIRAL LGPL Open
Source. This kind of open source gives Microsoft open sores. So
what is the north west Vatican(Redmond)
response when someone doesn’t agree with your religion? Call them a
heretic and if it is a really good idea incorporate it into your own religion.
Microsoft can’t use NHibernate. Why? … Here is a list of
reasons why:

  • Microsoft has a serious case
    of NIH syndrome
  • NHibernate sounds like
    Hibernate and that is Java and Microsoft isn’t allowed to do anything
    Java. Remember that law suit?
  • Hibernate Query Language
    doesn’t look enough like SQL Server’s SQL implementation
  • Adopting something great from
    the .NET community is a sign of
    weakness. Microsoft must pollute and confuse the solution space
    instead. See NUnit vs. MSTest, Nant vs. MSBuild, NDoc vs.
    Sandcastle.

Ok, so the above is a bit over the top, but I think I make
my point. The world would be a better place if Microsoft stopped
reinventing the wheel and just embraced existing libraries as the standards
they are. What really set me off was this bit of the blog post

EntityClient employs its own language, Entity SQL. An
Entity SQL query needs no change in order to work over different store
implementations of the same model. That is achieved through EntityClient’s
pluggable architecture.

 

This sound exactly like NHibernate to me.

While NHibernate doesn’t seem to have nearly the usage of NUnit, Nant or NDoc,
I have no doubt that the NHibernate community will continue to thrive, even
with the release of excellent tools from Microsoft for use with
EntityClient. NHibernate already has many excellent tools and it is here
today.

One huge difference between EntityClient and NHibernate is that EntityClient is
not a full ORM. It seems to be only the Dialect and Driver part of
NHibernate. From the same post

EntityClient does not attempt to materialize objects out of
the result set. Instead, it returns a plain DbDataReader for which those
applications may implement their own specialized object materialization, or
consume the DbDataReader directly.This does still sow confusion into the Data
Access space. My recommendation: Just ignore it. Go use
NHibernate (or CastleProject’s ActiveRecord).

More fun with rediculous corporate security awareness training

I wouldn’t have taken it if I hadn’t been told it is mandatory.  What a waste of time for a person who already takes security seriously.  I feel like a child who has been told to sit in the corner and listen even if I already know everything today’s lesson is going to cover.

So when taking the quit at the end of the 190 slide deck which I skipped through, I run across a question regarding “a secure network”  I answered incorrectly.  I felt the need to email the corporate security people this response:

Question 3 from the Final Exam
 
The more secure a network is, the
harder it is to use.
 
The
correct answer is false.  You want me to select true to continue.  I just wanted
to voice my objection to this.  This is not true.  In fact, do we even ever
“use” networks?  We use applications that use networks.  Programmers writing the
application may use the network as means for applications to communicate, but as
end users we don’t directly use the network.  Furthermore, a more secure network
protects me from stupid things like worms and certain viruses.  This in turn
makes my computer easier to use because I don’t get these worms and certain
viruses.  So in many ways a secure network is more easy to use than an insecure
network.

Yes, I know I am a bit of a prick at times 🙂

February AADND meeting on Wednesday the 14th.

Jennifer Marsman and Drew Robbins, Developer Evangelists for
Microsoft’s Heartland District, will be speaking at the Ann Arbor .NET
Developers Group
on Windows Presentation Foundation with talks entitled “3D
Graphics in the Windows Presentation Foundation” and “Layouts,
Styles and Templates in Windows Presentation Foundation”. They decided
that they would team-up for the meeting with Jennifer covering our tutorial
session and Drew the main. If you are looking for a jumpstart on WPF, don’t
miss AADND on February 14th starting at 6:00 pm at the Ann Arbor IT
Zone Spark Central located at 330 E. Liberty, Ann Arbor, MI 48104.

 

Tutorial with Jennifer Marsman: 3D Graphics in the Windows Presentation
Foundation

 

The Windows Presentation Foundation is Microsoft’s
unified presentation platform for Windows.  WPF provides an integrated set
of APIs allowing the developer to create 2D and 3D content with ease. 
Developers and designers can construct scalable, high-quality content in both
two and three dimensions using WPF’s advanced vector-based rendering
system.  In this session, we will discuss how to create 3D graphics in WPF.

 

Main Session with Drew Robbins: Layouts, Styles and
Templates in Windows Presentation Foundation

 

Windows Presentation Foundation is Microsoft’s unified
presentation subsystem for Windows, which enables developers and designers to
create visually stunning user experiences. One powerful feature of Windows
Presentation Foundation is the separation of the appearance of controls and the
behavior of controls. In this session, we’ll look at the power of layouts,
styles and templates and how you’ll use them in your applications. We’ll also
look at the underlying concepts that make them work and how you can use them to
compose your own WPF components.

Python makes me think about C#

I love going to the Michipug meetings. I don’t use python on a day to day basis, but I find that talking to those who do really helps me to think about things differently.

Thursday, even before going into the Michipug meeting, I was reading a python blog or something in anticipation of the meeting that night. Something I read triggered me to think about python’s filter, map, and reduce built-in functions. I wondered what .NET has to correspond to these. Well, List.FindAll and List.ConvertAll and their Array counterparts do the work of filter and map. That left reduce.

I couldn’t find reduce, so I whipped up an implementation. I started with just an integer implementation. Again, Func<T,T,T> is a delegate definition straight out of System.Query in the LINQ preview, or Rhino.Commons or wherever.


public int Reduce( Func<int,int,int> function, List<int> list )
{
IEnumerator<int> enumerator = list.GetEnumerator();
enumerator.MoveNext();
T result = enumerator.Current;
while(enumerator.MoveNext())
{
T item = enumerator.Current;
result = function( result, item );
}
return result;
}

Once I had this running, I just made it generic.


public T Reduce<T>( Func<T,T,T> function, IEnumerable<T> list )
{
IEnumerator<T> enumerator = list.GetEnumerator();
enumerator.MoveNext();
T result = enumerator.Current;
while(enumerator.MoveNext())
{
T item = enumerator.Current;
result = function( result, item );
}
return result;
}

I also changed the List<T> to IEnumerable<T> so that it would work with Arrays, Lists, or anything Enumberable.

So what is the point? Well, I don’t have one, other than “its cool!”

Its nice to write factorial as simply as this:


var res = Reduce( ( x, y )=> x * y, list );

or sum a list like this:


var res = Reduce( ( x, y )=> x + y, list );

Its very strange when string.Join(“, “…) doesn’t use Join


Reduce( (x,y) => string.Format("{0}, {1}",x ,y) , message)

And even stranger when you can reverse the join order


Reduce( (x,y) => string.Format("{1}, {0}",x ,y) , message)

What else can you do with reduce?

Well, I don’t know. Give a google for python reduce and you will see that Guido is even getting rid of filter, map, and reduce from Python in the future. So .NET just got filter and map in the form of Array and List member methods which take delegates as arguments, and python is removing filter and map in favor of its list comprehensions and generator expressions.

So what? Well, I don’t really think it means much. In the same article Guido talks about adding two functions, Any and All. .NET already has these in the form of Exists and TrueForAll as Array and List members.


// python: any(x > 42 for x in S) # True if any elements of S are > 42

S.Exists( x => x > 42 );

// python: all(x != 0 for x in S) # True if all elements if S are nonzero

S.TrueForAll( x => x != 0 );
I don’t see much of a difference in readability between the Python and the C#. They are merely different.

One of the very strange things about the .NET implementation is that Exists and TrueForAll aren’t members of the Array class, rather they are static members. So the invocation of the same thing on an Array is slightly different.


Array.Exists( S, x => x > 42 );
Array.TrueForAll( S, x => x != 0 );

C# 3.0 extension methods don’t help. Array inherits from IEnumerable. Nothing about its type is known for use by the compiler at compile time. You could try to implement Exists and TrueForAll, but you end up having to invoke like this:


S.Exists<int>( x => x > 42 );
S.TrueForAll<int>( x => x != 0 );

All this because I think about python. I should just write more boo, but alas, boo still doesn’t support Generics. Boo is great, but not for interoperating with Generic types from other .NET libraries.

It is still about CodeMash

Richard Hale Shaw at the Ann Arbor Computer Society meeting on Wednesday gave a good, detailed overview of the C# 2.0 features that are getting used to build interesting things in C# 3.0.

Everything came back to CodeMash. The topic reminded me of Bill Wagner’s CodeMash talk, and the talk he gave at Ann Arbor Dot Net Developers back in December. I had just converted my application from log4net to NLog and ran into a case where I didn’t want to execute some code unless I was logging it. NLog and log4net recommend putting your logger statement in an if block like

if (logger.IsLogErrorEnabled)
log.Error( "oh no!"+ SomeLongRunningFunctionWhichReturnsString() );

I prefer to have my log statements on one line, I find it clutters my source code less. Afterall, logging is NOT the primary concern of my code. I want to focus on the task and hand and obey single responsibility as much as I can.

It turns out C# 2.0 anonymous delegates provide a nice solution (and of course C# 3.0 lambdas make it more readable).

Lets assume our logger has an override with a signature of

public void Error( Func<string> function );

Where Func is straight out of System.Query or Rhino.Commons or wherever.

public delegate TR Func<TR>();

Now the overriden Error method on the Logger class accepts a method as input. If we turn logging off, this method never needs to be executed. Using it is not too ugly.


logger.Error(delegate() {return "oh no! " + SomeLongRunningFunctionWhichReturnsString(); } );

C# 3.0 brings lambdas to the syntax of the language and makes this a whole lot easier to write.


logger.Error( () => "oh no!" + SomeLongRunningFunctionWhichReturnsString() );

And that was only WEDNESDAY!!! WOW.

Thursday followed up strongly with a Michipug meeting where we talked python templating libraries. The format was awesome. We broke into little groups and each group explored the template library. I took a look at twiddler and it is very simple and elegant. I really feel like I grasp the whole thing and I only looked at it for a very short period of time. I don’t use enough python to really comment on any of the libraries we looked at. After looking at them, each group presented an overview of the template library. I think everyone enjoyed the format and learned a lot.

At both of these meetings everyone talked about CodeMash. All of the comments were positive. What a great event. I mentioned that my favorite thing was the presentations on Selenium and Niel Ford’s Productive Programmer presentation. These topics really transcend the CodeMash language barriers. The concepts being The Productive Programmer are really things that EVERY programmer should know. It doesn’t matter if you do Java, Ruby, C, C++, Python, Perl, C#, PHP, whatever. I found it so valuable because at any other language or technology specific conference you wouldn’t get panels like that. It simply wouldn’t fit. It fit perfectly at CodeMash.

LINQ to NHibernate

Best Quote from Oren on DNRtv:

Oren: “This is HQL, Hibernate Query Language. It is similar to the SQL look but it has more OO notation. …”

Carl: “Starting to look like LINQ a little bit.”

Oren: “Yes, it looks like LINQ, but this is string. This is string but what will happen is once LINQ passes beta status me or someone else from NHibernate community will write a LINQ adapter for NHibernate. I don’t know the exact name. It actually isn’t very hard. I talked with at TechEd isreal last year and it doesn’t look very hard at all to do this. The concept is very much the same.”

So, learn and use NHibernate (or Castle ActiveRecord) now. Don’t worry or fret about LINQ, DLINQ, LINQ to SQL, LINQ to Entities, LINQ to DataSets. The beauty of LINQ will be available for NHiberate. LINQ is not the death of NHibernate.

NHibernate is a vast library with many extensiblity points. NHibernate exists today, it has proven itself for years. Its intricacies are well understood by the community and there is excellent documentation surrounding it. Now I’m sure that LINQ to SQL will have reams of docoumentation as most Microsoft products eventually do. But, LINQ to SQL is for Microsoft SQL Server only. NHibernate has mappings to MSSQL, PostgreSQL, Firebird, MySQL, SQLite, even Access, and probably many others. By leaning on NHibernate you are assured a high level of compatibility with any RDBMS. Some organizations value this. I value this.