int open (__const char *__file, int __oflag, ...) { static int (*libc_open) (__const char *__file, int __oflag, ...) = NULL; void *handle; int open_handle; char *error; if (!libc_open) { handle = dlopen("/lib/libc.so.6", RTLD_LAZY); if (!handle) { fputs(dlerror(), stderr); exit(1); } libc_open = dlsym(handle, "open"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } } // custom implementation // we break permissions here, but it probably makes no difference on the AR.Drone mode_t mode = 0777; /* if(__oflag ) va_list arg_ptr; va_start(arg_ptr, 1); */ printf("AR.Pwn hooked open(%s, %d, %d)\n", __file, __oflag, mode); open_handle = libc_open(__file, __oflag, mode); printf("AR.Pwn open() returned %d\n", open_handle); if(strcmp(__file, "/dev/video0") == 0) { printf("AR.Pwn Detected open of video0; saving handle.\n"); hook_handle_video0 = open_handle; } else if(strcmp(__file, "/dev/video1") == 0) { printf("AR.Pwn Detected open of video1; saving handle.\n"); hook_handle_video1 = open_handle; } return open_handle; }
int main( void ) { struct reader *pp_readers[3]; test_init(); #ifndef TEST_NET char psz_tmp_path[] = "/tmp/libvlc_XXXXXX"; char *psz_url; int i_tmp_fd; log( "Test random file with libc, and stream\n" ); i_tmp_fd = vlc_mkstemp( psz_tmp_path ); fill_rand( i_tmp_fd, RAND_FILE_SIZE ); assert( i_tmp_fd != -1 ); assert( asprintf( &psz_url, "file://%s", psz_tmp_path ) != -1 ); assert( ( pp_readers[0] = libc_open( psz_tmp_path ) ) ); assert( ( pp_readers[1] = stream_open( psz_url ) ) ); test( pp_readers, 2, NULL ); for( unsigned int i = 0; i < 2; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); free( psz_url ); close( i_tmp_fd ); #else log( "Test http url with stream\n" ); alarm( 0 ); if( !( pp_readers[0] = stream_open( HTTP_URL ) ) ) { log( "WARNING: can't test http url" ); return 0; } test( pp_readers, 1, HTTP_MD5 ); for( unsigned int i = 0; i < 1; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); #endif return 0; }
int main( void ) { struct reader *pp_readers[3]; test_init(); #ifndef TEST_NET char psz_file[PATH_MAX]; char *psz_url; log( "Test local file with libc, and stream\n" ); assert( realpath( FILE_PATH, psz_file ) == psz_file ); assert( asprintf( &psz_url, "file://%s", psz_file ) != -1 ); assert( ( pp_readers[0] = libc_open( psz_file ) ) ); assert( ( pp_readers[1] = stream_open( psz_url ) ) ); test( pp_readers, 2, FILE_MD5 ); for( unsigned int i = 0; i < 2; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); free( psz_url ); #else log( "Test http url with stream\n" ); alarm( 0 ); if( !( pp_readers[0] = stream_open( HTTP_URL ) ) ) { log( "WARNING: can't test http url" ); return 0; } test( pp_readers, 1, HTTP_MD5 ); for( unsigned int i = 0; i < 1; ++i ) pp_readers[i]->pf_close( pp_readers[i] ); #endif return 0; }
int dvdcss_open_device ( dvdcss_t dvdcss ) { const char *psz_device = getenv( "DVDCSS_RAW_DEVICE" ); if( !psz_device ) { psz_device = dvdcss->psz_device; } print_debug( dvdcss, "opening target `%s'", psz_device ); #if defined( _WIN32 ) /* Initialize readv temporary buffer */ dvdcss->p_readv_buffer = NULL; dvdcss->i_readv_buf_size = 0; #endif /* if callback functions are initialized */ if( dvdcss->p_stream ) { print_debug( dvdcss, "using stream API for access" ); dvdcss->pf_seek = stream_seek; dvdcss->pf_read = stream_read; dvdcss->pf_readv = stream_readv; dvdcss->pf_maxspeed = stream_maxspeed; return 0; } #if defined( _WIN32 ) dvdcss->b_file = 1; /* If device is "X:" or "X:\", we are not actually opening a file. */ if (psz_device[0] && psz_device[1] == ':' && (!psz_device[2] || (psz_device[2] == '\\' && !psz_device[3]))) dvdcss->b_file = 0; if( !dvdcss->b_file ) { print_debug( dvdcss, "using Win2K API for access" ); dvdcss->pf_seek = win2k_seek; dvdcss->pf_read = win2k_read; dvdcss->pf_readv = win2k_readv; dvdcss->pf_maxspeed = win2k_maxspeed; return win2k_open( dvdcss, psz_device ); } else #elif defined( __OS2__ ) /* If device is "X:" or "X:\", we are not actually opening a file. */ if( psz_device[0] && psz_device[1] == ':' && ( !psz_device[2] || ( psz_device[2] == '\\' && !psz_device[3] ) ) ) { print_debug( dvdcss, "using OS/2 API for access" ); dvdcss->pf_seek = libc_seek; dvdcss->pf_read = libc_read; dvdcss->pf_readv = libc_readv; dvdcss->pf_maxspeed = libc_maxspeed; return os2_open( dvdcss, psz_device ); } else #endif { print_debug( dvdcss, "using libc API for access" ); dvdcss->pf_seek = libc_seek; dvdcss->pf_read = libc_read; dvdcss->pf_readv = libc_readv; dvdcss->pf_maxspeed = libc_maxspeed; return libc_open( dvdcss, psz_device ); } }