IDA-Pro and Pascal: Sets & Propagating Types

In Pascal there is the Set object, that you set (n<256) bits and then can later check if bit n is set or not. Sort of like a bool array.

When you decompile a DOS Pascal program the IDA-Pro Flirt signatures will find the Set functions, in this example we will focus Set::MemberOf

Set MemberOf
Set MemberOf

arg_0 is the Set object and arg_4 is the byte we are checking to see if it’s set. When this code is called it looks like this:

Set MemberOf in use
Set MemberOf in use

and the byte_152FE location is an unknown mess like so:

Set data
Set data

as we know this data is a Set object, it would be nice if it was represented as such. Now we could Declare this a structure variable (Alt-Q) by hand and then rename it.

Set Declare a structure variable (Alt-Q)
Set Declare a structure variable (Alt-Q)

This works for a few small cases, but in the Gold Box games, Sets are used to manage lots of things so there are too many of them. The best trick here is to get IDA-Pro to do the work for us.

First you will need to have created a Set structure (needed for the above manual process) that is 0x20 bytes long.

set-structure
set-structure

Now go back to Set::MemberOf and Associate a prototype to a function (Y) and change the prototype from:

Set Associate a prototype to a function (Y)
Set Associate a prototype to a function (Y)
int __stdcall far Set__MemberOf(__int32 _set);

to:

int __stdcall far Set__MemberOf(Set set, char);

and ta-da the code call Set::MemberOf is tidy:

set-member-of-in-use-clean
set-member-of-in-use-clean

and all the Set data blocks are typed for us also:

set-data-clean
set-data-clean

Magic!

Microsoft 'Really' Ad

Microsoft has a fantastic new ad ‘Really’ for their new mobile device OS (ht Andrew Lark).

It pushes a current trend to the extreme, and their claim of difference is “in and out faster”. Really?

I get absorbed in my mobile device not because it takes so long to do stuff - Microsoft’s claim - but because I enjoy the task I’m doing with the device.

Now the painful reality is that after Michaela also got a mobile device, we both are more inclined to pick them up and listen to podcasts/play solitaire, when everybody else is busy. I guess I did it before I just didn’t notice the impact.

The problem this induces is once the original people finish their task, they see others engaged in their own thing and therefore find another solo task. The technology that helps fill in the little gaps and avoid watching boring TV is actually also keeping us apart.

After noticing this, I find I need to-do nothing more, to allow a better something to happen, which feels counter intuitive.

Willow Hill Rocketry Group - 9th Oct

Today Jacob and I attended the Willow Hill Rocketry Group’s first launch day for the season. 21 Rockets were fired today from class A to class I motors, very fun to watch.

Here’s a small SD Outlaw rocket with a C motor in it:

And some photo’s

Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct
Willow Hill Rocketry Group - 9th Oct

It was a very fun couple of hours, and at the next flight day, some even bigger rockets will be launched. The big rockets of today’s launch were not photographed due to battery mismanagement.

IDA Pro and Pascal: base one arrays

Today I have finally solved how to handle Pascals base one arrays in IDA Pro.

So if you have a fixed size array block, it will normally be packed after some other data.

pascal memory layout
pascal memory layout

you can see the stru_1DA79 is an fixed size array from it’s use.

pascal array copy
pascal array copy

But when the base-1 array is indexed into, the results are messy and confusing

pascal array index ugly
pascal array index ugly

Yes it looks like the dword is being accessed not the actual array. For a long time I have worked around this with mega ugly repeat comments like:

_dword and [+2] = unk_1DA79[i-1].byte_0 and [+3] = unk_1DA79[i-1].byte_1_

Today I read enough help to finally workout how to do it correctly.

The first steps are to see above that the structure is 3 bytes wide, and create a structure for that (already done in the snaps above thus struct_6). Then in the incorrect usage shown above @ ovr032:0B51 select dword_1DA74 then Offset (User Defined)

Offset (user-defined)
Offset (user-defined)

Then set the Target delta to -3  (-1 * the size of structure (3))

pascal-fix-03
pascal-fix-03

and like magic it shows you correctly accessing the array

pascal-array-fixed
pascal-array-fixed

This ‘issue’ has only been the bane of my reverse engineering for like the last ten years.

Erlang and OTP in Action - Delayed Again...

Erlang and OTP in Action
Erlang and OTP in Action
In August, I was feeling spontaneous due to my new found love of purchasing stuff from Amazon and pre-ordered "[Erlang and OTP in Action](http://www.amazon.com/Erlang-OTP-Action-Martin-Logan/dp/1933988789)" with an eagerly awaited the September 1, 2010 shipping date. I was even hoping it might arrive before my trip to New Zealand, thus I could read this book in my spare time. Oh happy times.

Then a blow to my excitement, the release date slipped, now I was expecting a October 12 - October 18 delivery time. Ok, that’s fine, I’m still excited…

Today another blow, release date slipped again, now I get to wait till November 08 - November 15 for delivery, really not sure I care any more.

The value of spontaneous purchases should be realised before the guilt’s kick in. Evil pre-orders.

And the problem plaguing my mind is, most of the purchase was done with a voucher, that I’m not sure I have any more because I brought something…, so if I cancel my order do I lose my voucher money? How does that get refunded?

p.s. Wow, this book seems to be all over the file sharing networks.

updated 1 Nov: Delayed again, Estimated arrival date: December 09 2010 - December 15 2010, sigh!

update 22 Nov: It has been shipped, should get by 30th November!

update 30 Nov: It arrived today! Front cover is bent :( but the book has been an enjoyable read so far :)

New Zealand work trip: A rough start so far

I’ve had a very odd start to my two week work trip. Depending how far back you review I’ve:

  • Made the rest of my family grumpy because I’m getting to return to NZ before them, and they are the ones wanting to return

  • Booked my tickets through the work Orbitz account, which by itself was not bad, I choice the lowest cost flights*, but:

*   I had US internal flights using American Airlines, thus I will not get any Air New Zealand Air Dollars (like miles), and could only ticket to L.A in Peoria,  then in L.A. ticket the last legs, it's always nicer to ticket in the quieter airports

*   I flew to L.A. from Peoria via Chicago which is 1 + 4 hours of flying verse 2 + 2 via Denver

*   I was travelling to New Zealand via L.A. I have decided I prefer San Francisco, which is luckily my return route

*   I booked the international leg tickets under the United Airlines code-share (it's Air NZ flight), thus could not use my free Air NZ class upgrade to travel premium economy (which looks so much nicer) and I'm not sure I'll get the same value of Air Dollars (edit: same value earned)

*   I travelled to Christchurch from Auckland via an domestic flight NZ501 instead of the international NZ303. The later is way simpler and I had to re-ticket again in Auckland for some odd reason
  • But all those issues aside, I’m here

  • The travel was made hectic by finding out just after landing in Chicago that there had been an earthquake in Christchurch. Making contact with family in NZ and US used all my spare time between flights

*   This was due to Michaela and I only having cell phones in the US. Mine is a work phone so has a toll bar, and Michaela's is a new Verizon account and therefore she is not allowed to make tolls calls on it for the first year. WTF! we already had to pay $400USD bond for the first year to open the account
  • Now I’m here in Christchurch there are water/sewer problems, thus staying at my mother’s was not going to work, but luckily my brothers farm is self contained or just well stocked, so I am going to stay the night out there. Really weird seeing all the old brick buildings with toppled walls

So lots of lessons to learn for the next time I book tickets for a trip. Next time I’ll check the price differences of some of these options…

* actually I could have travelled via Australia to get to Christchurch, but that would have made four more hours of air travel, just for $150 USD return.

Fixing Wii Screen Resolution

This post is to help anybody that needs to reset their Wii’s screen resolution, whether that is because they have changed cables, or put it into the wrong mode.

The reason I have to fix my Wii’s resolution, is I own a New Zealand Wii, which defaults to PAL, and I have a US TV that only supports NTSC. Thus when my Wii resets (due to no power) it goes back into PAL mode and thus is usable.

There are a number of solutions posted on the Internet for resetting resolutions. With my PAL Wii I can confirm a couple of methods reset to system default (for me PAL):

Powering down for 5 minutes

Power on Wii, give it a few seconds to boot
Hold DOWN on the directional pad of the Wii remote
While holding DOWN, press the RESET button on the Wii

However, given our US TV is NTSC resetting to PAL is of no use, thus I present the order of screens for my Australasian Wii. To help with future manual resets.

Incorrect signal looks like this or worse
Incorrect signal looks like this or worse

Wait until the screen looks like picture one, this can take 5-10 minutes

Home Screen
Home Screen
Wii Menu
Wii Menu
Settings Menu
Settings Menu
Screen Selection
Screen Selection
Resolution Option
Resolution Option

Then relying on the vibration feedback, and limited screen left/right feedback, follow the set of screens to turn your PAL Wii into 480p mode.

Some advice I found on the internet was to use only the green channel of the component cable to plug into the composite plug. This did work to allow seeing the picture (albeit black & white) it was equally scrolling badly, thus was not a better solving mode.