mple hacks

This page contains links to some of my mple hacks. It is autogenerated from the comments (if any) at the head of each file.

FILE_FORMAT.txt(updated Tue Oct 2 20:47:42 2012)


FILE_FORMAT_v2.txt(updated Tue Oct 2 20:47:42 2012)


Makefile(updated Tue Oct 2 20:47:42 2012)
#
# Makefile for the MPLE hacks.
#


README(updated Tue Oct 2 20:47:42 2012)


common.c(updated Thu Dec 28 00:14:38 2006)
/* this file originally came from the mpg123 plugin, although I've
carved it up quite a bit. It's under GPL. */
#include <stdio.h>
#include <string.h>
#include <glib.h>
#include "mple.h"
#include "common.h"
#define MAX_SKIP_LENGTH (256 * 1024)
#define MPG_MD_STEREO 0
#define MPG_MD_JOINT_STEREO 1
#define MPG_MD_DUAL_CHANNEL 2
#define MPG_MD_MONO 3
#define ID3_GET_SIZE28(a, b, c, d) \


common.h(updated Sat Aug 13 16:51:50 2005)
/* private header file to attach common.c to mple.c */
/*
* MP3 file stuff
* This is largely to work around the huge number of globals present
* in the mpg123 code
*/
#define MAXFRAMESIZE 1792


glade(updated Sat Jul 4 07:20:57 2020)
Subdirectory
gnome_vfs_mple.c(updated Mon Aug 22 00:43:24 2005)
/*
* Portable Media Player VFS module for coping with Sony NW devices.
*
* URI Structure:
* mple://<playername>/<albumname>/<trackname>
*
* <playername> will have to be uniquefied if there's more than one;
* udev already appears to do this for us.
* <albumname> will also have to be uniquefied.
*
* I had hoped to have a "displayname"/"internal name" distinction,
* but gnome_vfs doesn't appear to support that.
*
* There is a major bug that I can't find in this code: if you delete
* a directory, Gnome apparently doesn't believe you, despite the fact
* that I appear to be returning the correct error codes, etc. This
* manifests through an infinite loop when you try to open up another
* directory.
*/
/*
* sources of help and sample code:
* http://developer.gnome.org/doc/API/2.0/gnome-vfs-2.0/gnome-vfs-writing-modules.html
* http://developer.imendio.com/wiki/Writing_GnomeVFS_Modules
*
* from the latter, chunks of this code are Copyright (C) 2003 Imendio HB
* and used under the provisions of the GPL, which means this code is
* GPL also.
*/
/*
* to-do list
*
* mple layer
* * access-by-filename
* - retcons the relevant data structures as needed
* * new/rename-by-unicode
*
* vfs layer
* * move files between folders - seems to work with read/write?
* * distinguish identically-named folders
* * distinguish identically-named files
* * improve file_info
* * leak hunting
* * clean out dead code, consolidate live code
*
*/
#include <libgnomevfs/gnome-vfs-module.h>
/* kludgerific */
#define _LARGEFILE64_SOURCE 1
#define _FILE_OFFSET_BITS 64
#include <libgnomevfs/gnome-vfs-module-shared.h>
#include <libgnomevfs/gnome-vfs.h>
#include <string.h>
#include <stdio.h>
#include <mple.h>
#include <iconv.h>
#include <id3tag.h>
#include <malloc.h>
#include <errno.h>


mp3filemanager.c(updated Tue Oct 2 20:47:42 2012)
/*
* This is a Gtk2 replacement for the MP3FileManager program shipped
* with the Sony NW-S23. It currently needs the following things
* fixed (X marks the ones I've fixed):
*
* X dropping folders at specific positions doesn't work; they always
* get appended to the end of the folder list. You can move 'em
* around once they're on the device, though.
* X changes are synced to the device far too often, and the syncing
* is a huge kludge that involves deleting the entire track/folder
* list, syncing that, then rebuilding the new list from
* scratch. Mostly this is because I need to add a few more hooks to
* mple.c
* X doesn't delete mp*.dat files when tracks are deleted from the
* UI. The index entries *are* deleted, so the mpdat files won't
* play, though.
* * Delete All button does nothing
* * You can't select more than one thing at a time from the
* list. This is a serious pain if you're trying to make bulk
* changes, such as moving a half-dozen tracks. This can't be fixed
* without subclassing, see below.
* * Delete All and Delete both have confirm dialogs in the Windows
* version.
* * The file transfer stuff needs a little fixing - the main window
* should be disabled; this is done with - I think - an
* application-modal window on Windows. A better idea would be to
* thread the transfer process so you could keep adding files while
* the current transfer is in progress.
* * You can't drop a deep directory structure on it and expect it to
* do something useful. Windows will collapse a Band/Album/Mp3.mp3
* filename into Folder "Band Album", Track Mp3.mp3
* X Files should be listed by the mp3 filename, not the mp3 title.
* * The windows version doesn't use a progress bar for
* transfers. While I like the progress bar, it does mean that the
* status bar is only half as wide as it should be.
* * It would be nice if I could handle any URI that drag-and-drop
* throws me; at the very least, dragging a URL from firefox into
* the gadget would be cool.
* * Context menu is broken
* * Context menu should allow you to edit the metadata of a file
* X The device path is hardcoded.
* * Mount/Unmount device would be neat
* * dropping is still not quite right
* - dropping a file at the end of the device
* - dropping a file onto a folder prepends instead of appends
*
* And internally;
* * the code is full of memory leaks. I did a dry-run with valgrind,
* but there's so much noise from Gtk and X that I gave up.
* * Globals. I hate globals. I hate hate hate hate them.
* * Might be smart to isolate the unix-specific stuff if I'm going to
* try building this on Windows at some point. There are probably
* glib functions to help me.
*
* The code is, in general, pretty horrible, in part because I'm
* trying to force the default GtkTree stuff to do things it's not
* really meant to do. At some point I need to learn how to subclass
* the GtkTreeStore so I can add on the bits I need, such as better
* drag/drop, edit on button-click rather than button-press, etc.
*
* The other reason the code is horrible is that I've not done any
* serious Gtk work before, and it's not exactly intuitive. I keep
* finding useful glib functions after I've spent half an hour writing
* equivalent code, too. Henry Spencer would be proud...
*/
/*


mple-cp.c(updated Sat May 20 20:46:23 2006)
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <mple.h>
#include <string.h>
#include <errno.h>
#include <iconv.h>
/*
* convert a UTF16BE string to UTF8 and print it. Because iconv messes
* with the i/o pointers, we need to keep two copies of each.
*/


mple-dump.c(updated Sat Aug 13 16:51:50 2005)
/*
* Dump the contents of the player. Takes a single parameter: the
* mount-point of the player.
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#include <errno.h>
#include <glib.h>
#include <iconv.h>
#include <time.h>
#include "mple.h"
/*
* convert a UTF16BE string to UTF8 and print it. Because iconv messes
* with the i/o pointers, we need to keep two copies of each.
*/


mple-get-msn.c(updated Sat Aug 27 08:47:45 2005)
/*
* Some of the MPLE magic bytes are set from the media serial number
* in the FAT header. This data is not accessible to non-root
* users. This is a small helper program to read the data. Note, it
* can read arbitrary devices, but only 4 bytes at 0x27.
*/
#include <stdio.h>
#include <errno.h>
#include <glib.h>
#include <string.h>
#include "mple.h"
/* this is the allowed device prefix. anything else will be rejected */
#define DEVICE_PREFIX "/dev/sd"


mple-load.c(updated Thu Sep 15 20:38:39 2005)
/* load files onto the Network Walkman */
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <glib.h>
#include <unistd.h>
#include "mple.h"


mple-rm.c(updated Tue Oct 2 20:47:42 2012)
/* load files onto the Network Walkman */
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <glib.h>
#include <mple.h>


mple-test.c(updated Sat Aug 13 16:51:50 2005)
/* test rig for MPLE functions */
/* caution: will delete the contents of whatever you tell it is the
test device */
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <glib.h>
#include <mple.h>
#define TEST_DEVICE "/var/tmp/NW-S23"
#define TEST_FILE "test.mp3"
/*
* The original MP3 code pads out short reads with zeros, which is
* fine and sensible for streaming but makes no sense, really, for
* file reads. This switches it on and off and adjusts the expected
* test results accordingly.
*/
#ifdef PAD_SHORT_READ
#define TEST_FILE_SIZE 703040
#define TEST_FILE_MS 43521
#define TEST_FILE_FRAMES 1682
#else
#define TEST_FILE_SIZE 702622
#define TEST_FILE_MS 43495
#define TEST_FILE_FRAMES 1681
#endif


mple.c(updated Tue Oct 2 20:47:42 2012)
/*
* Interfacing library for Sony's obfuscated MP3 file format as used
* on their network walkman devices
*
* Waider, March 2005
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <wchar.h>
#include <unistd.h>
#include <malloc.h>
#include <time.h>
#include <glib.h>
/* mp3 internals handling */
#include <id3tag.h>
/* hardware abstraction layer, for obtaining the serial off the device */
#ifdef HAL_VERSION
#include <libhal.h>
#if HAL_VERSION == 4
#define libhal_get_all_devices(x,y,z) hal_get_all_devices(x,y)
#define libhal_device_property_exists(w,x,y,z) \
hal_device_property_exists(w,x,y)
#define libhal_device_get_property_string(w,x,y,z) \
hal_device_get_property_string(w,x,y)
#define libhal_device_get_property_bool(w,x,y,z) \
hal_device_get_property_bool(w,x,y)
#define libhal_free_string(x) hal_free_string(x)
#define libhal_free_string_array(x) hal_free_string_array(x)
#endif
#endif
#include "mple.h"
#include "common.h"
/* Util functions */
/*
* effectively mkdir -p
* create directory PATH, including any required parent directories,
* using MODE as the file mode for each newly created directory.
*/


mple.conf(updated Wed Aug 17 14:37:30 2005)


mple.h(updated Sat Aug 13 16:51:50 2005)
#ifndef MPLE_H
#define MPLE_H
#include <glib.h>
/* I hate include files that aren't self-contained */
#include <time.h>
#include <id3tag.h>
#include <stdio.h>
#include <sys/stat.h>
#define DEFAULT_PB_TEMPLATE "%s/esys/pblist%d.dat"
#define DEFAULT_MP_TEMPLATE "%s/esys/nw-mp3/mp%04x.dat"
#define DEFAULT_MASTER_PBLIST 1
#define MAX_TRACKS 40000 /* according to the manual */
/* On-disk data structures and magic */
#define PBLIST_MAGIC "\x00\x03\xce\xa0"
#define MPDAT_MAGIC "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
/* This is used to find likely devices in HAL */
#define HAL_MAGIC "NETWORK WALKMAN"
/* Header structure from pblist file [incomplete] */



Waider Ugh. Did I write that?