Customize your Windows Terminal

Customize your Windows Terminal

Screenshot of Windows Terminal settings for the PowerShell profile
Screenshot of Windows Terminal settings for the PowerShell profile
  • Create your own theme (or use a default)
  • Configure theme in your PowerShell profile
    • If you don’t have a profile:
      • notepad $PROFILE
    • If you already have a profile:
      • ii $PROFILE
    • Set-PoshPrompt -Theme "Path\To\Theme.json"
Screenshot of Windows Terminal after following this guide
Screenshot of Windows Terminal after following this guide

Reverse engineering a keyboard lighting protocol – Step 1 – Capturing USB packets

Reverse engineering a keyboard lighting protocol – Step 1 – Capturing USB packets

Turn off the &#$@ lights!

A few days ago I got fed up again with the lights of my headset blinking while I was playing a game. I don’t use my headset if I don’t need to so it was laying on my desk, blinking and being annoying. I had double checked the settings of the SteelSeries application but lighting was turned off.

Diving deeper I found that the application uses a provider system that supports different applications and games that you could individually turn on or off.

Turning the provider off for the specific game resolved my issue and also made me realize two things were possible:

  1. You can get game state from certain games without writing an integration
  2. You can directly control RGB lighting of USB peripherals

Since I don’t use my headset often but I do use my keyboard a lot I want to try to come up with some nice ways of integrating lighting and certain events. I’m thinking about game events, meeting reminders, system notifications etc.

In this series we’ll look at how you can reverse engineer the lighting protocol used for your keyboard and write some code to control it.

Capturing USB packets

First thing we need to do is be able to capture USB packets so we can see what’s going on. You might want to download Wireshark and make sure that you check the box to install the included USBPcap. If you install USBPcap manually you don’t have the ability to select the interfaces in Wireshark.

Once you start it up, provided you have at least one USB controller, you will see a list of your USB controllers.

Starting window of Wireshark with USB controller capture interfaces shown

When you click the cog icon next to a capture interface, you get a dialog with a possibly long list of USB devices attached.

Wireshark list of connected USB devices

Since we want to focus on one device, we want our capture to be as specific as possible. As you can see the list of devices is pretty long and complex. I plugged in my keyboard into one of the front ports of my PC and it showed up as a new device (I saw a higher number appear so went with that).

Wireshark list of connected USB devices showing the newly connected keyboard

As you can see in the screenshot, the keyboard I have is implemented as a composite device which means it is implemented as multiple devices that are communicating with the computer. I guess it makes sense to implement and control the keyboard and the lighting as different devices. Each will show up in the capture log as a different path. Since this is the first USB interface and the device with ID 15 the keyboard devices will show up as “1.15.x”, where x is the actual device index.

Now we have to figure out what data would be useful. When you start capturing packets, the log will first show that a few informational packets will get sent to the host device at 1.15.0, and if you start typing it will list communication between the computer and 1.15.1. One packet from the keyboard to the computer on keypress, one back to acknowledge and also two packets when the key is released.

💡 Adding the “HID Data” column

In the screenshot below you can see I have added the HID Data column.

In order to do that you have to:

1. Click on a packet to see the contents in the lower pane
2. Scroll down a bit until you see the HID Data
3. Right click on the row that says “HID Data” and select “Apply as column”, the shortcut for that is CTRL + SHIFT + I

Wireshark capture log showing information packets and packets that are sent and received during key press and release

Since everything is working now, it’s time to fire up the keyboard software and see what it’s doing. Upon starting the Ducky software it starts sending a lot of messages to devices 1.15.3 and 1.15.4. Since the packets for 1.15.3 have no data in them and because it says “in” instead of “out” (I’m assuming that’s the transaction mode), I will apply a filter so Wireshark only shows packets for the device that we really want, the RGB lighting module.

Filtering on usb.dst == "1.15.4" shows that a whopping 491 packets get sent to the device to put it in some kind of, I guess, configuration mode. This might be important so I’ll save the filtered list for later and restart the capture. I saved it as JSON because that’s the only way the HID Data was in a usable format and that way I can easily parse it later if I want to generate some gigantic 2D byte array of packets.

List of packets that are sent to 1.15.4

Before this experience I had set my keyboard to “Backlighting Off”. Now let’s restart the capture with the filter still active and see what we get. I figured I would try out “Reactive Mode” since I know that lights up a single key when you press it, but in my test it only showed a few packets to activate the mode and nothing afterwards. Not useful since we want to directly control the lights.

After trying a few modes I finally found a mode called “Equalizer Mode” that kept sending packets to the device. In the screenshot below you can see four unique packets and then a list of packets that have mostly zeroes and start repeating at the end of the page. The first four packets are also sent at the end when the Ducky software was launching so that confirms my idea that those are some kind of activation packets and the rest start out with the same prefix so they must control the lights.

List of packets that are sent at the start of and during Equalizer Mode

Stay tuned for part 2 where we will dive deeper into the individual packets and write some code to send them to the device. Then we can see if this works or if we really need the 491 packets we captured when the software was starting up!

Blazor Server Hot Reload

Blazor Server Hot Reload

I was working on the UI of a Blazor Server project the other day and had this cycle going on:

  1. Run my application without a debugger attached (CTRL + F5 in Visual Studio)

    Quick note on this, if you don’t do this you have to rebuild the project yourself before changes are visible.

  1. Make a few changes
  2. Reload browser to see the changes
  3. Repeat from step 2

I would love to see the browser refresh automatically after making a change, unfortunately that is not yet available in VS and third party (JavaScript) solutions I have tried didn’t actually work.

After a little search I found that Blazor has a public API, containing everything I needed to have the browser reload when it loses the SignalR connection.

This is a really simple implementation and it might not work for your use case. Let me know if this is helpful to you or if you have a better alternative!

Breaking the debugger and keeping your context

Breaking the debugger and keeping your context

Some developers have a workflow which includes a lot of work with Edit & Continue.

Their workflow might look a bit like the following:

  1. Run the application
  2. Find the spot where the code needs to be changed
  3. Signal the debugger to break
  4. Close the window that opens (often with the code that was running, not your change, sometimes nothing because it was all external code)
  5. Make a change
  6. Continue the application and see if the change results in the right behavior
  7. Repeat steps 3 through 6

I’ve written a simple extension that does step 4 automatically if you use the new orange Break All button.

NameBreak In Current Document
IDBreakInCurrentDocument
LinkVisual Studio Marketplace
RepositoryGitHub

Tools

Tools

These are the tools I use almost daily both for my personal and professional computing needs.

More and more software is available from the Microsoft Store, which makes it easy to install everything you need from one place. One-click installation instead of setup wizards and configuration.

Development

Visual Studio

If you want to be on the cutting edge in the Microsoft / .NET world – and you want to be – you need Visual Studio.

OzCode

OzCode gives you a heads-up display with current values and a red/green visual indication of expressions and statements.

You can take snapshots of an instance and compare that to the current instance or even another snapshot, very helpful during debugging.

With LINQ analysis, you can see what the dataset is at every step of the expression.

NCrunch

The built-in Live Unit Testing feature in the Enterprise edition of Visual Studio does not give you clean errors when something is wrong.

NCrunch makes sure you have a fast red-green-refactor cycle when practicing Test-Driven Development.

LINQPad

LINQPad is a great prototyping tool, and the ability to quickly visualize the data you’re working with is just amazing.

There are editions for both .NET Framework and .NET Core.

RegexBuddy

For everything regular expressions. You can create and test expressions and also generate implementation code.

Beyond Compare

Easily diff files and directories.

System

7+ Taskbar Tweaker

7+ Taskbar Tweaker makes using the Windows 10 taskbar much better by keeping your pinned items on the left instead of using them for the first window.

Another great feature is also that you can close windows by clicking with the middle mouse button.

OneDrive

After having tried many backup solutions over the last few years, I finally ended up with OneDrive. While not a backup solution per se, sometimes simple is best.

LockHunter

Feel like deleting something, but you’re getting “in use” errors? LockHunter helps you find out what’s locking the file or directory that you want to delete.

f.lux

Must-have for when you stay up late – past Sesame Street.

Adapts the colors of your screen to match the time of day and uses warm colors at night.

It takes a while to adjust to this, but then it’s easier to go to sleep.

IPVanish

Stay safe when using unprotected or unknown networks.

Automatically connects to a VPN when using an open network.

HashTab

HashTab allows you to check the CRC or MD5 hash of a file.

Utilities

1Password

I recently migrated to 1Password because it can sync to each device without external tooling, works with 2FA, and has added security measures.

7-zip

The only archive manager you need.

X-Mouse Button Control

Easily bind mouse keys to all kinds of actions. It also allows you to specify a specific window or application.

AutoHotkey

By defining macro’s and hotkeys, you can automate tedious manual workflows.

WinDirStat

WinDirStat gives you a visual overview of your disk space usage. For those situations where you have 0 bytes left and aren’t quite sure what happened.

Documents

Office 365

No setup configuration needed. Just get your Office applications installed.

Adobe Acrobat Reader

Still the best PDF reader.

Notepad++

Easy to use improvement over Windows Notepad.

OneNote

I keep all my notes in OneNote in separate tabs, sections, or even books. Your content syncs with your account.