Saturday, October 10, 2015

Power Cables and Data Cables from Different Computers

Today I needed to get some data off of an unbootable hard drive that was in a mount in a machine. Since I did not have a special screwdriver and the mount looked very difficult to work with, I decided I would just leave the drive where it was and connect cables from the real machine to it. The problem with that idea was that all the SATA power cables in the real machine were super short and could not reach.

So I carefully positioned the two machines so that the data cable would reach the hard drive from the bootable machine and connected a power cable from the unbootable machine to the drive. I powered on the unbootable machine first (I'm sure it got stuck in BIOS or something, no monitor was on it), then the bootable machine. The contraption worked - the drive was accessible and stayed online as long as I kept the old machine on.

This is also a good trick for situations where a motherboard is out of power cable slots.

Friday, October 9, 2015

Abiathar Confidential - Security & Privacy

I have written these things before, but I thought it would be good to put them all together in one place for easy reference.

Abiathar operates almost completely offline. It works perfectly fine without an Internet connection, but when the Internet is accessible, Abiathar updates itself. That may raise some concerns about the security and privacy of the whole system.

Abiathar uses the network for only three operations: automatic self-update, VeriMaps verification and temporary logo display. On startup, it checks my public Dropbox to see if there is a new version available. If so, a prompt is displayed asking for confirmation. If the user accepts the update, the updater application downloads a script from my Dropbox that can perform only three types of operations: download a file, delete an existing file, and mark a downloaded file to be executed after other operations complete. The entire checking and download processes are done over TLS.

There is the possibility of a critical update, a situation in which I have deemed an update so necessary that Abiathar should not be used at all until the update is installed. This mechanism has never been used, and probably won't ever be - it's for updates that fix earth-shattering, data-destroying bugs. Even if this flag is set on an update, the user still has the option of canceling the update, though the prompt appears in the console window of the temporary updater program instead of the Windows Forms UI of Abiathar proper.

The VeriMaps verifier is used when a maps file that claims to be VeriMaps-signed is opened. The matching public certificate is retrieved from my Dropbox (again over a TLS connection) and used to verify the file's authenticity.

The final type of network usage is purely cosmetic: temporary changes of the big background image in the main form. On startup, a download of a file at a certain path in my Dropbox is attempted. If it succeeds, the resulting image replaces the standard blue-text logo. The downloaded image is not persisted at all on the client, and it is redownloaded for every launch as long as it exists. I have set a temporary logo only once, on Independence Day, as a test of the system.

No user data is ever sent out by Abiathar.

Thursday, October 8, 2015

Centering Objects on Other Objects

There are several programs in which I frequently find myself wanting to align some object to the center (either horizontal or vertical) of another object. Unfortunately, I rarely see that feature. Visual Studio has Format | Align | Centers (or Middles), but there does not appear to be such an option in Adobe Flash Pro (the IDE/designer, not the player). That's a shame, because a lot of the arrangements I would like to produce require perfect centering of objects on other objects.

There might be such an option in Flash, but I am not seeing it and Googling has not helped me yet.

Tuesday, October 6, 2015

.NET Monitor Locks are Re-Entrant

The purpose of the Monitor class in .NET (used by "SyncLock" in VB.NET and "lock" in C#) is to prevent different threads from entering a critical section at the same time. Care must be taken by the programmer to ensure that deadlocks - situations in which threads are waiting for each other directly or indirectly - are impossible. I recently needed to write a recursive function that happened to require careful threading, so I was concerned that the second invocation would hang waiting for the first to finish.

Fortunately, Monitor locks are re-entrant. If a section is entered for a given lock object on the same thread (e.g. in a recursive situation), the section will not be released until a matching amount of Exit calls are made. [Source: MSDN's article on Monitor.Enter]

Sunday, October 4, 2015

Power Failures Happen

Today while attempting to switch off my monitors, I accidentally hit the toggle button for my computer's power, immediately turning it off. Whoops. That's alright, NTFS is designed to be resilient in the face of power loss, so I turned my computer back on. After BIOS did its thing, Windows 8.1 ran some sort of "automatic repair" on my computer and attempted some operation. (Before asking me, and without telling me what it was!)

Automatic Repair couldn't fix the "problem", and so it dumped me into the repair mode UI. Since I was fairly certain that nothing was wrong with the machine, I chose the Continue (try to boot normally) option, which is under the advanced tools menu for some reason. After sitting at a black screen with high disk utilization for a few minutes, Windows came up as normal with only the expected event 51 entries in the Event Log.

So all that was a really long-winded way of saying that everything was fine.

I really wish more programmers would account for the fact that power failures can happen at any time, and that it shouldn't be an earth-shattering catastrophe if the program or machine doesn't go down gracefully. I understand that there are certain critical operations that cannot be continued if power is lost in the middle, but surely an attempt can be made to continue with whatever state was saved to disk before panicking and displaying scary messages to the user.

Saturday, October 3, 2015

Keep My Place in Disconnected Network Folder Structures

I frequently have to browse the directory trees of remote machines, and since mapping a network drive for each place would create a big mess (there are lots of places I need to look at), I have to use double-backslash UNC paths to get where I want. That works great, and I do my work until I need to go somewhere else. I then close my laptop - disconnecting it from the network - and carry it with me. When I reopen it, all the Explorer windows browsing network folders are showing me the Network screen (the list of computers on the domain).

That's rather inconvenient, because there is no indication of what I was doing with that window. It would be really nice if Explorer instead grayed everything and put up a "remote session disconnected" panel that could be clicked to attempt a new connection.

Thursday, October 1, 2015

Keeping Windows Forms Controls Centered

Windows Forms designers may find it necessary to keep a control centered in its container but not stretched if the container expands (e.g. if the user maximizes the window). The way to accomplish this is actually quite simple, and requires no math whatsoever. Simply setting the Anchor property to nothing along a certain axis results in the control staying perfectly centered without any change in size. Setting that property to Bottom only, for example, keeps the control's bottom edge stuck relative to the bottom of the container but allows it to slide horizontally to remain centered.