From 8dda4bc4f4fdb5d79af90022d44cd0e568b84899 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 9 May 2020 05:04:44 -0400 Subject: add -p password option --- Makefile | 2 +- README | 4 ++-- miragextract.1 | 56 ++++++++++++++++++++++++++++++++--------------------- miragextract.c | 17 +++++++++++++++- miragextract.html | 58 ++++++++++++++++++++++++++++++++----------------------- miragextract.rst | 45 ++++++++++++++++++++++++++---------------- 6 files changed, 115 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index 45ab4ea..0cb352c 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ RST2HTML=rst2html4.py # Hopefully, no user-serviceable parts below this line. PROJ=miragextract -VERSION=0.0.1 +VERSION=0.1.0 DOCS=README FAQ ChangeLog LICENSE $(PROJ).html diff --git a/README b/README index 48b0f0f..2f4f79d 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -README for miragextract v0.0.1 +README for miragextract v0.1.0 ============================== Description @@ -9,7 +9,7 @@ or converted to wav, flag, or ogg/vorbis (via libsndfile). Prerequisites ------------- -Requires GNU make, libmirage >= 3.0.0 and libsndfile (tested with 1.0.26, +Requires GNU make, libmirage >= 3.0.5 and libsndfile (tested with 1.0.26, other recent-ish versions should work). Since libmirage uses glib2, you'll need that as well. diff --git a/miragextract.1 b/miragextract.1 index a5e4730..a1842aa 100644 --- a/miragextract.1 +++ b/miragextract.1 @@ -1,6 +1,6 @@ .\" Man page generated from reStructuredText. . -.TH MIRAGEXTRACT 1 "2020-05-07" "0.0.1" "Urchlay" +.TH MIRAGEXTRACT 1 "2020-05-09" "0.1.0" "Urchlay" .SH NAME miragextract \- extract audio and data tracks from CD images . @@ -42,7 +42,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] . .SH SYNOPSIS .sp -miragextract [\fB\-l\fP] [\fB\-s\fP] [\fB\-t\fP track] [\fB\-b\fP base] [\fB\-f\fP fmt] [\fB\-q\fP quality ] \fBimage\-file\fP +miragextract [\fB\-l\fP] [\fB\-s\fP] [\fB\-t\fP track] [\fB\-b\fP base] [\fB\-f\fP fmt] [\fB\-p\fP passwd] [\fB\-q\fP quality ] \fBimage\-file\fP .SH DESCRIPTION .sp Extracts data and audio tracks from any CD image supported by libmirage. @@ -54,22 +54,8 @@ converted to wav, flac, or ogg/vorbis (via libsndfile). .B \-\-help Print short usage string. .TP -.B \-l -Lists the tracks in the image without extracting them. -.TP .B \-a -Extract only audio tracks. -.TP -.B \-d -Extract only data tracks. -.TP -.B \-s -Swaps bytes in audio tracks. Use this if your audio files sound -like white noise or gibberish. -.TP -.B \-t -Takes a track number (1\-99), and extracts only that one track. -Default behaviour is to extract all tracks. +Extract only audio tracks. Default is to extract all tracks. .TP .B \-b Sets the base filename for the output files. Default is \(aqtrack\(aq. @@ -77,6 +63,16 @@ Can be prefixed with a directory to write files in that dir, but the dir must already exist (example: \-b extracted/track). See also the \-n option. .TP +.B \-d +Extract only data tracks. Default is to extract all tracks. +.TP +.B \-f +Sets the format and filename extension for the output files. +Choices are \fBwav\fP, \fBogg\fP, \fBflac\fP, \fBcdda\fP (raw CD audio). Default is \fBwav\fP\&. +.TP +.B \-l +Lists the tracks in the image without extracting them. +.TP .B \-n Set the base filename to the input filename, minus its extension. E.g. for foo.cue, this is the same as saying "\-b foo". Beware of @@ -84,14 +80,24 @@ using input filenames with directory separators in them: the output files will be written in the same dir as the input file. Hopefully you have permission to write there. .TP -.B \-f -Sets the format and filename extension for the output files. -Choices are \fBwav\fP, \fBogg\fP, \fBflac\fP, \fBcdda\fP (raw CD audio). Default is \fBwav\fP\&. +.B \-p +Password for encrypted images. Note that anyone who can run \fBps(1)\fP +on your system can view the password. Also note that password +support in miragextract is \fIcompletely\fP untested: I have no +encrypted images to test with. .TP .B \-q Quality setting for ogg and flac output files. Integer from 0 to 10. Default is 7. Has very little effect on flac, and no effect on wav or cdda output. +.TP +.B \-s +Swaps bytes in audio tracks. Use this if your audio files sound +like white noise or gibberish. +.TP +.B \-t +Takes a track number (1\-99), and extracts only that one track. +Default behaviour is to extract all tracks. .UNINDENT .sp Always include a space between an option and its argument (e.g. \fB\-b foo\fP, not \fB\-bfoo\fP). @@ -147,8 +153,14 @@ play \-x \-t cdda track01.cdda As usual, 0 for success, non\-zero for failure. .SH BUGS .sp -There\(aqs not enough error checking. It\(aqs probably possible to make -miragextract segfault under some circumstances. +The \-p option should prompt for a password. +.sp +Not exactly a bug, per se, but miragextract can\(aqt deal with multi\-file +images where one of the files is missing or truncated. This is because +libmirage validates the image when it\(aqs loaded, and is unlikely to change. +.sp +Related to the above, there\(aqs no attempt to recover from +errors. miragextract exits as soon as it encounters an error of any kind. .\" EXAMPLES . .\" ======== diff --git a/miragextract.c b/miragextract.c index e9d570d..8e80529 100644 --- a/miragextract.c +++ b/miragextract.c @@ -28,6 +28,7 @@ int swap_bytes = 0; int autoname = 0; int want_data = 1; int want_audio = 1; +char *password = NULL; /* CD image state */ MirageContext *mirage = NULL; @@ -236,11 +237,16 @@ void usage(void) { printf( "miragextract v" VERSION " by B. Watson, WTFPL\n" "Usage: %s [-l] [-s] [-n] [-a] [-d] [-t track] [-b base]\n" - "%s[-f fmt] [-q quality] image-file\n" + "%s[-f fmt] [-q quality] [-p password] image-file\n" "See man page for details\n", self, spaces); exit(0); } +gchar *password_callback(gpointer user_data) { + if(!password) return NULL; + return g_strdup(password); +} + /* this should probably use something like getopts(), but I'm trying to avoid GNU extensions. */ void parse_args(int argc, char **argv) { @@ -290,6 +296,13 @@ void parse_args(int argc, char **argv) { } else die("-f option requires format argument"); break; + case 'p': + if(nextarg) { + argv++, argc--; + password = nextarg; + } else + die("-p option requires password"); + break; case 'q': if(nextarg) { argv++, argc--; @@ -339,6 +352,8 @@ int main(int argc, char **argv) { if(!mirage_initialize(&gerr)) die(NULL); + mirage_context_set_password_function(mirage, password_callback, NULL, NULL); + /* TODO: find out what image formats require multiple filenames, if any */ fn[0] = (gchar *)imagefile; fn[1] = NULL; diff --git a/miragextract.html b/miragextract.html index c657461..3fe03ad 100644 --- a/miragextract.html +++ b/miragextract.html @@ -5,7 +5,7 @@ miragextract - +