* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
-#include <stdlib.h> /* malloc(), free() */
-
-#ifdef WIN32
-# include <io.h>
-#else
-# include <stdio.h>
+#ifdef __LIBVLC__
+#ifdef HAVE_CONFIG_H
+# include "config.h"
#endif
-#ifdef __VLC__
-# include <vlc/vlc.h>
+# include <vlc_common.h>
# include <vlc_md5.h>
# include "libmp4.h"
+# include <vlc_charset.h>
#else
# include "drmsvl.h"
#endif
+#ifdef WIN32
+# include <io.h>
+#else
+# include <stdio.h>
+#endif
+
#ifdef HAVE_ERRNO_H
# include <errno.h>
#endif
#endif
/* In Solaris (and perhaps others) PATH_MAX is in limits.h. */
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <limits.h>
#ifdef __APPLE__
# include <mach/mach.h>
uint32_t pp_dec_keys[ AES_KEY_COUNT + 1 ][ 4 ];
};
-#ifdef __VLC__
+#ifdef __LIBVLC__
# define Digest DigestMD5
#else
/*****************************************************************************
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 * );
static void TinyShuffle8 ( uint32_t * );
static void DoExtShuffle ( uint32_t * );
-static int GetSystemKey ( uint32_t *, vlc_bool_t );
+static int GetSystemKey ( uint32_t *, bool );
static int WriteUserKey ( void *, uint32_t * );
static int ReadUserKey ( void *, uint32_t * );
static int GetUserKey ( void *, uint32_t * );
/*****************************************************************************
* drms_alloc: allocate a DRMS structure
*****************************************************************************/
-void *drms_alloc( char *psz_homedir )
+void *drms_alloc( const char *psz_homedir )
{
struct drms_s *p_drms;
- p_drms = malloc( sizeof(struct drms_s) );
-
- if( p_drms == NULL )
- {
+ p_drms = calloc( 1, sizeof(struct drms_s) );
+ if( !p_drms )
return NULL;
- }
-
- memset( p_drms, 0, sizeof(struct drms_s) );
strncpy( p_drms->psz_homedir, psz_homedir, PATH_MAX );
p_drms->psz_homedir[ PATH_MAX - 1 ] = '\0';
{
struct drms_s *p_drms = (struct drms_s *)_p_drms;
- if( p_drms->p_name != NULL )
- {
- free( (void *)p_drms->p_name );
- }
-
+ free( (void *)p_drms->p_name );
free( p_drms );
}
/*****************************************************************************
* drms_decrypt: unscramble a chunk of data
*****************************************************************************/
-void drms_decrypt( void *_p_drms, uint32_t *p_buffer, uint32_t i_bytes )
+void drms_decrypt( void *_p_drms, uint32_t *p_buffer, uint32_t i_bytes, uint32_t *p_key )
{
struct drms_s *p_drms = (struct drms_s *)_p_drms;
- uint32_t p_key[ 4 ];
+ uint32_t p_key_buf[ 4 ];
unsigned int i_blocks;
/* AES is a block cypher, round down the byte count */
i_bytes = i_blocks * 16;
/* Initialise the key */
- memcpy( p_key, p_drms->p_key, 16 );
+ if( !p_key )
+ {
+ p_key = p_key_buf;
+ memcpy( p_key, p_drms->p_key, 16 );
+ }
/* Unscramble */
while( i_blocks-- )
}
}
+/*****************************************************************************
+ * drms_get_p_key: copy the p_key into user buffer
+ ****************************************************************************/
+void drms_get_p_key( void *_p_drms, uint32_t *p_key )
+{
+ struct drms_s *p_drms = (struct drms_s *)_p_drms;
+
+ memcpy( p_key, p_drms->p_key, 16 );
+}
+
/*****************************************************************************
* drms_init: initialise a DRMS structure
*****************************************************************************
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 )
{
}
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 );
if( p_drms->i_user == 0 && p_drms->i_key == 0 )
{
- static char const p_secret[] = "tr1-th3n.y00_by3";
+ static const char p_secret[] = "tr1-th3n.y00_by3";
memcpy( p_drms->p_key, p_secret, 16 );
REVERSE( p_drms->p_key, 4 );
}
memcpy( p_priv, p_info, 64 );
memcpy( p_drms->p_key, md5.p_digest, 16 );
- drms_decrypt( p_drms, p_priv, 64 );
+ drms_decrypt( p_drms, p_priv, 64, NULL );
REVERSE( p_priv, 64 );
if( p_priv[ 0 ] != 0x6e757469 ) /* itun */
}
}
-#ifndef __VLC__
+#ifndef __LIBVLC__
/*****************************************************************************
* InitMD5: initialise an MD5 message
*****************************************************************************
uint32_t i_version )
{
char p_secret1[] = "Tv!*";
- static char const p_secret2[] = "____v8rhvsaAvOKM____FfUH%798=[;."
+ static const char p_secret2[] = "____v8rhvsaAvOKM____FfUH%798=[;."
"____f8677680a634____ba87fnOIf)(*";
unsigned int i;
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 ]++;
uint32_t *p_bordel = p_shuffle->p_bordel;
unsigned int i;
- static uint32_t i_secret = 0;
-
- static uint32_t p_secret3[] =
+ static const uint32_t p_secret3[] =
{
0xAAAAAAAA, 0x01757700, 0x00554580, 0x01724500, 0x00424580,
0x01427700, 0x00000080, 0xC1D59D01, 0x80144981, 0x815C8901,
0xD5DDB938, 0x5455A092, 0x5D95A013, 0x4415A192, 0xC5DD393A,
0x00000080, 0x55555555
};
+ static const uint32_t i_secret3 = sizeof(p_secret3)/sizeof(p_secret3[0]);
- static char p_secret4[] =
+ static const char p_secret4[] =
"pbclevtug (p) Nccyr Pbzchgre, Vap. Nyy Evtugf Erfreirq.";
-
- if( i_secret == 0 )
- {
- REVERSE( p_secret3, sizeof(p_secret3)/sizeof(p_secret3[ 0 ]) );
- for( ; p_secret4[ i_secret ] != '\0'; i_secret++ )
- {
-#define ROT13(c) (((c)>='A'&&(c)<='Z')?(((c)-'A'+13)%26)+'A':\
- ((c)>='a'&&(c)<='z')?(((c)-'a'+13)%26)+'a':c)
- p_secret4[ i_secret ] = ROT13(p_secret4[ i_secret ]);
- }
- i_secret++; /* include zero terminator */
- }
+ static const uint32_t i_secret4 = sizeof(p_secret4)/sizeof(p_secret4[0]); /* It include the terminal '\0' */
/* Using the MD5 hash of a memory block is probably not one-way enough
* for the iTunes people. This function randomises p_bordel depending on
{
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 );
+ uint32_t p_tmp3[i_secret3];
+ char p_tmp4[i_secret4];
+
+ memcpy( p_tmp3, p_secret3, sizeof(p_secret3) );
+ REVERSE( p_tmp3, i_secret3 );
+
+#define ROT13(c) (((c)>='A'&&(c)<='Z')?(((c)-'A'+13)%26)+'A':\
+ ((c)>='a'&&(c)<='z')?(((c)-'a'+13)%26)+'a':c)
+ for( uint32_t i = 0; i < i_secret4; i++ )
+ p_tmp4[i] = ROT13( p_secret4[i] );
+#undef ROT13
+
+ AddMD5( &md5, (const uint8_t *)p_tmp3, sizeof(p_secret3) );
+ AddMD5( &md5, (const uint8_t *)p_tmp4, i_secret4 );
}
EndMD5( &md5 );
*****************************************************************************
* Compute the system key from various system information, see HashSystemInfo.
*****************************************************************************/
-static int GetSystemKey( uint32_t *p_sys_key, vlc_bool_t b_ipod )
+static int GetSystemKey( uint32_t *p_sys_key, bool b_ipod )
{
- static char const p_secret5[ 8 ] = "YuaFlafu";
- static char const p_secret6[ 8 ] = "zPif98ga";
+ static const char p_secret5[ 8 ] = "YuaFlafu";
+ static const char p_secret6[ 8 ] = "zPif98ga";
struct md5_s md5;
int64_t i_ipod_id;
uint32_t p_system_hash[ 4 ];
/* 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 );
*****************************************************************************/
static int GetUserKey( void *_p_drms, uint32_t *p_user_key )
{
- static char const p_secret7[] = "mUfnpognadfgf873";
+ static const char p_secret7[] = "mUfnpognadfgf873";
struct drms_s *p_drms = (struct drms_s *)_p_drms;
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;
psz_ipod = getenv( "IPOD" );
- if( GetSystemKey( p_sys_key, psz_ipod ? VLC_TRUE : VLC_FALSE ) )
+ if( GetSystemKey( p_sys_key, psz_ipod ? true : false ) )
{
return -3;
}
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;
}
#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;
}
DWORD i_serial;
LPBYTE p_reg_buf;
- static LPCTSTR p_reg_keys[ 3 ][ 2 ] =
+ static const LPCTSTR p_reg_keys[ 3 ][ 2 ] =
{
{
_T("HARDWARE\\DESCRIPTION\\System"),
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++ )
{
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 );
IOObjectRelease( iterator );
}
+ CFRelease( match_dic );
}
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;
#else /* !defined( UNDER_CE ) */
-void *drms_alloc( char *psz_homedir ){ return 0; }
+void *drms_alloc( const char *psz_homedir ){ return NULL; }
void drms_free( void *a ){}
-void drms_decrypt( void *a, uint32_t *b, uint32_t c ){}
+void drms_decrypt( void *a, uint32_t *b, uint32_t c, uint32_t *k ){}
+void drms_get_p_key( void *p_drms, uint32_t *p_key ){}
int drms_init( void *a, uint32_t b, uint8_t *c, uint32_t d ){ return -1; }
#endif /* defined( UNDER_CE ) */