Changeset 3724ca76ddffbf77b3ede9805a9a0f9f8cabe661

Show
Ignore:
Timestamp:
26/01/04 18:15:40 (5 years ago)
Author:
Jon Lech Johansen <jlj@videolan.org>
git-committer:
Jon Lech Johansen <jlj@videolan.org> 1075137340 +0000
git-parent:

[b3e689d0e60cffe1d8c4406e2a280d8c0ba83c1a]

git-author:
Jon Lech Johansen <jlj@videolan.org> 1075137340 +0000
Message:
  • drms: bugfixes in sci handling, GetiPodID darwin support.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/mp4/drms.c

    rebb65f2 r3724ca7  
    33 ***************************************************************************** 
    44 * Copyright (C) 2004 VideoLAN 
    5  * $Id: drms.c,v 1.11 2004/01/23 20:58:52 jlj Exp $ 
     5 * $Id: drms.c,v 1.12 2004/01/26 17:15:40 jlj Exp $ 
    66 * 
    77 * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> 
     
    5555#endif 
    5656 
     57#ifdef SYS_DARWIN 
     58#   include <mach/mach.h> 
     59#   include <IOKit/IOKitLib.h> 
     60#   include <CoreFoundation/CFNumber.h> 
     61#endif 
     62 
    5763#ifdef HAVE_SYSFS_LIBSYSFS_H 
    58 #    include <sysfs/libsysfs.h> 
     64#   include <sysfs/libsysfs.h> 
    5965#endif 
    6066 
     
    131137 
    132138static void InitShuffle   ( struct shuffle_s *, uint32_t * ); 
    133 static void DoShuffle     ( struct shuffle_s *, uint32_t * ); 
     139static void DoShuffle     ( struct shuffle_s *, uint32_t *, uint32_t ); 
    134140 
    135141static int GetSystemKey   ( uint32_t *, vlc_bool_t ); 
     
    678684 
    679685/***************************************************************************** 
    680  * DoShuffle: shuffle 16 byte buffer 
     686 * DoShuffle: shuffle buffer 
    681687 ***************************************************************************** 
    682688 * This is so ugly and uses so many MD5 checksums that it is most certainly 
    683689 * one-way, though why it needs to be so complicated is beyond me. 
    684690 *****************************************************************************/ 
    685 static void DoShuffle( struct shuffle_s *p_shuffle, uint32_t *p_buffer ) 
     691static void DoShuffle( struct shuffle_s *p_shuffle, 
     692                       uint32_t *p_buffer, uint32_t i_size ) 
    686693{ 
    687694    struct md5_s md5; 
     
    734741 
    735742    /* XOR our buffer with the computed checksum */ 
    736     for( i = 0; i < 4; i++ ) 
     743    for( i = 0; i < i_size; i++ ) 
    737744    { 
    738745        p_buffer[ i ] ^= md5.p_digest[ i ]; 
     
    876883    uint32_t i, y; 
    877884    uint32_t *p_sci_data; 
     885    uint32_t i_user, i_key; 
    878886    uint32_t p_sys_key[ 4 ]; 
    879     uint32_t i_sci_size, i_blocks
     887    uint32_t i_sci_size, i_blocks, i_remaining
    880888    uint32_t *p_sci0, *p_sci1, *p_buffer; 
    881889    uint32_t p_sci_key[ 4 ]; 
     
    906914    /* Skip the first 4 bytes (some sort of header). Decrypt the rest. */ 
    907915    i_blocks = (i_sci_size - 4) / 16; 
     916    i_remaining = (i_sci_size - 4) - (i_blocks * 16); 
    908917    p_buffer = p_sci_data + 1; 
    909918 
     
    928937 
    929938        /* Shuffle the decrypted data using a custom routine */ 
    930         DoShuffle( &shuffle, p_tmp ); 
     939        DoShuffle( &shuffle, p_tmp, 4 ); 
    931940 
    932941        /* Copy this block back to p_buffer */ 
     
    934943 
    935944        p_buffer += 4; 
     945    } 
     946 
     947    if( i_remaining >= 4 ) 
     948    { 
     949        i_remaining /= 4; 
     950        REVERSE( p_buffer, i_remaining ); 
     951        DoShuffle( &shuffle, p_buffer, i_remaining ); 
    936952    } 
    937953 
     
    971987        } 
    972988 
    973         REVERSE( p_sci0, 1 ); 
    974         REVERSE( p_sci1, 1 ); 
    975         if( U32_AT( p_sci0 ) == p_drms->i_user && 
    976             ( ( U32_AT( p_sci1 ) == p_drms->i_key ) || 
    977               ( !p_drms->i_key ) || ( p_sci1 == (p_sci0 + 18) ) ) ) 
    978         { 
     989        i_user = U32_AT( p_sci0 ); 
     990        i_key = U32_AT( p_sci1 ); 
     991        REVERSE( &i_user, 1 ); 
     992        REVERSE( &i_key, 1 ); 
     993        if( i_user == p_drms->i_user && ( ( i_key == p_drms->i_key ) || 
     994            ( !p_drms->i_key && ( p_sci1 == (p_sci0 + 18) ) ) ) ) 
     995        { 
     996            memcpy( p_user_key, p_sci1 + 1, 16 ); 
    979997            REVERSE( p_sci1 + 1, 4 ); 
    980             memcpy( p_user_key, p_sci1 + 1, 16 ); 
    981             WriteUserKey( p_drms, p_user_key ); 
     998            WriteUserKey( p_drms, p_sci1 + 1 ); 
    982999            i_ret = 0; 
    9831000            break; 
     
    11851202    int i_ret = -1; 
    11861203 
     1204#define PROD_NAME   "iPod" 
     1205#define VENDOR_NAME "Apple Computer, Inc." 
     1206 
    11871207    char *psz_ipod_id = getenv( "IPODID" ); 
    11881208    if( psz_ipod_id != NULL ) 
     
    11921212    } 
    11931213 
    1194 #ifdef HAVE_SYSFS_LIBSYSFS_H 
     1214#ifdef SYS_DARWIN 
     1215    CFTypeRef value; 
     1216    mach_port_t port; 
     1217    io_object_t device; 
     1218    io_iterator_t iterator; 
     1219    CFMutableDictionaryRef matching_dic; 
     1220 
     1221    if( IOMasterPort( MACH_PORT_NULL, &port ) == KERN_SUCCESS ) 
     1222    { 
     1223        if( ( matching_dic = IOServiceMatching( "IOFireWireUnit" ) ) != NULL ) 
     1224        { 
     1225            CFDictionarySetValue( matching_dic, 
     1226                                  CFSTR("FireWire Vendor Name"), 
     1227                                  CFSTR(VENDOR_NAME) ); 
     1228            CFDictionarySetValue( matching_dic, 
     1229                                  CFSTR("FireWire Product Name"), 
     1230                                  CFSTR(PROD_NAME) ); 
     1231 
     1232            if( IOServiceGetMatchingServices( port, matching_dic, 
     1233                                              &iterator ) == KERN_SUCCESS ) 
     1234            { 
     1235                while( ( device = IOIteratorNext( iterator ) ) != NULL ) 
     1236                { 
     1237                    value = IORegistryEntryCreateCFProperty( device, 
     1238                        CFSTR("GUID"), kCFAllocatorDefault, kNilOptions ); 
     1239 
     1240                    if( value != NULL ) 
     1241                    { 
     1242                        if( CFGetTypeID( value ) == CFNumberGetTypeID() ) 
     1243                        { 
     1244                            long long i_ipod_id; 
     1245                            CFNumberGetValue( (CFNumberRef)value, 
     1246                                              kCFNumberLongLongType, 
     1247                                              &i_ipod_id ); 
     1248                            *p_ipod_id = i_ipod_id; 
     1249                            i_ret = 0; 
     1250                        } 
     1251 
     1252                        CFRelease( value ); 
     1253                    } 
     1254 
     1255                    IOObjectRelease( device ); 
     1256 
     1257                    if( !i_ret ) break; 
     1258                } 
     1259 
     1260                IOObjectRelease( iterator ); 
     1261            } 
     1262        } 
     1263 
     1264        mach_port_deallocate( mach_task_self(), port ); 
     1265    } 
     1266 
     1267#elif HAVE_SYSFS_LIBSYSFS_H 
    11951268    struct sysfs_bus *bus = NULL; 
    11961269    struct dlist *devlist = NULL; 
     
    12141287                    { 
    12151288                        if( ( strcmp( curattr->name, "model_name" ) == 0 ) && 
    1216                             ( strncmp( curattr->value, "iPod", 4 ) == 0 ) ) 
     1289                            ( strncmp( curattr->value, PROD_NAME, 
     1290                                       sizeof(PROD_NAME) ) == 0 ) ) 
    12171291                        { 
    12181292                            *p_ipod_id = strtoll( curdev->name, NULL, 16 );