Generating a unique ID for a Windows PC

Software licensing usually works by tying a product to a single PC. Identifying the PC in a unique manner usually requires generating some kind of unique ID.

Here’s a log of certain attributes of a Windows PC (a Parallels virtual machine) read using the Windows Management Instrumentation API of .NET. It was generated using the WMI Query utility available at GitHub.

Win32_BaseBoard.Manufacturer="Parallels Software International Inc."
Win32_BaseBoard.Name="Base Board"
Win32_BIOS.Manufacturer="Parallels Software International Inc."
Win32_BIOS.SMBIOSBIOSVersion="10.2.1 (29006) rev 0"
Win32_BIOS.SerialNumber="Parallels-FC C8 89 B7 D4 BF 4E 13 9D 53 D8 BC C1 9B 90 A8"
Win32_BIOS.Version="PRLS   - 1"
Win32_Processor.Name="Intel(R) Core(TM) i7-3840QM CPU @ 2.80GHz"
Win32_OperatingSystem.Name="Microsoft Windows 8 Pro|C:\WINDOWS|\Device\Harddisk0\Partition2"

The challenge in generating a unique ID is deciding which information to use. The ID itself can be generated fairly easily by hashing the information using a cryptographic hash function.

Use too much of the information above and you risk the ID changing frequently. Updating Parallels may result in changes to Win32_BIOS.SMBIOSBIOSVersion and Win32_BIOS.ReleaseDate. Upgrading Windows may result in changes to Win32_OperatingSystem.Name, Win32_OperatingSystem.OSArchitecture, and Win32_OperatingSystem.SerialNumber.

I’ve found Win32_BIOS.SerialNumber and Win32_Processor.ProcessorId to be fairly stable. They’ll only change if the PC’s motherboard is changed or its CPU. Not likely to happen that frequently with laptops.

Posted in .NET, Windows

git stash

git stash can be a useful mechanism to set aside work you’re not ready to commit yet.

To stash staged changes simply run

git stash

Files in working directory not added to index are not affected, unless you add the -u option to stash those as well.

To view a list of stashes

git stash list

To inspect details of latest stash

git stash show stash@{0}

0 is the id shown by stash list. Use of stash@{0} is optional for latest stash entry.

To apply changes in latest stash to working directory

git stash apply

To eliminate the latest stash (use pop to apply and drop)

git stash drop

If stash apply or pop fails due to conflicts, but you still want to stage the changes, try

git checkout stash -- .

-- indicates current branch. The single dot indicates path beginning at current directory, but may be several different path specs. stash may be replaced with stash@{0}, use a different id to work with older stashes.

Posted in Git

Recife from Shopping RioMar


Posted in Photography

git tag

This post summarizes some useful tag related commands. All commands assume a tag with value v1.0.0, a version number. To create an annotated tag

git tag -a v1.0.0 -m "a comment"

To list all tags

git tag

To view details and diff for a tag

git show v1.0.0

To delete a tag

git tag -d v1.0.0

To replace a tag when it already exists

git tag -a v1.0.0 -f -m "a comment"

To create a tag pointing to the same commit as another tag

git tag -a v1.0.0 v1.0.0-rc -m "a comment"

To create a tag pointing to a specific commit

git tag -a v1.0.0 commit -m "a comment"

To checkout working tree at tag (add option -b to create branch at that point in the tree)

git checkout v1.0.0

To view commit log with tags

git log --decorate=full

To push tags to origin (add -f to force update if tag exists on remote)

git push origin --tags

To push tag deletes to origin

git push origin :refs/tags/v1.0.0

For other commands and options use man git or man git-tag.

Posted in Git

USB bulk data transfer

USB bulk data transfers is how most data transfer occurs between a USB host such as a PC and a peripheral. This post shows, with help from a Total Phase Beagle USB 480, how the data transfer looks like. Here’s data captured using Data Center software and a Total Phase Beagle USB 480. According to the USB specification, all bits in a byte are written to the bus in little-endian fashion, and multi-byte values are also written in little-endian order. While the latter is still valid with the Beagle USB 480, single byte values are represented in their normal big-endian order.

bulk transfer

Each USB bulk data transfer is broken into smaller data transfers. Each of the smaller data transfers is initiated by a token packet, followed by a data packet, and an ACK packet.

Incoming transfers begin with a token packet, that has a PID (packet identifier) of IN (0x69) in the first byte. Actually, the PID is contained in the last 4 bits (0x9), the first 4 bits are a one’s complement of that value (0x6). The second and third bytes form a single word in little endian byte order, containing a 5-bit CRC, followed by a 4-bit endpoint ID, followed by a 7-bit device ID. Thus ASCII hex sequence 81 58 in the figure above, should be interpreted as 0x5881, which results in a CRC of 0x0B, an endpoint ID of 0x1, and a device ID of 0x01.

The token packet is followed by a data packet. The PID of the data packet may be DATA0 (0xC3) or DATA1 (0x4B) for full-speed, and also DATA2 (0x87) for high-speed bulk transfers. The data packet has a maximum payload size determined by the USB specification, and is described by wMaxPacketSize attribute in the endpoint descriptor. It may be 8, 16, 32, or 64 bytes for full-speed bulk endpoints (USB 1.1), and also 512 bytes for high-speed (USB 2.0) bulk endpoints. It is 64 bytes in the capture shown above. The payload is followed by a 2-byte CRC.

The ACK handshake packet indicates the end of data transfer. A bulk data transfer is composed of several such data transfers in sequence. The end of a bulk data transfer is signalled by a data packet that has less than wMaxPacketSize bytes. If the last, or only data packet, carries wMaxPacketSize, a data transfer containing data packet with payload size of 0 bytes is required.

Outgoing transfers are quite similar, except that the token packet uses a PID of OUT (0xE1, or 0x1 to be more accurate). Outgoing bulk data transfers can appear jumbled up with incoming bulk data transfers. Applications that leverage Beagle API need to take this into consideration, when parsing data captured on the bus.

Posted in Hardware, USB

Reflected pixel art

Reflection of John Hancock Center

Posted in Photography

git archive

To quickly get a source distribution in zip format

git archive --format=zip -o HEAD source/ README

Assuming, source code is under the folder source. README is a file in the same folder as source. Subfolders ignored by .gitignore are not archived. You can replace HEAD with a commit label. zip can be replaced with tar or tar.gz. See man git-archive for more details.

Posted in Miscellaneous

Get every new post delivered to your Inbox.

Join 82 other followers

%d bloggers like this: