]> git.sesse.net Git - vlc/blobdiff - modules/demux/mp4/drms.c
A bit of vlc/libvlc cleanup:
[vlc] / modules / demux / mp4 / drms.c
index 87f1e26c27279325908ee9dbbb5ce3121c476f48..5a8abaf5a1aa0100d39d43743b52805aa253ebd7 100644 (file)
 #   include <stdio.h>
 #endif
 
-#ifdef __VLC__
+#ifdef __LIBVLC__
 #   include <vlc/vlc.h>
 #   include <vlc_md5.h>
 #   include "libmp4.h"
-#   include "charset.h"
+#   include <vlc_charset.h>
 #else
 #   include "drmsvl.h"
 #endif
@@ -90,7 +90,7 @@ struct aes_s
     uint32_t pp_dec_keys[ AES_KEY_COUNT + 1 ][ 4 ];
 };
 
-#ifdef __VLC__
+#ifdef __LIBVLC__
 # define Digest DigestMD5
 #else
 /*****************************************************************************
@@ -146,7 +146,7 @@ struct drms_s
 static void InitAES       ( struct aes_s *, uint32_t * );
 static void DecryptAES    ( struct aes_s *, uint32_t *, const uint32_t * );
 
-#ifndef __VLC__
+#ifndef __LIBVLC__
 static void InitMD5       ( struct md5_s * );
 static void AddMD5        ( struct md5_s *, const uint8_t *, uint32_t );
 static void EndMD5        ( struct md5_s * );
@@ -334,7 +334,7 @@ int drms_init( void *_p_drms, uint32_t i_type,
             break;
 
         case FOURCC_name:
-            p_drms->p_name = strdup( p_info );
+            p_drms->p_name = (uint8_t*) strdup( (char *)p_info );
 
             if( p_drms->p_name == NULL )
             {
@@ -354,7 +354,7 @@ int drms_init( void *_p_drms, uint32_t i_type,
             }
 
             InitMD5( &md5 );
-            AddMD5( &md5, p_drms->p_name, strlen( p_drms->p_name ) );
+            AddMD5( &md5, p_drms->p_name, strlen( (char *)p_drms->p_name ) );
             AddMD5( &md5, p_drms->p_iviv, 16 );
             EndMD5( &md5 );
 
@@ -504,7 +504,7 @@ static void DecryptAES( struct aes_s *p_aes,
     }
 }
 
-#ifndef __VLC__
+#ifndef __LIBVLC__
 /*****************************************************************************
  * InitMD5: initialise an MD5 message
  *****************************************************************************
@@ -716,8 +716,8 @@ static void InitShuffle( struct shuffle_s *p_shuffle, uint32_t *p_sys_key,
         int32_t i_hash;
 
         InitMD5( &md5 );
-        AddMD5( &md5, (uint8_t *)p_sys_key, 16 );
-        AddMD5( &md5, (uint8_t *)p_secret1, 4 );
+        AddMD5( &md5, (const uint8_t *)p_sys_key, 16 );
+        AddMD5( &md5, (const uint8_t *)p_secret1, 4 );
         EndMD5( &md5 );
 
         p_secret1[ 3 ]++;
@@ -824,11 +824,11 @@ static void DoShuffle( struct shuffle_s *p_shuffle,
     {
         p_big_bordel[ i ] = U32_AT(p_bordel + i);
     }
-    AddMD5( &md5, (uint8_t *)p_big_bordel, 64 );
+    AddMD5( &md5, (const uint8_t *)p_big_bordel, 64 );
     if( p_shuffle->i_version == 0x01000300 )
     {
-        AddMD5( &md5, (uint8_t *)p_secret3, sizeof(p_secret3) );
-        AddMD5( &md5, (uint8_t *)p_secret4, i_secret );
+        AddMD5( &md5, (const uint8_t *)p_secret3, sizeof(p_secret3) );
+        AddMD5( &md5, (const uint8_t *)p_secret4, i_secret );
     }
     EndMD5( &md5 );
 
@@ -1522,21 +1522,21 @@ static int GetSystemKey( uint32_t *p_sys_key, vlc_bool_t b_ipod )
     /* Combine our system info hash with additional secret data. The resulting
      * MD5 hash will be our system key. */
     InitMD5( &md5 );
-    AddMD5( &md5, p_secret5, 8 );
+    AddMD5( &md5, (const uint8_t*)p_secret5, 8 );
 
     if( !b_ipod )
     {
-        AddMD5( &md5, (uint8_t *)p_system_hash, 6 );
-        AddMD5( &md5, (uint8_t *)p_system_hash, 6 );
-        AddMD5( &md5, (uint8_t *)p_system_hash, 6 );
-        AddMD5( &md5, p_secret6, 8 );
+        AddMD5( &md5, (const uint8_t *)p_system_hash, 6 );
+        AddMD5( &md5, (const uint8_t *)p_system_hash, 6 );
+        AddMD5( &md5, (const uint8_t *)p_system_hash, 6 );
+        AddMD5( &md5, (const uint8_t *)p_secret6, 8 );
     }
     else
     {
         i_ipod_id = U64_AT(&i_ipod_id);
-        AddMD5( &md5, (uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
-        AddMD5( &md5, (uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
-        AddMD5( &md5, (uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
+        AddMD5( &md5, (const uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
+        AddMD5( &md5, (const uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
+        AddMD5( &md5, (const uint8_t *)&i_ipod_id, sizeof(i_ipod_id) );
     }
 
     EndMD5( &md5 );
@@ -1634,10 +1634,10 @@ static int GetUserKey( void *_p_drms, uint32_t *p_user_key )
     struct aes_s aes;
     struct shuffle_s shuffle;
     uint32_t i, y;
-    uint32_t *p_sci_data;
+    uint32_t *p_sci_data = NULL;
     uint32_t i_user, i_key;
     uint32_t p_sys_key[ 4 ];
-    uint32_t i_sci_size, i_blocks, i_remaining;
+    uint32_t i_sci_size = 0, i_blocks, i_remaining;
     uint32_t *p_sci0, *p_sci1, *p_buffer;
     uint32_t p_sci_key[ 4 ];
     char *psz_ipod;
@@ -1779,31 +1779,35 @@ static int GetSCIData( char *psz_ipod, uint32_t **pp_sci,
     if( psz_ipod == NULL )
     {
 #ifdef WIN32
-        char *p_filename = "\\Apple Computer\\iTunes\\SC Info\\SC Info.sidb";
+        const wchar_t *wfile =
+                L"\\Apple Computer\\iTunes\\SC Info\\SC Info.sidb";
         typedef HRESULT (WINAPI *SHGETFOLDERPATH)( HWND, int, HANDLE, DWORD,
-                                                   LPSTR );
+                                                   LPWSTR );
         HINSTANCE shfolder_dll = NULL;
         SHGETFOLDERPATH dSHGetFolderPath = NULL;
+        wchar_t wpath[PATH_MAX];
 
         if( ( shfolder_dll = LoadLibrary( _T("SHFolder.dll") ) ) != NULL )
         {
             dSHGetFolderPath =
                 (SHGETFOLDERPATH)GetProcAddress( shfolder_dll,
-                                                 _T("SHGetFolderPathA") );
+                                                 _T("SHGetFolderPathW") );
         }
 
         if( dSHGetFolderPath != NULL &&
             SUCCEEDED( dSHGetFolderPath( NULL, CSIDL_COMMON_APPDATA,
-                                         NULL, 0, p_tmp ) ) )
+                                         NULL, 0, wpath ) ) )
         {
-            strncat( p_tmp, p_filename, min( strlen( p_filename ),
-                     (sizeof(p_tmp)/sizeof(p_tmp[0]) - 1) -
-                     strlen( p_tmp ) ) );
+            if (wcslen( wpath ) + wcslen( wfile ) >= PATH_MAX )
+            {
+                return -1;
+            }
+            wcscat( wpath, wfile );
 
-            psz_path = FromLocale( p_tmp );
+            psz_path = FromWide( wpath );
             strncpy( p_tmp, psz_path, sizeof( p_tmp ) - 1 );
             p_tmp[sizeof( p_tmp ) - 1] = '\0';
-            LocaleFree( psz_path );
+            free( psz_path );
             psz_path = p_tmp;
         }
 
@@ -1818,7 +1822,7 @@ static int GetSCIData( char *psz_ipod, uint32_t **pp_sci,
 #define ISCINFO "iSCInfo"
         if( strstr( psz_ipod, ISCINFO ) == NULL )
         {
-            snprintf( p_tmp, sizeof(p_tmp)/sizeof(p_tmp[0]) - 1,
+            snprintf( p_tmp, sizeof(p_tmp) - 1,
                       "%s/iPod_Control/iTunes/" ISCINFO "2", psz_ipod );
             psz_path = p_tmp;
         }
@@ -1906,7 +1910,7 @@ static int HashSystemInfo( uint32_t *p_system_hash )
 
     GetVolumeInformation( _T("C:\\"), NULL, 0, &i_serial,
                           NULL, NULL, NULL, 0 );
-    AddMD5( &md5, (uint8_t *)&i_serial, 4 );
+    AddMD5( &md5, (const uint8_t *)&i_serial, 4 );
 
     for( i = 0; i < sizeof(p_reg_keys) / sizeof(p_reg_keys[ 0 ]); i++ )
     {
@@ -1931,7 +1935,7 @@ static int HashSystemInfo( uint32_t *p_system_hash )
                                  NULL, NULL, p_reg_buf,
                                  &i_size ) == ERROR_SUCCESS )
             {
-                AddMD5( &md5, (uint8_t *)p_reg_buf, i_size );
+                AddMD5( &md5, (const uint8_t *)p_reg_buf, i_size );
             }
 
             free( p_reg_buf );
@@ -2033,7 +2037,7 @@ static int GetiPodID( int64_t *p_ipod_id )
         mach_port_deallocate( mach_task_self(), port );
     }
 
-#elif HAVE_SYSFS_LIBSYSFS_H
+#elif defined (HAVE_SYSFS_LIBSYSFS_H)
     struct sysfs_bus *bus = NULL;
     struct dlist *devlist = NULL;
     struct dlist *attributes = NULL;