Advertisement
Guest User

imgscpy.cxx

a guest
Apr 8th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.98 KB | None | 0 0
  1. // imgscpy.cxx
  2.  
  3. #include <fcntl.h>
  4. #include <io.h>
  5. #include <sys\stat.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <tchar.h>
  10.  
  11. #include <windows.h>
  12.  
  13.  
  14. const _TCHAR* cpsztAssetSubDir = (const _TCHAR*) TEXT( "\\AppData\\Local\\Packages\\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\\LocalState\\Assets\\" );
  15.  
  16.  
  17. int _tmain( int argc, _TCHAR* argv[ ] )
  18. {
  19.     struct _tfinddatai64_t tfnddtaInfo;
  20.  
  21.     _TCHAR* psztProfileDir = (_TCHAR*) _tgetenv( TEXT( "USERPROFILE" ) );
  22.  
  23.     _TCHAR* psztSpec = (_TCHAR*) new _TCHAR [ _tcslen( psztProfileDir ) + _tcslen( cpsztAssetSubDir ) + 10 ];
  24.  
  25.     _tcscpy( psztSpec, psztProfileDir );
  26.     _tcscat( psztSpec, cpsztAssetSubDir );
  27.     _tcscat( psztSpec, TEXT( "*.*" ) );
  28.  
  29.     long lhandle = (long) _tfindfirsti64( psztSpec, &tfnddtaInfo );
  30.  
  31.     if ( lhandle < 0 )
  32.     {
  33.         _tprintf( TEXT( "imgscpy: Unable to browse directory\n (spec='%s')\n" ), psztSpec );
  34.         return -1;
  35.     }
  36.  
  37.     do
  38.     {
  39.         if ( tfnddtaInfo.attrib & _A_SUBDIR );
  40.         else
  41.         {
  42.             if ( ( tfnddtaInfo.size > 24i64 ) && ( tfnddtaInfo.size <= 16777216i64 ) )
  43.             {
  44.                     _TCHAR* psztFile = (_TCHAR*) new _TCHAR [ _tcslen( psztProfileDir ) + _tcslen( cpsztAssetSubDir ) + _tcslen( tfnddtaInfo.name ) + 1 ];
  45.  
  46.                     _tcscpy( psztFile, psztProfileDir );
  47.                     _tcscat( psztFile, cpsztAssetSubDir );
  48.                     _tcscat( psztFile, tfnddtaInfo.name );
  49.  
  50.                     int nFile = (int) _topen( psztFile, _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, _S_IREAD );
  51.  
  52.                     if ( nFile > 0 )
  53.                     {
  54.                         static unsigned __int8 ui8Buf[ 30 ];
  55.  
  56.                         int nRead = (int) _read( nFile, (void*) &ui8Buf, 24 );
  57.  
  58.                         if ( ( ui8Buf[ 0 ] == 0xFF ) && ( ui8Buf[ 1 ] == 0xD8 ) && ( ui8Buf[ 2 ] == 0xFF ) && ( ui8Buf[ 3 ] == 0xE0 ) &&
  59.                                 ( ui8Buf[ 6 ] == 'J' ) && ( ui8Buf[ 7 ] == 'F' ) && ( ui8Buf[ 8 ] == 'I' ) && ( ui8Buf[ 9 ] == 'F' ) )
  60.                         {
  61.                             long lFilePos = 2;
  62.  
  63.                             while ( ui8Buf[ 2 ] == 0xFF )
  64.                             {
  65.                                 if ( ( ui8Buf[ 3 ] == 0xC0 ) || ( ui8Buf[ 3 ] == 0xC1 ) || ( ui8Buf[ 3 ] == 0xC2 ) ||
  66.                                         ( ui8Buf[ 3 ] == 0xC3 ) || ( ui8Buf[ 3 ] == 0xC9 ) || ( ui8Buf[ 3 ] == 0xCA ) ||
  67.                                         ( ui8Buf[ 3 ] == 0xCB ) ) break;
  68.  
  69.                                 lFilePos += 2 + ( (unsigned long) ui8Buf[ 4 ] << 8 ) + (unsigned long) ui8Buf[ 5 ];
  70.                                 if ( lFilePos + 12 > (long) tfnddtaInfo.size ) break;
  71.                                 if ( lseek( nFile, lFilePos, SEEK_SET ) == -1L );
  72.                                 nRead = _read( nFile, (void*) &( ui8Buf[ 2 ] ), 12 );
  73.                             }
  74.                         }
  75.  
  76.                         _close( nFile );
  77.  
  78.                         unsigned long ulHeight = 0ul;
  79.                         unsigned long ulWidth = 0ul;
  80.  
  81.                         // JPEG: first two bytes of ui8Buf are first two bytes of the JPEG file;
  82.                         //       rest of ui8Buf is the DCT frame
  83.                         if ( ( ui8Buf[ 0 ] == 0xFF ) && ( ui8Buf[ 1 ] == 0xD8 ) && ( ui8Buf[ 2 ] == 0xFF ) )
  84.                         {
  85.                             ulHeight = ( (unsigned long) ui8Buf[ 7 ] << 8 ) + (unsigned long) ui8Buf[ 8 ];
  86.                             ulWidth = ( (unsigned long) ui8Buf[ 9 ] << 8 ) + (unsigned long) ui8Buf[ 10 ];
  87.                         }
  88.  
  89.                         // only JPG images with Full HD dimension are copied
  90.                         if ( ( ulWidth == 1920ul ) && ( ulHeight == 1080ul ) )
  91.                         {
  92.                             LPTSTR lpsztSrcFile = (LPTSTR) psztFile;
  93.                             LPTSTR lpsztDestFile = (LPTSTR) new TCHAR [ _tcslen( tfnddtaInfo.name ) + 8 ];
  94.  
  95.                             lstrcpy( lpsztDestFile, TEXT( ".\\" ) );
  96.                             lstrcat( lpsztDestFile, (LPCTSTR) tfnddtaInfo.name );
  97.                             lstrcat( lpsztDestFile, TEXT( ".jpg" ) );
  98.  
  99.                             if ( CopyFile( lpsztSrcFile, lpsztDestFile, FALSE ) )
  100.                                 _tprintf( TEXT( "imgscpy: Image copy succeeded (image file='.\\%s.jpg').\n" ), tfnddtaInfo.name );
  101.                             else
  102.                                 _tprintf( TEXT( "imgscpy: Image copy failed (image file='.\\%s.jpg').\n" ), tfnddtaInfo.name );
  103.  
  104.                             lpsztSrcFile = (LPTSTR) NULL;
  105.  
  106.                             delete [ ] lpsztDestFile;
  107.                         }
  108.                     }
  109.                     else
  110.                     {
  111.                         _tprintf( TEXT( "imgscpy: Failed to open (file='%s').\n" ), psztFile );
  112.                     }
  113.  
  114.                     delete [ ] psztFile;
  115.                 }
  116.             }
  117.         }
  118.         while ( _tfindnexti64( lhandle, &tfnddtaInfo ) >= 0 );
  119.  
  120.         _findclose( lhandle );
  121.         delete [ ] psztSpec;
  122.     }
  123.  
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement