Hello! I'm osi

I build and break things

(and pretend to be a bear on the internet)

osi, a bear with green ears and a purple stripe
← back to works

Dindle

for myself

Dindle turns a 2010 Kindle Keyboard into a Deezer player: search, 320 kbps playback, likes, playlists, album art, a 25-track offline cache and resume-where-you-left-off, on a device with no touchscreen, 256 MB of RAM and a Linux 2.6.26 kernel.

No release is planned yet. It runs on one Kindle Keyboard and exists because the hardware is pleasant to program against.

Dindle playing a track

The app

One static ARM binary, no toolkit. It opens /dev/fb0 and paints it directly, reads the raw evdev devices and drives the stock audioServer over LIPC, so audio goes through the hardware MP3 decoder instead of software:

  • k3fb: inverted 4bpp panel, 1-bit text, partial (DU) updates
  • k3input: keyboard, five-way and volume rocker as one event stream
  • player: LIPC wrapper with per-call deadlines and a health probe
  • deezer: ARL login, search, get_url, Blowfish, library, playlists
  • cache: LRU index, 25 tracks / 250 MB, metadata and covers
  • ui: screens, tab bar, streaming, two-player preload, watchdog

The .azw2 is not part of the player. It is a ~300-line Java 1.4 Kindlet whose only job is to install the binary and launch it.

Launching it as a booklet

The library only runs Java Kindlets, so the app ships as a signed .azw2 that looks like a book. It depends on two things: the Kindlet Jailbreak from the Mobileread Kindlet Kit, which grants the sandbox AllPermission, and signature blocks built the way JDK 8 did them. Modern jarsigner adds CMS signed attributes (signingTime, CMSAlgorithmProtection) that the K3's verifier rejects, reporting the whole jar as unsigned; signing each .SF with openssl smime -sign -noattr avoids it.

The launcher then stops the framework, hands the panel over and returns. There is no nohup on the device, so the shell is detached by ignoring SIGHUP:

private void launchPlayer() throws IOException {
    String command = "export PATH=/usr/bin:/usr/sbin:/bin:/sbin; cd " + BASE
            + " && ./run.sh >> ui.log 2>&1 &";
    Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", command });
}

Installing itself

The player and its launcher are embedded in the jar. On open the Kindlet compares a build id and CRC against /mnt/us/k3deezer/.azw2, copies what changed through a .new file and an atomic rename (safe while an old binary is still running), and shows a splash with a progress bar. Account, session and cache are untouched, so updating is one tap.

The 5.9 MB binary is deliberately left unsigned inside the jar. Signing it makes cvm hash it on every start, which pushed opening the app past the container timeout; the classes stay signed and the framework still sees a developer application.

Deezer, reverse engineered

The Android app talks to two backends. An ARL cookie exchanges for a legacy gw-light session; track playback comes from media.deezer.com/v1/get_url, which returns an encrypted MP3; playlist writes go through the app's GraphQL endpoint at pipe.deezer.com, authenticated with a JWT from auth.deezer.com.

The media encryption is the interesting part: BFCBCSTRIPE encrypts only every third 2048-byte stripe, with a fixed IV and a per-track Blowfish key made from the MD5 of the track id XORed with a constant lifted from the APK.

sum := md5.Sum([]byte(id))
hex := fmt.Sprintf("%x", sum)
for i := 0; i < 16; i++ {
    key[i] = bfSecret[i] ^ hex[i] ^ hex[i+16]
}

Deezer also answers errors with empty null, [] or {} shapes rather than codes, and rights-restricted tracks fail at get_url with a token error the UI shows for five seconds before skipping. Free accounts get 128 kbps; the player asks for 320 and reports which one it got.

Playback

audioServer can only play files, so the first play of an uncached track downloads to a growing file and tails it into a FIFO, letting the decoder start on the first seconds:

size := int64(atomic.LoadInt32(&s.size))
if off < size {
    n, _ := in.ReadAt(buf, off)
    if n > 0 {
        if _, err := out.Write(buf[:n]); err != nil {
            return
        }
        off += int64(n)
    }
}

The next track is preloaded in a second player with a 1 MB head, and promoted with PlayerPrefetch + PlayerStart when it is needed. If LIPC keeps succeeding but the position never moves for 20 seconds, the player treats it as a dead pipeline and rebuilds the audio service.