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 --- miragextract.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'miragextract.c') 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; -- cgit v1.2.3