Category Archives: Uncategorized

Rigol oscilloscope binary file parser

Introduction

So, just a day before my vacation trip I got a brand new RIGOL DS1052E. I was very eager to get back from my travels to check out my new scope. Unfortunately, I soon discovered that there is no good program to parse the native wfm files generated by the scope.

There already exist several attempts in generating a parser for the file format. The first attempt seems to be a script for Matlab. But this script suffers from not parsing all the available information and doing errors in alternate trigger mode. There are several derivations of this code on the Internet – all suffering more or less from the same problems.

New code

The problem was finally solved by Dexter who successfully reverse-engineered most fields of the Rigol wfm file format and uses it in its awesome wfm_view program. Unfortunately, it does only work under Windows and closed-source. Fortunately, he opened up the source code regarding the parsing of the wfm file. While it is not usable in it’s own it can be used to extract a protocol definition from it.

Armed with this wealth of information, I’ve re-implemented the file parser in standard Python. The code has been tested with Python 2.7.3 and 3.3.0 and should work without any modification.

The code contains an example usage of the library, see wfmutil.py. Which can be used to

  • extract header information
  • export to CSV as if the CSV was generated on the scope
  • plot the waveform and its FFT. (This requires numpymatplotlib and scipy)

Example

Inspired by Dexter’s work, I’ve also put an antenna to one input of my Rigol DS1052E and could clearly see all the radio stations I have here:

Radio with a Rigol DS1052E

Get it

You can find the code on my Github page:

https://github.com/mabl/pyRigolWFM

Accessing an encrypted full disc image (LUKS;LVM)

So I typically use a full disc encryption with LVM over LUKS. So assume you have got an image from your harddisk via

dd if=/dev/sda of=image.img

You now want to access this data again – maybe you don’t even have the drive anymore. So here is a quick rundown how I did it just now.

First we look at the image:

% fdisk -l -u backup_x220_november_2012_sdb.img                        

Disk backup_x220_november_2012_sdb.img: 80.0 GB, 80026361856 bytes, 156301488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000589c6

                            Device Boot      Start         End      Blocks   Id  System
backup_x220_november_2012_sdb.img1            2048      499711      248832   83  Linux
backup_x220_november_2012_sdb.img2          501758   156301311    77899777    5  Extended
backup_x220_november_2012_sdb.img5          501760   156301311    77899776   83  Linux

Great! So all partitions are in there! We will use kpartx to map this file to a block device which you can use just as your normal drives.

% sudo kpartx -a -v backup_x220_november_2012_sdb.img
add map loop0p1 (254:3): 0 497664 linear /dev/loop0 2048
add map loop0p2 (254:4): 0 2 linear /dev/loop0 501758
add map loop0p5 : 0 155799552 linear /dev/loop0 501760

Even better, now we have the partitions on the image mapped to /dev/mapper/loop0px. It’s now straightforward to mount the encrypted drive loop0p5:

% sudo cryptsetup luksOpen /dev/mapper/loop0p5 imgroot
Enter passphrase for /dev/mapper/loop0p5:

Now find and open the LVM drives inside:

% sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "mikrocanonix" using metadata type lvm2

% sudo vgchange -a y mikrocanonix
  2 logical volume(s) in volume group "mikrocanonix" now active

% sudo mount /dev/mikrocanonix/root /mnt/

DONE!