From 000f083ad98ef9d3b93e6edb4da0074f33317cc1 Mon Sep 17 00:00:00 2001 From: Yunxiang Li Date: Sun, 17 Mar 2019 18:40:57 -0400 Subject: [PATCH] add function to dump decrypted m2ts --- src/libbluray/bluray.c | 15 +++++++++++++++ src/libbluray/bluray.h | 20 ++++++++++++++++++++ src/libbluray/disc/disc.c | 20 ++++++++++++++++++++ src/libbluray/disc/disc.h | 4 ++++ 4 files changed, 59 insertions(+) diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c index 3a356050..41e3127b 100644 --- a/src/libbluray/bluray.c +++ b/src/libbluray/bluray.c @@ -3765,6 +3765,21 @@ int bd_read_file(BLURAY *bd, const char *path, void **data, int64_t *size) return _bd_read_file(bd, NULL, path, data, size); } +struct bd_dir_s *bd_open_dir(BLURAY *bd, const char *dir) +{ + if (!bd || dir == NULL) { + return NULL; + } + return disc_open_dir(bd->disc, dir); +} + +struct bd_file_s *bd_open_file_dec(BLURAY *bd, const char *path) +{ + if (!bd || path == NULL) { + return NULL; + } + return disc_open_path_dec(bd->disc, path); +} /* * Metadata diff --git a/src/libbluray/bluray.h b/src/libbluray/bluray.h index 8eb8100b..aa0a271c 100644 --- a/src/libbluray/bluray.h +++ b/src/libbluray/bluray.h @@ -1094,6 +1094,26 @@ void bd_stop_bdj(BLURAY *bd); // shutdown BD-J and clean up resources */ int bd_read_file(BLURAY *, const char *path, void **data, int64_t *size); +/** + * + * Open a file/dir from BluRay Virtual File System. + * + * encrypted streams are decrypted, and because of how + * decryption works, it can only seek to (N*6144) bytes, + * and read 6144 bytes at a time. + * DO NOT mix any play functionalities with these functions. + * It might cause broken stream. In general, accessing + * mutiple file on disk at the same time is a bad idea. + * Caller must close with file_close()/dir_close(). + * + * @param bd BLURAY object + * @param dir target directory (relative to disc root) + * @param path path to the file (relative to disc root) + * @return BD_DIR_H * or BD_FILE_H *, NULL if failed + */ +struct bd_dir_s *bd_open_dir(BLURAY *, const char *dir); +struct bd_file_s *bd_open_file_dec(BLURAY *, const char *path); + #ifdef __cplusplus } diff --git a/src/libbluray/disc/disc.c b/src/libbluray/disc/disc.c index 6d555a1d..aa190612 100644 --- a/src/libbluray/disc/disc.c +++ b/src/libbluray/disc/disc.c @@ -579,6 +579,26 @@ int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_pa return 0; } +BD_FILE_H *disc_open_path_dec(BD_DISC *p, const char *rel_path) +{ + size_t size = strlen(rel_path); + char *suf = (size > 5) ? rel_path + (size - 5) : rel_path; + + /* check if it's a stream */ + if (strncmp(rel_path, "BDMV" DIR_SEP "STREAM", 11)) { // not equal + return disc_open_path(p, rel_path); + } else if (!strcmp(suf, ".m2ts")) { // equal + return disc_open_stream(p, suf - 5); + } else if (!strcmp(suf+1, ".MTS")) { // equal + return disc_open_stream(p, suf - 4); + } else if (!strcmp(suf, ".ssif")) { // equal + BD_DEBUG(DBG_FILE | DBG_CRIT, "error opening file %s, ssif is not yet supported.\n", rel_path); + } else { + BD_DEBUG(DBG_FILE | DBG_CRIT, "error opening file %s\n", rel_path); + } + return NULL; +} + /* * persistent properties storage */ diff --git a/src/libbluray/disc/disc.h b/src/libbluray/disc/disc.h index aa6909b7..33dd942e 100644 --- a/src/libbluray/disc/disc.h +++ b/src/libbluray/disc/disc.h @@ -80,8 +80,12 @@ BD_PRIVATE size_t disc_read_file(BD_DISC *disc, const char *dir, const char *fil /* Update virtual package */ BD_PRIVATE void disc_update(BD_DISC *disc, const char *overlay_root); +/* Cache file directly from BD-ROM */ BD_PRIVATE int disc_cache_bdrom_file(BD_DISC *p, const char *rel_path, const char *cache_path); +/* Open decrypted file */ +BD_PRIVATE struct bd_file_s *disc_open_path_dec(BD_DISC *p, const char *rel_path); + /* open BD-ROM directory (relative to disc root) */ BD_PRIVATE struct bd_dir_s *disc_open_bdrom_dir(BD_DISC *disc, const char *path);