My daily work involves episodes of the men who stare at goats bytes. Often its not one bunch of bytes, it’s two. And I need to compare them. That means in two levels. First in structure, second in content. A normal byte comparewon’t do in such cases.

I’ve written a lot of tooling for my every day life ever since. Also an ASN.1 viewer and editor. I thought about extending one of the exiting tools, but the job to do is comparison and I have a tool that I like to use for that job: Beyond Compare

DISCLAIMER: I’m not related to Scooter Software. I payed my license in full. They do not sponsor me. I just like the tool since years - even if they refuse to build a real dark theme, I haven’t found any better and,as for the dark theme, I keep looking every now and then…

Helpfully BC comes with a feature that lets you convert files before comparison. This is extremely useful, for instance when looking at XM or JSON files, you can pretty their format to match or for better readability.

Beyond Compare File Format Conversion Settings

I’m going to use this to convert the files in a way that let me easily see structural differences as well as content differences.

To do so I’ll just fire up certutil.exe or openssl and replace the leading index bytes. They are intended to show you on what position the following bytes are to find. In case of comparison they ensure a wall of red as each line is different if you are not looking at the exact same file.

using System.Diagnostics;
using System.IO;
using System.Linq;

namespace BeyondCompareAsnOneConverter {
  internal class Program {
    private static int Main(
      string[] args) {
      using (var proc = new Process {
               StartInfo = new ProcessStartInfo {
                 FileName = "certutil",
                 Arguments = $"-asn \"{args[0]}\"",
                 UseShellExecute = false,
                 RedirectStandardOutput = true,
                 RedirectStandardError = true
             }) {

        var output = proc.StandardOutput.ReadToEnd();

        output = string.Join(
              l => l.Length > 6
                ? l.Substring(6)
                : l));
        File.WriteAllText(args[1], output);

      return 0;

Here is the result in action:

Beyond Compare comparing ASN.1 data