Tuesday, August 5, 2008

Acquiring System privileges under Windows

At some occasions, while using a relatively recent version of Microsoft Windows (I'll refer XP and above, but 2000 might also work), it is required to acquire System privileges (aka LocalSystem). This might happen for malicious purposes, but also legitimate reasons exist, such as finding a bug in a service which runs under LocalSystem. At such occasions, one would like to get a terminal (cmd) that runs as LocalSystem.

Of course, one cannot login using LocalSystem, since it is not meant to be logged-in with. But this is not a reason to despair. Actually, opening a cmd under LocalSystem is quite easy:
open a cmd (using the currently logged-on user) and type:
at 00:00 /interactive "cmd"
This will create a new scheduled task, which will never run, and would open a new cmd using LocalSystem. Now, all you have to do is: Start->Run->tasks and run the newly created task (usually "At1"). The cmd window that just got opened allow you to run everything as if you were the System account.

Wednesday, July 30, 2008

Improving bubble sort

Most people believe that using Quick Sort or Merge Sort, would achieve the best sorting performance over a standard array. Even though this might be true in most (or at least some) cases, there are real world situations where a better solution can be applied.

Let's assume there's a big chance we are trying to sort an already sorted array, or almost-sorted array. What is an almost-sorted array? This is an array which is sorted beginning from some element which is not far from the first element.

Now, let's try to recall what bubble sort looks like:
for i = 1 to length(A)
  for j = length(A) downto i+1
   if A[j] < A[j-1] then
    swap A[j] with A[j-1]

This is a very simple implementation, but would cost O(n^2) even when we deal with an already sorted array. How could this be improved? Let's add a flag:
for i = 1 to length(A)
  swapped = false
  for j = length(A) downto i+1
   if A[j] < A[j-1] then
    swap A[j] with A[j-1]
    swapped = true
  if swapped = false then
   break

As you can probably see, once there's a full iteration in which no elements were swapped, the algorithm finishes. For an already sorted array, performance are now O(n). For an almost-sorted array (beginning item c), performance are O(cn). Not bad...

Monday, July 7, 2008

Dar the mailman

In the past few days, I've been working really hard on my final project. As mentioned before, it has something to do with e-mail and spam. The project requires me (actually us, I have a partner) to act both as a mail sender, and as a mail receiver. This is have to support any modern mail server, and also work with every major web mail providers (where most spam is usually met).


For some years I've known how to telnet to a SMTP server, and use it to send mail (which should be accounted as spam). When it comes to authorized mail servers, this is a bit trickier, as log-in mechanisms are required. Most use SSL or TLS, over semi-standard ports. So, I managed to write a python script to use gmail's SMTP server, using my gmail account (TODO: publish code). This made me happy, because I thought to myself it's gonna be easy. Well, not quite.


As it seems, the other major providers (hotmail, yahoo) would allow you to make telnet connection to their SMTP servers, but the log-in would fail. After a little research I found out that yahoo wants money for SMTP, and hotmail would simply not allow it altogether. Not good.


My next attempt was trying to use the mail provider's APIs. Google offers GData, while yahoo offers some other API. Microsoft offers only undocumented HTTPMail (webdav?) protocol. Once again, only the Google solution worked. Yahoo wants you to register your application, and your domain (hadn't bought one yet for the project) in order for the API to work. As for hotmail, well...

So, where does this leave us? It seems our last option is the one I've been trying to avoid: writing a parser (Perl or Python) for the web pages of the popular web mail providers, and normal SMTP and POP3/IMAP for other mail servers. Very cumbersome, error prone, hard labor and a waste of time.

Friday, June 20, 2008

Standards are Standards

We all know what standards in the software industry are worth. Some people sit in a room (could be virtual, but most of the time it's a real room), and decide how something should behave. Then, each software company takes the standard spec (or RFC or whatever) and implements it, and then some.

Recently, in the hardware industry, there is a large debate, with accusations and flame-throwing about who should be part of the design of the next USB 3.0 standard. Intel claims that by developing the standard all alone, it actually has a chance to become a standard. Just like the previous USBs. This is my interpretation of things, and you should read about it yourself. We all know what monopolies in the computer industries can cause, if they're wrong, and the standard that's on the topic is closed (that is, only one company controls the spec) or badly designed.

Lets compare it with other industries: Last week we've purchased new curtains for our living room. The "technician" that came to deliver the curtains, said that the bar (or pole) that holds the curtains is too thin, and we need a thicker one. A thicker bar, means a different hooks, which would be able to hold it. We didn't want to replace the hooks, cause we didn't want to drill extra holes in the wall. But when the "technician" realized that this is what is bothering us, he said "what? you don't have to drill new holes, the new hooks uses exactly the same holes as the old ones". This means that the screws would be in exactly the same distance as they were before, and no drilling was required, even though the new bar seems a little bit heavier.

So, now we have new curtains, with new hooks, and I wonder, when and where did the "curtain hanging guild" sat to decide how should the hooks be designed, and how comes they all agreed on the standard. In our (software-) world, that would have never happened.

Same game, different name

Each time there's a soccer tournament, I feel the urge to kicks some virtual balls into virtual goals. Now it's the time of UEFA EURO 2008, so I decided it's time to try EA's FIFA 08 (I just can't seem to like PES over FIFA). FYI, the game sells for 99 NIS in Israel, I guess it has something to do with the fact they're having hard time selling that game, and that it cost them 0$ (or some other small amount of money) to produce.

Why would I say such a thing? Because it's actually FIFA 07, packed in a different box, carrying a different name. The rest of the game is exactly the same. Same graphics, same engine, same sounds, same everything. It's a brave move from EA to release such a game, especially when a competition such as PES exists.

From what I read, the Xbox and PlayStation versions, include a better graphics engine, and better physics. If I stumble upon a PS3 with FIFA 08, I'll give it a try. In the meanwhile, I'm so disappointed. Though I still prefer it over PES.

Friday, June 13, 2008

"Buying" users, for free. Genius

Most people been in the academy, knows the nice trick of major software companies: the "student edition" or "express edition" (sufficient for students requirements) is given for free or a small fee. Later, when the student will be looking for a job, he'll be looking the tools he already knowns. So, if for the entire degree the students uses Visual Studio Express and Office Student Edition, this is what will be written in the resume, and this what the student will be looking for.
This week, something similar (not exactly the same) happened in my university. The university opened "for free" email account for every student (still in pilot, but will eventually cover thousand of students) at live.com. Actually, this is live., but login is done through live.com. Now, since I was chosen to the pilot, I'm a happy owner of Windows Live Hotmail account. Not sure what am I supposed to do with it, but the university promised it'll work under Firefox and Safari under any OS, so no complaints here. The thing with this account is the fact that it is not limited to the period of time I'll be a student. It's for a life-time, only that after I'll finish my degree, the account would start display ads (which it currently doesn't). So, next year, I'll become a regular live.com user, that sees ads and everything, which makes me a source of income to MS. So thanks to the university, MS could make more money. Just like giving Visual Studio for free, only easier. Come to think about it, only one word comes in mind: Genius.

Saturday, May 24, 2008

OpenDocument for University

Let me begin with good news, especially for myself: I'm done with university exams. Recently finished the last exams towards the M.SC, and now I feel the freedom back in my life. And since we talk about freedom, why not discuss free software?
Even though there are no more exams, there is this tiny little thing called "final project". As i might have mentioned before, it has something to do with email spam. Although it's quite late to start working on the project at this time of the academic year, I'm quite optimistic I'll manage to finish it on time. In the mean while, my partner and I are discussing with our project client (which is a Prof. in the department) about the contents of the project, in order to assemble a PDR which is agreed on everybody. Since we are good students for computer science, we'd picked the right tools for the job: OpenOffice writer and OpenOffice draw. This is not the first time we deliver documents in ODT format, but it is certainly the most comprehensive usage done. This perhaps won't sound as a big thing, but at our university, it is. I don't know much lecturers the would support these formats. Most still use MS Office, and might even force students to work with it as well. My intent is to base the entire project development with FLOSS, and become an evangelist in our department.
My original thought was way to advanced for our project mentor: we would do the entire research part of the project, and major parts of the development, and the community would assist us developing the rest of the project. This way, the final product would be far more polished and could be ready for real world use (as well as academia). I thought this could work, as I saw it worked for GNOME Do. But our mentor said he couldn't be sure we would do our part. I don't think he ever heard of Launchpad or Sourceforge for project management and tracking. Shame. Well, perhaps we cannot be too evangelist.
But we did make one small step for men.