├── bootstrap ├── m4 └── .dummy ├── SMP ├── .gitattributes ├── .gitignore ├── libbdplus.def ├── readme.txt ├── src │ └── libbdplus │ │ └── bdplus-version.h ├── libbdplus_with_latest_sdk.bat ├── unistd.h ├── SMP.patch ├── sys │ ├── time.h │ └── stat.h ├── config.h ├── libbdplus_files.props ├── stdio.h ├── appveyor.yml ├── libbdplus_deps.sln ├── libbdplus.sln └── project_get_dependencies.bat ├── src ├── libbdplus.pc.in ├── libbdplus │ ├── bdsvm │ │ ├── sha1.h │ │ ├── loader.h │ │ ├── slot.h │ │ ├── interface.h │ │ ├── trap_helper.h │ │ ├── event.h │ │ ├── diff.h │ │ ├── slot_data.h │ │ ├── dlx.h │ │ ├── event.c │ │ ├── segment.h │ │ ├── dlx_internal.h │ │ ├── trap_helper.c │ │ ├── trap.h │ │ ├── loader.c │ │ ├── slot.c │ │ └── diff.c │ ├── bdplus-version.h.in │ ├── internal.h │ ├── bdplus_data.h │ ├── bdplus_config.h │ └── bdplus.h ├── file │ ├── configfile.h │ ├── dirs.h │ ├── filesystem.h │ ├── dirs_darwin.c │ ├── file.c │ ├── file.h │ ├── dir_posix.c │ ├── dirs_win32.c │ ├── dir_win32.c │ ├── dirs_xdg.c │ ├── configfile.c │ ├── file_win32.c │ └── file_posix.c ├── util │ ├── mutex.h │ ├── strutl.h │ ├── logging.h │ ├── attributes.h │ ├── logging.c │ ├── strutl.c │ ├── macro.h │ └── mutex.c └── examples │ ├── bdplus_test.c │ └── convtab_dump.c ├── .gitignore ├── ChangeLog ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── ISSUE_TEMPLATE.md └── CONTRIBUTING.md ├── Makefile.am ├── README.markdown ├── .gitlab-ci.yml ├── README.md └── configure.ac /bootstrap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | autoreconf -vif 4 | -------------------------------------------------------------------------------- /m4/.dummy: -------------------------------------------------------------------------------- 1 | Please do not remove this file. 2 | It is used to help those using other VCS's like git and hg. 3 | -------------------------------------------------------------------------------- /SMP/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sln text eol=crlf 2 | *.vcxproj text eol=crlf 3 | *.vcxproj.filters text eol=crlf 4 | *.bat text eol=crlf -------------------------------------------------------------------------------- /src/libbdplus.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libbdplus 7 | Description: BD+ support library for Blu-ray playback 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -lbdplus 10 | Cflags: -I${includedir} 11 | -------------------------------------------------------------------------------- /SMP/.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | *.lib 3 | *.log 4 | *.tlog 5 | *.pdb 6 | *.ildb 7 | *.pgd 8 | *.pch 9 | *.manifest 10 | *.suo 11 | *.user 12 | *.sdf 13 | *.opensdf 14 | [Oo]bj/ 15 | *.exe 16 | !*.h 17 | !*.c 18 | !*.asm 19 | !*.def 20 | !*.rc 21 | *.sbr 22 | *.iobj 23 | *.ipdb 24 | .vs/ 25 | *.VC.db 26 | *.opendb 27 | *.ilk 28 | [Bb]in/ -------------------------------------------------------------------------------- /SMP/libbdplus.def: -------------------------------------------------------------------------------- 1 | 2 | EXPORTS 3 | bdplus_event 4 | bdplus_fixup 5 | bdplus_free 6 | bdplus_get_code_date 7 | bdplus_get_code_gen 8 | bdplus_get_version 9 | bdplus_init 10 | bdplus_m2ts 11 | bdplus_m2ts_close 12 | bdplus_mmap 13 | bdplus_psr 14 | bdplus_seek 15 | bdplus_set_mk 16 | bdplus_start -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.[oa] 2 | *~ 3 | *.lo 4 | *.la 5 | *.pc 6 | *.exe 7 | Makefile.in 8 | Makefile 9 | aclocal.m4 10 | m4/libtool.m4 11 | m4/ltoptions.m4 12 | m4/ltsugar.m4 13 | m4/ltversion.m4 14 | m4/lt~obsolete.m4 15 | autom4te.cache/ 16 | build-aux/ 17 | config.h.in 18 | config.h 19 | config.log 20 | config.status 21 | configure 22 | libtool 23 | .deps 24 | .libs 25 | src/libbdplus/bdplus-version.h 26 | src/bdplus_test 27 | src/convtab_dump 28 | stamp-h1 29 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2022-03-06: Version 0.2.0 2 | - Add support for cached conversion tables. 3 | - Fix config path charset issues in Win32. 4 | - Use BDPLUS_DEBUG_FILE environment variable for log file. 5 | - Export API functions automatically when creating Windows dll. 6 | - Improve Windows compatibility. 7 | - Improve error resilience and stability. 8 | - Fix leaks. 9 | 10 | 2015-01-23: Version 0.1.2 11 | - Add support for unmounted discs 12 | - Fix use after free 13 | 14 | 2014-05-27: Version 0.1.1 15 | - Support for gcrypt 1.6. 16 | - Fix out of tree builds. 17 | - Fix building without libaacs. 18 | 19 | 2013-12-18: Version 0.1.0 20 | - First release. 21 | - Support for BD+ generations 1 and 2. 22 | 23 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Current and Suggested Behavior 7 | 8 | 9 | ## Steps to Explain Enhancement 10 | 11 | 1. 12 | 2. 13 | 3. 14 | 4. 15 | 16 | ## Your Test Environment 17 | 18 | * Version Used: 19 | * Operating System and Version(s): 20 | * Compiler and version(s): -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/sha1.h: -------------------------------------------------------------------------------- 1 | /* public api for steve reid's public domain SHA-1 implementation */ 2 | /* this file is in the public domain */ 3 | 4 | #ifndef __SHA1_H 5 | #define __SHA1_H 6 | 7 | #include 8 | #include 9 | 10 | #include "util/attributes.h" 11 | 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | typedef struct { 18 | uint32_t state[5]; 19 | uint32_t count[2]; 20 | uint8_t buffer[64]; 21 | } SHA1_CTX; 22 | 23 | #define SHA1_DIGEST_SIZE 20 24 | 25 | BD_PRIVATE void sha_SHA1_Init(SHA1_CTX* context); 26 | BD_PRIVATE void sha_SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len); 27 | BD_PRIVATE void sha_SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* __SHA1_H */ 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Context 4 | 5 | 6 | ## Expected Behavior 7 | 8 | 9 | ## Actual Behavior 10 | 11 | 12 | ## Steps to Reproduce 13 | 14 | 1. 15 | 2. 16 | 3. 17 | 4. 18 | 19 | ## Your Environment 20 | 21 | * Version Used: 22 | * Operating System and Version: 23 | * Compiler and Version(s): 24 | 25 | ## Possible Fix 26 | 27 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/loader.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef LOADER_H_INCLUDED 22 | #define LOADER_H_INCLUDED 23 | 24 | #include "util/attributes.h" 25 | 26 | #include 27 | 28 | struct VM_s; 29 | struct bdplus_file; 30 | 31 | BD_PRIVATE int32_t loader_load_svm (struct bdplus_file *fp, const char *fname, struct VM_s *vm, int *p_gen, int *p_date); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/file/configfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2011-2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BDPLUS_CONFIGFILE_H 21 | #define BDPLUS_CONFIGFILE_H 22 | 23 | #include "util/attributes.h" 24 | 25 | #include 26 | #include 27 | 28 | #define BDPLUS_DIR "bdplus" 29 | 30 | BD_PRIVATE char * file_get_cache_dir(void) BD_ATTR_MALLOC; 31 | BD_PRIVATE char * file_get_config_dir(const char *file) BD_ATTR_MALLOC; 32 | 33 | BD_PRIVATE char * file_load(const char *path, uint32_t *p_size) BD_ATTR_MALLOC; 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/util/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2010 hpi1 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef LIBBLURAY_MUTEX_H_ 21 | #define LIBBLURAY_MUTEX_H_ 22 | 23 | #include "attributes.h" 24 | 25 | /* 26 | * recursive mutex 27 | */ 28 | 29 | typedef struct bd_mutex_s BD_MUTEX; 30 | struct bd_mutex_s { 31 | void *impl; 32 | }; 33 | 34 | BD_PRIVATE int bd_mutex_init(BD_MUTEX *p); 35 | BD_PRIVATE int bd_mutex_destroy(BD_MUTEX *p); 36 | 37 | BD_PRIVATE int bd_mutex_lock(BD_MUTEX *p); 38 | BD_PRIVATE int bd_mutex_unlock(BD_MUTEX *p); 39 | 40 | #endif // LIBBLURAY_MUTEX_H_ 41 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/slot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef SLOT_H_INCLUDED 21 | #define SLOT_H_INCLUDED 22 | 23 | #include 24 | 25 | #include "util/attributes.h" 26 | 27 | struct VM_s; 28 | 29 | BD_PRIVATE uint32_t slot_SlotAttach ( struct VM_s *, uint32_t, uint32_t, 30 | uint8_t *, uint8_t * ); 31 | BD_PRIVATE uint32_t slot_SlotRead ( struct VM_s *, uint8_t *, uint32_t ); 32 | BD_PRIVATE uint32_t slot_SlotWrite ( struct VM_s *, uint8_t * ); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/file/dirs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2011-2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BLURAY_DIRS_H 21 | #define BLURAY_DIRS_H 22 | 23 | #include "util/attributes.h" 24 | 25 | #ifdef _WIN32 26 | BD_PRIVATE int win32_mkdir(const char *dir); 27 | #endif 28 | 29 | /* 30 | * Config, cache and data dirs 31 | */ 32 | 33 | BD_PRIVATE const char *file_get_config_system(const char *dir); 34 | 35 | BD_PRIVATE char *file_get_config_home(void) BD_ATTR_MALLOC; 36 | BD_PRIVATE char *file_get_cache_home(void) BD_ATTR_MALLOC; 37 | BD_PRIVATE char *file_get_data_home(void) BD_ATTR_MALLOC; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /SMP/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This is a small list of steps in order to build libbdplus into a msvc dll and/or lib file. 3 | 4 | The project contains Release and Debug builds for static lib files (Debug/Release) 5 | as well as dynamic shared dll files (DebugDLL/ReleaseDLL). Along with the standard 6 | windows dll/lib configurations mentioned above there are also equivalent variants that 7 | can be used to compile for WinRT/UWP (These configurations have a WinRT suffix). 8 | There are also architecture configurations for either 32bit (x86) or 64bit (x64) compilation. 9 | Choose whichever project configuration meets your requirements. 10 | 11 | The project configurations support being built with various different windows SDK versions. 12 | By default they will use the lowest SDK version that would be available for Visual Studio 13 | version 2013 and up (This is the 8.1 SDK). However a batch file is also included 14 | (libbdplus_with_latest_sdk.bat) which can be used to auto detect the newest available SDK 15 | installed on the host machine and then open the project using that as the compilation SDK. 16 | 17 | When using the WinRT/UWP project configurations the projects will automatically compile towards 18 | the default application target for the Version of Visual Studio being used: 19 | VS 2013: 8.1 20 | VS 2015: 8.1 21 | VS 2017+: 10.0.10240.0 22 | 23 | -------------------------------------------------------------------------------- /src/util/strutl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef STRUTL_H_ 22 | #define STRUTL_H_ 23 | 24 | #include "attributes.h" 25 | 26 | #include 27 | 28 | BD_PRIVATE char * str_dup(const char *str) BD_ATTR_MALLOC; 29 | BD_PRIVATE char * str_printf(const char *fmt, ...) BD_ATTR_FORMAT_PRINTF(1,2) BD_ATTR_MALLOC; 30 | 31 | BD_PRIVATE const char * str_skip_white (const char *str); 32 | BD_PRIVATE const char * str_next_line (const char *str); 33 | 34 | BD_PRIVATE char * str_print_hex(char *out, const uint8_t *str, int count); 35 | 36 | #endif // STRUTL_H_ 37 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef INTERFACE_H_INCLUDED 21 | #define INTERFACE_H_INCLUDED 22 | 23 | #include "util/attributes.h" 24 | 25 | #include 26 | 27 | #define VALIDATE_ADDRESS( p, len) ((p) >= DLX_MEMORY_SIZE || (p) + (len) > DLX_MEMORY_SIZE || (p) + (len) < (p)) 28 | #define VALIDATE_ADDRESS_ALIGN(p, len) (VALIDATE_ADDRESS(p, len) || ((p) & 0x03) != 0) 29 | 30 | #define VALIDATE_ADDRESS_REAL( p, len) ((p) + (len-1) < (p)) 31 | 32 | 33 | struct VM_s; 34 | 35 | BD_PRIVATE void interface_trap ( struct VM_s *, uint32_t trap ); 36 | 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/trap_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef TRAP_HELPER_H 22 | #define TRAP_HELPER_H 23 | 24 | #include "util/attributes.h" 25 | 26 | #include "sha1.h" 27 | 28 | #include 29 | #include 30 | 31 | typedef struct sha_s { 32 | void *prev, *next; 33 | uint8_t *dst; // initialize from caller 34 | 35 | /* TODO: context should be mapped to VM address space */ 36 | SHA1_CTX sha; 37 | } sha_t; 38 | 39 | BD_PRIVATE sha_t *get_sha_ctx (sha_t **head, uint8_t *); 40 | BD_PRIVATE int free_sha_ctx (sha_t **head, sha_t *); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/event.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef EVENT_H_INCLUDED 21 | #define EVENT_H_INCLUDED 22 | 23 | #include 24 | 25 | #include "util/attributes.h" 26 | 27 | #define EVENT_Start 0x00000000 28 | #define EVENT_Shutdown 0x00000010 29 | #define EVENT_PlaybackFile 0x00000110 30 | #define EVENT_ApplicationLayer 0x00000210 31 | #define EVENT_ComputeSP 0x00000220 32 | 33 | 34 | struct VM_s; 35 | 36 | BD_PRIVATE void bdplus_send_event(struct VM_s *vm, uint32_t eventID, uint32_t arg1, 37 | uint32_t table, uint32_t segment); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /SMP/src/libbdplus/bdplus-version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BDPLUS_VERSION_H_ 21 | #define BDPLUS_VERSION_H_ 22 | 23 | #define BDPLUS_VERSION_CODE(major, minor, micro) \ 24 | (((major) * 10000) + \ 25 | ((minor) * 100) + \ 26 | ((micro) * 1)) 27 | 28 | #define BDPLUS_VERSION_MAJOR 0 29 | #define BDPLUS_VERSION_MINOR 2 30 | #define BDPLUS_VERSION_MICRO 0 31 | 32 | #define BDPLUS_VERSION_STRING "0.2.0" 33 | 34 | #define BDPLUS_VERSION \ 35 | BDPLUS_VERSION_CODE(BDPLUS_VERSION_MAJOR, BDPLUS_VERSION_MINOR, BDPLUS_VERSION_MICRO) 36 | 37 | #endif /* BDPLUS_VERSION_H_ */ 38 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/diff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef DIFF_H_INCLUDED 21 | #define DIFF_H_INCLUDED 22 | 23 | #include "util/attributes.h" 24 | 25 | #include 26 | 27 | // Due to legacy reasons, the old java Debugger initially stored everything 28 | // as little-endian, which was later corrected. Due to this, we define 29 | // a way to be backward compatible. It is unlikely new developers wants to use 30 | // this. 31 | #define BDPLUS_LOAD_SWAP 1 32 | 33 | 34 | BD_PRIVATE int32_t diff_loadcore ( uint8_t *, uint32_t, char *, uint32_t, uint32_t ); 35 | 36 | BD_PRIVATE uint32_t diff_hashdb_load( uint8_t *, uint8_t *, uint64_t, uint32_t *, uint8_t *); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/slot_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef SLOT_DATA_H_INCLUDED 21 | #define SLOT_DATA_H_INCLUDED 22 | 23 | #include 24 | 25 | #define BDPLUS_NUM_SLOTS 500 26 | #define BLURAY_VOLUMEID_LEN 16 27 | 28 | 29 | // 256 bytes. 30 | struct slot_s { 31 | uint8_t cMediaID[16]; // 00-0F Creator Media ID 32 | uint8_t mMediaID[16]; // 10-1F Last Update Media ID 33 | 34 | uint8_t privateData[16]; // 20-2F 35 | 36 | uint8_t authHash[20]; // 40-43 37 | 38 | uint8_t youguess[4]; // 44-47 39 | 40 | uint8_t sequence_counter[4]; // 48-4B 41 | 42 | uint8_t payload[180]; // 4C-FF 43 | }; 44 | 45 | typedef struct slot_s slot_t; 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/libbdplus/bdplus-version.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BDPLUS_VERSION_H_ 21 | #define BDPLUS_VERSION_H_ 22 | 23 | #define BDPLUS_VERSION_CODE(major, minor, micro) \ 24 | (((major) * 10000) + \ 25 | ((minor) * 100) + \ 26 | ((micro) * 1)) 27 | 28 | #define BDPLUS_VERSION_MAJOR @BDPLUS_VERSION_MAJOR@ 29 | #define BDPLUS_VERSION_MINOR @BDPLUS_VERSION_MINOR@ 30 | #define BDPLUS_VERSION_MICRO @BDPLUS_VERSION_MICRO@ 31 | 32 | #define BDPLUS_VERSION_STRING "@BDPLUS_VERSION_MAJOR@.@BDPLUS_VERSION_MINOR@.@BDPLUS_VERSION_MICRO@" 33 | 34 | #define BDPLUS_VERSION \ 35 | BDPLUS_VERSION_CODE(BDPLUS_VERSION_MAJOR, BDPLUS_VERSION_MINOR, BDPLUS_VERSION_MICRO) 36 | 37 | #endif /* BDPLUS_VERSION_H_ */ 38 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/dlx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef DLX_H_INCLUDED 21 | #define DLX_H_INCLUDED 22 | 23 | #include "util/attributes.h" 24 | 25 | #include 26 | 27 | #define BD_STEP_I 1 // Step one instruction 28 | #define BD_STEP_TRAP 2 // Step until next trap 29 | 30 | 31 | typedef struct VM_s VM; 32 | 33 | struct bdplus_s; 34 | 35 | BD_PRIVATE VM * dlx_initVM ( struct bdplus_s * ); 36 | BD_PRIVATE void dlx_freeVM ( VM ** ); 37 | BD_PRIVATE struct bdplus_s *dlx_getApp ( VM * ); 38 | 39 | BD_PRIVATE uint32_t dlx_getPC ( VM * ); 40 | BD_PRIVATE int32_t dlx_getWD ( VM * ); 41 | BD_PRIVATE uint32_t dlx_getIF ( VM * ); 42 | BD_PRIVATE uint8_t * dlx_getAddr ( VM * ); 43 | BD_PRIVATE uint32_t dlx_getAddrSize ( VM * ); 44 | BD_PRIVATE int32_t dlx_run ( VM *, int32_t ); 45 | BD_PRIVATE uint32_t dlx_num_breaks ( VM * ); 46 | BD_PRIVATE uint32_t dlx_num_traps ( VM * ); 47 | BD_PRIVATE uint32_t dlx_num_instructions ( VM * ); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /SMP/libbdplus_with_latest_sdk.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET PROJECT=libbdplus 4 | 5 | @REM Detect the newest available Windows SDK 6 | CALL :GetWindowsSdkVer 7 | 8 | @REM Open the project 9 | %PROJECT%.sln 10 | 11 | EXIT /B 0 12 | 13 | :GetWindowsSdkVer 14 | SET WindowsTargetPlatformVersion= 15 | 16 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin10SdkVer 17 | IF "%WindowsTargetPlatformVersion%"=="" CALL :GetWin81SdkVer 18 | EXIT /B 0 19 | 20 | :GetWin10SdkVer 21 | CALL :GetWin10SdkVerHelper HKLM\SOFTWARE\Wow6432Node > nul 2>&1 22 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE\Wow6432Node > nul 2>&1 23 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKLM\SOFTWARE > nul 2>&1 24 | IF errorlevel 1 CALL :GetWin10SdkVerHelper HKCU\SOFTWARE > nul 2>&1 25 | IF errorlevel 1 EXIT /B 1 26 | EXIT /B 0 27 | 28 | :GetWin10SdkVerHelper 29 | @REM Get Windows 10 SDK installed folder 30 | FOR /F "tokens=1,2*" %%i IN ('reg query "%1\Microsoft\Microsoft SDKs\Windows\v10.0" /v "InstallationFolder"') DO ( 31 | IF "%%i"=="InstallationFolder" ( 32 | SET WindowsSdkDir=%%~k 33 | ) 34 | ) 35 | 36 | @REM get windows 10 sdk version number 37 | SETLOCAL enableDelayedExpansion 38 | IF NOT "%WindowsSdkDir%"=="" FOR /f %%i IN ('dir "%WindowsSdkDir%include\" /b /ad-h /on') DO ( 39 | @REM Skip if Windows.h is not found in %%i\um. This would indicate that only the UCRT MSIs were 40 | @REM installed for this Windows SDK version. 41 | IF EXIST "%WindowsSdkDir%include\%%i\um\Windows.h" ( 42 | SET result=%%i 43 | IF "!result:~0,3!"=="10." ( 44 | SET SDK=!result! 45 | IF "!result!"=="%VSCMD_ARG_WINSDK%" SET findSDK=1 46 | ) 47 | ) 48 | ) 49 | 50 | IF "%findSDK%"=="1" SET SDK=%VSCMD_ARG_WINSDK% 51 | ENDLOCAL & SET WindowsTargetPlatformVersion=%SDK% 52 | IF "%WindowsTargetPlatformVersion%"=="" ( 53 | EXIT /B 1 54 | ) 55 | EXIT /B 0 56 | 57 | :GetWin81SdkVer 58 | SET WindowsTargetPlatformVersion=8.1 59 | EXIT /B 0 60 | -------------------------------------------------------------------------------- /SMP/unistd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MSVC unistd.h compatibility header. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SMP_UNISTD_H 24 | #define SMP_UNISTD_H 25 | 26 | #ifndef _MSC_VER 27 | # include_next 28 | #else 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #define R_OK 4 /* Test for read permission. */ 36 | #define W_OK 2 /* Test for write permission. */ 37 | //#define X_OK 1 /* execute permission - unsupported in windows*/ 38 | #define F_OK 0 /* Test for existence. */ 39 | 40 | #ifndef STDIN_FILENO 41 | #define STDIN_FILENO 0 42 | #endif 43 | 44 | #ifndef STDOUT_FILENO 45 | #define STDOUT_FILENO 1 46 | #endif 47 | 48 | #ifndef STDERR_FILENO 49 | #define STDERR_FILENO 2 50 | #endif 51 | 52 | #define srandom srand 53 | #define random rand 54 | 55 | #define inline __inline 56 | typedef int mode_t; 57 | #include 58 | typedef SSIZE_T ssize_t; 59 | 60 | #endif /* _MSC_VER */ 61 | 62 | #endif /* SMP_UNISTD_H */ -------------------------------------------------------------------------------- /SMP/SMP.patch: -------------------------------------------------------------------------------- 1 | diff --git a/src/file/dirs_win32.c b/src/file/dirs_win32.c 2 | index d73796a..1e01b14 100644 3 | --- a/src/file/dirs_win32.c 4 | +++ b/src/file/dirs_win32.c 5 | @@ -53,6 +53,7 @@ char *file_get_data_home(void) 6 | { 7 | wchar_t wdir[MAX_PATH]; 8 | 9 | +# if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) 10 | /* Get the "Application Data" folder for the user */ 11 | if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 12 | NULL, SHGFP_TYPE_CURRENT, wdir)) { 13 | @@ -63,6 +64,7 @@ char *file_get_data_home(void) 14 | } 15 | return appdir; 16 | } 17 | +#endif 18 | 19 | BD_DEBUG(DBG_FILE, "Can't find user configuration directory !\n"); 20 | return NULL; 21 | @@ -84,6 +86,7 @@ const char *file_get_config_system(const char *dir) 22 | if (appdir) 23 | return appdir; 24 | 25 | +# if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) 26 | /* Get the "Application Data" folder for all users */ 27 | if (S_OK == SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, 28 | NULL, SHGFP_TYPE_CURRENT, wdir)) { 29 | @@ -93,7 +96,9 @@ const char *file_get_config_system(const char *dir) 30 | WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL); 31 | } 32 | return appdir; 33 | - } else { 34 | + } else 35 | +#endif 36 | + { 37 | BD_DEBUG(DBG_FILE, "Can't find common configuration directory !\n"); 38 | return NULL; 39 | } 40 | diff --git a/src/util/attributes.h b/src/util/attributes.h 41 | index 1cc611c..4e68d7b 100644 42 | --- a/src/util/attributes.h 43 | +++ b/src/util/attributes.h 44 | @@ -50,7 +50,7 @@ 45 | # define BD_PRIVATE 46 | #endif 47 | 48 | -#if !defined(__GNUC__) || __GNUC__ < 3 49 | +#if ( !defined(__GNUC__) || __GNUC__ < 3 ) && !defined(__INTEL_COMPILER) 50 | # define BD_LIKELY(x) (x) 51 | # define BD_UNLIKELY(x) (x) 52 | #else 53 | -------------------------------------------------------------------------------- /src/util/logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2009-2010 Obliter0n 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef LOGGING_H_ 22 | #define LOGGING_H_ 23 | 24 | #include "attributes.h" 25 | 26 | #include 27 | 28 | enum debug_mask_enum { 29 | DBG_RESERVED = 0x0001, 30 | DBG_CONFIGFILE = 0x0002, 31 | DBG_FILE = 0x0004, 32 | //DBG_AACS = 0x0008, 33 | //DBG_MKB = 0x0010, 34 | //DBG_MMC = 0x0020, 35 | DBG_BLURAY = 0x0040, 36 | DBG_DIR = 0x0080, 37 | //DBG_NAV = 0x0100, 38 | DBG_BDPLUS = 0x0200, 39 | DBG_DLX = 0x0400, 40 | DBG_CRIT = 0x0800, // this is libbluray's default debug mask so use this if you want to display critical info 41 | //DBG_HDMV = 0x1000, 42 | 43 | DBG_BDPLUS_TRAP = 0x100000 | DBG_BDPLUS, 44 | DBG_BDPLUS_EVENT = 0x200000 | DBG_BDPLUS, 45 | }; 46 | 47 | typedef enum debug_mask_enum debug_mask_t; 48 | 49 | BD_PRIVATE extern uint32_t debug_mask; 50 | 51 | #define BD_DEBUG(MASK,...) \ 52 | do { \ 53 | if (BD_UNLIKELY((MASK) & debug_mask)) { \ 54 | bd_debug(__FILE__,__LINE__,MASK,__VA_ARGS__); \ 55 | } \ 56 | } while (0) 57 | 58 | BD_PRIVATE void bd_debug(const char *file, int line, uint32_t mask, const char *format, ...) BD_ATTR_FORMAT_PRINTF(4,5); 59 | 60 | 61 | #endif /* LOGGING_H_ */ 62 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/event.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #include "event.h" 21 | 22 | #include "dlx_internal.h" 23 | 24 | #include "util/logging.h" 25 | #include "util/macro.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | void bdplus_send_event(VM *vm, uint32_t eventID, uint32_t arg1, 32 | uint32_t table, uint32_t segment) 33 | { 34 | 35 | BD_DEBUG(DBG_BDPLUS_EVENT,"[bdplus] ** posting EVENT %X (%08X, %d, %d)\n", eventID, 36 | arg1, table, segment); 37 | 38 | if (!vm || !vm->addr) return; 39 | 40 | STORE4( &vm->addr[ 0x0 ], eventID ); 41 | STORE4( &vm->addr[ 0x4 ], arg1 ); 42 | STORE4( &vm->addr[ 0x8 ], table ); 43 | if (eventID == EVENT_ComputeSP) { 44 | 45 | STORE4( &vm->addr[ 0xC ], segment ); 46 | STORE4( &vm->addr[ 0x20 ], 0 ); // Set by Jumper, clearing MASK? 47 | STORE4( &vm->addr[ 0x24 ], 0 ); // Set by Jumper 48 | #if 0 49 | /* this should be set already ... */ 50 | if (plus->conv_tab) 51 | segment_setSegment(plus->conv_tab, table, segment); 52 | #endif 53 | } 54 | 55 | // Remember break location? 56 | // send_event sets R28, but it MUST be clear to start. 57 | 58 | // If we are Starting, don7t touch R28, since they must all be 0 at start. 59 | if (eventID != EVENT_Start) 60 | vm->R[28] = dlx_getPC(vm); 61 | 62 | dlx_setPC(vm, 0x1000); 63 | dlx_setWD(vm, 0x7FFFFFFF); 64 | vm->event_processing = 1; 65 | vm->event_current = eventID; 66 | } 67 | -------------------------------------------------------------------------------- /src/libbdplus/internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef INTERNAL_H_INCLUDED 22 | #define INTERNAL_H_INCLUDED 23 | 24 | #include "util/attributes.h" 25 | 26 | #include 27 | 28 | #ifndef BDPLUS_H_INCLUDED 29 | typedef struct bdplus_s bdplus_t; 30 | #endif 31 | 32 | /* 33 | * 34 | */ 35 | 36 | struct conv_table_s; 37 | struct bdplus_config_s; 38 | struct slot_s; 39 | 40 | BD_PRIVATE uint8_t *bdplus_getVolumeID( bdplus_t *plus ); 41 | BD_PRIVATE uint8_t *bdplus_getMediaKey( bdplus_t *plus ); 42 | BD_PRIVATE void bdplus_setConvTable( bdplus_t *plus, struct conv_table_s * ); 43 | BD_PRIVATE struct conv_table_s *bdplus_getConvTable ( bdplus_t *plus ); 44 | BD_PRIVATE struct bdplus_config_s *bdplus_getConfig ( bdplus_t *plus ); 45 | BD_PRIVATE char *bdplus_disc_cache_file( bdplus_t *plus, const char *file ); 46 | BD_PRIVATE char *bdplus_disc_findcachefile( bdplus_t *plus ); 47 | 48 | BD_PRIVATE void bdplus_getSlot ( bdplus_t *plus, uint32_t slot, struct slot_s *dst ); 49 | BD_PRIVATE void bdplus_getAttachStatus ( bdplus_t *plus, uint8_t *dst ); 50 | BD_PRIVATE void bdplus_resetSlotStatus ( bdplus_t *plus ); 51 | BD_PRIVATE uint32_t bdplus_slot_authenticate ( bdplus_t *plus, uint32_t slot, char *digest ); 52 | BD_PRIVATE uint32_t bdplus_new_slot ( bdplus_t *plus ); 53 | BD_PRIVATE void bdplus_slot_write ( bdplus_t *plus, struct slot_s *slot ); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /src/file/filesystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2015 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BDPLUS_FILESYSTEM_H_ 21 | #define BDPLUS_FILESYSTEM_H_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include 28 | 29 | #ifndef BD_PUBLIC 30 | # define BD_PUBLIC 31 | #endif 32 | 33 | /* Keep this compatible with libaacs ! */ 34 | typedef struct bdplus_file BDPLUS_FILE_H; 35 | struct bdplus_file 36 | { 37 | void *internal; 38 | 39 | void (*close) (BDPLUS_FILE_H *file); 40 | int64_t (*seek) (BDPLUS_FILE_H *file, int64_t offset, int32_t origin); 41 | int64_t (*tell) (BDPLUS_FILE_H *file); 42 | int (*eof) (BDPLUS_FILE_H *file); 43 | int64_t (*read) (BDPLUS_FILE_H *file, uint8_t *buf, int64_t size); 44 | int64_t (*write) (BDPLUS_FILE_H *file, const uint8_t *buf, int64_t size); 45 | }; 46 | 47 | /** 48 | * 49 | * Function that will be used to open a file 50 | * 51 | * NOTE: file name is relative to disc root directory ! 52 | * 53 | * @param handle application-specific handle 54 | * @param filename file to open 55 | * @return pointer to BDPLUS_FILE_H, NULL if error 56 | */ 57 | typedef BDPLUS_FILE_H* (*BDPLUS_FILE_OPEN)(void *handle, const char *filename); 58 | 59 | /** 60 | * 61 | * Register function pointer that will be used to open a file 62 | * 63 | * @param bdplus bdplus instance 64 | * @param handle handle that will be passed to file open function 65 | * @param p function pointer 66 | */ 67 | struct bdplus_s; 68 | 69 | BD_PUBLIC 70 | void bdplus_set_fopen(struct bdplus_s *bdplus, void *handle, BDPLUS_FILE_OPEN p); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif /* BDPLUS_FILESYSTEM_H_ */ 77 | -------------------------------------------------------------------------------- /src/file/dirs_darwin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2012 Konstantin Pavlov 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | #include "dirs.h" 25 | 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "util/strutl.h" 33 | #include "util/logging.h" 34 | 35 | #define USER_CFG_DIR "Library/Preferences" 36 | #define USER_CACHE_DIR "Library/Caches" 37 | #define USER_DATA_DIR "Library" 38 | #define SYSTEM_CFG_DIR "/Library/Preferences" 39 | 40 | 41 | char *file_get_config_home(void) 42 | { 43 | const char *user_home = getenv("HOME"); 44 | if (user_home && *user_home) { 45 | return str_printf("%s/%s", user_home, USER_CFG_DIR); 46 | } 47 | 48 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 49 | return NULL; 50 | } 51 | 52 | char *file_get_data_home(void) 53 | { 54 | const char *user_home = getenv("HOME"); 55 | if (user_home && *user_home) { 56 | return str_printf("%s/%s", user_home, USER_DATA_DIR); 57 | } 58 | 59 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 60 | return NULL; 61 | } 62 | 63 | char *file_get_cache_home(void) 64 | { 65 | const char *user_home = getenv("HOME"); 66 | if (user_home && *user_home) { 67 | return str_printf("%s/%s", user_home, USER_CACHE_DIR); 68 | } 69 | 70 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 71 | return NULL; 72 | } 73 | 74 | const char *file_get_config_system(const char *dir) 75 | { 76 | if (!dir) { 77 | // first call 78 | return SYSTEM_CFG_DIR; 79 | } 80 | 81 | return NULL; 82 | } 83 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/segment.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef SEGMENT_H_INCLUDED 22 | #define SEGMENT_H_INCLUDED 23 | 24 | #include "util/attributes.h" 25 | 26 | #include 27 | #include 28 | 29 | 30 | typedef struct conv_table_s conv_table_t; 31 | 32 | #ifndef BDPLUS_H_INCLUDED 33 | typedef struct bdplus_st_s bdplus_st_t; 34 | #endif 35 | 36 | struct bdplus_file; 37 | 38 | BD_PRIVATE uint32_t segment_numTables ( conv_table_t * ); 39 | BD_PRIVATE uint32_t segment_numEntries ( conv_table_t * ); 40 | 41 | BD_PRIVATE int32_t segment_setTable ( conv_table_t **, uint8_t *, uint32_t ); 42 | BD_PRIVATE int32_t segment_freeTable ( conv_table_t ** ); 43 | BD_PRIVATE uint32_t segment_mergeTables ( conv_table_t *, conv_table_t * ); 44 | BD_PRIVATE int32_t segment_activateTable ( conv_table_t * ); 45 | 46 | BD_PRIVATE int32_t segment_nextSegment ( conv_table_t *, uint32_t *, uint32_t * ); 47 | BD_PRIVATE int32_t segment_setSegment ( conv_table_t *, uint32_t, uint32_t ); 48 | BD_PRIVATE int32_t segment_decrypt ( conv_table_t *, uint8_t *, uint8_t * ); 49 | 50 | BD_PRIVATE int32_t segment_save ( conv_table_t *, FILE * ); 51 | BD_PRIVATE int32_t segment_load ( conv_table_t **, struct bdplus_file * ); 52 | 53 | BD_PRIVATE bdplus_st_t *segment_set_m2ts ( conv_table_t *, uint32_t ); 54 | BD_PRIVATE int32_t segment_patchfile ( conv_table_t *, uint32_t , FILE * ); 55 | BD_PRIVATE int32_t segment_patchseek ( bdplus_st_t *, uint64_t ); 56 | BD_PRIVATE int32_t segment_patch ( bdplus_st_t *, int32_t, uint8_t * ); 57 | BD_PRIVATE void segment_close_m2ts ( bdplus_st_t * ); 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /src/util/attributes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2010 hpi1 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef LIBBLURAY_ATTRIBUTES_H_ 21 | #define LIBBLURAY_ATTRIBUTES_H_ 22 | 23 | #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3 )) 24 | # if defined(_WIN32) 25 | # define BD_ATTR_FORMAT_PRINTF(format,var) __attribute__((__format__(__gnu_printf__,format,var))) 26 | # else 27 | # define BD_ATTR_FORMAT_PRINTF(format,var) __attribute__((__format__(__printf__,format,var))) 28 | # endif 29 | # define BD_ATTR_MALLOC __attribute__((__malloc__)) 30 | # define BD_ATTR_PACKED __attribute__((packed)) 31 | #else 32 | # define BD_ATTR_FORMAT_PRINTF(format,var) 33 | # define BD_ATTR_MALLOC 34 | # define BD_ATTR_PACKED 35 | #endif 36 | 37 | #if defined(_WIN32) 38 | # if defined(__GNUC__) 39 | # define BD_PUBLIC __attribute__((dllexport)) 40 | # define BD_PRIVATE 41 | # else 42 | # define BD_PUBLIC __declspec(dllexport) 43 | # define BD_PRIVATE 44 | # endif 45 | #elif defined(__GNUC__) && __GNUC__ >= 4 46 | # define BD_PUBLIC __attribute__((visibility("default"))) 47 | # define BD_PRIVATE __attribute__((visibility("hidden"))) 48 | #else 49 | # define BD_PUBLIC 50 | # define BD_PRIVATE 51 | #endif 52 | 53 | #if ( !defined(__GNUC__) || __GNUC__ < 3 ) && !defined(__INTEL_COMPILER) 54 | # define BD_LIKELY(x) (x) 55 | # define BD_UNLIKELY(x) (x) 56 | #else 57 | # define BD_LIKELY(x) __builtin_expect((x),1) 58 | # define BD_UNLIKELY(x) __builtin_expect((x),0) 59 | #endif 60 | 61 | #if defined(__GNUC__) && __GNUC__ > 3 62 | # define BD_USED __attribute__((warn_unused_result)) 63 | #else 64 | # define BD_USED 65 | #endif 66 | 67 | #endif /* LIBBLURAY_ATTRIBUTES_H_ */ 68 | -------------------------------------------------------------------------------- /src/file/file.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2014 Petri Hintukainen 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #if HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "file.h" 25 | 26 | #include "util/logging.h" 27 | #include "util/macro.h" 28 | #include "util/strutl.h" 29 | 30 | #include // SEEK_* 31 | #include // strchr 32 | 33 | 34 | int64_t file_size(BD_FILE_H *fp) 35 | { 36 | int64_t pos = file_tell(fp); 37 | int64_t res1 = file_seek(fp, 0, SEEK_END); 38 | int64_t length = file_tell(fp); 39 | int64_t res2 = file_seek(fp, pos, SEEK_SET); 40 | 41 | if (res1 < 0 || res2 < 0 || pos < 0 || length < 0) { 42 | return -1; 43 | } 44 | 45 | return length; 46 | } 47 | 48 | int file_mkdirs(const char *path) 49 | { 50 | int result = 0; 51 | char *dir = str_dup(path); 52 | char *end = dir; 53 | char *p; 54 | 55 | if (!dir) { 56 | return -1; 57 | } 58 | 59 | /* strip file name */ 60 | if (!(end = strrchr(end, DIR_SEP_CHAR))) { 61 | X_FREE(dir); 62 | return -1; 63 | } 64 | *end = 0; 65 | 66 | /* tokenize, stop to first existing dir */ 67 | while ((p = strrchr(dir, DIR_SEP_CHAR))) { 68 | if (!file_path_exists(dir)) { 69 | break; 70 | } 71 | *p = 0; 72 | } 73 | 74 | /* create missing dirs */ 75 | p = dir; 76 | while (p < end) { 77 | 78 | /* concatenate next non-existing dir */ 79 | while (*p) p++; 80 | if (p >= end) break; 81 | *p = DIR_SEP_CHAR; 82 | 83 | result = file_mkdir(dir); 84 | if (result < 0) { 85 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Error creating directory %s\n", dir); 86 | break; 87 | } 88 | BD_DEBUG(DBG_FILE, " created directory %s\n", dir); 89 | } 90 | 91 | X_FREE(dir); 92 | return result; 93 | } 94 | -------------------------------------------------------------------------------- /SMP/sys/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MSVC sys/time.h compatibility header. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SMP_SYS_TIME_H 24 | #define SMP_SYS_TIME_H 25 | 26 | #ifndef _MSC_VER 27 | # include_next 28 | #else 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | struct timezone 35 | { 36 | int tz_minuteswest; /* minutes W of Greenwich */ 37 | int tz_dsttime; /* type of dst correction */ 38 | }; 39 | 40 | static __inline int gettimeofday(struct timeval * tp, struct timezone * tzp) 41 | { 42 | FILETIME file_time; 43 | SYSTEMTIME system_time; 44 | ULARGE_INTEGER ularge; 45 | static int tzflag; 46 | 47 | GetSystemTime(&system_time); 48 | SystemTimeToFileTime(&system_time, &file_time); 49 | ularge.LowPart = file_time.dwLowDateTime; 50 | ularge.HighPart = file_time.dwHighDateTime; 51 | 52 | tp->tv_sec = (long) ((ularge.QuadPart - 116444736000000000Ui64) / 10000000L); 53 | tp->tv_usec = (long) (system_time.wMilliseconds * 1000); 54 | 55 | #if !(defined(WINAPI_FAMILY_PARTITION) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) 56 | if (NULL != tzp) 57 | { 58 | if (!tzflag) 59 | { 60 | _tzset(); 61 | tzflag++; 62 | } 63 | tzp->tz_minuteswest = _timezone / 60; 64 | tzp->tz_dsttime = _daylight; 65 | } 66 | #endif 67 | return 0; 68 | } 69 | 70 | #endif /* _MSC_VER */ 71 | 72 | #endif /* SMP_SYS_TIME_H */ -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/dlx_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef DLX_INTERNAL_H_INCLUDED 21 | #define DLX_INTERNAL_H_INCLUDED 22 | 23 | #include "util/attributes.h" 24 | 25 | #include "dlx.h" 26 | 27 | #include 28 | #include 29 | 30 | #define ADDR_MASK1 0x3FFFFF 31 | #define ADDR_MASK2 0x3FFFFE 32 | #define ADDR_MASK4 0x3FFFFC 33 | 34 | #define DLX_MEMORY_SIZE 0x400000 35 | 36 | /* 37 | * The DLX VM Structure 38 | */ 39 | 40 | #include 41 | 42 | struct bdplus_s; 43 | struct sha_s; 44 | 45 | struct VM_s { 46 | 47 | uint8_t *addr; // VM's memory area. 48 | uint32_t size; // Allocated size, probably 0x400000 49 | 50 | uint32_t PC; // Program Counter 51 | 52 | uint32_t R[32]; // R0 is always 0, and read only. 53 | // R31 is used by some instructions 54 | uint32_t IF; // Intruction Filter 55 | int32_t WD; // Watchdog timer 56 | 57 | uint32_t code_start; // Generally 0x1000. Set by first call to setPC 58 | uint32_t event_processing; // Set when we are processing events, clear on idle 59 | uint32_t event_current; // value of the current event. 60 | 61 | // Just statistics 62 | uint32_t num_breaks; 63 | uint32_t trap; 64 | uint32_t num_traps; 65 | uint32_t num_instructions; 66 | 67 | // Trace file handles, if used.. 68 | FILE *trace_PC; 69 | FILE *trace_WD; 70 | FILE *trace_IF; 71 | 72 | // for traps 73 | struct bdplus_s *plus; 74 | struct sha_s *sha_ctx_head; 75 | }; 76 | 77 | BD_PRIVATE uint32_t dlx_setPC ( VM *, uint32_t ); 78 | BD_PRIVATE int32_t dlx_setWD ( VM *, int32_t ); 79 | BD_PRIVATE uint32_t dlx_setIF ( VM *, uint32_t ); 80 | BD_PRIVATE uint32_t dlx_getStart ( VM * ); 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /src/util/logging.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2009-2010 Obliter0n 5 | * Copyright (C) 2013 VideoLAN 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. If not, see 19 | * . 20 | */ 21 | 22 | #if HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "logging.h" 27 | 28 | #include "file/file.h" 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | uint32_t debug_mask = (uint32_t)-1; /* set all bits to make sure bd_debug() is called for initialization */ 36 | 37 | void bd_debug(const char *file, int line, uint32_t mask, const char *format, ...) 38 | { 39 | static int debug_init = 0; 40 | static FILE *logfile = NULL; 41 | 42 | // Only call getenv() once. 43 | if (!debug_init) { 44 | debug_init = 1; 45 | logfile = stderr; 46 | 47 | char *env = NULL; 48 | if (debug_mask == (uint32_t)-1) { 49 | /* might be set by application with bd_set_debug_mask() */ 50 | debug_mask = DBG_CRIT; 51 | } 52 | if ((env = getenv("BD_DEBUG_MASK"))) 53 | debug_mask = strtol(env, NULL, 0); 54 | 55 | // Send DEBUG to file? 56 | if ((env = getenv("BDPLUS_DEBUG_FILE"))) { 57 | FILE *fp = fopen(env, "wb"); 58 | if (fp) { 59 | logfile = fp; 60 | setvbuf(logfile, NULL, _IONBF, 0); 61 | } else { 62 | fprintf(logfile, "%s:%d: Error opening log file %s\n", __FILE__, __LINE__, env); 63 | } 64 | } 65 | } 66 | 67 | if (mask & debug_mask) { 68 | const char *f = strrchr(file, DIR_SEP_CHAR); 69 | char buffer[4096], *pt = buffer; 70 | va_list args; 71 | 72 | pt += sprintf(buffer, "%s:%d: ", f ? f + 1 : file, line); 73 | 74 | va_start(args, format); 75 | vsnprintf(pt, sizeof(buffer) - (size_t)(intptr_t)(pt - buffer) - 1, format, args); 76 | va_end(args); 77 | 78 | fprintf(logfile, "%s", buffer); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/libbdplus/bdplus_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef BDPLUS_DATA_H_INCLUDED 22 | #define BDPLUS_DATA_H_INCLUDED 23 | 24 | #include "util/attributes.h" 25 | #include "util/mutex.h" 26 | 27 | #include "internal.h" 28 | 29 | #include "bdsvm/slot_data.h" 30 | 31 | #include 32 | 33 | /* 34 | * 35 | */ 36 | 37 | struct conv_table_s; 38 | struct bdplus_config_s; 39 | struct VM_s; 40 | 41 | struct bdplus_s { 42 | char *device_path; 43 | 44 | struct VM_s *vm; 45 | 46 | slot_t slots[BDPLUS_NUM_SLOTS]; 47 | uint32_t attached_slot; 48 | uint32_t free_slot; 49 | uint8_t attachedStatus[2]; 50 | 51 | uint8_t volumeID[BLURAY_VOLUMEID_LEN]; // This should probably be moved out,API? 52 | uint8_t mediaKey[BLURAY_VOLUMEID_LEN]; // This should probably be moved out,API? 53 | 54 | struct conv_table_s *conv_tab; /* conversion table from VM */ 55 | struct conv_table_s *cache_tab; 56 | 57 | struct bdplus_config_s *config; 58 | 59 | BD_MUTEX mutex; 60 | 61 | uint8_t loaded; 62 | uint8_t started; 63 | 64 | /* BD+ content code version */ 65 | int gen; 66 | int date; 67 | }; 68 | 69 | 70 | BD_PRIVATE int crypto_init( void ); 71 | 72 | BD_PRIVATE int32_t bdplus_load_svm ( bdplus_t *plus, const char *fname ); 73 | BD_PRIVATE int32_t bdplus_load_slots ( bdplus_t *plus, const char *fname ); 74 | BD_PRIVATE int32_t bdplus_save_slots ( bdplus_t *plus, const char *fname ); 75 | 76 | BD_PRIVATE int32_t bdplus_run_init ( struct VM_s *vm ); 77 | BD_PRIVATE int32_t bdplus_run_idle ( struct VM_s *vm ); 78 | BD_PRIVATE int32_t bdplus_run_convtab( bdplus_t *plus ); 79 | BD_PRIVATE int32_t bdplus_run_title ( bdplus_t *plus, uint32_t title ); 80 | BD_PRIVATE int32_t bdplus_run_m2ts ( bdplus_t *plus, uint32_t m2ts ); 81 | BD_PRIVATE int32_t bdplus_run_shutdown(bdplus_t *plus ); 82 | 83 | BD_PRIVATE int32_t bdplus_run_event210(struct VM_s *vm, uint32_t param); 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/file/file.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2015 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef FILE_H_ 21 | #define FILE_H_ 22 | 23 | #include "util/attributes.h" 24 | 25 | #include "filesystem.h" 26 | 27 | #include 28 | #include 29 | 30 | #ifdef _WIN32 31 | # define DIR_SEP "\\" 32 | # define DIR_SEP_CHAR '\\' 33 | #else 34 | # define DIR_SEP "/" 35 | # define DIR_SEP_CHAR '/' 36 | #endif 37 | 38 | typedef BDPLUS_FILE_H BD_FILE_H; 39 | typedef BDPLUS_FILE_OPEN BD_FILE_OPEN; 40 | 41 | /* 42 | * file access 43 | */ 44 | 45 | static inline void file_close(BD_FILE_H *fp) 46 | { 47 | fp->close(fp); 48 | } 49 | 50 | static inline int64_t file_tell(BD_FILE_H *fp) 51 | { 52 | return fp->tell(fp); 53 | } 54 | 55 | static inline BD_USED int64_t file_seek(BD_FILE_H *fp, int64_t offset, int32_t origin) 56 | { 57 | return fp->seek(fp, offset, origin); 58 | } 59 | 60 | static inline BD_USED size_t file_read(BD_FILE_H *fp, uint8_t *buf, size_t size) 61 | { 62 | return (size_t)fp->read(fp, buf, (int64_t)size); 63 | } 64 | 65 | #define file_open(cfg, fname) (cfg->fopen(cfg->fopen_handle, fname)) 66 | 67 | BD_PRIVATE int64_t file_size(BD_FILE_H *fp); 68 | 69 | BD_PRIVATE BDPLUS_FILE_OPEN file_open_default(void); 70 | 71 | /* 72 | * directory access 73 | */ 74 | 75 | typedef struct 76 | { 77 | char d_name[256]; 78 | } BD_DIRENT; 79 | 80 | typedef struct bdplus_dir_s BD_DIR_H; 81 | struct bdplus_dir_s 82 | { 83 | void* internal; 84 | void (*close)(BD_DIR_H *dir); 85 | int (*read)(BD_DIR_H *dir, BD_DIRENT *entry); 86 | }; 87 | 88 | typedef BD_DIR_H* (*BD_DIR_OPEN) (const char* dirname); 89 | 90 | #define dir_close(X) X->close(X) 91 | #define dir_read(X,Y) X->read(X,Y) 92 | 93 | BD_PRIVATE BD_DIR_OPEN dir_open_default(void); 94 | 95 | /* 96 | * local filesystem 97 | */ 98 | 99 | BD_PRIVATE int file_path_exists(const char *path); 100 | BD_PRIVATE int file_mkdir(const char *dir); 101 | BD_PRIVATE int file_mkdirs(const char *path); 102 | 103 | #endif /* FILE_H_ */ 104 | -------------------------------------------------------------------------------- /src/libbdplus/bdplus_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifndef BDPLUS_CONFIG_H_INCLUDED 21 | #define BDPLUS_CONFIG_H_INCLUDED 22 | 23 | #include "util/attributes.h" 24 | 25 | #include "file/filesystem.h" 26 | 27 | #include 28 | 29 | 30 | #define MEM_TYPE_PSR (1<<1) 31 | #define MEM_TYPE_GPR (2<<1) 32 | 33 | typedef struct { 34 | /* mapped memory region for DiscoveryRAM trap */ 35 | uint32_t start_address; 36 | uint32_t size; 37 | const uint8_t *mem; 38 | 39 | /* housekeeping */ 40 | uint8_t type; /* allow shadowing of preloaded data with live data */ 41 | void *memory; /* preloaded data, should be freed at shutdown */ 42 | } bdplus_ram_area_t; 43 | 44 | typedef struct bdplus_ram_s { 45 | unsigned num_area; 46 | bdplus_ram_area_t *area; 47 | } bdplus_ram_t; 48 | 49 | 50 | typedef struct bdplus_dev_s { 51 | uint32_t size; 52 | uint8_t *mem; 53 | } bdplus_dev_t; 54 | 55 | #define MAX_DEV_DISCOVERY 5 56 | 57 | 58 | typedef struct bdplus_ecdsa_key_s { 59 | char d[41]; 60 | char Qx[41]; 61 | char Qy[41]; 62 | } bdplus_ecdsa_key_t; 63 | 64 | #define MAX_ECDSA_KEYS 4 65 | 66 | 67 | typedef struct bdplus_aes_key_s { 68 | char key[16]; 69 | } bdplus_aes_key_t; 70 | 71 | #define MAX_AES_KEYS 10 72 | 73 | 74 | typedef struct bdplus_config_s { 75 | void *fopen_handle; 76 | BDPLUS_FILE_OPEN fopen; 77 | 78 | bdplus_ram_t *ram; /* mapped player memory */ 79 | bdplus_dev_t *dev; 80 | bdplus_ecdsa_key_t *ecdsa_keys; 81 | bdplus_aes_key_t *aes_keys; 82 | 83 | int num_aes_keys; 84 | 85 | void *regs; 86 | uint32_t (*psr_read) (void *, int); 87 | int (*psr_write)(void *, int, uint32_t); 88 | 89 | } bdplus_config_t; 90 | 91 | BD_PRIVATE int bdplus_config_load(const char *config_path /* optional */, 92 | bdplus_config_t **config); 93 | BD_PRIVATE void bdplus_config_mmap(bdplus_ram_t *ram, uint32_t type, void *mem, uint32_t size); 94 | BD_PRIVATE void bdplus_config_free(bdplus_config_t **config); 95 | 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS=-I m4 2 | 3 | EXTRA_DIST=bootstrap COPYING README.md 4 | 5 | SET_FEATURES = @SET_FEATURES@ 6 | SET_INCLUDES = -I$(top_srcdir)/src -I$(top_builddir)/src/libbdplus 7 | 8 | AM_CFLAGS = -std=c99 $(SET_FEATURES) $(SET_INCLUDES) $(LIBGCRYPT_CFLAGS) $(GPG_ERROR_CFLAGS) 9 | 10 | lib_LTLIBRARIES = libbdplus.la 11 | libbdplus_la_SOURCES=\ 12 | src/libbdplus/bdplus.h \ 13 | src/libbdplus/internal.c \ 14 | src/libbdplus/bdplus.c \ 15 | src/libbdplus/bdplus_data.h \ 16 | src/libbdplus/internal.h \ 17 | src/libbdplus/bdplus_config.c \ 18 | src/libbdplus/bdplus_config.h \ 19 | src/libbdplus/bdsvm/diff.h \ 20 | src/libbdplus/bdsvm/event.c \ 21 | src/libbdplus/bdsvm/event.h \ 22 | src/libbdplus/bdsvm/loader.c \ 23 | src/libbdplus/bdsvm/loader.h \ 24 | src/libbdplus/bdsvm/segment.c \ 25 | src/libbdplus/bdsvm/trap_helper.c \ 26 | src/libbdplus/bdsvm/trap.c \ 27 | src/libbdplus/bdsvm/slot.h \ 28 | src/libbdplus/bdsvm/slot_data.h \ 29 | src/libbdplus/bdsvm/segment.h \ 30 | src/libbdplus/bdsvm/interface.h \ 31 | src/libbdplus/bdsvm/dlx.c \ 32 | src/libbdplus/bdsvm/interface.c \ 33 | src/libbdplus/bdsvm/dlx.h \ 34 | src/libbdplus/bdsvm/dlx_internal.h \ 35 | src/libbdplus/bdsvm/diff.c \ 36 | src/libbdplus/bdsvm/slot.c \ 37 | src/libbdplus/bdsvm/trap.h \ 38 | src/libbdplus/bdsvm/trap_helper.h \ 39 | src/libbdplus/bdsvm/sha1.h \ 40 | src/libbdplus/bdsvm/sha1.c \ 41 | src/file/dirs.h \ 42 | src/file/file.h \ 43 | src/file/file.c \ 44 | src/file/filesystem.h \ 45 | src/file/configfile.c \ 46 | src/file/configfile.h \ 47 | src/util/attributes.h \ 48 | src/util/macro.h \ 49 | src/util/mutex.h \ 50 | src/util/mutex.c \ 51 | src/util/strutl.c \ 52 | src/util/strutl.h \ 53 | src/util/logging.c \ 54 | src/util/logging.h 55 | 56 | if HAVE_DARWIN 57 | libbdplus_la_SOURCES+= \ 58 | src/file/dirs_darwin.c 59 | else 60 | if HAVE_WIN32 61 | libbdplus_la_SOURCES+= \ 62 | src/file/dirs_win32.c 63 | else 64 | libbdplus_la_SOURCES+= \ 65 | src/file/dirs_xdg.c 66 | endif 67 | endif 68 | 69 | if HAVE_WIN32 70 | libbdplus_la_SOURCES+= \ 71 | src/file/dir_win32.c \ 72 | src/file/file_win32.c 73 | else 74 | libbdplus_la_SOURCES+= \ 75 | src/file/dir_posix.c \ 76 | src/file/file_posix.c 77 | endif 78 | 79 | pkginclude_HEADERS = \ 80 | src/libbdplus/bdplus.h \ 81 | src/libbdplus/bdplus-version.h 82 | 83 | libbdplus_la_LDFLAGS= -no-undefined -version-info $(LT_VERSION_INFO) 84 | libbdplus_la_LIBADD = $(LIBGCRYPT_LIBS) $(GPG_ERROR_LIBS) 85 | pkgconfigdir = $(libdir)/pkgconfig 86 | pkgconfig_DATA = src/libbdplus.pc 87 | 88 | 89 | # 90 | # examples 91 | # 92 | 93 | noinst_PROGRAMS = bdplus_test convtab_dump 94 | 95 | bdplus_test_SOURCES = src/examples/bdplus_test.c 96 | bdplus_test_CFLAGS = $(AM_CFLAGS) $(LIBAACS_CFLAGS) 97 | bdplus_test_LDADD = libbdplus.la 98 | bdplus_test_LDADD += $(LIBAACS_LIBS) 99 | 100 | convtab_dump_SOURCES = src/examples/convtab_dump.c 101 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | ShiftMediaProject libbdplus 2 | ============= 3 | [![GitHub issues](https://img.shields.io/github/issues/ShiftMediaProject/libbdplus.svg)](https://github.com/ShiftMediaProject/libbdplus/issues) 4 | [![license](https://img.shields.io/github/license/ShiftMediaProject/libbdplus.svg)](https://github.com/ShiftMediaProject/libbdplus) 5 | [![donate](https://img.shields.io/badge/donate-link-brightgreen.svg)](https://shiftmediaproject.github.io/8-donate/) 6 | ## ShiftMediaProject 7 | 8 | Shift Media Project aims to provide native Windows development libraries for libbdplus and associated dependencies to support simpler creation and debugging of rich media content directly within Visual Studio. [https://shiftmediaproject.github.io/](https://shiftmediaproject.github.io/) 9 | 10 | ## libbdplus 11 | 12 | libbdplus is a research project to implement the BD+ System Specifications. This research project provides, through an open-source library, a way to understand how the BD+ works. [https://www.videolan.org/developers/libbdplus.html](https://www.videolan.org/developers/libbdplus.html) 13 | 14 | ## Code 15 | 16 | This repository contains code from the corresponding upstream project with additional modifications to allow it to be compiled with Visual Studio. New custom Visual Studio projects are provided within the 'SMP' sub-directory. Refer to the 'readme' contained within the 'SMP' directory for further details. 17 | 18 | ## Issues 19 | 20 | Any issues related to the ShiftMediaProject specific changes should be sent to the [issues](https://github.com/ShiftMediaProject/libbdplus/issues) page for the repository. Any issues related to the upstream project should be sent upstream directly (see the issues information of the upstream repository for more details). 21 | 22 | ## License 23 | 24 | ShiftMediaProject original code is released under [LGPLv2.1](https://www.gnu.org/licenses/lgpl-2.1.html). All code from the upstream repository remains under its original license (see the license information of the upstream repository for more details). 25 | 26 | ## Copyright 27 | 28 | As this repository includes code from upstream project(s) it includes many copyright owners. ShiftMediaProject makes NO claim of copyright on any upstream code. However, all original ShiftMediaProject authored code is copyright ShiftMediaProject. For a complete copyright list please checkout the source code to examine license headers. Unless expressly stated otherwise all code submitted to the ShiftMediaProject project (in any form) is licensed under [LGPLv2.1](https://www.gnu.org/licenses/lgpl-2.1.html) and copyright is donated to ShiftMediaProject. If you submit code that is not your own work it is your responsibility to place a header stating the copyright. 29 | 30 | ## Contributing 31 | 32 | Patches related to the ShiftMediaProject specific changes should be sent as pull requests to the main repository. Any changes related to the upstream project should be sent upstream directly (see the contributing information of the upstream repository for more details). -------------------------------------------------------------------------------- /src/util/strutl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "strutl.h" 26 | 27 | #include "macro.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | char *str_dup(const char *str) 35 | { 36 | char *dup = NULL; 37 | 38 | if (str) { 39 | size_t size = strlen(str) + 1; 40 | dup = malloc(size); 41 | if (dup) { 42 | memcpy(dup, str, size); 43 | } 44 | } 45 | return dup; 46 | } 47 | 48 | char *str_printf(const char *fmt, ...) 49 | { 50 | /* Guess we need no more than 100 bytes. */ 51 | va_list ap; 52 | int len; 53 | int size = 100; 54 | char *tmp, *str = NULL; 55 | 56 | while (1) { 57 | 58 | tmp = realloc(str, size); 59 | if (tmp == NULL) { 60 | X_FREE(str); 61 | return NULL; 62 | } 63 | str = tmp; 64 | 65 | /* Try to print in the allocated space. */ 66 | va_start(ap, fmt); 67 | len = vsnprintf(str, size, fmt, ap); 68 | va_end(ap); 69 | 70 | /* If that worked, return the string. */ 71 | if (len > -1 && len < size) { 72 | return str; 73 | } 74 | 75 | /* Else try again with more space. */ 76 | if (len > -1) /* glibc 2.1 */ 77 | size = len+1; /* precisely what is needed */ 78 | else /* glibc 2.0 */ 79 | size *= 2; /* twice the old size */ 80 | } 81 | } 82 | 83 | const char *str_next_line(const char *p) 84 | { 85 | while (*p && *p != '\r' && *p != '\n') { 86 | p++; 87 | } 88 | while (*p && (*p == '\r' || *p == '\n' || *p == ' ')) { 89 | p++; 90 | } 91 | 92 | return p; 93 | } 94 | 95 | const char *str_skip_white(const char *p) 96 | { 97 | while (*p && (*p == ' ' || *p == '\r' || *p == '\n' || *p == '\t')) { 98 | p++; 99 | } 100 | 101 | return p; 102 | } 103 | 104 | char *str_print_hex(char *out, const uint8_t *buf, int count) 105 | { 106 | int zz; 107 | for (zz = 0; zz < count; zz++) { 108 | sprintf(out + (zz * 2), "%02x", buf[zz]); 109 | } 110 | 111 | return out; 112 | } 113 | -------------------------------------------------------------------------------- /SMP/config.h: -------------------------------------------------------------------------------- 1 | 2 | /* Define to 1 if you have the declaration of `strerror_r', and to 0 if you 3 | don't. */ 4 | #define HAVE_DECL_STRERROR_R 0 5 | 6 | /* Define to 1 if you have the header file, and it defines `DIR'. 7 | */ 8 | /* #undef HAVE_DIRENT_H */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | /* #undef HAVE_DLFCN_H */ 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_ERRNO_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_INTTYPES_H 1 18 | 19 | /* Define to 1 to use libaacs with bdplus_test */ 20 | /* #undef HAVE_LIBAACS */ 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_LIBGEN_H 1 24 | 25 | /* Define to 1 if you have the gpg-error library */ 26 | #define HAVE_LIBGPG_ERROR 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | /* #undef HAVE_LINUX_CDROM_H */ 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_MALLOC_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_MEMORY_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | /* #undef HAVE_MNTENT_H */ 39 | 40 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 41 | /* #undef HAVE_NDIR_H */ 42 | 43 | /* Define to 1 if you have the header file. */ 44 | /* #undef HAVE_PTHREAD_H */ 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_STDARG_H 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_STDINT_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_STDLIB_H 1 54 | 55 | /* Define to 1 if you have the `strerror_r' function. */ 56 | /* #undef HAVE_STRERROR_R */ 57 | 58 | /* Define to 1 if you have the header file. */ 59 | /* #undef HAVE_STRINGS_H */ 60 | 61 | /* Define to 1 if you have the header file. */ 62 | #define HAVE_STRING_H 1 63 | 64 | /* Define to 1 if `d_type' is a member of `struct dirent'. */ 65 | /* #undef HAVE_STRUCT_DIRENT_D_TYPE */ 66 | 67 | /* Define to 1 if you have the header file, and it defines `DIR'. 68 | */ 69 | /* #undef HAVE_SYS_DIR_H */ 70 | 71 | /* Define to 1 if you have the header file, and it defines `DIR'. 72 | */ 73 | /* #undef HAVE_SYS_NDIR_H */ 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #define HAVE_SYS_STAT_H 1 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #define HAVE_SYS_TIME_H 1 80 | 81 | /* Define to 1 if you have the header file. */ 82 | #define HAVE_SYS_TYPES_H 1 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #define HAVE_TIME_H 1 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #define HAVE_UNISTD_H 1 89 | 90 | /* Define as the return type of signal handlers (`int' or `void'). */ 91 | #define RETSIGTYPE void 92 | 93 | /* Define to 1 if you have the ANSI C header files. */ 94 | #define STDC_HEADERS 1 95 | 96 | /* Define to 1 if strerror_r returns char *. */ 97 | /* #undef STRERROR_R_CHAR_P */ 98 | -------------------------------------------------------------------------------- /SMP/libbdplus_files.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/trap_helper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #include "trap_helper.h" 22 | 23 | #include "util/logging.h" 24 | 25 | #include 26 | #include 27 | 28 | static sha_t *_new_sha_ctx(uint8_t *dst) 29 | { 30 | sha_t *ctx = malloc(sizeof(sha_t)); 31 | if (!ctx) { 32 | BD_DEBUG(DBG_CRIT, "out of memory\n"); 33 | return NULL; 34 | } 35 | memset(ctx, 0, sizeof(sha_t)); 36 | ctx->dst = dst; 37 | return ctx; 38 | } 39 | 40 | /* 41 | Search for a context matching key 'dst'. 42 | If one does not exist, allocate memory for it 43 | and add it to the linked list ctx_head. 44 | */ 45 | sha_t *get_sha_ctx(sha_t **ctx_head, uint8_t *dst) { 46 | sha_t *ctx_curr, *ctx_new; 47 | 48 | /* empty list ? */ 49 | if (!*ctx_head) { 50 | *ctx_head = _new_sha_ctx(dst); 51 | return *ctx_head; 52 | } 53 | 54 | /* if the list has members, search it */ 55 | for (ctx_curr = *ctx_head; ctx_curr; ctx_curr = ctx_curr->next) { 56 | if (ctx_curr->dst == dst) return ctx_curr; 57 | if (!ctx_curr->next) break; 58 | } 59 | 60 | /* if the dst in question isn't found, allocate space for it */ 61 | ctx_new = _new_sha_ctx(dst); 62 | if (ctx_new) { 63 | ctx_curr->next = ctx_new; 64 | ctx_new->prev = ctx_curr; 65 | } 66 | return ctx_new; 67 | } 68 | 69 | /* 70 | Remove the passed member from the linked list; 71 | free sha 72 | */ 73 | int free_sha_ctx(sha_t **ctx_head, sha_t *sha) { 74 | sha_t *tmp1, *tmp2; 75 | 76 | /* free all */ 77 | if (!sha) { 78 | while (*ctx_head) { 79 | sha = *ctx_head; 80 | *ctx_head = sha->next; 81 | free(sha); 82 | } 83 | return 0; 84 | } 85 | 86 | if (!sha->prev && !sha->next) { 87 | /* we're at the list head and there is only one member */ 88 | free(sha); 89 | *ctx_head = NULL; 90 | } else if (!sha->prev && sha->next) { 91 | /* we're at the list head and there are additional members */ 92 | *ctx_head = sha->next; 93 | (*ctx_head)->prev = NULL; 94 | free(sha); 95 | } else if (sha->prev && sha->next) { 96 | /* we're somewhere in the middle of the list */ 97 | tmp1 = sha->prev; 98 | tmp2 = sha->next; 99 | tmp1->next = tmp2; 100 | tmp2->prev = tmp1; 101 | free(sha); 102 | } 103 | else { 104 | /* we're at the end of the list */ 105 | tmp1 = sha->prev; 106 | tmp1->next = NULL; 107 | free(sha); 108 | } 109 | return 0; 110 | } 111 | 112 | /* END: trap_Sha */ 113 | -------------------------------------------------------------------------------- /src/file/dir_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2009-2010 John Stebbins 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #if HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "file.h" 25 | #include "util/macro.h" 26 | #include "util/logging.h" 27 | #include "util/strutl.h" 28 | 29 | #include 30 | #include 31 | #if defined(HAVE_DIRENT_H) 32 | # include 33 | #endif 34 | 35 | #if defined(__GLIBC__) && defined(__GLIBC_MINOR__) 36 | # if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 24) 37 | # define USE_READDIR 38 | # include 39 | # endif 40 | #endif 41 | 42 | static void _dir_close_posix(BD_DIR_H *dir) 43 | { 44 | if (dir) { 45 | closedir((DIR *)dir->internal); 46 | 47 | BD_DEBUG(DBG_DIR, "Closed POSIX dir (%p)\n", (void*)dir); 48 | 49 | X_FREE(dir); 50 | } 51 | } 52 | 53 | static void _error(const char *msg, int errnum, void *dir) 54 | { 55 | char buf[128]; 56 | if (strerror_r(errnum, buf, sizeof(buf))) { 57 | strcpy(buf, "?"); 58 | } 59 | BD_DEBUG(DBG_DIR | DBG_CRIT, "%s: %d %s (%p)\n", msg, errnum, buf, dir); 60 | } 61 | 62 | static int _dir_read_posix(BD_DIR_H *dir, BD_DIRENT *entry) 63 | { 64 | struct dirent *p_e; 65 | 66 | #ifdef USE_READDIR 67 | errno = 0; 68 | p_e = readdir((DIR*)dir->internal); 69 | if (!p_e && errno) { 70 | _error("Error reading directory", errno, dir); 71 | return -1; 72 | } 73 | #else /* USE_READDIR */ 74 | int result; 75 | struct dirent e; 76 | 77 | result = readdir_r((DIR*)dir->internal, &e, &p_e); 78 | if (result) { 79 | _error("Error reading directory", result, dir); 80 | return -result; 81 | } 82 | #endif /* USE_READDIR */ 83 | 84 | if (p_e == NULL) { 85 | return 1; 86 | } 87 | strncpy(entry->d_name, p_e->d_name, sizeof(entry->d_name)); 88 | entry->d_name[sizeof(entry->d_name) - 1] = 0; 89 | 90 | return 0; 91 | } 92 | 93 | static BD_DIR_H *_dir_open_posix(const char* dirname) 94 | { 95 | BD_DIR_H *dir = calloc(1, sizeof(BD_DIR_H)); 96 | 97 | if (!dir) { 98 | return NULL; 99 | } 100 | 101 | dir->close = _dir_close_posix; 102 | dir->read = _dir_read_posix; 103 | 104 | if ((dir->internal = opendir(dirname))) { 105 | BD_DEBUG(DBG_DIR, "Opened POSIX dir %s (%p)\n", dirname, (void*)dir); 106 | return dir; 107 | } 108 | 109 | BD_DEBUG(DBG_DIR, "Error opening dir %s\n", dirname); 110 | 111 | X_FREE(dir); 112 | 113 | return NULL; 114 | } 115 | 116 | BD_DIR_OPEN dir_open_default(void) 117 | { 118 | return _dir_open_posix; 119 | } 120 | -------------------------------------------------------------------------------- /src/file/dirs_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2011 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | #include "dirs.h" 25 | 26 | #include "util/logging.h" 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | int win32_mkdir(const char *dir) 37 | { 38 | wchar_t wdir[MAX_PATH]; 39 | 40 | MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH); 41 | 42 | if (!CreateDirectoryW(wdir, NULL)) 43 | return -1; 44 | return 0; 45 | } 46 | 47 | char *file_get_config_home(void) 48 | { 49 | return file_get_data_home(); 50 | } 51 | 52 | char *file_get_data_home(void) 53 | { 54 | wchar_t wdir[MAX_PATH]; 55 | 56 | # if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) 57 | /* Get the "Application Data" folder for the user */ 58 | if (S_OK == SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, 59 | NULL, SHGFP_TYPE_CURRENT, wdir)) { 60 | int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL); 61 | char *appdir = malloc(len); 62 | if (appdir) { 63 | WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL); 64 | } 65 | return appdir; 66 | } 67 | #endif 68 | 69 | BD_DEBUG(DBG_FILE, "Can't find user configuration directory !\n"); 70 | return NULL; 71 | } 72 | 73 | char *file_get_cache_home(void) 74 | { 75 | return file_get_data_home(); 76 | } 77 | 78 | const char *file_get_config_system(const char *dir) 79 | { 80 | static char *appdir = NULL; 81 | wchar_t wdir[MAX_PATH]; 82 | 83 | if (!dir) { 84 | // first call 85 | 86 | if (appdir) 87 | return appdir; 88 | 89 | # if !defined(WINAPI_FAMILY) || !(WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP) 90 | /* Get the "Application Data" folder for all users */ 91 | if (S_OK == SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, 92 | NULL, SHGFP_TYPE_CURRENT, wdir)) { 93 | int len = WideCharToMultiByte (CP_UTF8, 0, wdir, -1, NULL, 0, NULL, NULL); 94 | appdir = malloc(len); 95 | if (appdir) { 96 | WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, len, NULL, NULL); 97 | } 98 | return appdir; 99 | } else 100 | #endif 101 | { 102 | BD_DEBUG(DBG_FILE, "Can't find common configuration directory !\n"); 103 | return NULL; 104 | } 105 | } else { 106 | // next call 107 | return NULL; 108 | } 109 | 110 | return dir; 111 | } 112 | -------------------------------------------------------------------------------- /SMP/sys/stat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MSVC sys/stat.h compatibility header. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SMP_SYS_STAT_H 24 | #define SMP_SYS_STAT_H 25 | 26 | #ifndef _MSC_VER 27 | # include_next 28 | #else 29 | 30 | #include 31 | #if _VC_CRT_MAJOR_VERSION >= 14 32 | # include <../ucrt/sys/stat.h> 33 | #else 34 | # include <../include/sys/stat.h> 35 | #endif 36 | 37 | #ifndef S_ISBLK 38 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 39 | #endif 40 | 41 | #ifndef S_ISFIFO 42 | #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) 43 | #endif 44 | 45 | #ifndef S_ISCHR 46 | #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 47 | #endif 48 | 49 | #ifndef S_ISDIR 50 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 51 | #endif 52 | 53 | #ifndef S_ISREG 54 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 55 | #endif 56 | 57 | #ifndef S_ISLNK 58 | #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 59 | #endif 60 | 61 | #ifndef S_ISSOCK 62 | #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 63 | #endif 64 | 65 | #define _S_ISUID 0004000 66 | #define _S_ISGID 0002000 67 | #define _S_ISVTX 0001000 68 | 69 | #define S_ISUID _S_ISUID 70 | #define S_ISGID _S_ISGID 71 | #define S_ISVTX _S_ISVTX 72 | 73 | #define _S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) 74 | #define _S_IXUSR _S_IEXEC 75 | #define _S_IWUSR _S_IWRITE 76 | #define _S_IRUSR _S_IREAD 77 | #define _S_IRWXG (_S_IRWXU >> 3) 78 | #define _S_IXGRP (_S_IXUSR >> 3) 79 | #define _S_IWGRP (_S_IWUSR >> 3) 80 | #define _S_IRGRP (_S_IRUSR >> 3) 81 | #define _S_IRWXO (_S_IRWXG >> 3) 82 | #define _S_IXOTH (_S_IXGRP >> 3) 83 | #define _S_IWOTH (_S_IWGRP >> 3) 84 | #define _S_IROTH (_S_IRGRP >> 3) 85 | 86 | #ifndef S_IRWXU 87 | #define S_IRWXU _S_IRWXU 88 | #define S_IXUSR _S_IXUSR 89 | #define S_IWUSR _S_IWUSR 90 | #define S_IRUSR _S_IRUSR 91 | #endif 92 | #define S_IRWXG _S_IRWXG 93 | #define S_IXGRP _S_IXGRP 94 | #define S_IWGRP _S_IWGRP 95 | #define S_IRGRP _S_IRGRP 96 | #define S_IRWXO _S_IRWXO 97 | #define S_IXOTH _S_IXOTH 98 | #define S_IWOTH _S_IWOTH 99 | #define S_IROTH _S_IROTH 100 | 101 | #endif /* _MSC_VER */ 102 | 103 | #endif /* SMP_SYS_STAT_H */ -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/trap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef TRAP_H_INCLUDED 22 | #define TRAP_H_INCLUDED 23 | 24 | #include 25 | 26 | #include "util/attributes.h" 27 | 28 | struct bdplus_config_s; 29 | struct sha_s; 30 | 31 | #define STATUS_OK 0x00000000 32 | #define STATUS_INVALID_PARAMETER 0x80000001 33 | #define STATUS_NOT_SUPPORTED 0x80000002 34 | #define STATUS_INTERNAL_ERROR 0x80FFFFFF 35 | 36 | #define SHA_UPDATE 0x00000000 37 | #define SHA_INIT 0x00000001 38 | #define SHA_FINAL 0x00000002 39 | #define SHA_BLOCK 0x00000003 40 | 41 | #define SHA_BLOCK_SIZE 0x200 42 | #define SHA_DIGEST_LENGTH 20 43 | 44 | #ifndef MIN 45 | #define MIN(X, Y) ((X) <= (Y) ? (X) : (Y)) 46 | #endif 47 | 48 | BD_PRIVATE uint32_t TRAP_Finished ( void ); 49 | BD_PRIVATE uint32_t TRAP_FixUpTableSend ( uint32_t ); 50 | 51 | BD_PRIVATE uint32_t TRAP_Aes ( struct bdplus_config_s *, uint8_t *, uint8_t *, uint32_t, 52 | const uint8_t *, uint32_t, const uint8_t * ); 53 | BD_PRIVATE uint32_t TRAP_PrivateKey ( struct bdplus_config_s *, uint32_t, uint8_t *, uint8_t *, uint32_t, uint32_t ); 54 | BD_PRIVATE uint32_t TRAP_Random ( uint8_t *, uint32_t ); 55 | BD_PRIVATE uint32_t TRAP_Sha1 ( struct sha_s **, uint8_t *, uint8_t *, uint32_t, uint32_t ); 56 | 57 | BD_PRIVATE uint32_t TRAP_AddWithCarry ( uint32_t *, uint32_t *, uint32_t ); 58 | BD_PRIVATE uint32_t TRAP_MultiplyWithCarry ( uint32_t *, uint32_t *, uint32_t, uint32_t ); 59 | BD_PRIVATE uint32_t TRAP_XorBlock ( uint32_t *, uint32_t *, uint32_t ); 60 | 61 | BD_PRIVATE uint32_t TRAP_Memmove ( uint8_t *, uint8_t *, uint32_t ); 62 | BD_PRIVATE uint32_t TRAP_MemSearch ( uint8_t *, uint32_t, uint8_t *, uint32_t, uint32_t * ); 63 | BD_PRIVATE uint32_t TRAP_Memset ( uint8_t *, uint8_t, uint32_t ); 64 | 65 | // trap slot* is in slot.c 66 | 67 | BD_PRIVATE uint32_t TRAP_ApplicationLayer ( struct bdplus_config_s *, uint32_t, uint32_t, uint32_t * ); 68 | BD_PRIVATE uint32_t TRAP_Discovery ( struct bdplus_config_s *, uint32_t, uint32_t, uint8_t *, uint32_t *, uint8_t * ); 69 | BD_PRIVATE uint32_t TRAP_DiscoveryRAM ( struct bdplus_config_s *, uint32_t, uint8_t *, uint32_t ); // NS! 70 | BD_PRIVATE uint32_t TRAP_LoadContentCode ( struct bdplus_config_s *, uint8_t *, uint32_t, uint32_t, uint32_t *, uint8_t * ); 71 | BD_PRIVATE uint32_t TRAP_MediaCheck ( struct bdplus_config_s *, uint8_t *, uint32_t, uint32_t, uint32_t, uint32_t *, uint8_t * ); 72 | BD_PRIVATE uint32_t TRAP_RunNative ( ); 73 | BD_PRIVATE uint32_t TRAP_000570 ( /* ? nop/vendor specific?*/ ); 74 | 75 | BD_PRIVATE uint32_t TRAP_DebugLog ( uint8_t *, uint32_t ); 76 | BD_PRIVATE uint32_t TRAP_008020 ( ); 77 | BD_PRIVATE uint32_t TRAP_008030 ( ); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/file/dir_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2009-2010 John Stebbins 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #if HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "file.h" 25 | #include "util/macro.h" 26 | #include "util/logging.h" 27 | #include "util/strutl.h" 28 | 29 | #include 30 | #include 31 | #if defined(HAVE_DIRENT_H) 32 | # include 33 | #endif 34 | 35 | #include 36 | #include 37 | 38 | 39 | typedef struct { 40 | intptr_t handle; 41 | struct _wfinddata_t info; 42 | } dir_data_t; 43 | 44 | static void _dir_close_win32(BD_DIR_H *dir) 45 | { 46 | if (dir) { 47 | dir_data_t *priv = (dir_data_t*)dir->internal; 48 | 49 | _findclose(priv->handle); 50 | 51 | BD_DEBUG(DBG_DIR, "Closed WIN32 dir (%p)\n", (void*)dir); 52 | 53 | X_FREE(dir->internal); 54 | X_FREE(dir); 55 | } 56 | } 57 | 58 | static int _dir_read_win32(BD_DIR_H *dir, BD_DIRENT *entry) 59 | { 60 | dir_data_t *priv = (dir_data_t*)dir->internal; 61 | 62 | if (!priv->info.name[0]) { 63 | return 1; 64 | } 65 | if (!WideCharToMultiByte(CP_UTF8, 0, priv->info.name, -1, entry->d_name, sizeof(entry->d_name), NULL, NULL)) { 66 | return -1; 67 | } 68 | 69 | priv->info.name[0] = 0; 70 | _wfindnext(priv->handle, &priv->info); 71 | 72 | return 0; 73 | } 74 | 75 | static dir_data_t *_open_impl(const char *dirname) 76 | { 77 | dir_data_t *priv; 78 | char *filespec; 79 | wchar_t wfilespec[MAX_PATH]; 80 | int result; 81 | 82 | filespec = str_printf("%s" DIR_SEP "*", dirname); 83 | if (!filespec) { 84 | return NULL; 85 | } 86 | 87 | result = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filespec, -1, wfilespec, MAX_PATH); 88 | X_FREE(filespec); 89 | if (!result) { 90 | return NULL; 91 | } 92 | 93 | priv = calloc(1, sizeof(dir_data_t)); 94 | if (!priv) { 95 | return NULL; 96 | } 97 | 98 | priv->handle = _wfindfirst(wfilespec, &priv->info); 99 | if (priv->handle == -1) { 100 | X_FREE(priv); 101 | } 102 | 103 | return priv; 104 | } 105 | 106 | static BD_DIR_H *_dir_open_win32(const char* dirname) 107 | { 108 | BD_DIR_H *dir = calloc(1, sizeof(BD_DIR_H)); 109 | dir_data_t *priv = NULL; 110 | 111 | if (!dir) { 112 | return NULL; 113 | } 114 | 115 | priv = _open_impl(dirname); 116 | if (priv) { 117 | BD_DEBUG(DBG_DIR, "Opened WIN32 dir %s (%p)\n", dirname, (void*)dir); 118 | dir->close = _dir_close_win32; 119 | dir->read = _dir_read_win32; 120 | dir->internal = priv; 121 | 122 | return dir; 123 | } 124 | 125 | BD_DEBUG(DBG_DIR, "Error opening dir %s\n", dirname); 126 | X_FREE(dir); 127 | 128 | return NULL; 129 | } 130 | 131 | BD_DIR_OPEN dir_open_default(void) 132 | { 133 | return _dir_open_win32; 134 | } 135 | -------------------------------------------------------------------------------- /src/file/dirs_xdg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2013 Petri Hintukainen 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | #include "dirs.h" 25 | 26 | #include "util/strutl.h" 27 | #include "util/logging.h" 28 | 29 | #include 30 | #include 31 | 32 | /* 33 | * Based on XDG Base Directory Specification 34 | * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html 35 | */ 36 | 37 | #define USER_CFG_DIR ".config" 38 | #define USER_CACHE_DIR ".cache" 39 | #define USER_DATA_DIR ".local/share" 40 | #define SYSTEM_CFG_DIR "/etc/xdg" 41 | 42 | 43 | char *file_get_config_home(void) 44 | { 45 | const char *xdg_home = getenv("XDG_CONFIG_HOME"); 46 | if (xdg_home && *xdg_home) { 47 | return str_dup(xdg_home); 48 | } 49 | 50 | const char *user_home = getenv("HOME"); 51 | if (user_home && *user_home) { 52 | return str_printf("%s/%s", user_home, USER_CFG_DIR); 53 | } 54 | 55 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 56 | return NULL; 57 | } 58 | 59 | char *file_get_data_home(void) 60 | { 61 | const char *xdg_home = getenv("XDG_DATA_HOME"); 62 | if (xdg_home && *xdg_home) { 63 | return str_dup(xdg_home); 64 | } 65 | 66 | const char *user_home = getenv("HOME"); 67 | if (user_home && *user_home) { 68 | return str_printf("%s/%s", user_home, USER_DATA_DIR); 69 | } 70 | 71 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 72 | return NULL; 73 | } 74 | 75 | char *file_get_cache_home(void) 76 | { 77 | const char *xdg_cache = getenv("XDG_CACHE_HOME"); 78 | if (xdg_cache && *xdg_cache) { 79 | return str_dup(xdg_cache); 80 | } 81 | 82 | const char *user_home = getenv("HOME"); 83 | if (user_home && *user_home) { 84 | return str_printf("%s/%s", user_home, USER_CACHE_DIR); 85 | } 86 | 87 | BD_DEBUG(DBG_FILE, "Can't find user home directory ($HOME) !\n"); 88 | return NULL; 89 | } 90 | 91 | const char *file_get_config_system(const char *dir) 92 | { 93 | static char *dirs = NULL; // "dir1\0dir2\0...\0dirN\0\0" 94 | 95 | if (!dirs) { 96 | const char *xdg_sys = getenv("XDG_CONFIG_DIRS"); 97 | 98 | if (xdg_sys && *xdg_sys) { 99 | 100 | dirs = calloc(1, strlen(xdg_sys) + 2); 101 | if (!dirs) { 102 | return NULL; 103 | } 104 | strcpy(dirs, xdg_sys); 105 | 106 | char *pt = dirs; 107 | while (NULL != (pt = strchr(pt, ':'))) { 108 | *pt++ = 0; 109 | } 110 | 111 | } else { 112 | dirs = str_printf("%s%c%c", SYSTEM_CFG_DIR, 0, 0); 113 | } 114 | } 115 | 116 | if (!dir) { 117 | // first call 118 | dir = dirs; 119 | } else { 120 | // next call 121 | dir += strlen(dir) + 1; 122 | if (!*dir) { 123 | // end of list 124 | dir = NULL; 125 | } 126 | } 127 | 128 | return dir; 129 | } 130 | -------------------------------------------------------------------------------- /src/util/macro.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2009-2010 Obliter0n 4 | * Copyright (C) 2009-2010 John Stebbins 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef MACRO_H_ 22 | #define MACRO_H_ 23 | 24 | #include /* free() */ 25 | 26 | #define MKINT_BE16(X) ( (X)[0] << 8 | (X)[1] ) 27 | #define MKINT_BE24(X) ( (X)[0] << 16 | (X)[1] << 8 | (X)[2] ) 28 | #define MKINT_BE32(X) ( (unsigned)((X)[0]) << 24 | (X)[1] << 16 | (X)[2] << 8 | (X)[3] ) 29 | #define X_FREE(X) ( free(X), X = NULL ) 30 | 31 | #define BD_MIN(a,b) ((a)<(b)?(a):(b)) 32 | #define BD_MAX(a,b) ((a)>(b)?(a):(b)) 33 | 34 | /* 35 | * 36 | */ 37 | 38 | // endian safe fetch 39 | 40 | //#define FETCH4(X) (uint32_t)(((uint32_t)(X)[0]<<24)|(X)[1]<<16|(X)[2]<<8|(X)[3]) 41 | static inline uint32_t FETCH4(const void *pv) { 42 | const uint8_t *p = pv; 43 | return (uint32_t)p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; 44 | } 45 | 46 | //#define FETCHU2(X) (uint32_t)((uint16_t)(((X)[0]<<8)|(X)[1])) 47 | static inline uint32_t FETCHU2(const void *pv) { 48 | const uint8_t *p = pv; 49 | return (uint32_t)p[0] << 8 | p[1]; 50 | } 51 | 52 | // Sign extended version 53 | //#define FETCHS2(X) (int32_t)((int16_t)(((X)[0]<<8)|(X)[1])) 54 | static inline int32_t FETCHS2(const void *pv) { 55 | return (int32_t)(int16_t)FETCHU2(pv); 56 | } 57 | 58 | //#define STORE2(X, Y) (X)[1]=(((Y))&0xff);(X)[0]=(((Y)>>8)&0xff); 59 | static inline void STORE2(void *pv, uint32_t v) { 60 | uint8_t *p = pv; 61 | p[1] = v; 62 | p[0] = v >> 8; 63 | } 64 | //#define STORE4(X, Y) (X)[3]=((Y)&0xff);(X)[2]=(((Y)>>8)&0xff);(X)[1]=(((Y)>>16)&0xff);(X)[0]=(((Y)>>24)&0xff); 65 | static inline void STORE4(void *pv, uint32_t v) { 66 | uint8_t *p = pv; 67 | STORE2(p + 2, v); 68 | STORE2(p, v >> 16); 69 | } 70 | //#define STORE8(X, Y) (X)[7]=((Y)&0xff);(X)[6]=(((Y)>>8)&0xff);(X)[5]=(((Y)>>16)&0xff);(X)[4]=(((Y)>>24)&0xff);(X)[3]=(((Y)>>32)&0xff);(X)[2]=(((Y)>>40)&0xff);(X)[1]=(((Y)>>48)&0xff);(X)[0]=(((Y)>>56)&0xff); 71 | static inline void STORE8(void *pv, uint64_t v) { 72 | uint8_t *p = pv; 73 | STORE4(p + 4, v); 74 | STORE4(p, v >> 32); 75 | } 76 | 77 | #define BD_MAX_SSIZE ((int64_t)(((size_t)-1)>>1)) 78 | 79 | /* 80 | * automatic cast from void* (malloc/calloc/realloc) 81 | */ 82 | 83 | #ifdef __cplusplus 84 | 85 | template 86 | class auto_cast_wrapper 87 | { 88 | public: 89 | template friend auto_cast_wrapper auto_cast(const R& x); 90 | template operator U() { return static_cast(p); } 91 | 92 | private: 93 | auto_cast_wrapper(const T& x) : p(x) {} 94 | auto_cast_wrapper(const auto_cast_wrapper& o) : p(o.p) {} 95 | 96 | auto_cast_wrapper& operator=(const auto_cast_wrapper&); 97 | 98 | const T& p; 99 | }; 100 | 101 | template 102 | auto_cast_wrapper auto_cast(const R& x) 103 | { 104 | return auto_cast_wrapper(x); 105 | } 106 | 107 | # define calloc(n,s) auto_cast(calloc(n,s)) 108 | # define malloc(s) auto_cast(malloc(s)) 109 | # define realloc(p,s) auto_cast(realloc(p,s)) 110 | # define refcnt_realloc(p,s) auto_cast(refcnt_realloc(p,s)) 111 | #endif /* __cplusplus */ 112 | 113 | 114 | #endif /* MACRO_H_ */ 115 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - build 3 | 4 | variables: 5 | GIT_SUBMODULE_STRATEGY: normal 6 | 7 | build-debian: 8 | image: registry.videolan.org/vlc-debian-unstable:20200529132440 9 | stage: build 10 | tags: 11 | - docker 12 | - amd64 13 | script: 14 | - ./bootstrap 15 | - mkdir build 16 | - cd build 17 | - ../configure --without-libaacs 18 | - make -j $(getconf _NPROCESSORS_ONLN) 19 | 20 | build-macos: 21 | stage: build 22 | tags: 23 | - catalina 24 | - amd64 25 | script: 26 | - curl -sS -O https://artifacts.videolan.org/vlc/macos-x86_64/vlc-contrib-x86_64-apple-darwin19-58c8b6aba888c666612e91d1cbb012aea630c853.tar.bz2 27 | - tar xf vlc-contrib-x86_64-apple-darwin19-58c8b6aba888c666612e91d1cbb012aea630c853.tar.bz2 28 | - cd x86_64-apple-darwin19 29 | - curl -sS -o ./change_prefix.sh 'https://git.videolan.org/?p=vlc.git;a=blob_plain;f=contrib/src/change_prefix.sh;hb=HEAD' 30 | - chmod +x ./change_prefix.sh 31 | - ./change_prefix.sh 32 | - export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`pwd -P`/lib/pkgconfig/" 33 | - export PATH="$PATH:`pwd -P`/bin/" 34 | - cd ../ 35 | - ./bootstrap 36 | - mkdir build 37 | - cd build 38 | - ../configure --without-libaacs 39 | - make -j $(getconf _NPROCESSORS_ONLN) 40 | - make install DESTDIR=`pwd`/artifacts 41 | artifacts: 42 | name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" 43 | paths: 44 | - build/artifacts/ 45 | expire_in: 1 week 46 | 47 | build-win64: 48 | image: registry.videolan.org/vlc-debian-win64:20201106143728 49 | stage: build 50 | tags: 51 | - docker 52 | - amd64 53 | script: 54 | - wget -nv https://artifacts.videolan.org/vlc/win64/vlc-contrib-x86_64-w64-mingw32-45c21cd73727ddcd1af843a34dc4ca8648cc872c.tar.bz2 55 | - tar xf vlc-contrib-x86_64-w64-mingw32-45c21cd73727ddcd1af843a34dc4ca8648cc872c.tar.bz2 56 | - cd x86_64-w64-mingw32 57 | - wget -nv -O ./change_prefix.sh 'https://git.videolan.org/?p=vlc.git;a=blob_plain;f=contrib/src/change_prefix.sh;hb=HEAD' 58 | - chmod +x ./change_prefix.sh 59 | - ./change_prefix.sh 60 | - cd .. 61 | - export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`realpath x86_64-w64-mingw32`/lib/pkgconfig/" 62 | - export PATH="$PATH:`realpath x86_64-w64-mingw32`/bin/" 63 | - ./bootstrap 64 | - mkdir build 65 | - cd build 66 | - ../configure --host=x86_64-w64-mingw32 --without-libaacs 67 | - make -j $(getconf _NPROCESSORS_ONLN) 68 | - make install DESTDIR=`pwd`/artifacts 69 | artifacts: 70 | name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" 71 | paths: 72 | - build/artifacts/ 73 | expire_in: 1 week 74 | 75 | build-win32: 76 | image: registry.videolan.org/vlc-debian-win32:20201106141924 77 | stage: build 78 | tags: 79 | - docker 80 | - amd64 81 | script: 82 | - wget -nv https://artifacts.videolan.org/vlc/win32/vlc-contrib-i686-w64-mingw32-45c21cd73727ddcd1af843a34dc4ca8648cc872c.tar.bz2 83 | - tar xf vlc-contrib-i686-w64-mingw32-45c21cd73727ddcd1af843a34dc4ca8648cc872c.tar.bz2 84 | - cd i686-w64-mingw32 85 | - wget -nv -O ./change_prefix.sh 'https://git.videolan.org/?p=vlc.git;a=blob_plain;f=contrib/src/change_prefix.sh;hb=HEAD' 86 | - chmod +x ./change_prefix.sh 87 | - ./change_prefix.sh 88 | - cd .. 89 | - export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:`realpath i686-w64-mingw32`/lib/pkgconfig/" 90 | - export PATH="$PATH:`realpath i686-w64-mingw32`/bin/" 91 | - ./bootstrap 92 | - mkdir build 93 | - cd build 94 | - ../configure --host=i686-w64-mingw32 --without-libaacs 95 | - make -j $(getconf _NPROCESSORS_ONLN) 96 | - make install DESTDIR=`pwd`/artifacts 97 | artifacts: 98 | name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" 99 | paths: 100 | - build/artifacts/ 101 | expire_in: 1 week 102 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | This project provides additional functionality beyond what is provided by the project that it is based off. 4 | Ensure that any issues/pull requests submitted to this project are only for functionality that was provided by 5 | this project. Any issues/pull requests that are based off of the upstream project should be directed directly to them. 6 | 7 | When contributing a pull-request to this repository, please first discuss the change you wish to make via issue 8 | with the owners of this repository before making a change. Ensure that the change is only related to functionality 9 | provided by this project only. 10 | 11 | Please note we have a code of conduct, please follow it in all your interactions with the project. 12 | 13 | ## Submitting Changes 14 | 15 | Changes are excepted by submitting a pull request directly to the projects Github page. 16 | When creating the pull request the provided template should be used to ensure all required information is provided. 17 | 18 | ## Code of Conduct 19 | 20 | ### Our Pledge 21 | 22 | In the interest of fostering an open and welcoming environment, we as 23 | contributors and maintainers pledge to making participation in our project and 24 | our community a harassment-free experience for everyone, regardless of age, body 25 | size, disability, ethnicity, gender identity and expression, level of experience, 26 | nationality, personal appearance, race, religion, or sexual identity and 27 | orientation. 28 | 29 | ### Our Standards 30 | 31 | Examples of behavior that contributes to creating a positive environment 32 | include: 33 | 34 | * Using welcoming and inclusive language 35 | * Being respectful of differing viewpoints and experiences 36 | * Gracefully accepting constructive criticism 37 | * Focusing on what is best for the community 38 | * Showing empathy towards other community members 39 | 40 | Examples of unacceptable behavior by participants include: 41 | 42 | * The use of sexualized language or imagery and unwelcome sexual attention or 43 | advances 44 | * Trolling, insulting/derogatory comments, and personal or political attacks 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate in a 49 | professional setting 50 | 51 | ### Our Responsibilities 52 | 53 | Project maintainers are responsible for clarifying the standards of acceptable 54 | behavior and are expected to take appropriate and fair corrective action in 55 | response to any instances of unacceptable behavior. 56 | 57 | Project maintainers have the right and responsibility to remove, edit, or 58 | reject comments, commits, code, wiki edits, issues, and other contributions 59 | that are not aligned to this Code of Conduct, or to ban temporarily or 60 | permanently any contributor for other behaviors that they deem inappropriate, 61 | threatening, offensive, or harmful. 62 | 63 | ### Scope 64 | 65 | This Code of Conduct applies both within project spaces and in public spaces 66 | when an individual is representing the project or its community. Examples of 67 | representing a project or community include using an official project e-mail 68 | address, posting via an official social media account, or acting as an appointed 69 | representative at an online or offline event. Representation of a project may be 70 | further defined and clarified by project maintainers. 71 | 72 | ### Enforcement 73 | 74 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 75 | reported by contacting the project team. All 76 | complaints will be reviewed and investigated and will result in a response that 77 | is deemed necessary and appropriate to the circumstances. The project team is 78 | obligated to maintain confidentiality with regard to the reporter of an incident. 79 | Further details of specific enforcement policies may be posted separately. 80 | 81 | Project maintainers who do not follow or enforce the Code of Conduct in good 82 | faith may face temporary or permanent repercussions as determined by other 83 | members of the project's leadership. 84 | 85 | ### Attribution 86 | 87 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 88 | available at [http://contributor-covenant.org/version/1/4][version] 89 | 90 | [homepage]: http://contributor-covenant.org 91 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /src/file/configfile.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | #include "configfile.h" 25 | 26 | #include "file.h" 27 | #include "dirs.h" 28 | #include "util/logging.h" 29 | #include "util/macro.h" 30 | #include "util/strutl.h" 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #define MIN_FILE_SIZE 1 38 | #define MAX_FILE_SIZE 0xffffff 39 | 40 | 41 | char *file_get_cache_dir(void) 42 | { 43 | char *cache = file_get_cache_home(); 44 | char *dir; 45 | 46 | if (!cache) { 47 | return NULL; 48 | } 49 | 50 | dir = str_printf("%s/%s/", cache, BDPLUS_DIR); 51 | X_FREE(cache); 52 | file_mkdirs(dir); 53 | 54 | return dir; 55 | } 56 | 57 | static char *_probe_config_dir(const char *base, const char *vm, const char *file) 58 | { 59 | char *dir = str_printf("%s/%s/%s/%s", base, BDPLUS_DIR, vm, file); 60 | BDPLUS_FILE_H *fp; 61 | 62 | if (!dir) { 63 | return NULL; 64 | } 65 | 66 | fp = file_open_default()(NULL, dir); 67 | 68 | if (fp) { 69 | file_close(fp); 70 | *(strrchr(dir, '/') + 1) = 0; 71 | BD_DEBUG(DBG_BDPLUS, "Found VM config from %s\n", dir); 72 | return dir; 73 | } 74 | 75 | BD_DEBUG(DBG_BDPLUS, "VM config not found from %s\n", dir); 76 | free(dir); 77 | return NULL; 78 | } 79 | 80 | char *file_get_config_dir(const char *file) 81 | { 82 | char *dir = NULL; 83 | const char *vm; 84 | char *config_home; 85 | const char *base; 86 | 87 | vm = getenv("BDPLUS_VM_ID"); 88 | if (!vm) { 89 | vm = "vm0"; 90 | } 91 | 92 | /* try home directory */ 93 | config_home = file_get_config_home(); 94 | if (!config_home) { 95 | return NULL; 96 | } 97 | dir = _probe_config_dir(config_home, vm, file); 98 | X_FREE(config_home); 99 | if (dir) { 100 | return dir; 101 | } 102 | 103 | /* try system config dirs */ 104 | base = file_get_config_system(NULL); 105 | while (base) { 106 | dir = _probe_config_dir(base, vm, file); 107 | if (dir) { 108 | return dir; 109 | } 110 | base = file_get_config_system(base); 111 | } 112 | 113 | return NULL; 114 | } 115 | 116 | static char *_load_fp(BDPLUS_FILE_H *fp, uint32_t *p_size) 117 | { 118 | char *data = NULL; 119 | int64_t size, read_size; 120 | 121 | size = file_size(fp); 122 | 123 | if (size < MIN_FILE_SIZE || size > MAX_FILE_SIZE) { 124 | BD_DEBUG(DBG_FILE, "Invalid file size\n"); 125 | return NULL; 126 | } 127 | 128 | data = malloc(size + 1); 129 | if (!data) { 130 | BD_DEBUG(DBG_FILE, "Out of memory\n"); 131 | return NULL; 132 | } 133 | 134 | read_size = file_read(fp, (void *)data, size); 135 | 136 | if (read_size != size) { 137 | BD_DEBUG(DBG_FILE, "Error reading file\n"); 138 | free(data); 139 | return NULL; 140 | } 141 | 142 | data[size] = 0; 143 | 144 | if (p_size) { 145 | *p_size = size; 146 | } 147 | 148 | return data; 149 | } 150 | 151 | char *file_load(const char *path, uint32_t *p_size) 152 | { 153 | char *mem; 154 | BDPLUS_FILE_H *fp; 155 | 156 | if (!path) { 157 | return NULL; 158 | } 159 | 160 | fp = file_open_default()(NULL, path); 161 | 162 | if (!fp) { 163 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Error loading %s\n", path); 164 | return NULL; 165 | } 166 | 167 | mem = _load_fp(fp, p_size); 168 | 169 | file_close(fp); 170 | 171 | return mem; 172 | } 173 | -------------------------------------------------------------------------------- /SMP/stdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MSVC stdio.h compatibility header. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SMP_STDIO_H 24 | #define SMP_STDIO_H 25 | 26 | #ifndef _MSC_VER 27 | # include_next 28 | #else 29 | 30 | #include 31 | #if _VC_CRT_MAJOR_VERSION >= 14 32 | # include <../ucrt/stdio.h> 33 | #else 34 | # include <../include/stdio.h> 35 | # define snprintf _snprintf 36 | #endif 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #ifndef SSIZE_MAX 46 | # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) 47 | #endif 48 | 49 | static __inline ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *fp) 50 | { 51 | ssize_t result; 52 | size_t cur_len = 0; 53 | 54 | if (lineptr == NULL || n == NULL || fp == NULL) { 55 | errno = EINVAL; 56 | return -1; 57 | } 58 | if (*lineptr == NULL || *n == 0) { 59 | char *new_lineptr; 60 | *n = 120; 61 | new_lineptr = (char *)realloc(*lineptr, *n); 62 | if (new_lineptr == NULL) { 63 | result = -1; 64 | return result; 65 | } 66 | *lineptr = new_lineptr; 67 | } 68 | 69 | for (;;) { 70 | int i; 71 | i = getc(fp); 72 | if (i == EOF) { 73 | result = -1; 74 | break; 75 | } 76 | if (cur_len + 1 >= *n) { 77 | size_t needed_max = SSIZE_MAX < SIZE_MAX ? (size_t)SSIZE_MAX + 1 : SIZE_MAX; 78 | size_t needed = 2 * *n + 1; 79 | char *new_lineptr; 80 | if (needed_max < needed) { 81 | needed = needed_max; 82 | } 83 | if (cur_len + 1 >= needed) { 84 | result = -1; 85 | errno = EOVERFLOW; 86 | return result; 87 | } 88 | new_lineptr = (char *)realloc(*lineptr, needed); 89 | if (new_lineptr == NULL) { 90 | result = -1; 91 | return result; 92 | } 93 | *lineptr = new_lineptr; 94 | *n = needed; 95 | } 96 | (*lineptr)[cur_len] = i; 97 | cur_len++; 98 | if (i == delimiter) { 99 | break; 100 | } 101 | } 102 | (*lineptr)[cur_len] = '\0'; 103 | result = cur_len ? cur_len : result; 104 | 105 | return result; 106 | } 107 | 108 | static __inline ssize_t getline(char **lineptr, size_t *n, FILE *stream) 109 | { 110 | return getdelim(lineptr, n, '\n', stream); 111 | } 112 | 113 | static __inline int vasprintf(char **res, char const *fmt, va_list args) 114 | { 115 | int r, sz = _vscprintf(fmt, args); 116 | if (sz >= 0) { 117 | if ((*res = malloc(sz + 1)) == NULL) { 118 | return -1; 119 | } 120 | r = vsnprintf(*res, sz + 1, fmt, args); 121 | if ((r < 0) || (r > sz)) { 122 | free(*res); 123 | *res = NULL; 124 | return -1; 125 | } 126 | return r; 127 | } else { 128 | return -1; 129 | } 130 | } 131 | 132 | static __inline int asprintf(char **strp, const char *fmt, ...) 133 | { 134 | int r; 135 | va_list ap; 136 | va_start(ap, fmt); 137 | r = vasprintf(strp, fmt, ap); 138 | va_end(ap); 139 | return(r); 140 | } 141 | 142 | #define fseeko _fseeki64 143 | #define ftello _ftelli64 144 | 145 | #endif /* _MSC_VER */ 146 | 147 | #endif /* SMP_STDIO_H */ -------------------------------------------------------------------------------- /src/libbdplus/bdplus.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #ifndef BDPLUS_H_INCLUDED 22 | #define BDPLUS_H_INCLUDED 23 | 24 | #include 25 | 26 | #ifndef BD_PUBLIC 27 | # define BD_PUBLIC 28 | #endif 29 | 30 | /* opaque types */ 31 | 32 | typedef struct bdplus_s bdplus_t; 33 | typedef struct bdplus_st_s bdplus_st_t; 34 | 35 | /* Memory region types for bdplus_mmap() */ 36 | 37 | #define MMAP_ID_PSR 0 38 | #define MMAP_ID_GPR 1 39 | 40 | /* Events from application to bdplus */ 41 | 42 | #define BDPLUS_EVENT_START 0x00000000 43 | #define BDPLUS_EVENT_TITLE 0x00000110 44 | #define BDPLUS_EVENT_APPLICATION 0x00000210 45 | #define BDPLUS_RUN_CONVTAB 0xffffffff /* get conversion table when disc is played without menus */ 46 | 47 | 48 | /* 49 | * Get the bdplus library version number. 50 | * 51 | */ 52 | BD_PUBLIC 53 | void bdplus_get_version(int *major, int *minor, int *micro); 54 | 55 | 56 | /* 57 | * Initialise the bdplus library. 58 | * 59 | * @param path Path to BD disc root 60 | * @param config_path Path to BD+ configuration (optional) 61 | * @param vid BD disc Volume ID 62 | * @return bdplus handle, NULL on error 63 | */ 64 | BD_PUBLIC 65 | bdplus_t *bdplus_init(const char *path, const char *config_path, const uint8_t *vid); 66 | 67 | /* get BD+ content code generation */ 68 | BD_PUBLIC 69 | int32_t bdplus_get_code_gen(bdplus_t *plus); 70 | 71 | /* get BD+ content code release date */ 72 | BD_PUBLIC 73 | int32_t bdplus_get_code_date(bdplus_t *plus); 74 | 75 | BD_PUBLIC 76 | int32_t bdplus_is_cached(bdplus_t *plus); 77 | 78 | 79 | /* 80 | * Release the bdplus library. 81 | * 82 | * @param bdplus handle 83 | */ 84 | BD_PUBLIC 85 | void bdplus_free(bdplus_t *); 86 | 87 | 88 | /* 89 | * Map player memory region. 90 | * 91 | * @param id Memory region type 92 | * @param mem Memory region address 93 | */ 94 | BD_PUBLIC 95 | void bdplus_mmap(bdplus_t *, uint32_t id, void *mem); 96 | 97 | /* 98 | * Set media key 99 | * 100 | * @param mk BD disc Media Key 101 | */ 102 | BD_PUBLIC 103 | void bdplus_set_mk(bdplus_t *, const uint8_t *mk); 104 | 105 | 106 | /* 107 | * Register PSR handler functions. 108 | * 109 | * @param regs Application-specific handle for psr_read/psr_write 110 | * @param psr_read Function used to read from PSR 111 | * @param psr_write Function used to write to PSR 112 | */ 113 | BD_PUBLIC 114 | void bdplus_psr(bdplus_t *, 115 | void *regs, 116 | uint32_t (*psr_read) (void *regs, int reg), 117 | int (*psr_write)(void *regs, int reg, uint32_t value)); 118 | 119 | 120 | /* 121 | * Start the bdplus VM 122 | */ 123 | BD_PUBLIC 124 | int32_t bdplus_start(bdplus_t *); 125 | 126 | 127 | /* 128 | * Send event to the bdplus VM. 129 | * 130 | * @param event event type (BDPLUS_EVENT_*) 131 | */ 132 | BD_PUBLIC 133 | int32_t bdplus_event(bdplus_t *, uint32_t event, uint32_t param1, uint32_t param2); 134 | 135 | 136 | /* 137 | * Stream interface 138 | */ 139 | 140 | 141 | /* 142 | * Select m2ts file for playback. 143 | * 144 | * @param m2ts m2ts file number 145 | * @return stream handle, NULL on error 146 | */ 147 | BD_PUBLIC 148 | bdplus_st_t *bdplus_m2ts(bdplus_t *, uint32_t m2ts); 149 | 150 | 151 | /* 152 | * Close stream handle. 153 | */ 154 | BD_PUBLIC 155 | void bdplus_m2ts_close(bdplus_st_t *); 156 | 157 | 158 | /* 159 | * Notify stream seek. 160 | * 161 | * @param offset new byte offset of the stream. 162 | */ 163 | BD_PUBLIC 164 | int32_t bdplus_seek(bdplus_st_t *, uint64_t offset); 165 | 166 | /* 167 | * Patch stream buffer. 168 | * 169 | * @param len buffer length 170 | * @param buffer stream data 171 | * @return Number of patches performed for the buffer (statistics). 172 | */ 173 | BD_PUBLIC 174 | int32_t bdplus_fixup(bdplus_st_t *, int len, uint8_t *buffer); 175 | 176 | 177 | 178 | #endif /* BDPLUS_H_INCLUDED */ 179 | -------------------------------------------------------------------------------- /src/examples/bdplus_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "libbdplus/bdplus.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef HAVE_LIBAACS 33 | #include 34 | #endif 35 | 36 | static uint8_t _hex_byte(char c) 37 | { 38 | if (c >= '0' && c <= '9') { 39 | return c - '0'; 40 | } 41 | else if (c >= 'a' && c <= 'f') { 42 | return c - 'a' + 10; 43 | } 44 | else if (c >= 'A' && c <= 'F') { 45 | return c - 'A' + 10; 46 | } 47 | else { 48 | fprintf(stderr, "invalid char in hex string: 0x%02X (%c)\n", c, c); 49 | exit(1); 50 | } 51 | 52 | return 0; 53 | } 54 | 55 | static void _libaacs_get_vid(uint8_t *vid, uint8_t *mk, const char *root) 56 | { 57 | #ifndef HAVE_LIBAACS 58 | fprintf(stderr, "libaacs support not enabled. Please provide VID in command line.\n"); 59 | exit(1); 60 | #else 61 | AACS *aacs = aacs_open(root, NULL); 62 | unsigned ii; 63 | 64 | if (!aacs) { 65 | fprintf(stderr, "aacs_open() failed. Please provide VID in command line.\n"); 66 | exit(1); 67 | } 68 | 69 | const uint8_t *aacs_vid = aacs_get_vid(aacs); 70 | if (!aacs_vid) { 71 | fprintf(stderr, "aacs_get_vid() failed. Please provide VID in command line.\n"); 72 | aacs_close(aacs); 73 | exit(1); 74 | } 75 | memcpy(vid, aacs_vid, 16); 76 | 77 | const uint8_t *aacs_mk = aacs_get_mk(aacs); 78 | if (!aacs_mk) { 79 | fprintf(stderr, "aacs_get_mk() failed.\n"); 80 | aacs_close(aacs); 81 | exit(1); 82 | } 83 | memcpy(mk, aacs_mk, 16); 84 | 85 | aacs_close(aacs); 86 | 87 | printf("got vid from libaacs: "); 88 | for (ii = 0; ii < 16; ii++) { 89 | printf("%02X", vid[ii]); 90 | } 91 | printf("\n"); 92 | #endif 93 | } 94 | 95 | int main(int argc, char **argv) 96 | { 97 | uint8_t vid[16], mk[16] = {0}; 98 | unsigned ii; 99 | 100 | if (argc < 2) { 101 | #ifndef HAVE_LIBAACS 102 | fprintf(stderr, "%s /path/tobluray \r\n", argv[0]); 103 | #else 104 | fprintf(stderr, "%s /path/tobluray [VID]\r\n", argv[0]); 105 | #endif 106 | fprintf(stderr, "Where we expect to find /path/tobluray/BDSVM/\r\n"); 107 | exit(1); 108 | } 109 | 110 | if (argc < 3) { 111 | _libaacs_get_vid(vid, mk, argv[1]); 112 | } else { 113 | if (strlen(argv[2]) != 32) { 114 | fprintf(stderr, "invalid VID (should be 32 chars)\n"); 115 | exit(1); 116 | } 117 | for (ii = 0; ii < 16; ii++) { 118 | vid[ii] = (_hex_byte(argv[2][2*ii]) << 4) | _hex_byte(argv[2][2*ii + 1]); 119 | } 120 | } 121 | 122 | printf("Opening bdplus ...\n"); 123 | 124 | bdplus_t *bd = bdplus_init(argv[1], NULL, vid); 125 | 126 | if (!bd) { 127 | fprintf(stderr, "bdplus_init() failed\n"); 128 | exit(1); 129 | } 130 | 131 | int dd = bdplus_get_code_date(bd); 132 | printf("BD+ content code generation %d (released %d-%02d-%02d)\n\n", 133 | bdplus_get_code_gen(bd), dd >> 16, (dd >> 8) & 0xff, dd & 0xff); 134 | 135 | bdplus_set_mk(bd, mk); 136 | if (bdplus_start(bd) < 0) { 137 | fprintf(stderr, "bdplus_start() failed\n"); 138 | } 139 | 140 | /* Try to get conversion table without actually playing the disc. */ 141 | bdplus_event(bd, BDPLUS_RUN_CONVTAB, 32, 0); 142 | 143 | for (ii = 0; ii < 32; ii++) { 144 | bdplus_event(bd, BDPLUS_EVENT_TITLE, ii, 0); 145 | } 146 | 147 | for (ii = 0; ii < 32; ii++) { 148 | bdplus_st_t *st = bdplus_m2ts(bd, ii); 149 | if (st) { 150 | printf("BD+ active for %05d.m2ts\n", ii); 151 | bdplus_m2ts_close(st); 152 | } 153 | } 154 | 155 | printf("Cleaning up...\n"); 156 | 157 | bdplus_free(bd); 158 | 159 | exit(0); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/util/mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2010-2014 hpi1 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #if HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "mutex.h" 25 | 26 | #include "logging.h" 27 | #include "macro.h" 28 | 29 | #if defined(_WIN32) 30 | # include 31 | #elif defined(HAVE_PTHREAD_H) 32 | # include 33 | #else 34 | # error no mutex support found 35 | #endif 36 | 37 | 38 | #if defined(_WIN32) 39 | 40 | typedef struct { 41 | CRITICAL_SECTION cs; 42 | } MUTEX_IMPL; 43 | 44 | static int _mutex_lock(MUTEX_IMPL *p) 45 | { 46 | EnterCriticalSection(&p->cs); 47 | return 0; 48 | } 49 | 50 | static int _mutex_unlock(MUTEX_IMPL *p) 51 | { 52 | LeaveCriticalSection(&p->cs); 53 | return 0; 54 | } 55 | 56 | static int _mutex_init(MUTEX_IMPL *p) 57 | { 58 | InitializeCriticalSection(&p->cs); 59 | return 0; 60 | } 61 | 62 | static int _mutex_destroy(MUTEX_IMPL *p) 63 | { 64 | DeleteCriticalSection(&p->cs); 65 | return 0; 66 | } 67 | 68 | 69 | #elif defined(HAVE_PTHREAD_H) 70 | 71 | typedef struct { 72 | int lock_count; 73 | pthread_t owner; 74 | pthread_mutex_t mutex; 75 | } MUTEX_IMPL; 76 | 77 | static int _mutex_init(MUTEX_IMPL *p) 78 | { 79 | p->owner = (pthread_t)-1; 80 | p->lock_count = 0; 81 | 82 | if (pthread_mutex_init(&p->mutex, NULL)) { 83 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_init() failed !\n"); 84 | return -1; 85 | } 86 | 87 | return 0; 88 | } 89 | 90 | static int _mutex_lock(MUTEX_IMPL *p) 91 | { 92 | if (pthread_equal(p->owner, pthread_self())) { 93 | /* recursive lock */ 94 | p->lock_count++; 95 | return 0; 96 | } 97 | 98 | if (pthread_mutex_lock(&p->mutex)) { 99 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_lock() failed !\n"); 100 | return -1; 101 | } 102 | 103 | p->owner = pthread_self(); 104 | p->lock_count = 1; 105 | 106 | return 0; 107 | } 108 | 109 | static int _mutex_unlock(MUTEX_IMPL *p) 110 | { 111 | if (!pthread_equal(p->owner, pthread_self())) { 112 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_unlock(): not owner !\n"); 113 | return -1; 114 | } 115 | 116 | p->lock_count--; 117 | if (p->lock_count > 0) { 118 | return 0; 119 | } 120 | 121 | /* unlock */ 122 | 123 | p->owner = (pthread_t)-1; 124 | 125 | if (pthread_mutex_unlock(&p->mutex)) { 126 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_unlock() failed !\n"); 127 | return -1; 128 | } 129 | 130 | return 0; 131 | } 132 | 133 | static int _mutex_destroy(MUTEX_IMPL *p) 134 | { 135 | _mutex_lock(p); 136 | _mutex_unlock(p); 137 | 138 | if (pthread_mutex_destroy(&p->mutex)) { 139 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "pthread_mutex_destroy() failed !\n"); 140 | return -1; 141 | } 142 | 143 | return 0; 144 | } 145 | 146 | #endif /* HAVE_PTHREAD_H */ 147 | 148 | int bd_mutex_lock(BD_MUTEX *p) 149 | { 150 | if (!p->impl) { 151 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_lock() failed !\n"); 152 | return -1; 153 | } 154 | return _mutex_lock((MUTEX_IMPL*)p->impl); 155 | } 156 | 157 | int bd_mutex_unlock(BD_MUTEX *p) 158 | { 159 | if (!p->impl) { 160 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_unlock() failed !\n"); 161 | return -1; 162 | } 163 | return _mutex_unlock((MUTEX_IMPL*)p->impl); 164 | } 165 | 166 | int bd_mutex_init(BD_MUTEX *p) 167 | { 168 | p->impl = calloc(1, sizeof(MUTEX_IMPL)); 169 | if (!p->impl) { 170 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_init() failed !\n"); 171 | return -1; 172 | } 173 | 174 | if (_mutex_init((MUTEX_IMPL*)p->impl) < 0) { 175 | X_FREE(p->impl); 176 | return -1; 177 | } 178 | 179 | return 0; 180 | } 181 | 182 | int bd_mutex_destroy(BD_MUTEX *p) 183 | { 184 | if (!p->impl) { 185 | BD_DEBUG(DBG_BLURAY|DBG_CRIT, "bd_mutex_destroy() failed !\n"); 186 | return -1; 187 | } 188 | 189 | if (_mutex_destroy((MUTEX_IMPL*)p->impl) < 0) { 190 | return -1; 191 | } 192 | 193 | X_FREE(p->impl); 194 | return 0; 195 | } 196 | 197 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/loader.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * Copyright (C) 2013 VideoLAN 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #include "loader.h" 22 | 23 | #include "dlx.h" 24 | 25 | #include "file/file.h" 26 | #include "util/logging.h" 27 | #include "util/macro.h" 28 | #include "util/strutl.h" 29 | 30 | #include 31 | 32 | 33 | static int _code_version_check(uint8_t *hdr, int *p_gen, int *p_date) 34 | { 35 | // known BD+ content code generations 36 | static const uint16_t gentbl[][3] = { 37 | // 38 | // Year,Month,Day Manufacturer First title Notes 39 | // 40 | { 2007, 6, 8 }, // gen 1: CRI "The Day After Tomorrow" First BD+. Content watermarking. 41 | { 2007, 12, 20 }, // gen 2: "Mrs Doubtfire" TRAP_MediaCheck (checks if content is encrypted with AACS). 42 | { 2008, 4, 14 }, // gen 3: Macrovision "Jumper" Useless FUEs, TRAP_DebugLog, BD-J <-> BD+ handshake. 43 | { 2008, 8, 22 }, // gen 4: "Futurama: Benders Game" MK.enc (encrypted java code). 44 | { 2009, 2, 2 }, // gen 5: "Slumdog Millionaire" Variable handshake return codes. 45 | { 2009, 3, 31 }, // gen 6: "Valkyrie" MK.enc --> 77773.jar 46 | { 2009, 8, 18 }, // gen 7: "Ice Age 3" 00003.svm 47 | { 2010, 3, 6 }, // gen 8: "Avatar" Native code. Permanent handshake during playback. 48 | { 2010, 9, 3 }, // gen 9: "Knight and Day" 00004.svm, 00005.svm. New native code. 49 | { 2011, 2, 28 }, // gen 10: "Rabbit Hole" 50 | { 2011, 6, 1 }, // gen 11: "Star Wars" 51 | { 2011, 11, 16 }, // gen 12/13: Irdeto "Contagion" 52 | { 2011, 11, 16 }, // -,,- 53 | { 2012, 8, 7 }, // gen 14: "Prometheus" 54 | { 2013, 1, 25 }, // gen 15: "Parental Guidance" 55 | { 2013, 4, 30 }, // gen 16: "Stoker" StreetLock. 56 | }; 57 | 58 | unsigned int year = hdr[0x0d] << 8 | hdr[0x0e]; 59 | unsigned int month = hdr[0x0f]; 60 | unsigned int day = hdr[0x10]; 61 | unsigned int gen; 62 | 63 | for (gen = 0; gen < sizeof(gentbl) / sizeof(gentbl[0]); gen++) { 64 | if ( year < gentbl[gen][0] || 65 | (year == gentbl[gen][0] && month < gentbl[gen][1]) || 66 | (year == gentbl[gen][0] && month == gentbl[gen][1] && day < gentbl[gen][2])) { 67 | break; 68 | } 69 | } 70 | 71 | BD_DEBUG(DBG_BDPLUS, "[bdplus] BD+ code created: %04d-%02d-%02d (BD+ generation %d)\n", year, month, day, gen); 72 | 73 | if (p_gen) { 74 | *p_gen = gen; 75 | } 76 | if (p_date) { 77 | *p_date = (hdr[0x0d] << 24) | (hdr[0x0e] << 16) | (hdr[0x0f] << 8) | hdr[0x10]; 78 | } 79 | 80 | if (gen > 3) { 81 | BD_DEBUG(DBG_BDPLUS | DBG_CRIT, "[bdplus] WARNING: BD+ generation %d not tested / supported\n", gen); 82 | return -1; 83 | } 84 | 85 | return 0; 86 | } 87 | 88 | int32_t loader_load_svm(BDPLUS_FILE_H *fp, const char *fname, VM *vm, int *p_gen, int *p_date) 89 | { 90 | uint32_t len; 91 | uint8_t *addr = dlx_getAddr(vm); 92 | 93 | // Read BD SVM header 94 | if (file_read(fp, addr, 0x18) != 0x18) { 95 | BD_DEBUG(DBG_BDPLUS | DBG_CRIT, "[bdplus] Error reading header from %s\n", fname); 96 | return -1; 97 | } 98 | 99 | if (memcmp(addr, "BDSVM_CC", 8)) { 100 | BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[bdplus] %s failed signature match\n", fname); 101 | } 102 | 103 | _code_version_check(addr, p_gen, p_date); 104 | 105 | // Pull out length 106 | len = FETCH4(&addr[0x14]); 107 | 108 | BD_DEBUG(DBG_BDPLUS,"[bdplus] svm size %08X (%u)\n", len, len); 109 | 110 | if (len >= dlx_getAddrSize(vm)) { 111 | BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[bdplus] Section too long (%d) in %s\n", len, fname); 112 | return -1; 113 | } 114 | 115 | // read length data 116 | if (file_read(fp, addr, len) != len) { 117 | BD_DEBUG(DBG_BDPLUS | DBG_CRIT, "[bdplus] Error reading section from %s\n", fname); 118 | return -1; 119 | } 120 | 121 | file_close(fp); 122 | 123 | BD_DEBUG(DBG_BDPLUS,"[bdplus] loaded core '%s'\n", fname); 124 | 125 | // clear first 0x1000 bytes 126 | memset(addr, 0, 0x1000); 127 | 128 | return 0; 129 | } 130 | -------------------------------------------------------------------------------- /src/file/file_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2009-2010 Obliter0n 4 | * Copyright (C) 2009-2010 John Stebbins 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library. If not, see 18 | * . 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #if defined(__MINGW32__) 26 | /* ftello64() and fseeko64() prototypes from stdio.h */ 27 | # undef __STRICT_ANSI__ 28 | #endif 29 | 30 | #include "file.h" 31 | #include "util/macro.h" 32 | #include "util/logging.h" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | static void _file_close(BD_FILE_H *file) 41 | { 42 | if (file) { 43 | if (fclose((FILE *)file->internal)) { 44 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Error closing WIN32 file (%p)\n", (void*)file); 45 | } 46 | 47 | BD_DEBUG(DBG_FILE, "Closed WIN32 file (%p)\n", (void*)file); 48 | 49 | X_FREE(file); 50 | } 51 | } 52 | 53 | static int64_t _file_seek(BD_FILE_H *file, int64_t offset, int32_t origin) 54 | { 55 | #if defined(__MINGW32__) 56 | return fseeko64((FILE *)file->internal, offset, origin); 57 | #else 58 | return _fseeki64((FILE *)file->internal, offset, origin); 59 | #endif 60 | } 61 | 62 | static int64_t _file_tell(BD_FILE_H *file) 63 | { 64 | #if defined(__MINGW32__) 65 | return ftello64((FILE *)file->internal); 66 | #else 67 | return _ftelli64((FILE *)file->internal); 68 | #endif 69 | } 70 | 71 | static int64_t _file_read(BD_FILE_H *file, uint8_t *buf, int64_t size) 72 | { 73 | if (size > 0 && size < BD_MAX_SSIZE) { 74 | return (int64_t)fread(buf, 1, (size_t)size, (FILE *)file->internal); 75 | } 76 | 77 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid read of size %" PRId64 " (%p)\n", size, (void*)file); 78 | return 0; 79 | } 80 | 81 | static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size) 82 | { 83 | if (size > 0 && size < BD_MAX_SSIZE) { 84 | return (int64_t)fwrite(buf, 1, (size_t)size, (FILE *)file->internal); 85 | } 86 | 87 | if (size == 0) { 88 | if (fflush((FILE *)file->internal)) { 89 | BD_DEBUG(DBG_FILE, "fflush() failed (%p)\n", (void*)file); 90 | return -1; 91 | } 92 | return 0; 93 | } 94 | 95 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %" PRId64 " (%p)\n", size, (void*)file); 96 | return 0; 97 | } 98 | 99 | static BD_FILE_H *_file_open(void *handle, const char* filename) 100 | { 101 | BD_FILE_H *file; 102 | FILE *fp; 103 | wchar_t wfilename[MAX_PATH], wmode[8]; 104 | const char *mode = "rb"; 105 | (void)handle; 106 | 107 | if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, filename, -1, wfilename, MAX_PATH) || 108 | !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, wmode, 8)) { 109 | 110 | BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename); 111 | return NULL; 112 | } 113 | 114 | fp = _wfopen(wfilename, wmode); 115 | if (!fp) { 116 | BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename); 117 | return NULL; 118 | } 119 | 120 | file = calloc(1, sizeof(BD_FILE_H)); 121 | if (!file) { 122 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Error opening file %s (out of memory)\n", filename); 123 | fclose(fp); 124 | return NULL; 125 | } 126 | 127 | file->internal = fp; 128 | file->close = _file_close; 129 | file->seek = _file_seek; 130 | file->read = _file_read; 131 | file->write = _file_write; 132 | file->tell = _file_tell; 133 | 134 | BD_DEBUG(DBG_FILE, "Opened WIN32 file %s (%p)\n", filename, (void*)file); 135 | return file; 136 | } 137 | 138 | BD_FILE_H* (*file_open)(void *handle, const char* filename) = _file_open; 139 | 140 | BD_FILE_OPEN file_open_default(void) 141 | { 142 | return _file_open; 143 | } 144 | 145 | int file_path_exists(const char *path) 146 | { 147 | wchar_t wpath[MAX_PATH]; 148 | 149 | if (!MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, MAX_PATH)) { 150 | return -1; 151 | } 152 | 153 | DWORD dwAttrib = GetFileAttributesW(wpath); 154 | if (dwAttrib != INVALID_FILE_ATTRIBUTES) { 155 | return 0; 156 | } 157 | return -1; 158 | } 159 | 160 | int file_mkdir(const char *dir) 161 | { 162 | wchar_t wdir[MAX_PATH]; 163 | 164 | if (!MultiByteToWideChar(CP_UTF8, 0, dir, -1, wdir, MAX_PATH)) { 165 | return -1; 166 | } 167 | if (!CreateDirectoryW(wdir, NULL)) 168 | return -1; 169 | return 0; 170 | } 171 | -------------------------------------------------------------------------------- /src/file/file_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbluray 3 | * Copyright (C) 2009-2010 Obliter0n 4 | * Copyright (C) 2009-2010 John Stebbins 5 | * Copyright (C) 2010-2015 Petri Hintukainen 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2.1 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library. If not, see 19 | * . 20 | */ 21 | 22 | #if HAVE_CONFIG_H 23 | #include "config.h" 24 | #endif 25 | 26 | #include "file.h" 27 | #include "util/macro.h" 28 | #include "util/logging.h" 29 | 30 | #include 31 | #include 32 | #include // remove() 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef __ANDROID__ 42 | # undef lseek 43 | # define lseek lseek64 44 | # undef off_t 45 | # define off_t off64_t 46 | #endif 47 | 48 | static void _file_close(BD_FILE_H *file) 49 | { 50 | if (file) { 51 | if (close((int)(intptr_t)file->internal)) { 52 | BD_DEBUG(DBG_CRIT | DBG_FILE, "Error closing POSIX file (%p)\n", (void*)file); 53 | } 54 | 55 | BD_DEBUG(DBG_FILE, "Closed POSIX file (%p)\n", (void*)file); 56 | 57 | X_FREE(file); 58 | } 59 | } 60 | 61 | static int64_t _file_seek(BD_FILE_H *file, int64_t offset, int32_t origin) 62 | { 63 | off_t result = lseek((int)(intptr_t)file->internal, offset, origin); 64 | if (result == (off_t)-1) { 65 | BD_DEBUG(DBG_FILE, "lseek() failed (%p)\n", (void*)file); 66 | return -1; 67 | } 68 | return (int64_t)result; 69 | } 70 | 71 | static int64_t _file_tell(BD_FILE_H *file) 72 | { 73 | return _file_seek(file, 0, SEEK_CUR); 74 | } 75 | 76 | static int64_t _file_read(BD_FILE_H *file, uint8_t *buf, int64_t size) 77 | { 78 | ssize_t got, result; 79 | 80 | if (size <= 0 || size >= BD_MAX_SSIZE) { 81 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid read of size %" PRId64 " (%p)\n", size, (void*)file); 82 | return 0; 83 | } 84 | 85 | for (got = 0; got < (ssize_t)size; got += result) { 86 | result = read((int)(intptr_t)file->internal, buf + got, size - got); 87 | if (result < 0) { 88 | if (errno != EINTR) { 89 | BD_DEBUG(DBG_FILE, "read() failed (%p)\n", (void*)file); 90 | break; 91 | } 92 | result = 0; 93 | } else if (result == 0) { 94 | // hit EOF. 95 | break; 96 | } 97 | } 98 | return (int64_t)got; 99 | } 100 | 101 | static int64_t _file_write(BD_FILE_H *file, const uint8_t *buf, int64_t size) 102 | { 103 | ssize_t written, result; 104 | 105 | if (size <= 0 || size >= BD_MAX_SSIZE) { 106 | if (size == 0) { 107 | if (fsync((int)(intptr_t)file->internal)) { 108 | BD_DEBUG(DBG_FILE, "fsync() failed (%p)\n", (void*)file); 109 | return -1; 110 | } 111 | return 0; 112 | } 113 | BD_DEBUG(DBG_FILE | DBG_CRIT, "Ignoring invalid write of size %" PRId64 " (%p)\n", size, (void*)file); 114 | return 0; 115 | } 116 | 117 | for (written = 0; written < (ssize_t)size; written += result) { 118 | result = write((int)(intptr_t)file->internal, buf + written, size - written); 119 | if (result < 0) { 120 | if (errno != EINTR) { 121 | BD_DEBUG(DBG_FILE, "write() failed (%p)\n", (void*)file); 122 | break; 123 | } 124 | result = 0; 125 | } 126 | } 127 | return (int64_t)written; 128 | } 129 | 130 | static BD_FILE_H *_file_open(void *handle, const char* filename) 131 | { 132 | BD_FILE_H *file; 133 | int fd = -1; 134 | int flags = 0; 135 | int mode = 0; 136 | (void)handle; 137 | 138 | flags = O_RDONLY; 139 | 140 | #ifdef O_CLOEXEC 141 | flags |= O_CLOEXEC; 142 | #endif 143 | #ifdef O_BINARY 144 | flags |= O_BINARY; 145 | #endif 146 | 147 | fd = open(filename, flags, mode); 148 | if (fd < 0) { 149 | BD_DEBUG(DBG_FILE, "Error opening file %s\n", filename); 150 | return NULL; 151 | } 152 | 153 | file = calloc(1, sizeof(BD_FILE_H)); 154 | if (!file) { 155 | close(fd); 156 | BD_DEBUG(DBG_FILE, "Error opening file %s (out of memory)\n", filename); 157 | return NULL; 158 | } 159 | 160 | file->close = _file_close; 161 | file->seek = _file_seek; 162 | file->read = _file_read; 163 | file->write = _file_write; 164 | file->tell = _file_tell; 165 | 166 | file->internal = (void*)(intptr_t)fd; 167 | 168 | BD_DEBUG(DBG_FILE, "Opened POSIX file %s (%p)\n", filename, (void*)file); 169 | return file; 170 | } 171 | 172 | BD_FILE_H* (*file_open)(void *handle, const char* filename) = _file_open; 173 | 174 | BD_FILE_OPEN file_open_default(void) 175 | { 176 | return _file_open; 177 | } 178 | 179 | int file_path_exists(const char *path) 180 | { 181 | struct stat s; 182 | return stat(path, &s); 183 | } 184 | 185 | int file_mkdir(const char *dir) 186 | { 187 | return mkdir(dir, S_IRWXU); 188 | } 189 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # libbdplus 2 | 3 | **libbdplus** is a research project for a cross-platform open-source implementation of the BD+ VM system. 4 | 5 | # Disclaimer 6 | 7 | This library is written for the purpose of playing Blu-ray movies. 8 | 9 | It is intended for software that want to support Blu-ray playback (such as VLC and 10 | MPlayer). We, the authors of this library, do not condone nor endorse piracy. 11 | 12 | This library is simply a tool for playback of Blu-ray movies. Like any tool, the 13 | use of this tool can also be abused. There are already numerous laws in 14 | different countries and juridictions all over the world that protect copyrighted 15 | material, such as Blu-ray movies. 16 | 17 | With that said, it would have been impossible for us to distribute this library 18 | with terms such as "you cannot use this library for piracy", because this would 19 | violate the Open Source Definition and the LGPL license. 20 | Instead, we present to everyone this disclaimer. 21 | 22 | As a reminder, here is also the disclaimer found at the beginning of any movie 23 | in relation to copyrights. 24 | 25 | ## ATTENTION 26 | 27 | International agreement and national laws protect copyrighted motion pictures, 28 | videotapes, and sound recordings. 29 | 30 | UNAUTHORIZED REPRODUCTION, EXHIBITION OR DISTRIBUTION OF COPYRIGHTED MOTION 31 | PICTURES CAN RESULT IN SEVERE CRIMINAL AND CIVIL PENALTIES UNDER THE LAWS OF 32 | YOUR COUNTRY. 33 | 34 | The International Criminal Police Organization - INTERPOL, has expressed its 35 | concern about motion picture and sound recording piracy to all of its member 36 | national police forces. (Resolution adopted at INTERPOL General Assembly, 37 | Stockholm, Sweden, September 8, 1977.) 38 | 39 | # Contribute 40 | 41 | To contribute, just compile the library and open merge requests on the repository: 42 | https://code.videolan.org/videolan/libbdplus 43 | 44 | ## CoC 45 | 46 | The [VideoLAN Code of Conduct](https://wiki.videolan.org/CoC) applies to this project. 47 | 48 | ## CLA 49 | 50 | There is no CLA. 51 | 52 | People will keep their copyright and their authorship rights, while adhering to the license. 53 | 54 | VideoLAN will only have the collective work rights. 55 | 56 | 57 | 58 | 59 | 60 | # Welcome to the BD+ library 61 | 62 | This library is not complete, in that it will never be complete and 63 | will always require updates to stay up to date with the latest Bluray 64 | disks released. 65 | 66 | The general flow on this library is that the higher level 'player' 67 | code will call us if there exist a "BDSVM/00000.svm" file on the disk. If 68 | this is the case it will call bdplus_init(), connect the library with 69 | other parts of BluRay player and call bdplus_start(). 70 | 71 | BD+ VM executes the DLX assembled code inside the SVM file. 72 | This will perform thousands of AES, SHA, file reads and detailed 73 | memory checks to guess the authenticity of the player. 74 | 75 | If all goes well, the SVM will eventually spit out a 'conversion 76 | table'. This is a large table (usually about 1-2MB but it varies) which 77 | contains offsets into the M2TS video file. (usually the main title). 78 | 79 | The video file has been purposely corrupted at random places. These 80 | offsets, and 12 bytes of data for each one, is used to repair the 81 | video file. 82 | 83 | However, the conversion table is also 'encoded' (XOR). So the VM is 84 | further executed to ask for the decode-keys for each part (segment) of 85 | the conversion table. 86 | 87 | ============================================ 88 | 89 | the BD+ library will need various keys to perform its task. More 90 | precisely, it needs: 91 | 92 | 6 AES Player keys (each 16 bytes) 93 | 94 | There are also 5 dumps of the Player Discovery replies. 95 | 96 | There is player memory dumps that needs to be simulated. Including 97 | player name, version and executable map. 98 | 99 | Configuration directory (vm0) is searched from following places: 100 | 101 | Linux (xdg specification): 102 | /etc/xdg/bdplus/ 103 | $HOME/.config/bdplus/ 104 | 105 | Windows: 106 | %APPDATA%/bdplus/ 107 | 108 | Mac OS: 109 | ~/Library/Preferences/bdplus/ 110 | 111 | Configuration data is not included with libbdplus. 112 | 113 | ============================================ 114 | 115 | The BD+ design also uses 'slots', that is like a save-file stored on 116 | NVRam/USB-Stick or similar permanent storage. The slot layout is 500 117 | slots of 256 bytes each. The SVM can request a new/free slot to 118 | write, or look for one previously written. In here it can store 119 | information for future play attempts. 120 | 121 | Slots are stored in the following file: 122 | 123 | Linux (xdg specification): 124 | $HOME/.cache/bdplus/slots.bin 125 | 126 | Windows: 127 | %APPDATA%/bdplus/slots.bin 128 | 129 | Mac OS: 130 | ~/Library/Caches/bdplus/ 131 | 132 | 133 | ============================================ 134 | 135 | The SVM also communicates with BluRay player BDJ and HDMV subsystems, 136 | using the PSR102, PSR103 and PSR104 registers. To set up callback 137 | functions for communication, BluRay player calls bdplus_set_psr(). 138 | 139 | ============================================ 140 | 141 | What if things go wrong? And they will! Each new disk brought out will 142 | potentially expose new issues with libbdplus. There are things that 143 | can be done to help fix libbdplus. 144 | 145 | You can set environment variables: 146 | 147 | DBG_BDPLUS : General BDPlus debugging, traps etc. 148 | 149 | where you can watch the SVM perform its various tasks. It is quite 150 | hard to know where it goes wrong, unless you have something to compare 151 | against though. I don't know if we can record traps and breaks anymore... 152 | 153 | DBG_DLX: In-depth DLX assembly instruction debugging. 154 | 155 | This is very verbose and shows the DLX instructions executing. It 156 | would be unlikely to be bugs in the DLX opcodes, but you never 157 | know. Included for amusements sake. 158 | 159 | -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/slot.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #include "slot.h" 21 | #include "slot_data.h" 22 | 23 | #include "dlx.h" 24 | #include "trap.h" 25 | 26 | #include "libbdplus/internal.h" 27 | 28 | #include "util/logging.h" 29 | #include "util/macro.h" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /* 36 | This procedure call is used to request privileged access to a 37 | specified slot. Prior to granting such access, the code making the 38 | request is authenticated. The procedure's input parameters identify 39 | the slot number and the code length. The procedure determines the 40 | starting address of the code to be granted access (e.g., the address 41 | in the content's memory following the instruction invoking the 42 | SlotAttach operation). Using the address and the specified length, 43 | the procedure then computes a cryptographic hash (e.g., using SHA-1) 44 | of the code. If the hash result does not match the value of the 45 | authorization hash stored in the slot then slot zero is attached and 46 | an error is returned. Otherwise, the requested slot number becomes 47 | the slot that is currently attached. As a special case, the calling 48 | code can specify a slot number of (-1) to request that a new slot be 49 | allocated. Then the player selects a slot to overwrite (as described 50 | below), clears it out (e.g., by setting creator media ID to the 51 | current media ID, zeroing the other slot fields, and incrementing 52 | write counter) and attaches to the slot. If the interpreter supports 53 | interrupts or other capabilities that could cause the unexpected 54 | execution of potentially-untrusted code, these should be disabled to 55 | avoid the introduction of malicious code while a slot is 56 | attached. The return value is the attached slot number, or an error 57 | code if the operation failed (e.g., because of a code hash mismatch) 58 | */ 59 | 60 | uint32_t slot_SlotAttach(VM *vm, 61 | uint32_t slot, uint32_t codeLen, 62 | uint8_t *codeStart, uint8_t *PCp) 63 | { 64 | uint32_t PC, IF, hash_len; 65 | uint8_t *hash = NULL; 66 | uint8_t digest1[SHA_DIGEST_LENGTH], digest2[SHA_DIGEST_LENGTH]; 67 | 68 | BD_DEBUG(DBG_BDPLUS,"[slot] trap_SlotAttach(%d)\n", slot); 69 | 70 | PC = dlx_getPC(vm) - 4; // Pull back 4 71 | IF = dlx_getIF(vm); 72 | 73 | if (slot == 0xFFFFFFFF) 74 | return bdplus_new_slot(dlx_getApp(vm)); 75 | 76 | if ( slot >= BDPLUS_NUM_SLOTS ) 77 | return STATUS_INVALID_PARAMETER; 78 | 79 | // Use 16 bytes from code_start, 80 | // Use codeLen*4 bytes from PC 81 | // Use IF 82 | 83 | hash_len=sizeof(uint32_t) * (1 + 1 + 4 + codeLen);//PC+IF+codeStart+codeLen 84 | 85 | // Allocate area to hold the hash data, since codeLen is dynamic. 86 | hash = (uint8_t *) malloc( hash_len ); 87 | 88 | if (!hash) return STATUS_INTERNAL_ERROR; 89 | 90 | // Assign the values 91 | STORE4(&hash[0], PC); 92 | STORE4(&hash[4], IF); 93 | memcpy(&hash[8], codeStart, 16); 94 | memcpy(&hash[24], PCp, codeLen * sizeof(uint32_t) ); 95 | 96 | // Hash that buffer 97 | gcry_md_hash_buffer(GCRY_MD_SHA1, digest1, hash, hash_len); 98 | 99 | // Hash that hash again 100 | gcry_md_hash_buffer(GCRY_MD_SHA1, digest2, digest1, sizeof(digest1)); 101 | 102 | // Release buffer 103 | X_FREE(hash); 104 | 105 | if (bdplus_slot_authenticate(dlx_getApp(vm), slot, (char *)digest2)) { 106 | return STATUS_OK; 107 | } 108 | 109 | return STATUS_INVALID_PARAMETER; 110 | } 111 | 112 | 113 | uint32_t slot_SlotRead(VM *vm, 114 | uint8_t *dst, uint32_t slot) 115 | { 116 | 117 | BD_DEBUG(DBG_BDPLUS,"[slot] trap_SlotRead(%d)\n", slot); 118 | 119 | if (slot == 0xFFFFFFFF) { // Status? 120 | 121 | bdplus_getAttachStatus(dlx_getApp(vm), dst); 122 | 123 | return STATUS_OK; 124 | } 125 | 126 | if ( slot >= BDPLUS_NUM_SLOTS ) 127 | return STATUS_INVALID_PARAMETER; 128 | 129 | BD_DEBUG(DBG_BDPLUS,"[slot] shoving slot %d to memory %p\n", slot, dst); 130 | 131 | bdplus_getSlot(dlx_getApp(vm), slot, (slot_t *)dst); 132 | 133 | return STATUS_OK; 134 | } 135 | 136 | 137 | uint32_t slot_SlotWrite(VM *vm, 138 | uint8_t *src) 139 | { 140 | slot_t newslot; 141 | uint32_t counter; 142 | slot_t *newContents = (slot_t *)src; 143 | 144 | BD_DEBUG(DBG_BDPLUS,"[slot] trap_SlotWrite()\n"); 145 | 146 | bdplus_getSlot(dlx_getApp(vm), 0xFFFFFFFF, &newslot); 147 | 148 | memcpy(newslot.mMediaID, newContents->mMediaID, sizeof(newslot.mMediaID)); 149 | memcpy(newslot.privateData, 150 | newContents->privateData, sizeof(newslot.privateData)); 151 | memcpy(newslot.authHash, newContents->authHash, sizeof(newslot.authHash)); 152 | memcpy(newslot.payload, newContents->payload, sizeof(newslot.payload)); 153 | 154 | // Update sequence counter 155 | counter = FETCH4(newslot.sequence_counter); 156 | counter++; 157 | STORE4(newslot.sequence_counter, counter); 158 | 159 | bdplus_slot_write(dlx_getApp(vm), &newslot); 160 | 161 | return STATUS_OK; 162 | } 163 | 164 | 165 | -------------------------------------------------------------------------------- /SMP/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | branches: 4 | only: 5 | - master 6 | skip_non_tags: true 7 | clone_depth: 10 8 | 9 | configuration: Release+ReleaseDLLStaticDeps 10 | 11 | platform: x86+x64 12 | 13 | environment: 14 | GITHUBTOKEN: 15 | secure: c9Sads7Y16h7FP+LrR3IjVygYAgh8GByE8TtazxDg7jpPVxc+XDV81z7MoUc2Ada 16 | matrix: 17 | - MSVC_VER: 12 18 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 19 | - MSVC_VER: 14 20 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 21 | - MSVC_VER: 15 22 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 23 | - MSVC_VER: 16 24 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 25 | - MSVC_VER: 17 26 | APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 27 | 28 | install: 29 | # Install GitLink 30 | - cmd: nuget install gitlink -Version 2.4.0 31 | - cmd: for /f "tokens=*" %%f in ('dir /s /b gitlink.exe') do copy /b %%f .\ 32 | 33 | before_build: 34 | # Backup platform so it is not affected by vcvars 35 | - cmd: SET PLATFORMBACK=%PLATFORM% 36 | 37 | # Setup msvc environment for required compiler version (specified by MSVC_VER) 38 | - ps: >- 39 | if ($env:MSVC_VER -eq 17) { 40 | $env:VCVARS="C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" 41 | } elseif ($env:MSVC_VER -eq 16) { 42 | $env:VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" 43 | } elseif ($env:MSVC_VER -eq 15) { 44 | $env:VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" 45 | } else { 46 | $env:VSCOMNTOOLS=(Get-Content ("env:VS" + "$env:MSVC_VER" + "0COMNTOOLS")) 47 | $env:VCVARS="%VSCOMNTOOLS%\..\..\VC\vcvarsall.bat" 48 | } 49 | 50 | - cmd: call "%VCVARS%" amd64 51 | 52 | # Detect latest available windows sdk version 53 | - ps: >- 54 | if ($env:MSVC_VER -eq 12) { 55 | $env:WindowsSDKVersion=8.1 56 | } else { 57 | $env:WindowsSDKVersion=$env:WindowsSDKVersion.TrimEnd('\') 58 | } 59 | 60 | # Reset platform 61 | - cmd: SET PLATFORM=%PLATFORMBACK% 62 | 63 | # Create build project to compile all configurations and platforms at once 64 | - ps: >- 65 | $script = @' 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | %(PlatformList.Identity) 77 | 78 | 79 | 80 | Configuration=%(ConfigurationList.Identity);Platform=$(CurrentPlatform);OutDir=$(MSBuildThisFileDirectory)build_out\;WindowsTargetPlatformVersion=SDK_VER 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | %(PlatformList.Identity) 90 | 91 | 92 | 93 | 94 | 95 | '@ 96 | 97 | 98 | $script = $script -replace "APPVEYOR_PROJECT_NAME", "$env:APPVEYOR_PROJECT_NAME" 99 | 100 | $script = $script -replace "APPVEYOR_REPO_NAME", "$env:APPVEYOR_REPO_NAME" 101 | 102 | $script = $script -replace "APPVEYOR_REPO_COMMIT", "$env:APPVEYOR_REPO_COMMIT" 103 | 104 | $script = $script -replace "APPVEYOR_MSVC_VER", "$env:MSVC_VER" 105 | 106 | $script = $script -replace "SDK_VER", "$env:WindowsSDKVersion" 107 | 108 | $script | Out-File build.vcxproj 109 | 110 | # Set Targets path so that gitlink works correctly 111 | - ps: $env:MSBUILDDIR=((Get-Command msbuild.exe).Path | Split-Path -parent) 112 | - ps: >- 113 | if ($env:MSVC_VER -eq 17) { 114 | $env:VCTargetsPath="$env:MSBUILDDIR\..\..\..\Microsoft\VC\v170\" 115 | } elseif ($env:MSVC_VER -eq 16) { 116 | $env:VCTargetsPath="$env:MSBUILDDIR\..\..\Microsoft\VC\v160\" 117 | } elseif ($env:MSVC_VER -eq 15) { 118 | $env:VCTargetsPath="$env:MSBUILDDIR\..\..\..\Common7\IDE\VC\VCTargets" 119 | } else { 120 | $env:VCTargetsPath="$env:MSBUILDDIR\..\..\..\Microsoft.Cpp\v4.0\V${env:MSVC_VER}0" 121 | } 122 | 123 | # Use project supplied script to download all required dependency libraries 124 | - cmd: call "%APPVEYOR_BUILD_FOLDER%\SMP\project_get_dependencies.bat" 125 | 126 | build: 127 | project: build.vcxproj 128 | parallel: true 129 | verbosity: minimal 130 | 131 | after_build: 132 | # Copy licenses for dependencies 133 | - cmd: copy /y %APPVEYOR_BUILD_FOLDER%\..\prebuilt\licenses\*.* %APPVEYOR_BUILD_FOLDER%\build_out\licenses\ 134 | 135 | artifacts: 136 | - path: build_out 137 | name: $(APPVEYOR_PROJECT_NAME)_$(APPVEYOR_REPO_TAG_NAME)_msvc$(MSVC_VER) 138 | type: zip 139 | 140 | deploy: 141 | - provider: GitHub 142 | tag: $(APPVEYOR_REPO_TAG_NAME) 143 | description: Pre-built static and shared libraries in 32b and 64b for $(APPVEYOR_PROJECT_NAME) $(APPVEYOR_REPO_TAG_NAME) 144 | auth_token: 145 | secure: c9Sads7Y16h7FP+LrR3IjVygYAgh8GByE8TtazxDg7jpPVxc+XDV81z7MoUc2Ada 146 | artifact: $(APPVEYOR_PROJECT_NAME)_$(APPVEYOR_REPO_TAG_NAME)_msvc$(MSVC_VER) 147 | force_update: true -------------------------------------------------------------------------------- /src/examples/convtab_dump.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2013 VideoLAN 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | // endian safe fetch 26 | #define FETCH4(X) (uint32_t)(((X)[0]<<24)|(X)[1]<<16|(X)[2]<<8|(X)[3]) 27 | #define FETCHU2(X) (uint32_t)((uint16_t)(((X)[0]<<8)|(X)[1])) 28 | 29 | // raw table 30 | #define MAX_TAB_SIZE 64*1024*1024 31 | uint8_t tab[MAX_TAB_SIZE]; 32 | uint32_t index[0xffff]; 33 | 34 | static size_t _read_tab(const char *file) 35 | { 36 | FILE *fp = fopen(file, "rb"); 37 | size_t len; 38 | 39 | if (!fp) { 40 | perror("fopen(): "); 41 | return 0; 42 | } 43 | 44 | memset(tab, 0, MAX_TAB_SIZE); 45 | 46 | len = fread(tab, 1, MAX_TAB_SIZE, fp); 47 | if (len < 1) { 48 | perror("fread(): "); 49 | } 50 | 51 | fclose(fp); 52 | 53 | printf("Read %zd bytes from %s\n", len, file); 54 | 55 | return len; 56 | } 57 | 58 | int main(int argc, char **argv) 59 | { 60 | uint32_t numTables, table; 61 | uint32_t ptr = 0; 62 | uint32_t offset = 0; 63 | int errors = 0; 64 | 65 | if (argc < 2) { 66 | fprintf(stderr, "%s /path/to/conv_tab.bin\n", argv[0]); 67 | exit(1); 68 | } 69 | 70 | if (_read_tab(argv[1]) < 1) { 71 | fprintf(stderr, "Error reading %s\n", argv[1]); 72 | exit(1); 73 | } 74 | 75 | numTables = FETCHU2(&tab[ptr]); 76 | ptr += 2; 77 | 78 | printf("%d tables:\n", numTables); 79 | 80 | 81 | for (table = 0; table < numTables; table++) { 82 | uint32_t tableID, numSegments, segment; 83 | 84 | tableID = FETCH4(&tab[ptr]); 85 | ptr += 4; 86 | numSegments = FETCHU2(&tab[ptr]); 87 | ptr += 2; 88 | 89 | printf("Table %d: %05d.m2ts (%d segments)\n", table, tableID, numSegments); 90 | 91 | for (segment = 0; segment < numSegments; segment++) { 92 | uint32_t numEntries, entry; 93 | uint64_t prev_off1 = 0; 94 | 95 | offset = FETCH4(&tab[ptr + (segment * 4) ]); 96 | 97 | numEntries = FETCH4(&tab[offset]); 98 | offset += 4; 99 | 100 | printf(" Segment %d: %d entries\n", segment, numEntries); 101 | 102 | // read index table 103 | for (entry = 0; entry < numEntries; entry++) { 104 | index[entry] = FETCH4(&tab[offset]); 105 | offset += 4; 106 | } 107 | 108 | // read data 109 | for (entry = 0; entry < numEntries; entry++) { 110 | 111 | uint8_t flags = tab[ offset ]; 112 | offset += 1; 113 | 114 | uint32_t tmp = FETCH4(&tab[offset]); // only fetch 3bytes, 24 bits. 115 | offset += 3; 116 | tmp &= 0xFFFFFF00; 117 | 118 | uint32_t patch0_address_adjust = (tmp & 0xFFF00000) >> 20; 119 | uint32_t patch1_address_adjust = (tmp & 0x000FFF00) >> 8; 120 | 121 | uint32_t patch0_buffer_offset = tab[offset++]; 122 | uint32_t patch1_buffer_offset = tab[offset++]; 123 | uint8_t patch0[5], patch1[5]; 124 | 125 | memcpy(patch0, &tab[ offset ], sizeof(patch0)); 126 | offset += 5; 127 | memcpy(patch1, &tab[ offset ], sizeof(patch1)); 128 | offset += 5; 129 | 130 | uint64_t off0 = (( (uint64_t)index[entry] + 131 | (uint64_t)patch0_address_adjust) * 132 | (uint64_t)0xC0 + 133 | (uint64_t)patch0_buffer_offset); 134 | 135 | uint64_t off1 = (( (uint64_t)index[entry] + 136 | (uint64_t)patch0_address_adjust + 137 | (uint64_t)patch1_address_adjust) * 138 | (uint64_t)0xC0 + 139 | (uint64_t)patch1_buffer_offset); 140 | 141 | printf(" Entry %d: flags 0x%x (%d)\n", entry, flags, flags>>6); 142 | printf(" %08X %08X: %02X %02X %02X %02X %02X\n", 143 | (uint32_t)(off0 >> 32), (uint32_t)(off0 & 0xffffffff), 144 | patch0[0], patch0[1], patch0[2], patch0[3], patch0[4]); 145 | printf(" %08X %08X: %02X %02X %02X %02X %02X\n", 146 | (uint32_t)(off1 >> 32), (uint32_t)(off1 & 0xffffffff), 147 | patch1[0], patch1[1], patch1[2], patch1[3], patch1[4]); 148 | 149 | if ((flags >> 6) == 3) { 150 | printf(" *** invalid flags ***\n"); 151 | errors++; 152 | } 153 | if ((flags >> 6) == 1) { 154 | if (patch0_buffer_offset < 8 || patch1_buffer_offset < 8) { 155 | printf(" *** Invalid in-packet offset (inside ts header) ***\n"); 156 | errors++; 157 | } 158 | if (patch0_buffer_offset > 187 || patch1_buffer_offset > 187) { 159 | printf(" *** Invalid in-packet offset (overwrite) ***\n"); 160 | errors++; 161 | } 162 | if (off0 >= off1) { 163 | printf(" *** invalid offset (off0 >= off1) ***\n"); 164 | errors++; 165 | } 166 | if (off0 < prev_off1) { 167 | printf(" *** invalid offset sequence (not monotonic) ***\n"); 168 | errors++; 169 | } 170 | prev_off1 = off1; 171 | } 172 | 173 | } // for entry 174 | 175 | } // for segment 176 | 177 | ptr = offset; 178 | 179 | } // for table 180 | 181 | return errors; 182 | } 183 | -------------------------------------------------------------------------------- /SMP/libbdplus_deps.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | VisualStudioVersion = 12.0.30501.0 4 | MinimumVisualStudioVersion = 12.0.30501.0 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbdplus", "libbdplus.vcxproj", "{B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}" 6 | ProjectSection(ProjectDependencies) = postProject 7 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E} = {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E} 8 | EndProjectSection 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{F20032DA-72B6-4D5A-9EF5-3D304315B376}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgcrypt", "..\..\libgcrypt\SMP\libgcrypt.vcxproj", "{5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}" 13 | ProjectSection(ProjectDependencies) = postProject 14 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105} = {A04A762D-A8D7-4F68-9B79-FBE63C6BE105} 15 | EndProjectSection 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgpg-error", "..\..\libgpg-error\SMP\libgpg-error.vcxproj", "{A04A762D-A8D7-4F68-9B79-FBE63C6BE105}" 18 | EndProject 19 | Global 20 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 21 | Debug|x64 = Debug|x64 22 | Debug|x86 = Debug|x86 23 | DebugDLL|x64 = DebugDLL|x64 24 | DebugDLL|x86 = DebugDLL|x86 25 | Release|x64 = Release|x64 26 | Release|x86 = Release|x86 27 | ReleaseDLL|x64 = ReleaseDLL|x64 28 | ReleaseDLL|x86 = ReleaseDLL|x86 29 | ReleaseDLLStaticDeps|x64 = ReleaseDLLStaticDeps|x64 30 | ReleaseDLLStaticDeps|x86 = ReleaseDLLStaticDeps|x86 31 | EndGlobalSection 32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 33 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x64.ActiveCfg = Debug|x64 34 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x64.Build.0 = Debug|x64 35 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x86.ActiveCfg = Debug|Win32 36 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x86.Build.0 = Debug|Win32 37 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x64.ActiveCfg = DebugDLL|x64 38 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x64.Build.0 = DebugDLL|x64 39 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x86.ActiveCfg = DebugDLL|Win32 40 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x86.Build.0 = DebugDLL|Win32 41 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x64.ActiveCfg = Release|x64 42 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x64.Build.0 = Release|x64 43 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x86.ActiveCfg = Release|Win32 44 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x86.Build.0 = Release|Win32 45 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x64.ActiveCfg = ReleaseDLL|x64 46 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x64.Build.0 = ReleaseDLL|x64 47 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x86.ActiveCfg = ReleaseDLL|Win32 48 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x86.Build.0 = ReleaseDLL|Win32 49 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x64.ActiveCfg = ReleaseDLLStaticDeps|x64 50 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x64.Build.0 = ReleaseDLLStaticDeps|x64 51 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x86.ActiveCfg = ReleaseDLLStaticDeps|Win32 52 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x86.Build.0 = ReleaseDLLStaticDeps|Win32 53 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Debug|x64.ActiveCfg = Debug|x64 54 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Debug|x64.Build.0 = Debug|x64 55 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Debug|x86.ActiveCfg = Debug|Win32 56 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Debug|x86.Build.0 = Debug|Win32 57 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.DebugDLL|x64.ActiveCfg = DebugDLL|x64 58 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.DebugDLL|x64.Build.0 = DebugDLL|x64 59 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.DebugDLL|x86.ActiveCfg = DebugDLL|Win32 60 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.DebugDLL|x86.Build.0 = DebugDLL|Win32 61 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Release|x64.ActiveCfg = Release|x64 62 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Release|x64.Build.0 = Release|x64 63 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Release|x86.ActiveCfg = Release|Win32 64 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.Release|x86.Build.0 = Release|Win32 65 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLL|x64.ActiveCfg = ReleaseDLL|x64 66 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLL|x64.Build.0 = ReleaseDLL|x64 67 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLL|x86.ActiveCfg = ReleaseDLL|Win32 68 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLL|x86.Build.0 = ReleaseDLL|Win32 69 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLLStaticDeps|x64.ActiveCfg = Release|x64 70 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLLStaticDeps|x64.Build.0 = Release|x64 71 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLLStaticDeps|x86.ActiveCfg = Release|Win32 72 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E}.ReleaseDLLStaticDeps|x86.Build.0 = Release|Win32 73 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Debug|x64.ActiveCfg = Debug|x64 74 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Debug|x64.Build.0 = Debug|x64 75 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Debug|x86.ActiveCfg = Debug|Win32 76 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Debug|x86.Build.0 = Debug|Win32 77 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.DebugDLL|x64.ActiveCfg = DebugDLL|x64 78 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.DebugDLL|x64.Build.0 = DebugDLL|x64 79 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.DebugDLL|x86.ActiveCfg = DebugDLL|Win32 80 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.DebugDLL|x86.Build.0 = DebugDLL|Win32 81 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Release|x64.ActiveCfg = Release|x64 82 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Release|x64.Build.0 = Release|x64 83 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Release|x86.ActiveCfg = Release|Win32 84 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.Release|x86.Build.0 = Release|Win32 85 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLL|x64.ActiveCfg = ReleaseDLL|x64 86 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLL|x64.Build.0 = ReleaseDLL|x64 87 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLL|x86.ActiveCfg = ReleaseDLL|Win32 88 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLL|x86.Build.0 = ReleaseDLL|Win32 89 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLLStaticDeps|x64.ActiveCfg = Release|x64 90 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLLStaticDeps|x64.Build.0 = Release|x64 91 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLLStaticDeps|x86.ActiveCfg = Release|Win32 92 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105}.ReleaseDLLStaticDeps|x86.Build.0 = Release|Win32 93 | EndGlobalSection 94 | GlobalSection(SolutionProperties) = preSolution 95 | HideSolutionNode = FALSE 96 | EndGlobalSection 97 | GlobalSection(NestedProjects) = preSolution 98 | {5D7A23EF-09DE-4C75-8ED1-F783BAACFC7E} = {F20032DA-72B6-4D5A-9EF5-3D304315B376} 99 | {A04A762D-A8D7-4F68-9B79-FBE63C6BE105} = {F20032DA-72B6-4D5A-9EF5-3D304315B376} 100 | EndGlobalSection 101 | EndGlobal 102 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl library version number 2 | m4_define([bdplus_major], 0) 3 | m4_define([bdplus_minor], 2) 4 | m4_define([bdplus_micro], 0) 5 | m4_define([bdplus_version],[bdplus_major.bdplus_minor.bdplus_micro]) 6 | 7 | dnl library (.so) version 8 | # 9 | dnl update when making new release 10 | # 11 | dnl - If there are no ABI changes, increase revision. 12 | dnl - If ABI is changed backwards-compatible way, increase current and age. Set revision to 0. 13 | dnl - If ABI is broken, increase current and set age and revision to 0. 14 | # 15 | dnl Library file name will be libbdplus.(current-age).age.revision 16 | # 17 | m4_define([lt_current], 2) 18 | m4_define([lt_age], 2) 19 | m4_define([lt_revision], 0) 20 | 21 | dnl initilization 22 | AC_INIT([libbdplus], bdplus_version, [http://www.videolan.org/developers/libbdplus.html]) 23 | AC_CONFIG_AUX_DIR([build-aux]) 24 | AC_CONFIG_MACRO_DIR([m4]) 25 | AC_CANONICAL_SYSTEM 26 | AM_INIT_AUTOMAKE([foreign tar-ustar dist-bzip2 no-dist-gzip subdir-objects]) 27 | AC_CONFIG_HEADERS(config.h) 28 | 29 | dnl Enable silent rules only when available (automake 1.11 or later). 30 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 31 | 32 | SET_FEATURES="-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112L" 33 | 34 | case "${host_os}" in 35 | "") 36 | SYS=unknown 37 | ;; 38 | *mingw* | *cygwin* | *wince* | *mingwce*) 39 | case "${host_os}" in 40 | *wince* | *mingwce* | *mingw32ce*) 41 | SYS=mingwce 42 | ;; 43 | *mingw*) 44 | SYS=mingw32 45 | AC_DEFINE([_WIN32_WINNT], 0x0501, [Define to '0x0500' for Windows XP APIs.]) 46 | AC_DEFINE([_WIN32_IE], 0x0501, [Define to '0x0501' for IE 5.01.]) 47 | ;; 48 | esac 49 | ;; 50 | *darwin*) 51 | SYS=darwin 52 | ;; 53 | *) 54 | SYS="${host_os}" 55 | ;; 56 | esac 57 | 58 | AM_CONDITIONAL(HAVE_WIN32, test "${SYS}" = "mingw32") 59 | AM_CONDITIONAL(HAVE_DARWIN, test "${SYS}" = "darwin") 60 | 61 | dnl messages 62 | library_not_found="Could not find required library!" 63 | function_not_found="Could not find required function!" 64 | 65 | dnl configure options 66 | AC_ARG_ENABLE([werror], 67 | [AS_HELP_STRING([--enable-werror], [set warnings as errors via -Werror @<:@default=disabled@:>@])]) 68 | 69 | AC_ARG_ENABLE([extra-warnings], 70 | [AS_HELP_STRING([--disable-extra-warnings], [set extra warnings @<:@default=enabled@:>@])]) 71 | 72 | AC_ARG_ENABLE([optimizations], 73 | [AS_HELP_STRING([--disable-optimizations], [disable optimizations @<:@default=enabled@:>@])]) 74 | 75 | dnl override platform specific check for dependent libraries 76 | dnl otherwise libtool linking of shared libraries will 77 | dnl fail on anything other than pass_all. 78 | AC_CACHE_VAL(lt_cv_deplibs_check_method, 79 | [lt_cv_deplibs_check_method=pass_all]) 80 | 81 | dnl required programs 82 | AC_PROG_CC 83 | AC_PROG_LIBTOOL 84 | AC_LIBTOOL_WIN32_DLL 85 | 86 | dnl required types 87 | AC_TYPE_SIGNAL 88 | 89 | dnl required headers 90 | AC_CHECK_HEADERS([stdarg.h sys/types.h dirent.h errno.h libgen.h malloc.h]) 91 | AC_CHECK_HEADERS([stdlib.h mntent.h linux/cdrom.h inttypes.h]) 92 | AC_CHECK_HEADERS([sys/time.h time.h]) 93 | 94 | dnl required structures 95 | AC_STRUCT_DIRENT_D_TYPE 96 | 97 | dnl required system services 98 | AC_SYS_LARGEFILE 99 | 100 | dnl required functions 101 | AC_CHECK_FUNC([snprintf],, [AC_MSG_ERROR($function_not_found)]) 102 | 103 | dnl pthread check (not on win32) 104 | AS_IF([test "${SYS}" != "mingw32"], [ 105 | AC_CHECK_HEADERS([pthread.h], , 106 | [AC_MSG_ERROR([pthread required])]) 107 | AC_SEARCH_LIBS([pthread_create], [pthread], , 108 | [AC_MSG_ERROR([pthread required])]) 109 | ]) 110 | 111 | dnl gcrypt check 112 | 113 | AC_ARG_WITH(libgcrypt-prefix, 114 | AC_HELP_STRING([--with-libgcrypt-prefix=PFX], 115 | [prefix where libgcrypt is installed (optional)]), 116 | libgcrypt_config_prefix="$withval", libgcrypt_config_prefix="") 117 | if test x$libgcrypt_config_prefix != x ; then 118 | if test x${LIBGCRYPT_CONFIG+set} != xset ; then 119 | LIBGCRYPT_CONFIG=$libgcrypt_config_prefix/bin/libgcrypt-config 120 | fi 121 | fi 122 | 123 | AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no) 124 | if test x"$LIBGCRYPT_CONFIG" = xno; then 125 | AC_MSG_ERROR([libgcrypt not found on system]) 126 | else 127 | LIBGCRYPT_CFLAGS=`$LIBGCRYPT_CONFIG --cflags` 128 | LIBGCRYPT_LIBS=`$LIBGCRYPT_CONFIG --libs` 129 | AC_SUBST(LIBGCRYPT_CFLAGS) 130 | AC_SUBST(LIBGCRYPT_LIBS) 131 | fi 132 | AC_FUNC_STRERROR_R 133 | 134 | dnl use re-entrant version of gcrypt_error() from gpg-error 135 | 136 | AC_ARG_WITH(gpg-error-prefix, 137 | AC_HELP_STRING([--with-gpg-error-prefix=PFX], 138 | [prefix where gpg-error is installed (optional)]), 139 | gpg_error_config_prefix="$withval", gpg_error_config_prefix="") 140 | if test x$gpg_error_config_prefix != x ; then 141 | if test x${GPG_ERROR_CONFIG+set} != xset ; then 142 | GPG_ERROR_CONFIG=$gpg_error_config_prefix/bin/gpg-error-config 143 | fi 144 | fi 145 | 146 | AC_PATH_PROG(GPG_ERROR_CONFIG, gpg-error-config, no) 147 | if test x"$GPG_ERROR_CONFIG" = xno; then 148 | AC_MSG_ERROR([gpg-error not found on system]) 149 | else 150 | GPG_ERROR_CFLAGS=`$GPG_ERROR_CONFIG --cflags` 151 | GPG_ERROR_LIBS=`$GPG_ERROR_CONFIG --libs` 152 | AC_SUBST(GPG_ERROR_CFLAGS) 153 | AC_SUBST(GPG_ERROR_LIBS) 154 | AC_DEFINE(HAVE_LIBGPG_ERROR, 1, [Define to 1 if you have the gpg-error library]) 155 | fi 156 | 157 | dnl libaacs (for bdplus_test) 158 | AC_ARG_WITH([libaacs], 159 | [AS_HELP_STRING([--without-libaacs], [build bdplus_test without libaacs support @<:@default=with@:>@])]) 160 | AS_IF([test "x$with_libaacs" != "xno"], [ 161 | PKG_CHECK_MODULES([LIBAACS], [libaacs >= 0.7.0], 162 | [with_libaacs=yes; AC_DEFINE([HAVE_LIBAACS], [1], 163 | [Define to 1 to use libaacs with bdplus_test])], 164 | [with_libaacs=no]) 165 | ]) 166 | 167 | CC_CHECK_CFLAGS_APPEND([-Wall -Wdisabled-optimization -Wpointer-arith ]dnl 168 | [-Wredundant-decls -Wcast-qual -Wwrite-strings -Wtype-limits -Wundef ]dnl 169 | [-Wmissing-prototypes -Wshadow]) 170 | 171 | CC_CHECK_CFLAGS_APPEND([-Werror=implicit-function-declaration ]dnl 172 | [-Werror-implicit-function-declaration], 173 | [break;]) 174 | 175 | CC_CHECK_WERROR 176 | AS_IF([test "x$enable_werror" = "xyes"], [ 177 | CFLAGS="${CFLAGS} $cc_cv_werror" 178 | ]) 179 | 180 | AS_IF([test "x$enable_extra_warnings" != "xno"], [ 181 | CC_CHECK_CFLAGS_APPEND([-Wextra -Winline]) 182 | ]) 183 | 184 | AS_IF([test "x$enable_optimizations" != "xno"], [ 185 | CC_CHECK_CFLAGS_APPEND([-O3 -fomit-frame-pointer]) 186 | ]) 187 | 188 | 189 | dnl export library version number 190 | BDPLUS_VERSION_MAJOR=bdplus_major() 191 | AC_SUBST(BDPLUS_VERSION_MAJOR) 192 | BDPLUS_VERSION_MINOR=bdplus_minor() 193 | AC_SUBST(BDPLUS_VERSION_MINOR) 194 | BDPLUS_VERSION_MICRO=bdplus_micro() 195 | AC_SUBST(BDPLUS_VERSION_MICRO) 196 | 197 | dnl export library (.so) version 198 | LT_VERSION_INFO="lt_current:lt_revision:lt_age" 199 | AC_SUBST(LT_VERSION_INFO) 200 | 201 | dnl generate output files 202 | AC_SUBST(SET_FEATURES) 203 | AC_CONFIG_FILES([Makefile src/libbdplus.pc src/libbdplus/bdplus-version.h]) 204 | AC_OUTPUT 205 | -------------------------------------------------------------------------------- /SMP/libbdplus.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | VisualStudioVersion = 12.0.30501.0 4 | MinimumVisualStudioVersion = 12.0.30501.0 5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbdplus", "libbdplus.vcxproj", "{B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}" 6 | EndProject 7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libbdplus_winrt", "libbdplus_winrt.vcxproj", "{A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}" 8 | EndProject 9 | Global 10 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 11 | Debug|x64 = Debug|x64 12 | Debug|x86 = Debug|x86 13 | DebugDLL|x64 = DebugDLL|x64 14 | DebugDLL|x86 = DebugDLL|x86 15 | DebugDLLWinRT|x64 = DebugDLLWinRT|x64 16 | DebugDLLWinRT|x86 = DebugDLLWinRT|x86 17 | DebugWinRT|x64 = DebugWinRT|x64 18 | DebugWinRT|x86 = DebugWinRT|x86 19 | Release|x64 = Release|x64 20 | Release|x86 = Release|x86 21 | ReleaseDLL|x64 = ReleaseDLL|x64 22 | ReleaseDLL|x86 = ReleaseDLL|x86 23 | ReleaseDLLStaticDeps|x64 = ReleaseDLLStaticDeps|x64 24 | ReleaseDLLStaticDeps|x86 = ReleaseDLLStaticDeps|x86 25 | ReleaseDLLWinRT|x64 = ReleaseDLLWinRT|x64 26 | ReleaseDLLWinRT|x86 = ReleaseDLLWinRT|x86 27 | ReleaseDLLWinRTStaticDeps|x64 = ReleaseDLLWinRTStaticDeps|x64 28 | ReleaseDLLWinRTStaticDeps|x86 = ReleaseDLLWinRTStaticDeps|x86 29 | ReleaseWinRT|x64 = ReleaseWinRT|x64 30 | ReleaseWinRT|x86 = ReleaseWinRT|x86 31 | EndGlobalSection 32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 33 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x64.ActiveCfg = Debug|x64 34 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x64.Build.0 = Debug|x64 35 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x86.ActiveCfg = Debug|Win32 36 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x86.Build.0 = Debug|Win32 37 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x64.ActiveCfg = DebugDLL|x64 38 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x64.Build.0 = DebugDLL|x64 39 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x86.ActiveCfg = DebugDLL|Win32 40 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x86.Build.0 = DebugDLL|Win32 41 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x64.ActiveCfg = DebugDLL|x64 42 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x86.ActiveCfg = DebugDLL|Win32 43 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x64.ActiveCfg = Debug|x64 44 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x86.ActiveCfg = Debug|Win32 45 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x64.ActiveCfg = Release|x64 46 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x64.Build.0 = Release|x64 47 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x86.ActiveCfg = Release|Win32 48 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x86.Build.0 = Release|Win32 49 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x64.ActiveCfg = ReleaseDLL|x64 50 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x64.Build.0 = ReleaseDLL|x64 51 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x86.ActiveCfg = ReleaseDLL|Win32 52 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x86.Build.0 = ReleaseDLL|Win32 53 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x64.ActiveCfg = ReleaseDLLStaticDeps|x64 54 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x64.Build.0 = ReleaseDLLStaticDeps|x64 55 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x86.ActiveCfg = ReleaseDLLStaticDeps|Win32 56 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x86.Build.0 = ReleaseDLLStaticDeps|Win32 57 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x64.ActiveCfg = ReleaseDLL|x64 58 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x86.ActiveCfg = ReleaseDLL|Win32 59 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x64.ActiveCfg = ReleaseDLLStaticDeps|x64 60 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x86.ActiveCfg = ReleaseDLLStaticDeps|Win32 61 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x64.ActiveCfg = Release|x64 62 | {B30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x86.ActiveCfg = Release|Win32 63 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x64.ActiveCfg = DebugWinRT|x64 64 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Debug|x86.ActiveCfg = DebugWinRT|Win32 65 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x64.ActiveCfg = DebugDLLWinRT|x64 66 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLL|x86.ActiveCfg = DebugDLLWinRT|Win32 67 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x64.ActiveCfg = DebugDLLWinRT|x64 68 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x64.Build.0 = DebugDLLWinRT|x64 69 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x86.ActiveCfg = DebugDLLWinRT|Win32 70 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugDLLWinRT|x86.Build.0 = DebugDLLWinRT|Win32 71 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x64.ActiveCfg = DebugWinRT|x64 72 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x64.Build.0 = DebugWinRT|x64 73 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x86.ActiveCfg = DebugWinRT|Win32 74 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.DebugWinRT|x86.Build.0 = DebugWinRT|Win32 75 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x64.ActiveCfg = ReleaseWinRT|x64 76 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.Release|x86.ActiveCfg = ReleaseWinRT|Win32 77 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x64.ActiveCfg = ReleaseDLLWinRT|x64 78 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLL|x86.ActiveCfg = ReleaseDLLWinRT|Win32 79 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x64.ActiveCfg = ReleaseDLLWinRTStaticDeps|x64 80 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLStaticDeps|x86.ActiveCfg = ReleaseDLLWinRTStaticDeps|Win32 81 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x64.ActiveCfg = ReleaseDLLWinRT|x64 82 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x64.Build.0 = ReleaseDLLWinRT|x64 83 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x86.ActiveCfg = ReleaseDLLWinRT|Win32 84 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRT|x86.Build.0 = ReleaseDLLWinRT|Win32 85 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x64.ActiveCfg = ReleaseDLLWinRTStaticDeps|x64 86 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x64.Build.0 = ReleaseDLLWinRTStaticDeps|x64 87 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x86.ActiveCfg = ReleaseDLLWinRTStaticDeps|Win32 88 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseDLLWinRTStaticDeps|x86.Build.0 = ReleaseDLLWinRTStaticDeps|Win32 89 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x64.ActiveCfg = ReleaseWinRT|x64 90 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x64.Build.0 = ReleaseWinRT|x64 91 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x86.ActiveCfg = ReleaseWinRT|Win32 92 | {A30D4367-E5BF-4A9E-8BEE-18E79B5CF7E5}.ReleaseWinRT|x86.Build.0 = ReleaseWinRT|Win32 93 | EndGlobalSection 94 | GlobalSection(SolutionProperties) = preSolution 95 | HideSolutionNode = FALSE 96 | EndGlobalSection 97 | GlobalSection(ExtensibilityGlobals) = postSolution 98 | SolutionGuid = {50845F2E-2151-495D-B424-9082EF486CB2} 99 | EndGlobalSection 100 | EndGlobal 101 | -------------------------------------------------------------------------------- /SMP/project_get_dependencies.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SETLOCAL EnableDelayedExpansion 3 | 4 | SET UPSTREAMURL=https://github.com/ShiftMediaProject 5 | SET DEPENDENCIES=( ^ 6 | libgcrypt ^ 7 | ) 8 | 9 | REM Get passed in list of dependencies to skip 10 | SET PASSDEPENDENCIES=%~1 11 | 12 | REM Check if git is installed and available 13 | IF "%MSVC_VER%"=="" ( 14 | git status >NUL 2>&1 15 | IF ERRORLEVEL 1 ( 16 | ECHO A working copy of git was not found. To use this script you must first install git for windows. 17 | GOTO exitOnError 18 | ) 19 | ) 20 | 21 | REM Store current directory and ensure working directory is the location of current .bat 22 | SET CURRDIR="%CD%" 23 | cd "%~dp0" 24 | 25 | REM Initialise error check value 26 | SET ERROR=0 27 | 28 | cd ..\.. 29 | FOR %%I IN %DEPENDENCIES% DO ( 30 | ECHO !PASSDEPENDENCIES! | FINDSTR /C:"%%I" >NUL 2>&1 || ( 31 | REM Check if MSVC_VER environment variable is set 32 | IF "%MSVC_VER%"=="" ( 33 | CALL :cloneOrUpdateRepo "%%I" || GOTO exitOnError 34 | ) ELSE ( 35 | CALL :downloadLibs "%%I" || GOTO exitOnError 36 | ) 37 | ) 38 | ) 39 | cd "%CURRDIR%" >NUL 40 | GOTO exit 41 | 42 | REM Function to clone or update a repo 43 | REM cloneOrUpdateRepo: RepoName 44 | REM RepoName = Name of the repository 45 | :cloneOrUpdateRepo 46 | SET REPONAME=%~1 47 | REM Check if the repo folder already exists 48 | IF EXIST "%REPONAME%" ( 49 | ECHO %REPONAME%: Existing folder found. Checking for updates... 50 | cd %REPONAME% 51 | REM Check if any updates are available 52 | FOR /f %%J IN ('git rev-parse HEAD') do set CURRHEAD=%%J 53 | FOR /f %%J IN ('git ls-remote origin HEAD') do set ORIGHEAD=%%J 54 | IF "!CURRHEAD!"=="!ORIGHEAD!" ( 55 | ECHO %REPONAME%: Repository up to date. 56 | ) ELSE ( 57 | REM Stash any uncommited changes then update from origin 58 | ECHO %REPONAME%: Updates available. Updating repository... 59 | git checkout master --quiet 60 | git stash --quiet 61 | git pull origin master --quiet -ff 62 | git stash pop --quiet 63 | ) 64 | cd ..\ 65 | ) ELSE ( 66 | ECHO %REPONAME%: Existing folder not found. Cloning repository... 67 | REM Clone from the origin repo 68 | SET REPOURL=%UPSTREAMURL%/%REPONAME%.git 69 | git clone !REPOURL! --quiet 70 | IF ERRORLEVEL 1 ( 71 | ECHO %REPONAME%: Git clone failed. 72 | GOTO exitOnError 73 | ) 74 | REM Initialise autocrlf options to fix cross platform interoperation 75 | REM Once updated the repo needs to be reset to correct the local line endings 76 | cd %REPONAME% 77 | git config --local core.autocrlf false 78 | git rm --cached -r . --quiet 79 | git reset --hard --quiet 80 | cd ..\ 81 | ) 82 | REM Add current repo to list of already passed dependencies 83 | SET PASSDEPENDENCIES=%PASSDEPENDENCIES% %REPONAME% 84 | REM Check if the repo itself has required dependencies 85 | IF EXIST "%REPONAME%\SMP\project_get_dependencies.bat" ( 86 | ECHO %REPONAME%: Found additional dependencies... 87 | ECHO. 88 | cd %REPONAME%\SMP 89 | project_get_dependencies.bat "!PASSDEPENDENCIES!" || EXIT /B 1 90 | cd ..\.. 91 | ) 92 | ECHO. 93 | EXIT /B %ERRORLEVEL% 94 | 95 | REM Function to download existing prebuilt libraries 96 | REM downloadLibs: RepoName 97 | REM RepoName = Name of the repository 98 | :downloadLibs 99 | SET REPONAME=%~1 100 | REM Get latest release 101 | ECHO %REPONAME%: Getting latest release... 102 | SET UPSTREAMAPIURL=%UPSTREAMURL:github.com=api.github.com/repos% 103 | REM Check if secure OAuth is available 104 | IF "%GITHUBTOKEN%" == "" ( 105 | powershell -nologo -noprofile -command "$currentMaxTls = [Math]::Max([Net.ServicePointManager]::SecurityProtocol.value__,[Net.SecurityProtocolType]::Tls.value__);$newTlsTypes = [enum]::GetValues('Net.SecurityProtocolType') | ?{ $_ -gt $currentMaxTls };ForEach ($newTls in $newTlsTypes) { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $newTls };try { Invoke-RestMethod -Uri %UPSTREAMAPIURL%/%REPONAME%/releases/latest > latest.json } catch {exit 1}" 106 | ) ELSE ( 107 | powershell -nologo -noprofile -command "$currentMaxTls = [Math]::Max([Net.ServicePointManager]::SecurityProtocol.value__,[Net.SecurityProtocolType]::Tls.value__);$newTlsTypes = [enum]::GetValues('Net.SecurityProtocolType') | ?{ $_ -gt $currentMaxTls };ForEach ($newTls in $newTlsTypes) { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $newTls };try { Invoke-RestMethod -Uri %UPSTREAMAPIURL%/%REPONAME%/releases/latest -Headers @{'Authorization' = 'token %GITHUBTOKEN%'} > latest.json } catch {exit 1}" 108 | ) 109 | IF ERRORLEVEL 1 ( ECHO Failed getting latest %REPONAME% release & EXIT /B 1 ) 110 | REM Get tag for latest release 111 | FOR /F "tokens=* USEBACKQ" %%F IN (`TYPE latest.json ^| FINDSTR /B "tag_name"`) DO SET TAG=%%F 112 | FOR /F "tokens=2 delims=: " %%F in ("%TAG%") DO SET TAG=%%F 113 | IF "%TAG%"=="" ( ECHO Failed getting latest %REPONAME% release tag information & EXIT /B 1 ) 114 | REM Get download name of latest release 115 | SET LIBNAME= 116 | FOR /F "tokens=* USEBACKQ" %%F IN (`TYPE latest.json ^| FINDSTR "name="`) DO ( SET TEMPF=%%F 117 | SET TEMPF=!TEMPF:*name=! 118 | IF "!TEMPF:~1,3!"=="lib" ( SET LIBNAME=!TEMPF:~1! ) 119 | ) 120 | FOR /F "tokens=1 delims=_" %%F in ("%LIBNAME%") DO SET LIBNAME=%%F 121 | IF "%LIBNAME%"=="" ( ECHO Failed getting latest %REPONAME% release name information & EXIT /B 1 ) 122 | DEL /F /Q latest.json 123 | REM Get the download location for the required tag 124 | SET TAG2=%TAG:+=.% 125 | SET DLURL=%UPSTREAMURL%/%REPONAME%/releases/download/%TAG%/%LIBNAME%_%TAG2%_msvc%MSVC_VER%.zip 126 | REM Download a pre-built archive and extract 127 | ECHO %REPONAME%: Downloading %LIBNAME%_%TAG%_msvc%MSVC_VER%.zip... 128 | SET PREBUILTDIR=prebuilt 129 | MKDIR %PREBUILTDIR% >NUL 2>&1 130 | powershell -nologo -noprofile -command "$currentMaxTls = [Math]::Max([Net.ServicePointManager]::SecurityProtocol.value__,[Net.SecurityProtocolType]::Tls.value__);$newTlsTypes = [enum]::GetValues('Net.SecurityProtocolType') | ?{ $_ -gt $currentMaxTls };ForEach ($newTls in $newTlsTypes) { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor $newTls };try { (New-Object Net.WebClient).DownloadFile('%DLURL%', '%PREBUILTDIR%\temp.zip') } catch {exit 1}" 131 | IF ERRORLEVEL 1 ( ECHO Failed downloading %DLURL% & EXIT /B 1 ) 132 | powershell -nologo -noprofile -command "Add-Type -AssemblyName System.IO.Compression.FileSystem; $zip=[System.IO.Compression.ZipFile]::OpenRead('%PREBUILTDIR%\temp.zip'); foreach ($item in $zip.Entries) { try {$file=(Join-Path -Path .\%PREBUILTDIR% -ChildPath $item.FullName); $null=[System.IO.Directory]::CreateDirectory((Split-Path -Path $file)); [System.IO.Compression.ZipFileExtensions]::ExtractToFile($item,$file,$true)} catch {exit 1} }" 133 | IF ERRORLEVEL 1 ( ECHO Failed extracting downloaded archive & EXIT /B 1 ) 134 | DEL /F /Q %PREBUILTDIR%\\temp.zip 135 | ECHO. 136 | EXIT /B %ERRORLEVEL% 137 | 138 | :exitOnError 139 | cd "%CURRDIR%" 140 | SET ERROR=1 141 | 142 | :exit 143 | REM Directly exit if an AppVeyor build 144 | IF NOT "%APPVEYOR%"=="" ( 145 | GOTO return 146 | ) 147 | REM Return the passed dependency list 148 | ( 149 | ENDLOCAL 150 | SET PASSDEPENDENCIES=%PASSDEPENDENCIES% 151 | ) 152 | 153 | REM Check if this was launched from an existing terminal or directly from .bat 154 | REM If launched by executing the .bat then pause on completion 155 | ECHO %CMDCMDLINE% | FINDSTR /L %COMSPEC% >NUL 2>&1 156 | IF %ERRORLEVEL% == 0 IF "%~1"=="" PAUSE 157 | 158 | :return 159 | EXIT /B %ERROR% -------------------------------------------------------------------------------- /src/libbdplus/bdsvm/diff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of libbdplus 3 | * Copyright (C) 2008-2010 Accident 4 | * 5 | * This library is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU Lesser General Public 7 | * License as published by the Free Software Foundation; either 8 | * version 2.1 of the License, or (at your option) any later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Lesser General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Lesser General Public 16 | * License along with this library. If not, see 17 | * . 18 | */ 19 | 20 | #include "diff.h" 21 | #include "dlx.h" 22 | #include "trap.h" 23 | 24 | #include "util/logging.h" 25 | #include "util/macro.h" 26 | #include "util/strutl.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | /* 35 | * DiffArchive File Format: 36 | * 37 | * All values are LE! 38 | * 39 | * len | name | description 40 | * -------+----------+------------ 41 | * 4 | size | size of contained files. all files have same size. 42 | * 4 | count | number of contained files 43 | * count * 44 | * 4 | diffcnt | total number of diff-segments for this file 45 | * diffcnt * 46 | * 4 | start | start of diff 47 | * 4 | length | length of diff 48 | * length | data | raw data that differs from previous file 49 | * 50 | */ 51 | 52 | 53 | #if 0 54 | int32_t diff_isarchive(char *fname) 55 | { 56 | int32_t len; 57 | 58 | if (!fname || !*fname) return 0; 59 | 60 | len = strlen(fname); 61 | 62 | if ((len > 15) && 63 | (!str_match(fname, ".*diffarchive\\.bin$", 1))) 64 | return 1; 65 | 66 | return 0; 67 | } 68 | #endif 69 | 70 | 71 | int32_t diff_loadcore(uint8_t *addr, uint32_t vmsize, char *fname, 72 | uint32_t trap, uint32_t flags) 73 | { 74 | FILE *fd; 75 | uint32_t currtrap = 0; 76 | uint32_t currdiff = 0; 77 | uint32_t size, count, diffcnt, start, length; 78 | 79 | fd = fopen(fname, "rb"); 80 | if (!fd) return errno; 81 | 82 | BD_DEBUG(DBG_BDPLUS,"[diff] opened '%s' to find trap %d...\n", fname, trap); 83 | 84 | if (fread(&size, sizeof(size), 1, fd) != 1) goto fail; 85 | if (fread(&count, sizeof(count), 1, fd) != 1) goto fail; 86 | 87 | // Now BE 88 | size = FETCH4((uint8_t*)&size); 89 | count = FETCH4((uint8_t*)&count); 90 | 91 | BD_DEBUG(DBG_BDPLUS,"[diff] Memory size is %08X, num diff-files %08X\n", size, count); 92 | 93 | if (trap >= count) { 94 | fclose(fd); 95 | return -1; 96 | } 97 | if (size > vmsize) { 98 | BD_DEBUG(DBG_BDPLUS,"[diff] Diff size larger than vmsize\n"); 99 | fclose(fd); 100 | return -2; // Safety 101 | } 102 | 103 | // Clear the area first. 104 | memset(addr, 0, vmsize); 105 | 106 | // Process diffs from the start to the image we want. 107 | for (currtrap = 0; currtrap <= trap; currtrap++) { 108 | if (fread(&diffcnt, sizeof(diffcnt), 1, fd) != 1) goto fail; 109 | diffcnt = FETCH4((uint8_t*)&diffcnt); 110 | BD_DEBUG(DBG_BDPLUS," trap %08X has %d diffs\n", currtrap, diffcnt); 111 | for (currdiff = 0; currdiff < diffcnt; currdiff++) { 112 | if (fread(&start, sizeof(diffcnt), 1, fd) != 1) goto fail; 113 | if (fread(&length, sizeof(diffcnt), 1, fd) != 1) goto fail; 114 | // Read in the bytes. 115 | start = FETCH4((uint8_t*)&start); 116 | length = FETCH4((uint8_t*)&length); 117 | 118 | if ((uint64_t)start + length > (uint64_t)vmsize) { 119 | BD_DEBUG(DBG_BDPLUS,"[diff] Diff skipping load (would exceed vmsize)\n"); 120 | fclose(fd); 121 | return -2; 122 | } 123 | if (fread(&addr[ start ], length, 1, fd) != 1) goto fail; 124 | } // currdiff 125 | 126 | } // currtrap 127 | 128 | fclose(fd); 129 | 130 | // Little endian load? 131 | // Swap the whole area. 132 | if (flags & BDPLUS_LOAD_SWAP) { 133 | uint32_t i; 134 | uint8_t u1,u2,u3,u4; 135 | for (i = 0; i < vmsize; i+=4 ) { 136 | u1 = addr[i]; 137 | u2 = addr[i+1]; 138 | u3 = addr[i+2]; 139 | u4 = addr[i+3]; 140 | addr[i+3] = u1; 141 | addr[i+2] = u2; 142 | addr[i+1] = u3; 143 | addr[i] = u4; 144 | } 145 | } 146 | 147 | return 0; 148 | 149 | fail: 150 | BD_DEBUG(DBG_BDPLUS,"[diff] archive failed at reading trap %08X diff %08X\n", 151 | currtrap, currdiff); 152 | fclose(fd); 153 | return -1; 154 | 155 | } 156 | 157 | 158 | 159 | struct sha_hdr_s { 160 | uint8_t digest[SHA_DIGEST_LENGTH]; 161 | uint32_t next; 162 | uint32_t len; 163 | }; 164 | 165 | uint32_t diff_hashdb_load(uint8_t *hashname, uint8_t *fname, uint64_t offset, 166 | uint32_t *len, uint8_t *dst) 167 | { 168 | uint8_t *namehash; 169 | uint8_t digest[SHA_DIGEST_LENGTH]; 170 | FILE *fd; 171 | struct sha_hdr_s sha_hdr; 172 | uint32_t shalen; 173 | 174 | BD_DEBUG(DBG_BDPLUS,"[diff] Attempting to open '%s' looking for '%s'\n", 175 | hashname, fname); 176 | 177 | fd = fopen((char *)hashname, "rb"); 178 | if (!fd) return STATUS_INVALID_PARAMETER; 179 | 180 | 181 | shalen = sizeof(offset) + sizeof(*len) + strlen((char *)fname) + 1; 182 | namehash = (uint8_t *)malloc( shalen ); 183 | if (!namehash) { 184 | fclose(fd); 185 | return STATUS_INTERNAL_ERROR; 186 | } 187 | 188 | // SHA[64bit-offset, 32bit-len, filename] 189 | STORE8(&namehash[0], offset); 190 | STORE4(&namehash[sizeof(offset)], *len); 191 | strcpy((char *)&namehash[sizeof(offset)+sizeof(*len)], 192 | (char *)fname); 193 | 194 | char str[512]; 195 | BD_DEBUG(DBG_BDPLUS,"[diff] namehash: %s\n", 196 | str_print_hex(str, namehash, shalen)); 197 | 198 | // Hash it. 199 | gcry_md_hash_buffer(GCRY_MD_SHA1, digest, namehash, shalen - 1); 200 | X_FREE(namehash); 201 | 202 | memset(str, 0, sizeof(str)); 203 | BD_DEBUG(DBG_BDPLUS,"[diff] find hashdb: %s\n", 204 | str_print_hex(str, digest, sizeof(digest))); 205 | 206 | while(fread(&sha_hdr, sizeof(sha_hdr), 1, fd) == 1) { 207 | 208 | memset(str, 0, sizeof(str)); 209 | BD_DEBUG(DBG_BDPLUS,"[diff] read hashdb: %s\n", 210 | str_print_hex(str, sha_hdr.digest, sizeof(digest))); 211 | 212 | sha_hdr.next = FETCH4((uint8_t *)&sha_hdr.next); 213 | if (sha_hdr.next < sizeof(sha_hdr.len)) { 214 | BD_DEBUG(DBG_BDPLUS,"[diff] invalid data in hash_db.bin\n"); 215 | break; 216 | } 217 | if (!memcmp(digest, sha_hdr.digest, sizeof(digest))) { 218 | // Found the digest we are looking for 219 | sha_hdr.len = FETCH4((uint8_t *)&sha_hdr.len); 220 | BD_DEBUG(DBG_BDPLUS,"[diff] found digest, reading %08X (%u) bytes...\n", 221 | sha_hdr.next - (uint32_t)sizeof(sha_hdr.len), 222 | sha_hdr.next - (uint32_t)sizeof(sha_hdr.len)); 223 | 224 | // Read in all digests, perhaps error checking? 225 | if (fread(dst, sha_hdr.next - sizeof(sha_hdr.len), 1, fd) != 1) { 226 | BD_DEBUG(DBG_BDPLUS,"[diff] Short read on hash_db.bin!\n"); 227 | } 228 | // Update new len 229 | *len = sha_hdr.len; 230 | fclose(fd); 231 | return STATUS_OK; 232 | } // if digest match 233 | 234 | // Seek past this entry, "next" number of bytes from "next" position, 235 | // but we read "next" AND "len". 236 | if (fseek(fd, sha_hdr.next - sizeof(sha_hdr.len), SEEK_CUR) < 0) { 237 | BD_DEBUG(DBG_BDPLUS,"[diff] Seek to next hash_db.bin failed\n"); 238 | break; 239 | } 240 | 241 | } // while fread 242 | 243 | fclose(fd); 244 | 245 | *len = 0; 246 | return STATUS_INVALID_PARAMETER; 247 | } 248 | 249 | 250 | 251 | --------------------------------------------------------------------------------