Commit 33f5f7cc authored by Accident's avatar Accident

Accident: Re-tooled bdplus to load dynamically, and attempt to produce

          conv_tab, support seek and fixup methods.
          Make calls to dlopen be separate.
          Changed debug output to universal, added debug output to
          file support.
parent a4d944e2
...@@ -23,7 +23,7 @@ AC_TYPE_SIGNAL ...@@ -23,7 +23,7 @@ AC_TYPE_SIGNAL
AC_HEADER_TIME AC_HEADER_TIME
AC_CHECK_HEADERS([stdarg.h varargs.h sys/time.h sys/types.h dirent.h sys/file.h sys/param.h sys/statfs.h sys/vfs.h sys/statvfs.h errno.h libgen.h time.h malloc.h stdlib.h mntent.h linux/cdrom.h]) AC_CHECK_HEADERS([stdarg.h varargs.h sys/time.h sys/types.h dirent.h sys/file.h sys/param.h sys/statfs.h sys/vfs.h sys/statvfs.h errno.h libgen.h time.h malloc.h stdlib.h mntent.h linux/cdrom.h dlfcn.h])
# mount depends on param # mount depends on param
AC_CHECK_HEADERS([sys/mount.h], [], [], [#if HAVE_SYS_PARAM_H AC_CHECK_HEADERS([sys/mount.h], [], [], [#if HAVE_SYS_PARAM_H
......
...@@ -7,7 +7,7 @@ AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/libbdplus ...@@ -7,7 +7,7 @@ AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_builddir)/src/libbdplus
# The master library, # The master library,
lib_LTLIBRARIES=libbluray.la lib_LTLIBRARIES=libbluray.la
libbluray_la_SOURCES= bluray.c bluray.h libbluray_la_SOURCES= bluray.c bluray.h file/dl_posix.c
libbluray_la_LIBADD = libaacs/libaacs.la libbdplus/libbdplus.la libbdnav/libbdnav.la libbluray_la_LIBADD = libaacs/libaacs.la libbdplus/libbdplus.la libbdnav/libbdnav.la
libbluray_la_LDFLAGS= -version-info 0:0:0 libbluray_la_LDFLAGS= -version-info 0:0:0
......
...@@ -10,52 +10,35 @@ ...@@ -10,52 +10,35 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <dlfcn.h>
#include <stdio.h> #include <stdio.h>
#include "bluray.h" #include "bluray.h"
#include "util/macro.h" #include "util/macro.h"
#include "util/logging.h" #include "util/logging.h"
#include "util/strutl.h"
#include "file/dl.h"
BLURAY *bd_open(const char* device_path, const char* keyfile_path) BLURAY *bd_open(const char* device_path, const char* keyfile_path)
{ {
BLURAY *bd = calloc(1, sizeof(BLURAY)); BLURAY *bd = calloc(1, sizeof(BLURAY));
if (device_path) { if (device_path) {
bd->device_path = strdup(device_path); strncpy(bd->device_path, device_path, 100); // <-- FIXME. bufrun,size,term
bd->aacs = NULL; bd->aacs = NULL;
bd->h_libaacs = NULL; bd->h_libaacs = NULL;
bd->fp = NULL; bd->fp = NULL;
if (keyfile_path) { if (keyfile_path) {
if ((bd->h_libaacs = dlopen("libaacs.so", RTLD_LAZY))) { //if ((bd->h_libaacs = dlopen("libaacs.so", RTLD_LAZY))) {
if ((bd->h_libaacs = dl_dlopen("aacs"))) {
fptr_p_void fptr; fptr_p_void fptr;
uint8_t *vid; uint8_t *vid;
DEBUG(DBG_BLURAY, "Downloaded libaacs (0x%08x)\n", bd->h_libaacs); DEBUG(DBG_BLURAY, "Downloaded libaacs (0x%08x)\n", bd->h_libaacs);
if ((fptr = dlsym(bd->h_libaacs, "aacs_open"))) { fptr_p_void fptr = dl_dlsym(bd->h_libaacs, "aacs_open");
if ((bd->aacs = fptr(device_path, keyfile_path))) { bd->aacs = fptr(device_path, keyfile_path);
if ((fptr = dlsym(bd->h_libaacs, "aacs_get_vid"))) {
vid = fptr(bd->aacs);
}
if ((bd->h_libbdplus = dlopen("libbdplus.so", RTLD_LAZY))) {
DEBUG(DBG_BLURAY, "Downloaded libbdplus (0x%08x)\n", bd->h_libbdplus);
if ((fptr = dlsym(bd->h_libbdplus, "bdplus_open"))) {
if (!(bd->bdplus = fptr(device_path, keyfile_path, vid))) {
DEBUG(DBG_BLURAY, "libbdplus ret NULL!\n");
}
}
} else {
DEBUG(DBG_BLURAY, "libbdplus not found!\n");
}
} else {
DEBUG(DBG_BLURAY | DBG_CRIT, "libaacs failed to initialize! If this disc is encrypted, you will not be able to play it\n");
}
}
} else { } else {
DEBUG(DBG_BLURAY, "libaacs not found!\n"); DEBUG(DBG_BLURAY, "libaacs not found!\n");
} }
...@@ -63,7 +46,38 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path) ...@@ -63,7 +46,38 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
DEBUG(DBG_BLURAY | DBG_CRIT, "No keyfile provided. You will not be able to make use of crypto functionality (0x%08x)\n", bd); DEBUG(DBG_BLURAY | DBG_CRIT, "No keyfile provided. You will not be able to make use of crypto functionality (0x%08x)\n", bd);
} }
bd->int_buf_off = 6144;
// Take a quick stab to see if we want/need bdplus
// we should fix this, and add various string functions.
{
uint8_t vid[16] = {0}; // FIXME
FILE_H *fd;
char *tmp = NULL;
tmp = str_printf("%s/BDSVM/00000.svm", bd->device_path);
if ((fd = file_open(tmp, "rb"))) {
file_close(fd);
DEBUG(DBG_BDPLUS, "attempting to load libbdplus\n");
if ((bd->h_libbdplus = dl_dlopen("bdplus"))) {
DEBUG(DBG_BLURAY, "Downloaded libbdplus (0x%08x)\n",
bd->h_libbdplus);
fptr_p_void bdplus_init = dl_dlsym(bd->h_libbdplus, "bdplus_init");
//bdplus_t *bdplus_init(path,configfile_path,*vid );
if (bdplus_init)
bd->bdplus = bdplus_init(device_path, keyfile_path, vid);
// Since we will call these functions a lot, we assign them
// now.
bd->bdplus_seek = dl_dlsym(bd->h_libbdplus, "bdplus_seek");
bd->bdplus_fixup = dl_dlsym(bd->h_libbdplus, "bdplus_fixup");
} // dlopen
} // file_open
X_FREE(tmp);
}
DEBUG(DBG_BLURAY, "BLURAY initialized! (0x%08x)\n", bd); DEBUG(DBG_BLURAY, "BLURAY initialized! (0x%08x)\n", bd);
} else { } else {
...@@ -77,22 +91,23 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path) ...@@ -77,22 +91,23 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
void bd_close(BLURAY *bd) void bd_close(BLURAY *bd)
{ {
if (bd->h_libaacs) { if (bd->h_libaacs && bd->aacs) {
if (bd->aacs) { fptr_p_void fptr = dl_dlsym(bd->h_libaacs, "aacs_close");
fptr_p_void fptr = dlsym(bd->h_libaacs, "aacs_close"); fptr(bd->aacs);
fptr(bd->aacs);
}
dlclose(bd->h_libaacs); dl_dlclose(bd->h_libaacs);
} }
if (bd->h_libbdplus) { if (bd->h_libbdplus && bd->bdplus) {
if (bd->bdplus) { fptr_p_void bdplus_free = dl_dlsym(bd->h_libbdplus, "bdplus_free");
fptr_p_void fptr = dlsym(bd->h_libbdplus, "bdplus_close"); if (bdplus_free) bdplus_free(bd->bdplus);
fptr(bd->bdplus); bd->bdplus = NULL;
}
dl_dlclose(bd->h_libbdplus);
bd->h_libbdplus = NULL;
dlclose(bd->h_libaacs); bd->bdplus_seek = NULL;
bd->bdplus_fixup = NULL;
} }
if (bd->fp) { if (bd->fp) {
...@@ -121,6 +136,9 @@ uint64_t bd_seek(BLURAY *bd, uint64_t pos) ...@@ -121,6 +136,9 @@ uint64_t bd_seek(BLURAY *bd, uint64_t pos)
bd->int_buf_off = 6144; bd->int_buf_off = 6144;
DEBUG(DBG_BLURAY, "Seek to %ld (0x%08x)\n", bd->s_pos, bd); DEBUG(DBG_BLURAY, "Seek to %ld (0x%08x)\n", bd->s_pos, bd);
if (bd->bdplus_seek && bd->bdplus)
bd->bdplus_seek(bd->bdplus, pos);
} }
return bd->s_pos; return bd->s_pos;
...@@ -138,11 +156,12 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len) ...@@ -138,11 +156,12 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len)
if (bd->int_buf_off == 6144) { if (bd->int_buf_off == 6144) {
int read_len; int read_len;
if ((read_len = file_read(bd->fp, bd->int_buf, 6144)) == 6144) { if ((read_len = file_read(bd->fp, buf, len))) {
if (bd->h_libaacs && bd->aacs) { if (bd->h_libaacs && bd->aacs) {
if ((bd->libaacs_decrypt_unit = dlsym(bd->h_libaacs, "aacs_decrypt_unit"))) { // FIXME: calling dlsym for every read() call.
if (!bd->libaacs_decrypt_unit(bd->aacs, bd->int_buf, read_len, 0)) { if ((bd->libaacs_decrypt_unit = dl_dlsym(bd->h_libaacs, "aacs_decrypt_unit"))) {
DEBUG(DBG_BLURAY, "Unable decrypt unit! (0x%08x)\n", bd); if (!bd->libaacs_decrypt_unit(bd->aacs, buf, len, bd->s_pos)) {
DEBUG(DBG_BLURAY, "Unable decrypt unit! (0x%08x)\n", bd);
return 0; return 0;
} }
...@@ -157,8 +176,10 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len) ...@@ -157,8 +176,10 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len)
bd->int_buf_off = 0; bd->int_buf_off = 0;
} }
buf[out_len++] = bd->int_buf[bd->int_buf_off++]; if (bd->bdplus_fixup && bd->bdplus)
} bd->bdplus_fixup(bd->bdplus, len, buf);
bd->s_pos += len;
bd->s_pos += len; bd->s_pos += len;
...@@ -173,7 +194,7 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len) ...@@ -173,7 +194,7 @@ int bd_read(BLURAY *bd, unsigned char *buf, int len)
return 0; return 0;
} }
int bd_select_title(BLURAY *bd, uint64_t title) int bd_select_title(BLURAY *bd, uint32_t title)
{ {
char f_name[100]; char f_name[100];
...@@ -195,6 +216,13 @@ int bd_select_title(BLURAY *bd, uint64_t title) ...@@ -195,6 +216,13 @@ int bd_select_title(BLURAY *bd, uint64_t title)
DEBUG(DBG_BLURAY, "Title %s selected! (0x%08x)\n", f_name, bd); DEBUG(DBG_BLURAY, "Title %s selected! (0x%08x)\n", f_name, bd);
if (bd->h_libbdplus && bd->bdplus) {
fptr_p_void bdplus_set_title;
bdplus_set_title = dl_dlsym(bd->h_libbdplus, "bdplus_set_title");
if (bdplus_set_title)
bdplus_set_title(bd->bdplus, title);
}
return 1; return 1;
} }
......
...@@ -17,6 +17,9 @@ struct bluray { ...@@ -17,6 +17,9 @@ struct bluray {
uint64_t s_size; uint64_t s_size;
uint64_t s_pos; uint64_t s_pos;
void *aacs, *bdplus; void *aacs, *bdplus;
void *bdplus; // bdplus container
fptr_p_void bdplus_seek; // frequently called
fptr_p_void bdplus_fixup; // frequently called
void *h_libaacs, *h_libbdplus, *h_libbdnav; void *h_libaacs, *h_libbdplus, *h_libbdnav;
fptr_int libaacs_decrypt_unit; fptr_int libaacs_decrypt_unit;
uint8_t int_buf[6144]; uint8_t int_buf[6144];
...@@ -29,7 +32,7 @@ void bd_close(BLURAY *bd); // Free libb ...@@ -29,7 +32,7 @@ void bd_close(BLURAY *bd); // Free libb
uint64_t bd_seek(BLURAY *bd, uint64_t pos); // Seek to pos in currently selected title file uint64_t bd_seek(BLURAY *bd, uint64_t pos); // Seek to pos in currently selected title file
int bd_read(BLURAY *bd, unsigned char *buf, int len); // Read from currently selected title file, decrypt if possible int bd_read(BLURAY *bd, unsigned char *buf, int len); // Read from currently selected title file, decrypt if possible
int bd_select_title(BLURAY *bd, uint64_t title); // Select an m2ts file (title is the file number, e.g. title = 123 will select 00123.m2ts) int bd_select_title(BLURAY *bd, uint32_t title); // Select an m2ts file (title is the file number, e.g. title = 123 will select 00123.m2ts)
uint64_t bd_get_title_size(BLURAY *bd); // Returns file size in bytes of currently selected title, 0 in no title selected uint64_t bd_get_title_size(BLURAY *bd); // Returns file size in bytes of currently selected title, 0 in no title selected
uint64_t bd_tell(BLURAY *bd); // Return current pos uint64_t bd_tell(BLURAY *bd); // Return current pos
......
...@@ -41,7 +41,7 @@ int main(int argc, char **argv) ...@@ -41,7 +41,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
#if 0
// Technically not required, yet // Technically not required, yet
if (bdplus_init(NULL, NULL, NULL)) goto fail; if (bdplus_init(NULL, NULL, NULL)) goto fail;
...@@ -70,17 +70,17 @@ int main(int argc, char **argv) ...@@ -70,17 +70,17 @@ int main(int argc, char **argv)
result = bdplus_run_convtab(vm); result = bdplus_run_convtab(vm);
printf("run_convtab said %d\n", result); printf("run_convtab said %d\n", result);
#endif
printf("Cleaning up...\n"); printf("Cleaning up...\n");
fail: fail:
if (vm) { if (vm) {
bdplus_VM_free(vm); // bdplus_VM_free(vm);
vm = NULL; vm = NULL;
} }
bdplus_free(); // bdplus_free();
exit(0); exit(0);
} }
......
#include <stdio.h> #include <stdio.h>
#if HAVE_MALLOC_H
#include <malloc.h> #include <malloc.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
......
#ifndef DL_H_
#define DL_H_
// We don't bother aliasing dlopen to dlopen_posix, since only one
// of the .C files will be compiled and linked, the right one for the
// platform.
// Note the dlopen takes just the name part. "aacs", internally we
// translate to "libaacs.so" "libaacs.dylib" or "aacs.dll".
void *dl_dlopen ( const char* path );
void *dl_dlsym ( void* handle, const char* symbol );
int dl_dlclose ( void* handle );
#endif /* DL_H_ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_LIMITS_H
#include <limits.h>
#endif
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#include "dl.h"
#include "../util/macro.h"
#include "../util/logging.h"
// Note the dlopen takes just the name part. "aacs", internally we
// translate to "libaacs.so" "libaacs.dylib" or "aacs.dll".
void *dl_dlopen ( const char* name )
{
char *path;
int len;
void *result;
#ifdef __APPLE__
len = strlen(name) + 3 + 6 + 1;
path = (char *) malloc(len);
if (!path) return NULL;
snprintf(path, len, "lib%s.dylib", name);
#else
len = strlen(name) + 3 + 3 + 1;
path = (char *) malloc(len);
if (!path) return NULL;
snprintf(path, len, "lib%s.so", name);
#endif
DEBUG(DBG_BDPLUS, "searching for library '%s' ...\n", path);
result = dlopen(path, RTLD_LAZY);
free(path);
return result;
}
void *dl_dlsym ( void* handle, const char* symbol )
{
return dlsym(handle, symbol);
}
int dl_dlclose ( void* handle )
{
return dlclose(handle);
}
...@@ -85,3 +85,6 @@ FILE_H *file_open_linux(const char* filename, const char *mode) ...@@ -85,3 +85,6 @@ FILE_H *file_open_linux(const char* filename, const char *mode)
return NULL; return NULL;
} }
...@@ -33,6 +33,13 @@ void debug(char *file, int line, uint32_t mask, const char *format, ...) ...@@ -33,6 +33,13 @@ void debug(char *file, int line, uint32_t mask, const char *format, ...)
} else { } else {
debug_mask = DBG_CRIT; debug_mask = DBG_CRIT;
} }
// Send DEBUG to file?
if ((env = getenv("BD_DEBUG_FILE"))) {
freopen(env, "wb", stderr);
setvbuf(stderr, NULL, _IOLBF, 0);
}
} }
if (mask & debug_mask) { if (mask & debug_mask) {
......
...@@ -19,7 +19,9 @@ enum debug_mask_enum { ...@@ -19,7 +19,9 @@ enum debug_mask_enum {
DBG_BLURAY = 64, DBG_BLURAY = 64,
DBG_DIR = 128, DBG_DIR = 128,
DBG_NAV = 256, DBG_NAV = 256,
DBG_CRIT = 512 // this is libbluray's default debug mask so use this if you want to display critical info DBG_BDPLUS = 512,
DBG_DLX = 1024
DBG_CRIT = 2048 // this is libbluray's default debug mask so use this if you want to display critical info
}; };
typedef enum debug_mask_enum debug_mask_t; typedef enum debug_mask_enum debug_mask_t;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment