1
0
Fork 0

file abs fixes

aacs work
This commit is contained in:
cRTrn13 2009-10-15 22:06:24 +00:00
parent d17e2ea27d
commit 1f790c589a
4 changed files with 47 additions and 54 deletions

View File

@ -31,6 +31,40 @@ void bd_close(BLURAY *bd)
X_FREE(bd);
dlclose(bd->libbdplus_h);
dlclose(bd->libaacs_h);
}
off_t bd_seek(BLURAY *bd, off_t pos)
{
if (pos < bd->s_size) {
bd->s_pos = pos - (pos % 6144);
file_seek(bd->fp, bd->s_pos, SEEK_SET);
}
return bd->s_pos;
}
int bd_read(BLURAY *bd, unsigned char *buf, int len)
{
if (len + bd->s_pos < bd->s_size) {
int read;
if ((read = file_read(bd->fp, buf, len))) {
if (bd->libaacs_h) {
typedef int* (*fptr)();
fptr fptr_s = dlsym(bd->libaacs_h, "aacs_decrypt_unit");
if (!fptr_s(bd->aacs, buf, len)) {
return 0;
}
}
bd->s_pos += len;
return read;
}
}
return 0;
}

View File

@ -1,34 +1,3 @@
#include "file.h"
extern const struct file_type file_linux;
FILE_H *file_open(const char *filename, const char *mode)
{
return file_linux.open(filename, mode); // only linux for now
}
void file_close(FILE_H *file)
{
file->close(file);
}
int64_t file_seek(FILE_H *file, int64_t offset, int32_t origin)
{
return file->seek(file, offset, origin);
}
int64_t file_tell(FILE_H *file)
{
return file->tell(file);
}
int file_read(FILE_H *file, uint8_t *buf, int64_t size)
{
return file->read(file, buf, size);
}
int file_write(FILE_H *file, uint8_t *buf, int64_t size)
{
return file->write(file, buf, size);
}

View File

@ -5,11 +5,15 @@
#include <stdint.h>
#include <unistd.h>
enum OS {
LINUX,
OSX,
BSD,
};
//#ifdef __LINUX__
#define file_open file_open_linux
//#endif
#define file_close(X) X->close(X)
#define file_seek(X,Y,Z) X->seek(X,Y,Z)
#define file_tell(X) X->tell(X)
#define file_read(X,Y,Z) X->read(X,Y,Z)
#define file_write(X,Y,Z) X->write(X,Y,Z)
typedef struct file FILE_H;
struct file
@ -22,17 +26,6 @@ struct file
int (*write)(FILE_H *file, uint8_t *buf, int64_t size);
};
struct file_type
{
enum OS os;
FILE_H *(*open)(const char *filename, const char *mode);
};
FILE_H *file_open(const char *filename, const char *mode);
void file_close(FILE_H *file);
int64_t file_seek(FILE_H *file, int64_t offset, int32_t origin);
int64_t file_tell(FILE_H *file);
int file_read(FILE_H *file, uint8_t *buf, int64_t size);
int file_write(FILE_H *file, uint8_t *buf, int64_t size);
extern FILE_H *file_open_linux(const char* filename, const char *mode);
#endif /* FILE_H_ */

View File

@ -3,6 +3,7 @@
#include <stdio.h>
#include "file.h"
#include "../util/macro.h"
FILE_H *file_open_linux(const char* filename, const char *mode);
void file_close_linux(FILE_H *file);
@ -15,6 +16,7 @@ int file_write_linux(FILE_H *file, uint8_t *buf, int64_t size);
void file_close_linux(FILE_H *file)
{
fclose((FILE *)file->internal);
X_FREE(file->internal);
}
int64_t file_seek_linux(FILE_H *file, int64_t offset, int32_t origin)
@ -56,8 +58,3 @@ FILE_H *file_open_linux(const char* filename, const char *mode)
return NULL;
}
const struct file_type file_linux = {
LINUX,
file_open_linux
};