ref: 1a1e8a9df4c4f9ad3a038c8cba0b94f4e8609319
parent: cffc4a4bd2891ea84082ea0801cb8271cef17f6e
author: menno <menno>
date: Sun Jan 11 10:53:51 EST 2004
mp4ff bugfixes
--- a/common/mp4ff/drms.c
+++ b/common/mp4ff/drms.c
@@ -2,7 +2,7 @@
* drms.c : DRMS
*****************************************************************************
* Copyright (C) 2004 VideoLAN
- * $Id: drms.c,v 1.2 2004/01/11 13:59:33 menno Exp $
+ * $Id: drms.c,v 1.3 2004/01/11 15:52:18 menno Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
@@ -23,21 +23,11 @@
#include <stdlib.h> /* malloc(), free() */
-#ifdef WIN32
-#include <io.h>
-#include <stdio.h>
-#else
-#include <stdio.h>
-#endif
-
-//#include <vlc/vlc.h>
#include "mp4ffint.h"
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
+#ifdef ITUNES_DRM
-#ifdef WIN32
+#ifdef _WIN32
#include <tchar.h>
#include <shlobj.h>
#include <windows.h>
@@ -46,8 +36,6 @@
#include "drms.h"
#include "drmstables.h"
-//#include "libmp4.h"
-
static __inline uint32_t U32_AT( void * _p )
{
uint8_t * p = (uint8_t *)_p;
@@ -537,7 +525,7 @@
{
int i_ret = 0;
-#ifdef WIN32
+#ifdef _WIN32
HKEY i_key;
uint32_t i;
DWORD i_size;
@@ -605,11 +593,11 @@
return( i_ret );
}
-static int get_sci_data( uint32_t **pp_sci, uint32_t *p_sci_size )
+static int get_sci_data( uint32_t p_sci[ 11 ][ 4 ] )
{
int i_ret = -1;
-#ifdef WIN32
+#ifdef _WIN32
HANDLE i_file;
DWORD i_size, i_read;
TCHAR p_path[ MAX_PATH ];
@@ -643,24 +631,18 @@
OPEN_EXISTING, 0, NULL );
if( i_file != INVALID_HANDLE_VALUE )
{
+ i_read = sizeof(p_sci[ 0 ]) * 11;
i_size = GetFileSize( i_file, NULL );
- if( i_size != INVALID_FILE_SIZE &&
- i_size > (sizeof(*pp_sci[ 0 ]) * 22) )
+ if( i_size != INVALID_FILE_SIZE && i_size >= i_read )
{
- *pp_sci = malloc( i_size * 2 );
- if( *pp_sci != NULL )
+ i_size = SetFilePointer( i_file, 4, NULL, FILE_BEGIN );
+ if( i_size != /*INVALID_SET_FILE_POINTER*/ ((DWORD)-1))
{
- if( ReadFile( i_file, *pp_sci, i_size, &i_read, NULL ) &&
- i_read == i_size )
+ if( ReadFile( i_file, p_sci, i_read, &i_size, NULL ) &&
+ i_size == i_read )
{
- *p_sci_size = i_size;
i_ret = 0;
}
- else
- {
- free( (void *)*pp_sci );
- *pp_sci = NULL;
- }
}
}
@@ -667,11 +649,6 @@
CloseHandle( i_file );
}
}
-
- if( shfolder_dll != NULL )
- {
- FreeLibrary( shfolder_dll );
- }
#endif
return( i_ret );
@@ -799,7 +776,7 @@
}
}
-static int get_sys_key( uint32_t *p_sys_key )
+int drms_get_sys_key( uint32_t *p_sys_key )
{
uint32_t p_tmp[ 128 ];
uint32_t p_tmp_key[ 4 ];
@@ -824,97 +801,14 @@
return( 0 );
}
-struct drms_s
+int drms_get_user_key( uint32_t *p_sys_key, uint32_t *p_user_key )
{
- uint32_t i_user;
- uint32_t i_key;
- uint8_t *p_iviv;
- uint8_t *p_name;
- uint32_t i_name_len;
-
- uint32_t *p_tmp;
- uint32_t i_tmp_len;
-
- uint32_t p_key[ 4 ];
- uint32_t p_ctx[ 128 ];
-
- char *psz_homedir;
-};
-
-#define P_DRMS ((struct drms_s *)p_drms)
-
-#if 0
-static int rw_user_key( void *p_drms, uint32_t i_rw, uint32_t *p_user_key )
-{
- FILE *file;
- int i_ret = -1;
- char sz_path[ MAX_PATH ];
-
-#define DRMS_PI_DIRNAME "drms"
-#ifdef WIN32
-#define DRMS_DIRNAME DRMS_PI_DIRNAME
-#else
-#define DRMS_DIRNAME "." DRMS_PI_DIRNAME
-#endif
-
- if( i_rw )
- {
- sprintf( sz_path, /* (sizeof(sz_path)/sizeof(sz_path[ 0 ])) - 1, */
- "%s/" DRMS_DIRNAME "/%08X.%03d", P_DRMS->psz_homedir,
- P_DRMS->i_user, P_DRMS->i_key );
-
- file = fopen( sz_path, "r" );
- if( file != NULL )
- {
- i_ret = fread( p_user_key, sizeof(*p_user_key),
- 4, file ) == 4 ? 0 : -1;
- fclose( file );
- }
- }
- else
- {
- sprintf( sz_path, /*(sizeof(sz_path)/sizeof(sz_path[ 0 ])) - 1,*/
- "%s/" DRMS_DIRNAME, P_DRMS->psz_homedir );
-
-#if defined( HAVE_ERRNO_H )
-# if defined( WIN32 )
- if( !mkdir( sz_path ) || errno == EEXIST )
-# else
- if( !mkdir( sz_path, 0755 ) || errno == EEXIST )
-# endif
-#else
- if( !mkdir( sz_path ) )
-#endif
- {
- sprintf( sz_path, /* (sizeof(sz_path)/sizeof(sz_path[ 0 ])) - 1,*/
- "%s/" DRMS_DIRNAME "/%08X.%03d", P_DRMS->psz_homedir,
- P_DRMS->i_user, P_DRMS->i_key );
-
- file = fopen( sz_path, "w" );
- if( file != NULL )
- {
- i_ret = fwrite( p_user_key, sizeof(*p_user_key),
- 4, file ) == 4 ? 0 : -1;
- fclose( file );
- }
- }
- }
-
- return( i_ret );
-}
-#endif
-
-static int get_user_key( void *p_drms, uint32_t *p_user_key )
-{
- uint32_t i, y;
- uint32_t *p_tmp;
+ uint32_t i;
+ uint32_t p_tmp[ 4 ];
uint32_t *p_cur_key;
uint32_t p_acei[ 41 ];
uint32_t p_ctx[ 128 ];
- uint32_t p_sys_key[ 4 ];
- uint32_t i_sci_size;
- uint32_t *p_sci[ 2 ];
- int i_ret = -1;
+ uint32_t p_sci[ 2 ][ 11 ][ 4 ];
uint32_t p_sci_key[ 4 ] =
{
@@ -921,104 +815,63 @@
0x6E66556D, 0x6E676F70, 0x67666461, 0x33373866
};
-#if 0
- if( !rw_user_key( p_drms, 1, p_user_key ) )
+ if( p_sys_key == NULL )
{
- return( 0 );
- }
-#endif
+ if( drms_get_sys_key( p_tmp ) )
+ {
+ return( -1 );
+ }
- if( get_sys_key( p_sys_key ) )
- {
- return( -1 );
+ p_sys_key = p_tmp;
}
-
- if( get_sci_data( &p_sci[ 0 ], &i_sci_size ) )
+ if( get_sci_data( p_sci[ 0 ] ) )
{
return( -1 );
}
- p_tmp = p_sci[ 0 ];
- p_sci[ 1 ] = (uint32_t *)(((uint8_t *)p_sci[ 0 ]) + i_sci_size);
- i_sci_size -= sizeof(*p_sci[ 0 ]);
-
init_ctx( p_ctx, p_sys_key );
for( i = 0, p_cur_key = p_sci_key;
- i < i_sci_size / sizeof(P_DRMS->p_key); i++ )
+ i < sizeof(p_sci[ 0 ])/sizeof(p_sci[ 0 ][ 0 ]); i++ )
{
- y = i * sizeof(*p_sci[ 0 ]);
-
- ctx_xor( p_ctx, p_sci[ 0 ] + y + 1, p_sci[ 1 ] + y + 1,
+ ctx_xor( p_ctx, &p_sci[ 0 ][ i ][ 0 ], &p_sci[ 1 ][ i ][ 0 ],
p_drms_tab3, p_drms_tab4 );
- block_xor( p_sci[ 1 ] + y + 1, p_cur_key, p_sci[ 1 ] + y + 1 );
+ block_xor( &p_sci[ 1 ][ i ][ 0 ], p_cur_key, &p_sci[ 1 ][ i ][ 0 ] );
- p_cur_key = p_sci[ 0 ] + y + 1;
+ p_cur_key = &p_sci[ 0 ][ i ][ 0 ];
}
acei_init( p_acei, p_sys_key );
- for( i = 0; i < i_sci_size / sizeof(P_DRMS->p_key); i++ )
+ for( i = 0; i < sizeof(p_sci[ 1 ])/sizeof(p_sci[ 1 ][ 0 ]); i++ )
{
- y = i * sizeof(*p_sci[ 1 ]);
-
- acei( p_acei, (uint8_t *)(p_sci[ 1 ] + y + 1),
- sizeof(P_DRMS->p_key) );
+ acei( p_acei, (uint8_t *)&p_sci[ 1 ][ i ][ 0 ],
+ sizeof(p_sci[ 1 ][ i ]) );
}
- y = 0;
- i = U32_AT( &p_sci[ 1 ][ 5 ] );
- i_sci_size -= 21 * sizeof(*p_sci[ 1 ]);
- p_sci[ 1 ] += 22;
- p_sci[ 0 ] = NULL;
+ memcpy( p_user_key, &p_sci[ 1 ][ 10 ][ 0 ], sizeof(p_sci[ 1 ][ i ]) );
- while( i_sci_size > 0 && i > 0 )
- {
- if( p_sci[ 0 ] == NULL )
- {
- i_sci_size -= 18 * sizeof(*p_sci[ 1 ]);
- if( i_sci_size <= 0 )
- {
- break;
- }
+ return( 0 );
+}
- p_sci[ 0 ] = p_sci[ 1 ];
- y = U32_AT( &p_sci[ 1 ][ 17 ] );
- p_sci[ 1 ] += 18;
- }
+struct drms_s
+{
+ uint8_t *p_iviv;
+ uint32_t i_iviv_len;
+ uint8_t *p_name;
+ uint32_t i_name_len;
- if( !y )
- {
- i--;
- p_sci[ 0 ] = NULL;
- continue;
- }
+ uint32_t *p_tmp;
+ uint32_t i_tmp_len;
- if( U32_AT( &p_sci[ 0 ][ 0 ] ) == P_DRMS->i_user &&
- ( i_sci_size >=
- (sizeof(P_DRMS->p_key) + sizeof(p_sci[ 1 ][ 0 ]) ) ) &&
- ( ( U32_AT( &p_sci[ 1 ][ 0 ] ) == P_DRMS->i_key ) ||
- ( !P_DRMS->i_key ) || ( p_sci[ 1 ] == (p_sci[ 0 ] + 18) ) ) )
- {
- memcpy( p_user_key, &p_sci[ 1 ][ 1 ], sizeof(P_DRMS->p_key) );
-// rw_user_key( p_drms, 0, p_user_key );
- i_ret = 0;
- break;
- }
+ uint32_t p_key[ 4 ];
+ uint32_t p_ctx[ 128 ];
+};
- y--;
- p_sci[ 1 ] += 5;
- i_sci_size -= 5 * sizeof(*p_sci[ 1 ]);
- }
+#define P_DRMS ((struct drms_s *)p_drms)
- free( (void *)p_tmp );
-
- return( i_ret );
-}
-
-
-void *drms_alloc( char *psz_homedir )
+void *drms_alloc()
{
struct drms_s *p_drms;
@@ -1035,19 +888,6 @@
free( (void *)p_drms );
p_drms = NULL;
}
-
- p_drms->psz_homedir = malloc( MAX_PATH );
- if( p_drms->psz_homedir != NULL )
- {
- strncpy( p_drms->psz_homedir, psz_homedir, MAX_PATH );
- p_drms->psz_homedir[ MAX_PATH - 1 ] = '\0';
- }
- else
- {
- free( (void *)p_drms->p_tmp );
- free( (void *)p_drms );
- p_drms = NULL;
- }
}
return( (void *)p_drms );
@@ -1065,11 +905,6 @@
free( (void *)P_DRMS->p_iviv );
}
- if( P_DRMS->psz_homedir != NULL )
- {
- free( (void *)P_DRMS->psz_homedir );
- }
-
if( P_DRMS->p_tmp != NULL )
{
free( (void *)P_DRMS->p_tmp );
@@ -1117,39 +952,27 @@
switch( i_type )
{
- case DRMS_INIT_USER:
+ case DRMS_INIT_UKEY:
{
- if( i_len < sizeof(P_DRMS->i_user) )
+ if( i_len != sizeof(P_DRMS->p_key) )
{
i_ret = -1;
break;
}
- P_DRMS->i_user = U32_AT( p_info );
+ init_ctx( P_DRMS->p_ctx, (uint32_t *)p_info );
}
break;
- case DRMS_INIT_KEY:
- {
- if( i_len < sizeof(P_DRMS->i_key) )
- {
- i_ret = -1;
- break;
- }
-
- P_DRMS->i_key = U32_AT( p_info );
- }
- break;
-
case DRMS_INIT_IVIV:
{
- if( i_len < sizeof(P_DRMS->p_key) )
+ if( i_len != sizeof(P_DRMS->p_key) )
{
i_ret = -1;
break;
}
- P_DRMS->p_iviv = malloc( sizeof(P_DRMS->p_key) );
+ P_DRMS->p_iviv = malloc( i_len );
if( P_DRMS->p_iviv == NULL )
{
i_ret = -1;
@@ -1156,15 +979,14 @@
break;
}
- memcpy( P_DRMS->p_iviv, p_info, sizeof(P_DRMS->p_key) );
+ memcpy( P_DRMS->p_iviv, p_info, i_len );
+ P_DRMS->i_iviv_len = i_len;
}
break;
case DRMS_INIT_NAME:
{
- P_DRMS->i_name_len = strlen( p_info );
-
- P_DRMS->p_name = malloc( P_DRMS->i_name_len );
+ P_DRMS->p_name = malloc( i_len );
if( P_DRMS->p_name == NULL )
{
i_ret = -1;
@@ -1171,7 +993,8 @@
break;
}
- memcpy( P_DRMS->p_name, p_info, P_DRMS->i_name_len );
+ memcpy( P_DRMS->p_name, p_info, i_len );
+ P_DRMS->i_name_len = i_len;
}
break;
@@ -1189,7 +1012,7 @@
TAOS_INIT( p_tmp, 0 );
taos_add3( p_tmp, P_DRMS->p_name, P_DRMS->i_name_len );
- taos_add3( p_tmp, P_DRMS->p_iviv, sizeof(P_DRMS->p_key) );
+ taos_add3( p_tmp, P_DRMS->p_iviv, P_DRMS->i_iviv_len );
memcpy( p_priv, &p_tmp[ 4 ], sizeof(p_priv[ 0 ]) * 2 );
i = (p_tmp[ 4 ] / 8) & 63;
i = i >= 56 ? 120 - i : 56 - i;
@@ -1196,14 +1019,6 @@
taos_add3( p_tmp, p_drms_tab_tend, i );
taos_add3( p_tmp, (uint8_t *)p_priv, sizeof(p_priv[ 0 ]) * 2 );
- if( get_user_key( p_drms, P_DRMS->p_key ) )
- {
- i_ret = -1;
- break;
- }
-
- init_ctx( P_DRMS->p_ctx, P_DRMS->p_key );
-
memcpy( p_priv, p_info, 64 );
memcpy( P_DRMS->p_key, p_tmp, sizeof(P_DRMS->p_key) );
drms_decrypt( p_drms, p_priv, sizeof(p_priv) );
@@ -1211,8 +1026,6 @@
init_ctx( P_DRMS->p_ctx, &p_priv[ 6 ] );
memcpy( P_DRMS->p_key, &p_priv[ 12 ], sizeof(P_DRMS->p_key) );
- free( (void *)P_DRMS->psz_homedir );
- P_DRMS->psz_homedir = NULL;
free( (void *)P_DRMS->p_name );
P_DRMS->p_name = NULL;
free( (void *)P_DRMS->p_iviv );
@@ -1225,4 +1038,6 @@
}
#undef P_DRMS
+
+#endif
--- a/common/mp4ff/drms.h
+++ b/common/mp4ff/drms.h
@@ -2,7 +2,7 @@
* drms.h : DRMS
*****************************************************************************
* Copyright (C) 2004 VideoLAN
- * $Id: drms.h,v 1.2 2004/01/11 13:59:33 menno Exp $
+ * $Id: drms.h,v 1.3 2004/01/11 15:52:18 menno Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
@@ -21,11 +21,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-#define DRMS_INIT_KEY 0
+
+#define DRMS_INIT_UKEY 0
#define DRMS_INIT_IVIV 1
#define DRMS_INIT_NAME 2
#define DRMS_INIT_PRIV 3
-#define DRMS_INIT_USER 4
extern int drms_get_sys_key( uint32_t *p_sys_key );
extern int drms_get_user_key( uint32_t *p_sys_key,
--- a/common/mp4ff/drmstables.h
+++ b/common/mp4ff/drmstables.h
@@ -2,7 +2,7 @@
* drmstables.h : DRMS tables
*****************************************************************************
* Copyright (C) 2004 VideoLAN
- * $Id: drmstables.h,v 1.1 2004/01/10 18:55:24 menno Exp $
+ * $Id: drmstables.h,v 1.2 2004/01/11 15:52:18 menno Exp $
*
* Author: Jon Lech Johansen <jon-vl@nanocrew.net>
*
@@ -20,6 +20,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
+
static uint32_t p_drms_tab1[ 10 ] =
{
--- a/common/mp4ff/mp4atom.c
+++ b/common/mp4ff/mp4atom.c
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
-** $Id: mp4atom.c,v 1.16 2004/01/11 13:59:33 menno Exp $
+** $Id: mp4atom.c,v 1.17 2004/01/11 15:52:18 menno Exp $
**/
#include <stdlib.h>
@@ -173,10 +173,6 @@
return ATOM_PRIV;
else if (mp4ff_atom_compare(a,b,c,d, 'i','v','i','v'))
return ATOM_IVIV;
- else if (mp4ff_atom_compare(a,b,c,d, 'u','s','e','r'))
- return ATOM_USER;
- else if (mp4ff_atom_compare(a,b,c,d, 'k','e','y',' '))
- return ATOM_KEY;
else
return ATOM_UNKNOWN;
}
@@ -335,9 +331,17 @@
int32_t i;
uint8_t atom_type = 0;
uint8_t header_size = 0;
+ uint32_t drms_user_key[4];
- f->track[f->total_tracks - 1]->p_drms = drms_alloc();
+ if (drms_get_user_key(NULL, drms_user_key) == 0)
+ {
+ f->track[f->total_tracks - 1]->p_drms = drms_alloc();
+ drms_init( f->track[f->total_tracks - 1]->p_drms,
+ DRMS_INIT_UKEY, (uint8_t *)drms_user_key,
+ sizeof(drms_user_key) );
+ }
+
for (i = 0; i < 6; i++)
{
mp4ff_read_char(f); /* reserved */
@@ -446,40 +450,6 @@
return 0;
}
-
-static int32_t mp4ff_read_user(mp4ff_t *f, uint64_t size)
-{
- uint8_t *data = malloc(size);
- mp4ff_read_data(f, data, size);
-
- if (f->track[f->total_tracks - 1]->p_drms != 0)
- {
- drms_init(f->track[f->total_tracks - 1]->p_drms,
- DRMS_INIT_USER, data, sizeof(uint32_t) * 4 );
- }
-
- if (data)
- free(data);
-
- return 0;
-}
-
-static int32_t mp4ff_read_key(mp4ff_t *f, uint64_t size)
-{
- uint8_t *data = malloc(size);
- mp4ff_read_data(f, data, size);
-
- if (f->track[f->total_tracks - 1]->p_drms != 0)
- {
- drms_init(f->track[f->total_tracks - 1]->p_drms,
- DRMS_INIT_KEY, data, sizeof(uint32_t) * 4 );
- }
-
- if (data)
- free(data);
-
- return 0;
-}
#endif
static int32_t mp4ff_read_stsd(mp4ff_t *f)
@@ -796,10 +766,6 @@
mp4ff_read_name(f, size-8);
} else if (atom_type == ATOM_PRIV) {
mp4ff_read_priv(f, size-8);
- } else if (atom_type == ATOM_USER) {
- mp4ff_read_user(f, size-8);
- } else if (atom_type == ATOM_KEY) {
- mp4ff_read_key(f, size-8);
#endif
#ifdef USE_TAGGING
} else if (atom_type == ATOM_META) {
--- a/common/mp4ff/mp4ff.dsp
+++ b/common/mp4ff/mp4ff.dsp
@@ -25,7 +25,7 @@
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
-CPP=cl.exe
+CPP=xicl6.exe
RSC=rc.exe
!IF "$(CFG)" == "mp4ff - Win32 Release"
@@ -49,7 +49,7 @@
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=link.exe -lib
+LIB32=xilink6.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -74,7 +74,7 @@
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
-LIB32=link.exe -lib
+LIB32=xilink6.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
@@ -89,6 +89,10 @@
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
+SOURCE=.\drms.c
+# End Source File
+# Begin Source File
+
SOURCE=.\mp4atom.c
# End Source File
# Begin Source File
@@ -115,6 +119,14 @@
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\drms.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\drmstables.h
+# End Source File
# Begin Source File
SOURCE=.\mp4ff.h
--- a/common/mp4ff/mp4ffint.h
+++ b/common/mp4ff/mp4ffint.h
@@ -22,7 +22,7 @@
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
-** $Id: mp4ffint.h,v 1.13 2004/01/11 13:59:33 menno Exp $
+** $Id: mp4ffint.h,v 1.14 2004/01/11 15:52:18 menno Exp $
**/
#ifndef MP4FF_INTERNAL_H
@@ -74,8 +74,6 @@
#define ATOM_FRMA 152
#define ATOM_IVIV 153
#define ATOM_PRIV 154
-#define ATOM_USER 155
-#define ATOM_KEY 156
#define ATOM_UNKNOWN 255
#define ATOM_FREE ATOM_UNKNOWN
--
⑨