Fixing backslashes in SVN from windows

August 19th, 2010

At Iminent someone did something horrible:
The trunk pretty much contained:

  • file a
  • dir b
    • dir c
      • file d
    • file e

And someone ,on presumably a mac or a *nix machine, added the directory “b\c”. In *nix, where the SVN server was run, this was a perfectly valid directory name. On Windows, what most of us run on, the backslash is a directory seperator.

So when TortoiseSVN tries update or check-out, it fails to create a directory like that. Even worse, when you try to delete the offending directory from the “Browse Repository”, it actually interpreted the \ as a directory seperator, so while you wanted to delete directory “b\c”, it ended up deleting directory c in b. My boss had fixed this by completely removing the trunk, and putting in a new one from his working copy, but this way you lose all history of the files, and any changes that he had made to the working set were not visible anywhere.

I fixed it by doing the following:

  • First, you branch from the Trunk revision just before those faulty directories were added.
  • Then you carefully merge all changes from trunk from that point to HEAD to that branch, while excluding all revisions that add those offending directories.
  • Then you branch the current trunk to a branch like “MessedUpTrunkBackup” using TortoiseSVN Repository browser (You can’t do it by checkout + branch, as checkout fails)
  • Then you delete the current trunk, again using the repository browser.
  • Then you copy the clean branch you made earlier to trunk, using either the repository browser or by using normal branching methods.

Tada: You now have a new trunk, without the offending changes, but with full history on all files, and you can safely issue a checkout, or an update on an earlier working copy :)

I am aware it’s probably possible to cleanly revert those changes from a *nix box, but we didn’t have any available at the moment, so I had to do it this way.

V8 crashing with ‘Uncaught RangeError: Maximum call stack size exceeded’

July 14th, 2010

While working with V8 in another process, it kept crashing at initialization with the message ‘Uncaught RangeError: Maximum call stack size exceeded’. I wasn’t doing anything big, just initialization.
After about 3 hour of debugging, I found out what was wrong. Normally, V8 will assume that you have no more than 512KB of stack space. To prevent stack overflows, it will take a stack address, substract 512kb from it, and remember that address. If it ever passes that address, it’ll throw a RangeError.

The problem lies in the fact that the program I was working with had a stack somewhere around 0×60000 or 384kb. V8 then substracts 512 from that, but instead of getting a nice stack-boundary, it ends up with an incredibly big number due to integer underflow. The next time it checks the stack, it compares the stack address (still somewhere around 0×60000) with it’s calculated stack limited (which, due to the underflow, is about 0xFFFE0000), and assumes it has a stack overflow.

To fix this, I had to manually set the stack limit. Basically, the following code takes a random stack address, divides it by 2, and uses that as the lower-limit to the stack:

	v8::ResourceConstraints rc;
	rc.set_stack_limit((uint32_t *)(((uint32_t)&rc)/2));
	v8::SetResourceConstraints(&rc);

New Live Messenger APIs

July 6th, 2010

While the old messenger APIs have been steadily crumbling the past few versions, and the latest WLM10 beta having made it nearly useless, I was amazed to find several new APIs.
One of them is the “LivePlatform” API, which seems to be what messenger is using to retrieve the contact list and social news.
I don’t have time to investigate this fully, but I did get to put together a small demo. To try it, create a new console application in C#, add C:\Program Files\Windows Live\Contacts\LivePlatform.dll as a reference, and put in the following code in Main:

 LivePlatform.LivePlatformFactory factory=new LivePlatform.LivePlatformFactory();
            LivePlatform.ILiveIdentityCollection ids = factory.IdentityService.CachedIdentities;
            System.Console.WriteLine("Cached identities");
            for (int i = 0; i < ids.Count; i++)
            {
                LivePlatform.ILiveIdentity id = ids[i];
                if (id.HasPassword)
                    System.Console.WriteLine("\t"+id.Username);
            }
            System.Console.Write("Username: ");
            string szUsername = System.Console.ReadLine();
            LivePlatform.ILiveIdentity found = null;
            for (int i = 0; i < ids.Count; i++)
            {
                LivePlatform.ILiveIdentity id = ids[i];
                if (id.HasPassword && id.Username.ToLower().Equals(szUsername.ToLower()))
                {
                    found = id;
                    break;
                }
            }
            string szPassword = "";
            if (found == null)
            {
                System.Console.Write("Password: ");
                szPassword = System.Console.ReadLine();
            }
            platform=(found==null)?factory.CreateEx(szUsername,szPassword):factory.Create(found);
            platform.Config["BlockingSignin"] = true; //Don't set this to make Signin non-blocking. You'll have to wire up events to listen for OnReady before you do anything, though.
            platform.Signin(null);
            System.Console.WriteLine("Full name: "+platform.Me.FullName);
            LivePlatform.ILiveObjectCollection query = platform.Query("type(contact)");
            System.Console.WriteLine(String.Format("Contacts: {0}", query.Count));
            for (int c = 0; c < query.Count; c++)
            {
                LivePlatform.ILiveObject obj = query[c];
                LivePlatform.ILiveContact contact = obj as LivePlatform.ILiveContact;
                System.Console.WriteLine(String.Format("{0} ({1})", contact.FullName,(contact.Emails.Count>0)?contact.Emails[0].Address:"none"));
            }
            System.Console.WriteLine("Press enter to quit");
            System.Console.ReadLine();

It’ll print your full name, as well as your full contact list. Also note that if you added your facebook account, those contacts will show up too.
Some other queries I saw when debugging messenger:

type(invite)
type(contact) and contacts:canHideFrom(true)
type(contact)
type(contact) and contacts:isHidingFrom(true) and contancts:canHideFrom(true)
type(contact)
type(circle)
type(category)
type(category) and contacts:isfavorite(true)
type(contact) and contacts:isonline(true)
type(category) and contacts:isfavorite(true)

I believe that hooking this API in messenger might allow for some pretty cool tricks, for example something like BuddyFuse.

As a final note, I’d like to say that I’m posting this because I’m hoping more sharing might make the messenger community more like it once was. If you find out more about this API, or other new APIs, please be so kind to share them too so a new sharing eco-system might emerge. Thanks.

EDIT: Added cached identities.

CyanogenMod modded

April 26th, 2010

For my Nexus One, I’ve been trying a few new ROMs. One that is supposedly very good is CyanogenMod, and I personally kinda like it.
One downside however, is that the power widget colors for features turned on have been changed to an ugly light blue-ish color, that completely mismatches with any other android user interface parts. So I did what any respectable tinkerer would do, and changed them back to green. Here’s how I did it, hoping these instructions might help other people with the same or related problems. Note that all the tools I uesd should be easy to find using google :)

Apparently, the power widget is in Settings.apk. This file also contains a lot of other stuff, and not suprisingly the settings dialogs are among those. Seeing as CyanogenMod adds quite a bit to the settings dialogs, simply putting back a stock Settings.apk is not an option.
So instead, we should change something inside of Settings.apk. This is what I did to get the Settings.apk (and back it up) using the Android SDK:

adb remount
adb shell
cd /system/app
cp Settings.apk Settings.bak
exit
adb pull /system/app/Settings.apk Settings.zip

Then I opened Settings.zip with winrar, and browsed around. I found the files needed in res/drawable-hdpi under filenames appwidget_settings_ind_on_?.9.png and appwidget_settings_ind_mid_?.9.png (where ? is c, r and l).
My first attempt was simply to change the colors using GIMP, but that messed up the scaling of the pictures.
To fix that, I used a program called tweakpng, and removed all PNG chunks not in the original file, and copied the one chunk that the new file didn’t have from the old file.
This targets the scaling issues, but somehow I still had some weird blue lines through the images.
Instead of turning it to white as I wanted, I figured the normal Android green would be sufficient too. So I set out to get it from a stock ROM.
I found the stock Nexus ROM, and found the system.img. Apparently it’s a YAFFS2 filesystem, and after some googling, I found a tool unyaffs (needed to compile that on a linux box) to extract it. As said before I couldn’t just take the Settings.apk from there, so instead I renamed it to Settings_orig.zip, and with winrar moved the files I found earlier from the original into the modified zip file.
Then I used

adb push Settings.zip /system/app/Settings.apk

to push it back onto my device.
After re-adding the widget, the colors were green again :D

Compiling V8? Do not use Python x64!

January 6th, 2010

When compiling Google V8 on Windows, do not use an AMD64 version of Python.
Firstly, the scons installer will not function, as it can’t find a python version in the registry.
Secondly, even if you just install scons manually, the V8 SConstruct file will fail. Because the return value from platform.machine() is now AMD64, the GuessArchitecture function in V8’s build script will not recognize a valid architecture, and the entire thing will fail.
If you just uninstall Python, and re-install an x86 version, everything will function fine.

My rtorrent setup

July 28th, 2009

I hate leaving my main desktop turned on at night. I’m pretty sure it has something to do with the fact that it’s: a) noisy, b) in the same room I sleep in, and I: c) can’t sleep with a lot of noise or light in my room. This is why I have a seperate computer (without monitor that is) in another room that does all the stuff I’d want to be doing at night. It used to record from the TV channel, but dutch television sucks when it comes to good series, so a while ago I put a torrent client on there. Here’s a description of my old setup, and how I set it up today.
Read the rest of this entry »

LiveScratcher first public alpha

July 17th, 2009

What’s that? a new forum? and a weird development announcement? Go check it out!

I’ll be spending today on writing up documentation on that forum and doing quick bugfixes.

Disappointing discoveries

July 15th, 2009

Normally it’s pretty cool to find new APIs in Messenger. Imagine my excitement when I found a new interface named “IMSNMessengerConversationWnd2″ that seemed to inherit from the already known IMSNMessengerConversationWnd interface. Two new functions appeared to have been added. Hurrah!

So I spent 3 hours of my time debugging and testing these new functions. Turns out they’re not nearly as exciting as I had hoped:

	[
	  odl,
	  uuid(929BB08C-B50C-4ECD-B68C-175F0B69A544),
	  helpstring("MSN Messenger Conversation Window Interface Ex"),
	  dual,
	  oleautomation
	]
	interface IMSNMessengerConversationWnd2 : IMSNMessengerConversationWnd {
		[id(0x0000080c), propget, helpstring("Get the window text.")]
		HRESULT WindowTitle([out, retval] BSTR* bstrWindowTitle);
		[id(0x0000080c), propput, helpstring("Set the window text.")]
		HRESULT WindowTitle([in] BSTR bstrWindowTitle);
	};

I’ve tested this in Vista, it gets and sets the window titlebar. As Vista doesn’t use the borderless-windows that WLM9 uses on XP, I’m not sure if it works on that, but I suspect that this interface has been specially generated for precisely that.

Well, either way, have fun with it. Sure hope my time has been useful for someone :p

Javascript Haskell mash-up

July 14th, 2009

With LiveScratcher I’m working a lot with JavaScript, and I’ve really grown to love the language. For example, today I stumbled upon this blog post. It’s a JavaScript implementation of a lot of Haskell tricks and functions, including a quick “curry” function (read the blog post to find out what it is).

Just felt that was worth sharing :)

LiveScratcher: Now what?

July 13th, 2009

LiveScratcher, and it’s early abandoned brother project Modumes, have been in the pipeline for months now. I think I had the initial idea of a modular extension platform for Messenger well over a year ago. Either way, I never really had a lot of time to put some real work into it. Until now, that is. Holidays have started two weeks ago, and I’ve been crashing at my parent’s place (free food ;) ) and working on LiveScratcher non-stop since. I hadn’t quite expected it (what would you expect from a project that’s been in the making for months without any results), but I feel that the end of the road (or at least something worth showing) is near :)

I’ve put up the initial scaffolding for the Messenger API, and am currently filling in the functionality for the Messenger, Contact, and Conversation classes. The DirectUI (messenger’s user-interface library) module is in a somewhat usable state, and I’ve even written an old-style UIFile parser to it (written completely in Javascript). One package I haven’t started on is the Interop (= communication with external libraries) one, but the plan for that one is well established in my head, and shouldn’t be too hard to implement.

For now I’m aiming for something that is on-par with Messenger Plus!’s scripting, but once I reach that I hope to keep expanding and surpass it greatly. One of the advantages I have is the extensibility. Each package can export certain functionality, and as such anyone is free to extend the API as they wish. Someone could make a package solely dedicated to communicating with facebook or twitter, and other developers can then use those packages from their scripts, for example creating a script that keeps your facebook or twitter friends updated on how many contacts you have.

Here’s a list of a few things that are done and worth mentioning:

  • Minimal main system: the main system *only* contains the bare necessities needed to load the modules and scripts. As such you can replace virtually anything with your own implementation; Don’t like the standard Console? take it out and write your own.
  • Google’s V8 JavaScript engine: The same engine that’s behind the blittering speed of Google Chrome. A downside is that things like “new ActiveXObject” aren’t supported, but upsides are plenty: It’s fast, it’s flexible, it’s standards compliant, and it actually allowed me to do the DirectUI stuff (Microsoft’s JScript was a bitch when it came to threading, V8 just sticks to one)
  • Code searching package: No more hard-coding of patch offsets, simply define what kind of pattern you’re looking for, and this package will find the offset(s) for you. It’ll optimize multiple patterns so only one pass over the memory is needed, so it should be really fast, and it’ll run in the background and only keep your script waiting minimally: it will return the offset the millisecond it’s found, and continue searching in the background.
  • Quick and simple console package that outputs script errors, and exports functions to add messages, warnings, or errors so you have an easy way to output data to the user.
  • DirectUI access: Want to remove a button from messenger? add a new one? Move the wordwheel to the bottom of the contact list? It’s all possible.
  • UIFile parser completely implemented in JavaScript, allows you to define your own output callbacks (or use existing ones), so someone could easily stick in a UIB compiler.
  • Packages can consist of modules (DLLs) or scripts, or even a combination of both.
  • The actual Messenger API is a mess, there’s about three different ways to do things, and half of the functionality is often broken. But as a package developer you don’t have to worry about that: I’ve taken the time to write a Messenger package that takes care of all that for you, and exports an easy to use interface for your scripts to use :)
  • Need some functionality that’s not yet in LiveScratcher but is in Plus? For now there’s a PlusCom package that allows you to make a (string values only) bridge between a Plus! script and a LiveScratcher package.
    I’m not sure if this will be useful when it’s all done, but it was a nice experiment, and might come in handy with other things.
  • Need to pop up a toast? That’s already in the Messenger module :) with callbacks and everything. And not fake lookalike toasts, nope, actual real Messenger toasts with custom text.

Now, it all sounds really great when I put it like this, but there’s also a bunch of things that are missing (but that I do plan to implement some day):

  • Debugger: as of now, all you have is some errors in the console if something goes wrong. I’m planning on exposing the V8 debugger protocol and write a nice debugger plugin for Eclipse or Notepad++ or something like that.
  • More advanced Interop: For now I’m focussing on an interop approach like Plus!. A simpe way to call external libraries with integers or strings, and some memory block class for pointer stuff. When I have the time I’m hoping to come up with a nicer approach that allows you to specify a structure and it will make a memory-block automatically and catch all get/set calls to it.
  • Protocol level stuff: For now I’m focussing on exposing all the API based stuff, but at some point I hope to write a proxy/protocol-analysing package that would allow for similar functionality to Messenger Discoveries’s plugins.
  • RichEdit hooking: It’s going to be a big project, but I do hope to implement some kind of RichEdit hook and expose that, so scripts can implement new mark-up stuff. For example implement Plus!’s coloring, or implement a LateX package that automatically converts latex to images.

Well, now you know most of what it is and my plans about it. If for some reason you got excited (sure hope you did ;) ) and want to take a look and give some feedback, please don’t hesitate to contact me. Just leave a comment and I’ll get in touch with you. I’ll gladly send it over and give you all the help you need to get using it. At this point however I’m not quite comfortable with just uploading it here (as it’s still very very crude and rough around the edges), so you will have to personally ask me if you want to take a peek ;)