[libbdplus-devel] [Git][videolan/libbdplus][master] 3 commits: Use fs wrappers to load cached convtab
Petri Hintukainen (@hpi)
gitlab at videolan.org
Sat Oct 16 19:34:59 UTC 2021
Petri Hintukainen pushed to branch master at VideoLAN / libbdplus
Commits:
806dc355 by anonymous at 2021-10-16T22:32:23+03:00
Use fs wrappers to load cached convtab
- - - - -
67c29e22 by anonymous at 2021-10-16T22:32:26+03:00
Support disabled patches with in-stream tables
Required with later discs (? 2016 -):
Some patches corrupt good parts of stream.
- - - - -
bd404373 by anonymous at 2021-10-16T22:32:29+03:00
Use helpers
- - - - -
3 changed files:
- src/libbdplus/bdplus.c
- src/libbdplus/bdsvm/segment.c
- src/libbdplus/bdsvm/segment.h
Changes:
=====================================
src/libbdplus/bdplus.c
=====================================
@@ -247,15 +247,17 @@ int32_t bdplus_start(bdplus_t *plus)
cachefile = bdplus_disc_findcachefile(plus);
if (cachefile && !plus->cache_tab) {
- FILE *fp = fopen(cachefile, "rb");
+ BD_FILE_H *fp = file_open_default()(NULL, cachefile);
if (fp) {
conv_table_t *ct = NULL;
- BD_DEBUG(DBG_BDPLUS|DBG_CRIT, "[bdplus] loading cached conversion table...\n");
+ BD_DEBUG(DBG_BDPLUS|DBG_CRIT, "[bdplus] loading cached conversion table %s ...\n", cachefile);
if(segment_load(&ct, fp) == 1) {
segment_activateTable(ct);
plus->cache_tab = ct;
}
- fclose(fp);
+ file_close(fp);
+ } else {
+ BD_DEBUG(DBG_BDPLUS | DBG_CRIT, "[bdplus] Error opening %s\n", cachefile);
}
}
=====================================
src/libbdplus/bdsvm/segment.c
=====================================
@@ -30,6 +30,7 @@
#include "util/logging.h"
#include "util/macro.h"
#include "util/strutl.h"
+#include "file/file.h"
#include <stdlib.h>
#include <inttypes.h>
@@ -440,6 +441,7 @@ static int32_t segment_setMasks(conv_table_t **conv_tab, uint8_t *Table, size_t
{
conv_table_t *ct;
uint32_t ptr = 0;
+ unsigned rec_size = 16;
if (!Table || !len) return -1;
@@ -457,7 +459,11 @@ static int32_t segment_setMasks(conv_table_t **conv_tab, uint8_t *Table, size_t
ct = *conv_tab;
if (!memcmp(Table, "SEGK", 4)) {
- if (memcmp(Table, "SEGK0100", 8)) {
+ if (!memcmp(Table, "SEGK0200", 8)) {
+ BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[segment] segment mask file with FM_ID (version %8.8s)\n", Table);
+ rec_size += 8;
+ }
+ else if (memcmp(Table, "SEGK0100", 8)) {
BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[segment] unsupported segment mask file version %8.8s\n", Table);
return -1;
}
@@ -467,7 +473,7 @@ static int32_t segment_setMasks(conv_table_t **conv_tab, uint8_t *Table, size_t
//return -1;
}
- while (ptr + 4 + 2 + 16 <= len) {
+ while (ptr + 4 + 2 + rec_size <= len) {
subtable_t *subtable;
segment_t *segment;
uint32_t tableID, subtableID;
@@ -507,6 +513,13 @@ static int32_t segment_setMasks(conv_table_t **conv_tab, uint8_t *Table, size_t
memcpy(segment->key, &Table[ptr], 16);
ptr += 16;
+ if (rec_size >= 16+8) {
+ memcpy(segment->mask, &Table[ptr], 8);
+ ptr += 8;
+ } else {
+ /* not available, enable all */
+ memset(segment->mask, 0xff, sizeof(segment->mask));
+ }
}
return ct->numTables;
@@ -965,21 +978,26 @@ static int segment_sortby_tableid(const void *a1, const void *a2)
}
-int32_t segment_load(conv_table_t **conv_tab, FILE *fd)
+int32_t segment_load(conv_table_t **conv_tab, BD_FILE_H *fp)
{
- uint32_t fileLen;
- uint32_t len;
+ int64_t fileLen;
+ int64_t len;
uint8_t *buffer = NULL;
BD_DEBUG(DBG_BDPLUS | DBG_CRIT,"[segment] loading cached convTable file\n");
- fseek(fd, 0L, SEEK_END);
- fileLen=ftell(fd);
- rewind(fd);
- buffer=(uint8_t *)malloc(fileLen+1);
- len=fread(buffer, fileLen, 1, fd);
+
+ fileLen = file_size(fp);
+ if (fileLen < 2 || fileLen > 0x400000)
+ return -1;
+
+ buffer = (uint8_t *)malloc(fileLen);
+ if (!buffer)
+ return -1;
+
+ len = file_read(fp, buffer, fileLen);
// Save the table to VM
- if (len) {
+ if (len == fileLen) {
// Decode the table into C structures.
if (fileLen > 8 && !memcmp(buffer, "SEGK0", 5))
segment_setMasks(conv_tab, buffer, fileLen);
@@ -1197,10 +1215,7 @@ int32_t segment_patchfile(conv_table_t *ct, uint32_t table, FILE *fd)
// PATCH 0
- offset = (( (uint64_t)entry->index +
- (uint64_t)entry->patch0_address_adjust) *
- (uint64_t)0xC0 +
- (uint64_t)entry->patch0_buffer_offset);
+ offset = _entry_offset0(entry);
if (firsttime) {
BD_DEBUG(DBG_BDPLUS,"[segment] would seek to %016"PRIx64" to write patch0\n",
@@ -1221,11 +1236,7 @@ int32_t segment_patchfile(conv_table_t *ct, uint32_t table, FILE *fd)
// PATCH 1
- offset = (( (uint64_t)entry->index +
- (uint64_t)entry->patch0_address_adjust +
- (uint64_t)entry->patch1_address_adjust) *
- (uint64_t)0xC0 +
- (uint64_t)entry->patch1_buffer_offset);
+ offset = _entry_offset1(entry);
if (firsttime) {
BD_DEBUG(DBG_BDPLUS,"[segment] would seek to %016"PRIx64" to write patch1\n",
@@ -1437,6 +1448,17 @@ static int ts_parse_desc_0x89(bdplus_st_t *ct, const unsigned spn, const unsigne
segment = &st->Segments[ sp_id ];
+ /* check Forensic Mark ID */
+ if (((d[4] ^ mask[0]) >> 6) == 2) {
+ unsigned fm_id_pos = (d[4] ^ mask[0]) & 0x3f;
+ unsigned fm_id_bit = segment->mask[ 7 - (fm_id_pos >> 3) ] & (1 << (fm_id_pos & 0x07));
+ BD_DEBUG(DBG_BDPLUS, "[segment] %s type 2 patch (FM_ID_bit_pos = %d, FM_ID_bit = %d)\n",
+ fm_id_bit ? "activated" : "deactivated", fm_id_pos, !!fm_id_bit);
+ if (fm_id_bit == 0) {
+ return 0;
+ }
+ }
+
#define E1_CACHE_SIZE 50 /* there must be some upper bound in the specs (?) */
/* keep ordered list of next patches */
if (segment->Entries == NULL) {
@@ -1536,11 +1558,7 @@ int32_t segment_patch(bdplus_st_t *ct, int len, uint8_t *buffer)
// Skip any entries that are in-active.
if (!entry->active) continue;
-
- offset0 = (((uint64_t)entry->index +
- (uint64_t)entry->patch0_address_adjust) *
- (uint64_t)0xC0 +
- (uint64_t)entry->patch0_buffer_offset);
+ offset0 = _entry_offset0(entry);
// If this Entry is beyond this buffer, stop here, we need
// more data.
@@ -1549,12 +1567,7 @@ int32_t segment_patch(bdplus_st_t *ct, int len, uint8_t *buffer)
return patches;
}
-
- offset1 = (( (uint64_t)entry->index +
- (uint64_t)entry->patch0_address_adjust +
- (uint64_t)entry->patch1_address_adjust) *
- (uint64_t)0xC0 +
- (uint64_t)entry->patch1_buffer_offset);
+ offset1 = _entry_offset1(entry);
// While this Entry (patch1) is (completely) before this
// buffer, skip to the next
=====================================
src/libbdplus/bdsvm/segment.h
=====================================
@@ -33,6 +33,8 @@ typedef struct conv_table_s conv_table_t;
typedef struct bdplus_st_s bdplus_st_t;
#endif
+struct bdplus_file;
+
BD_PRIVATE uint32_t segment_numTables ( conv_table_t * );
BD_PRIVATE uint32_t segment_numEntries ( conv_table_t * );
@@ -46,7 +48,7 @@ BD_PRIVATE int32_t segment_setSegment ( conv_table_t *, uint32_t, uint32_t
BD_PRIVATE int32_t segment_decrypt ( conv_table_t *, uint8_t *, uint8_t * );
BD_PRIVATE int32_t segment_save ( conv_table_t *, FILE * );
-BD_PRIVATE int32_t segment_load ( conv_table_t **,FILE * );
+BD_PRIVATE int32_t segment_load ( conv_table_t **, struct bdplus_file * );
BD_PRIVATE bdplus_st_t *segment_set_m2ts ( conv_table_t *, uint32_t );
BD_PRIVATE int32_t segment_patchfile ( conv_table_t *, uint32_t , FILE * );
View it on GitLab: https://code.videolan.org/videolan/libbdplus/-/compare/f4b8e043fa45021ec6e503574f658705a33e9337...bd404373d18b268e9e628db2f29151a60dce35ea
--
View it on GitLab: https://code.videolan.org/videolan/libbdplus/-/compare/f4b8e043fa45021ec6e503574f658705a33e9337...bd404373d18b268e9e628db2f29151a60dce35ea
You're receiving this email because of your account on code.videolan.org.
More information about the libbdplus-devel
mailing list