Changeset 3724ca76ddffbf77b3ede9805a9a0f9f8cabe661
- 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
| rebb65f2 |
r3724ca7 |
|
| 3 | 3 | ***************************************************************************** |
|---|
| 4 | 4 | * 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 $ |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * Authors: Jon Lech Johansen <jon-vl@nanocrew.net> |
|---|
| … | … | |
| 55 | 55 | #endif |
|---|
| 56 | 56 | |
|---|
| | 57 | #ifdef SYS_DARWIN |
|---|
| | 58 | # include <mach/mach.h> |
|---|
| | 59 | # include <IOKit/IOKitLib.h> |
|---|
| | 60 | # include <CoreFoundation/CFNumber.h> |
|---|
| | 61 | #endif |
|---|
| | 62 | |
|---|
| 57 | 63 | #ifdef HAVE_SYSFS_LIBSYSFS_H |
|---|
| 58 | | # include <sysfs/libsysfs.h> |
|---|
| | 64 | # include <sysfs/libsysfs.h> |
|---|
| 59 | 65 | #endif |
|---|
| 60 | 66 | |
|---|
| … | … | |
| 131 | 137 | |
|---|
| 132 | 138 | static void InitShuffle ( struct shuffle_s *, uint32_t * ); |
|---|
| 133 | | static void DoShuffle ( struct shuffle_s *, uint32_t * ); |
|---|
| | 139 | static void DoShuffle ( struct shuffle_s *, uint32_t *, uint32_t ); |
|---|
| 134 | 140 | |
|---|
| 135 | 141 | static int GetSystemKey ( uint32_t *, vlc_bool_t ); |
|---|
| … | … | |
| 678 | 684 | |
|---|
| 679 | 685 | /***************************************************************************** |
|---|
| 680 | | * DoShuffle: shuffle 16 byte buffer |
|---|
| | 686 | * DoShuffle: shuffle buffer |
|---|
| 681 | 687 | ***************************************************************************** |
|---|
| 682 | 688 | * This is so ugly and uses so many MD5 checksums that it is most certainly |
|---|
| 683 | 689 | * one-way, though why it needs to be so complicated is beyond me. |
|---|
| 684 | 690 | *****************************************************************************/ |
|---|
| 685 | | static void DoShuffle( struct shuffle_s *p_shuffle, uint32_t *p_buffer ) |
|---|
| | 691 | static void DoShuffle( struct shuffle_s *p_shuffle, |
|---|
| | 692 | uint32_t *p_buffer, uint32_t i_size ) |
|---|
| 686 | 693 | { |
|---|
| 687 | 694 | struct md5_s md5; |
|---|
| … | … | |
| 734 | 741 | |
|---|
| 735 | 742 | /* XOR our buffer with the computed checksum */ |
|---|
| 736 | | for( i = 0; i < 4; i++ ) |
|---|
| | 743 | for( i = 0; i < i_size; i++ ) |
|---|
| 737 | 744 | { |
|---|
| 738 | 745 | p_buffer[ i ] ^= md5.p_digest[ i ]; |
|---|
| … | … | |
| 876 | 883 | uint32_t i, y; |
|---|
| 877 | 884 | uint32_t *p_sci_data; |
|---|
| | 885 | uint32_t i_user, i_key; |
|---|
| 878 | 886 | uint32_t p_sys_key[ 4 ]; |
|---|
| 879 | | uint32_t i_sci_size, i_blocks; |
|---|
| | 887 | uint32_t i_sci_size, i_blocks, i_remaining; |
|---|
| 880 | 888 | uint32_t *p_sci0, *p_sci1, *p_buffer; |
|---|
| 881 | 889 | uint32_t p_sci_key[ 4 ]; |
|---|
| … | … | |
| 906 | 914 | /* Skip the first 4 bytes (some sort of header). Decrypt the rest. */ |
|---|
| 907 | 915 | i_blocks = (i_sci_size - 4) / 16; |
|---|
| | 916 | i_remaining = (i_sci_size - 4) - (i_blocks * 16); |
|---|
| 908 | 917 | p_buffer = p_sci_data + 1; |
|---|
| 909 | 918 | |
|---|
| … | … | |
| 928 | 937 | |
|---|
| 929 | 938 | /* Shuffle the decrypted data using a custom routine */ |
|---|
| 930 | | DoShuffle( &shuffle, p_tmp ); |
|---|
| | 939 | DoShuffle( &shuffle, p_tmp, 4 ); |
|---|
| 931 | 940 | |
|---|
| 932 | 941 | /* Copy this block back to p_buffer */ |
|---|
| … | … | |
| 934 | 943 | |
|---|
| 935 | 944 | 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 ); |
|---|
| 936 | 952 | } |
|---|
| 937 | 953 | |
|---|
| … | … | |
| 971 | 987 | } |
|---|
| 972 | 988 | |
|---|
| 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 ); |
|---|
| 979 | 997 | 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 ); |
|---|
| 982 | 999 | i_ret = 0; |
|---|
| 983 | 1000 | break; |
|---|
| … | … | |
| 1185 | 1202 | int i_ret = -1; |
|---|
| 1186 | 1203 | |
|---|
| | 1204 | #define PROD_NAME "iPod" |
|---|
| | 1205 | #define VENDOR_NAME "Apple Computer, Inc." |
|---|
| | 1206 | |
|---|
| 1187 | 1207 | char *psz_ipod_id = getenv( "IPODID" ); |
|---|
| 1188 | 1208 | if( psz_ipod_id != NULL ) |
|---|
| … | … | |
| 1192 | 1212 | } |
|---|
| 1193 | 1213 | |
|---|
| 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 |
|---|
| 1195 | 1268 | struct sysfs_bus *bus = NULL; |
|---|
| 1196 | 1269 | struct dlist *devlist = NULL; |
|---|
| … | … | |
| 1214 | 1287 | { |
|---|
| 1215 | 1288 | 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 ) ) |
|---|
| 1217 | 1291 | { |
|---|
| 1218 | 1292 | *p_ipod_id = strtoll( curdev->name, NULL, 16 ); |
|---|