Guest User

Untitled

a guest
Apr 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. size_t __cdecl fread(void *DstBuf, size_t ElementSize, size_t Count, FILE *File)
  2. {
  3.   size_t result; // eax@2
  4.   DWORD v5; // [sp+0h] [bp-24h]@15
  5.   int bytesFilled; // [sp+4h] [bp-20h]@10
  6.   int bufSIze; // [sp+8h] [bp-1Ch]@4
  7.   int fHnd; // [sp+10h] [bp-14h]@17
  8.   unsigned int v9; // [sp+14h] [bp-10h]@1
  9.   unsigned int maxBytesFilled; // [sp+18h] [bp-Ch]@1
  10.   void *bytesDestination; // [sp+1Ch] [bp-8h]@1
  11.   int v12; // [sp+20h] [bp-4h]@22
  12.  
  13.   bytesDestination = DstBuf;
  14.   v9 = Count * ElementSize;
  15.   maxBytesFilled = Count * ElementSize;
  16.   if ( Count * ElementSize )
  17.   {
  18.     if ( File->_flag & 0x10C )
  19.       bufSIze = File->_bufsiz;
  20.     else
  21.       bufSIze = 4096;
  22.     while ( maxBytesFilled )
  23.     {
  24.       if ( File->_flag & 0x10C && File->_cnt )
  25.       {
  26.         if ( maxBytesFilled >= File->_cnt )
  27.           bytesFilled = File->_cnt;
  28.         else
  29.           bytesFilled = maxBytesFilled;
  30.         memcpy(bytesDestination, File->_ptr, bytesFilled);
  31.         maxBytesFilled -= bytesFilled;
  32.         File->_cnt -= bytesFilled;
  33.         File->_ptr += bytesFilled;
  34.         bytesDestination = (char *)bytesDestination + bytesFilled;
  35.       }
  36.       else
  37.       {
  38.         if ( maxBytesFilled < bufSIze )
  39.         {
  40.           v12 = _filbuf(File);
  41.           if ( v12 == -1 )
  42.             return (v9 - maxBytesFilled) / ElementSize;
  43.           *(_BYTE *)bytesDestination = v12;
  44.           bytesDestination = (char *)bytesDestination + 1;
  45.           --maxBytesFilled;
  46.           bufSIze = File->_bufsiz;
  47.         }
  48.         else
  49.         {
  50.           if ( bufSIze )
  51.             v5 = maxBytesFilled - maxBytesFilled % bufSIze;
  52.           else
  53.             v5 = maxBytesFilled;
  54.           fHnd = _read(File->_file, (int)bytesDestination, v5);
  55.           if ( !fHnd )
  56.           {
  57.             File->_flag |= 0x10u;
  58.             return (v9 - maxBytesFilled) / ElementSize;
  59.           }
  60.           if ( fHnd == -1 )
  61.           {
  62.             File->_flag |= 0x20u;
  63.             return (v9 - maxBytesFilled) / ElementSize;
  64.           }
  65.           maxBytesFilled -= fHnd;
  66.           bytesDestination = (char *)bytesDestination + fHnd;
  67.         }
  68.       }
  69.     }
  70.     result = Count;
  71.   }
  72.   else
  73.   {
  74.     result = 0;
  75.   }
  76.   return result;
  77. }
Add Comment
Please, Sign In to add comment