Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // imgscpy.cxx
- #include <fcntl.h>
- #include <io.h>
- #include <sys\stat.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tchar.h>
- #include <windows.h>
- const _TCHAR* cpsztAssetSubDir = (const _TCHAR*) TEXT( "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets\\" );
- int _tmain( int argc, _TCHAR* argv[ ] )
- {
- struct _tfinddatai64_t tfnddtaInfo;
- _TCHAR* psztProfileDir = (_TCHAR*) _tgetenv( TEXT( "USERPROFILE" ) );
- _TCHAR* psztSpec = (_TCHAR*) new _TCHAR [ _tcslen( psztProfileDir ) + _tcslen( cpsztAssetSubDir ) + 10 ];
- _tcscpy( psztSpec, psztProfileDir );
- _tcscat( psztSpec, cpsztAssetSubDir );
- _tcscat( psztSpec, TEXT( "*.*" ) );
- long lhandle = (long) _tfindfirsti64( psztSpec, &tfnddtaInfo );
- if ( lhandle < 0 )
- {
- _tprintf( TEXT( "imgscpy: Unable to browse directory\n (spec='%s')\n" ), psztSpec );
- return -1;
- }
- do
- {
- if ( tfnddtaInfo.attrib & _A_SUBDIR );
- else
- {
- if ( ( tfnddtaInfo.size > 24i64 ) && ( tfnddtaInfo.size <= 16777216i64 ) )
- {
- _TCHAR* psztFile = (_TCHAR*) new _TCHAR [ _tcslen( psztProfileDir ) + _tcslen( cpsztAssetSubDir ) + _tcslen( tfnddtaInfo.name ) + 1 ];
- _tcscpy( psztFile, psztProfileDir );
- _tcscat( psztFile, cpsztAssetSubDir );
- _tcscat( psztFile, tfnddtaInfo.name );
- int nFile = (int) _topen( psztFile, _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, _S_IREAD );
- if ( nFile > 0 )
- {
- static unsigned __int8 ui8Buf[ 30 ];
- int nRead = (int) _read( nFile, (void*) &ui8Buf, 24 );
- if ( ( ui8Buf[ 0 ] == 0xFF ) && ( ui8Buf[ 1 ] == 0xD8 ) && ( ui8Buf[ 2 ] == 0xFF ) && ( ui8Buf[ 3 ] == 0xE0 ) &&
- ( ui8Buf[ 6 ] == 'J' ) && ( ui8Buf[ 7 ] == 'F' ) && ( ui8Buf[ 8 ] == 'I' ) && ( ui8Buf[ 9 ] == 'F' ) )
- {
- long lFilePos = 2;
- while ( ui8Buf[ 2 ] == 0xFF )
- {
- if ( ( ui8Buf[ 3 ] == 0xC0 ) || ( ui8Buf[ 3 ] == 0xC1 ) || ( ui8Buf[ 3 ] == 0xC2 ) ||
- ( ui8Buf[ 3 ] == 0xC3 ) || ( ui8Buf[ 3 ] == 0xC9 ) || ( ui8Buf[ 3 ] == 0xCA ) ||
- ( ui8Buf[ 3 ] == 0xCB ) ) break;
- lFilePos += 2 + ( (unsigned long) ui8Buf[ 4 ] << 8 ) + (unsigned long) ui8Buf[ 5 ];
- if ( lFilePos + 12 > (long) tfnddtaInfo.size ) break;
- if ( lseek( nFile, lFilePos, SEEK_SET ) == -1L );
- nRead = _read( nFile, (void*) &( ui8Buf[ 2 ] ), 12 );
- }
- }
- _close( nFile );
- unsigned long ulHeight = 0ul;
- unsigned long ulWidth = 0ul;
- // JPEG: first two bytes of ui8Buf are first two bytes of the JPEG file;
- // rest of ui8Buf is the DCT frame
- if ( ( ui8Buf[ 0 ] == 0xFF ) && ( ui8Buf[ 1 ] == 0xD8 ) && ( ui8Buf[ 2 ] == 0xFF ) )
- {
- ulHeight = ( (unsigned long) ui8Buf[ 7 ] << 8 ) + (unsigned long) ui8Buf[ 8 ];
- ulWidth = ( (unsigned long) ui8Buf[ 9 ] << 8 ) + (unsigned long) ui8Buf[ 10 ];
- }
- // only JPG images with Full HD dimension are copied
- if ( ( ulWidth == 1920ul ) && ( ulHeight == 1080ul ) )
- {
- LPTSTR lpsztSrcFile = (LPTSTR) psztFile;
- LPTSTR lpsztDestFile = (LPTSTR) new TCHAR [ _tcslen( tfnddtaInfo.name ) + 8 ];
- lstrcpy( lpsztDestFile, TEXT( ".\\" ) );
- lstrcat( lpsztDestFile, (LPCTSTR) tfnddtaInfo.name );
- lstrcat( lpsztDestFile, TEXT( ".jpg" ) );
- if ( CopyFile( lpsztSrcFile, lpsztDestFile, FALSE ) )
- _tprintf( TEXT( "imgscpy: Image copy succeeded (image file='.\\%s.jpg').\n" ), tfnddtaInfo.name );
- else
- _tprintf( TEXT( "imgscpy: Image copy failed (image file='.\\%s.jpg').\n" ), tfnddtaInfo.name );
- lpsztSrcFile = (LPTSTR) NULL;
- delete [ ] lpsztDestFile;
- }
- }
- else
- {
- _tprintf( TEXT( "imgscpy: Failed to open (file='%s').\n" ), psztFile );
- }
- delete [ ] psztFile;
- }
- }
- }
- while ( _tfindnexti64( lhandle, &tfnddtaInfo ) >= 0 );
- _findclose( lhandle );
- delete [ ] psztSpec;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement