Advertisement
Guest User

StreamingPartitionReader::process

a guest
Jun 14th, 2015
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.67 KB | None | 0 0
  1. void __thiscall fb::StreamingPartitionReader::process(fb::StreamingPartitionReader *this, void *data, unsigned int inByteCount)
  2. {
  3.   fb::StreamingPartitionReader *StreamingPartitionReader; // ebx@1
  4.   char *position; // esi@5
  5.   fb::StreamingPartitionReader::ReaderState curentState; // ecx@7
  6.   signed int bytesToEOF; // eax@7
  7.   unsigned int Magic; // ecx@11
  8.   void *v8; // eax@21
  9.   unsigned int v9; // ST20_4@21
  10.   unsigned int MetaSize; // eax@22
  11.   unsigned int PayLoadSize; // ecx@22
  12.   fb::InternalDatabasePartition *Partition; // eax@22
  13.   bool isMetaDataLeft; // cf@25
  14.   int metaDataLeft; // esi@25
  15.   unsigned int *pMetaDataLeft; // eax@25
  16.   size_t realMetaDataLeft; // edi@27
  17.   char *v17; // eax@28
  18.   bool v18; // zf@29
  19.   char *v19; // eax@30
  20.   char *startOfMetaData; // ecx@32
  21.   int v21; // edx@32
  22.   fb::StreamingPartitionImportEntry *importEntries; // eax@32
  23.   int endOfImports; // eax@32
  24.   unsigned int sizeOfFieldDescriptors; // edx@32
  25.   int endOfTypeStringTable; // eax@32
  26.   int endOfFieldDescriptors; // eax@32
  27.   int sizeOfTypeDescriptors; // edx@32
  28.   int endOfTypeDescriptors; // eax@32
  29.   unsigned int sizeofInstances; // edx@32
  30.   int endOfInstances; // eax@32
  31.   unsigned int endOfArrayList; // edx@32
  32.   int payLoadLeft; // edi@39
  33.   unsigned int *pPayLoadLeft; // eax@39
  34.   size_t realPayLoadLeft; // esi@41
  35.   char *payLoadPos; // eax@42
  36.   int v36; // edi@43
  37.   char *pPayload; // eax@47
  38.   unsigned int stringTableSize; // ecx@47
  39.   fb::Log::Stream f_; // [sp+Ch] [bp-148h]@16
  40.   char *const cursorEnd; // [sp+13Ch] [bp-18h]@4
  41.   unsigned int byteCount; // [sp+140h] [bp-14h]@7
  42.   char *cursor; // [sp+144h] [bp-10h]@4
  43.   int v43; // [sp+150h] [bp-4h]@16
  44.   char complete_3; // [sp+15Fh] [bp+Bh]@4
  45.  
  46.   StreamingPartitionReader = this;
  47.   if ( (unsigned __int8)data & 0xF )
  48.   {
  49.     fb::Log::formattedLog(&stru_39E10FC, "%s", &secret);
  50.     if ( fb::Log::shouldBreak() )
  51.       __debugbreak();
  52.   }
  53.   cursor = (char *)data;
  54.   cursorEnd = (char *)data + inByteCount;
  55.   complete_3 = 0;
  56.   while ( 1 )
  57.   {
  58.     position = cursor;
  59.     if ( cursor == cursorEnd )
  60.     {
  61.       if ( inByteCount )
  62.         break;
  63.     }
  64.     curentState = StreamingPartitionReader->m_currentState;
  65.     bytesToEOF = cursorEnd - cursor;
  66.     byteCount = cursorEnd - cursor;
  67.     switch ( curentState )
  68.     {
  69.       case 0:
  70.         if ( (unsigned int)bytesToEOF <= 0x50 )
  71.         {
  72.           fb::Log::formattedLog(&stru_39E10E8, "%s", &secret);
  73.           if ( fb::Log::shouldBreak() )
  74.             __debugbreak();
  75.         }
  76.         qmemcpy(&StreamingPartitionReader->m_header, position, sizeof(StreamingPartitionReader->m_header));
  77.         Magic = StreamingPartitionReader->m_header.magic;
  78.         if ( Magic == 0xFB2D1CE )
  79.         {
  80.           StreamingPartitionReader->m_endianSwapRequired = 0;
  81.         }
  82.         else if ( Magic == _byteswap_ulong(0xFB2D1CEu) )
  83.         {
  84.           StreamingPartitionReader->m_endianSwapRequired = 1;
  85.           fb::endianSwapInplace(&StreamingPartitionReader->m_header);
  86.         }
  87.         else
  88.         {
  89.           if ( fb::Log::c_logFilter & 0x20 )
  90.           {
  91.             fb::Log::Stream::Stream(&f_, &stru_39E10D4, s_logContext);
  92.             v43 = 0;
  93.             fb::operator<<((fb::OutAsciiStream *)&f_.vfptr, "Bad EBX partition header magic");
  94.             fb::Log::Stream::process(&f_);
  95.             v43 = -1;
  96.             fb::Log::Stream::~Stream(&f_);
  97.           }
  98.           if ( fb::Log::shouldBreak() )
  99.             __debugbreak();
  100.         }
  101.         if ( StreamingPartitionReader->m_header.metaSize + StreamingPartitionReader->m_header.payloadSize == byteCount )
  102.         {
  103.           complete_3 = 1;
  104.         }
  105.         else
  106.         {
  107.           v8 = operator new[](StreamingPartitionReader->m_header.metaSize);
  108.           v9 = StreamingPartitionReader->m_header.payloadSize;
  109.           StreamingPartitionReader->m_metadataBuffer = (char *)v8;
  110.           StreamingPartitionReader->m_metadataInputCursor = 0;
  111.           StreamingPartitionReader->m_payloadBuffer = (char *)operator new[](v9);
  112.           StreamingPartitionReader->m_payloadInputCursor = 0;
  113.         }
  114.         MetaSize = StreamingPartitionReader->m_header.metaSize;
  115.         PayLoadSize = StreamingPartitionReader->m_header.payloadSize;
  116.         cursor += 0x50;
  117.         StreamingPartitionReader->m_metadataOutstanding = MetaSize - 0x50;
  118.         Partition = StreamingPartitionReader->m_partition;
  119.         StreamingPartitionReader->m_payloadOutstanding = PayLoadSize;
  120.         if ( Partition )
  121.           fb::InternalDatabaseDomain::setPartitionGuid(
  122.             Partition->m_domain,
  123.             Partition,
  124.             &StreamingPartitionReader->m_header.partitionGuid);
  125.         StreamingPartitionReader->m_currentState = 1;
  126.         continue;
  127.       case 1:
  128.         isMetaDataLeft = StreamingPartitionReader->m_metadataOutstanding < bytesToEOF;
  129.         metaDataLeft = (int)&StreamingPartitionReader->m_metadataOutstanding;
  130.         pMetaDataLeft = &StreamingPartitionReader->m_metadataOutstanding;
  131.         if ( !isMetaDataLeft )
  132.           pMetaDataLeft = &byteCount;
  133.         realMetaDataLeft = *pMetaDataLeft;
  134.         if ( complete_3 )
  135.         {
  136.           v17 = cursor;
  137.           cursor += realMetaDataLeft;
  138.           StreamingPartitionReader->m_currentState = 2;
  139.           StreamingPartitionReader->m_metadata = v17;
  140.         }
  141.         else
  142.         {
  143.           memcpy(
  144.             &StreamingPartitionReader->m_metadataBuffer[StreamingPartitionReader->m_metadataInputCursor],
  145.             cursor,
  146.             realMetaDataLeft);
  147.           StreamingPartitionReader->m_metadataInputCursor += realMetaDataLeft;
  148.           v18 = *(_DWORD *)metaDataLeft == realMetaDataLeft;
  149.           *(_DWORD *)metaDataLeft -= realMetaDataLeft;
  150.           if ( v18 )
  151.           {
  152.             v19 = StreamingPartitionReader->m_metadataBuffer;
  153.             StreamingPartitionReader->m_currentState = 2;
  154.             StreamingPartitionReader->m_metadata = v19;
  155.           }
  156.           cursor += realMetaDataLeft;
  157.         }
  158.         continue;
  159.       case 2:
  160.         startOfMetaData = StreamingPartitionReader->m_metadata;
  161.         v21 = StreamingPartitionReader->m_header.importCount;
  162.         importEntries = (fb::StreamingPartitionImportEntry *)StreamingPartitionReader->m_metadata;
  163.         StreamingPartitionReader->m_importEntries = importEntries;
  164.         endOfImports = (int)&importEntries[v21];
  165.         sizeOfFieldDescriptors = (16 * StreamingPartitionReader->m_header.fieldDescriptorCount + 15) & 0xFFFFFFF0;
  166.         StreamingPartitionReader->m_metaStringBlock = (const char *)endOfImports;
  167.         endOfTypeStringTable = StreamingPartitionReader->m_header.typeStringTableSize + endOfImports;
  168.         StreamingPartitionReader->m_fieldDescriptors = (fb::StreamingPartitionFieldDescriptor *)endOfTypeStringTable;
  169.         endOfFieldDescriptors = sizeOfFieldDescriptors + endOfTypeStringTable;
  170.         sizeOfTypeDescriptors = 16 * StreamingPartitionReader->m_header.typeDescriptorCount;
  171.         StreamingPartitionReader->m_typeDescriptors = (fb::StreamingPartitionTypeDescriptor *)endOfFieldDescriptors;
  172.         endOfTypeDescriptors = sizeOfTypeDescriptors + endOfFieldDescriptors;
  173.         sizeofInstances = (12 * StreamingPartitionReader->m_header.typeCount + 15) & 0xFFFFFFF0;
  174.         StreamingPartitionReader->m_instanceEntries = (fb::StreamingPartitionInstanceEntry *)endOfTypeDescriptors;
  175.         endOfInstances = sizeofInstances + endOfTypeDescriptors;
  176.         endOfArrayList = endOfInstances + ((12 * StreamingPartitionReader->m_header.arrayCount + 15) & 0xFFFFFFF0);
  177.         StreamingPartitionReader->m_arrayEntries = (fb::StreamingPartitionArrayEntry *)endOfInstances;
  178.         if ( (char *)endOfArrayList != &startOfMetaData[StreamingPartitionReader->m_header.metaSize - 80] )
  179.         {
  180.           fb::Log::formattedLog(&stru_39E10C0, "%s", &secret);
  181.           if ( fb::Log::shouldBreak() )
  182.             __debugbreak();
  183.         }
  184.         if ( StreamingPartitionReader->m_endianSwapRequired )
  185.         {
  186.           fb::endianSwapInplace(
  187.             StreamingPartitionReader->m_importEntries,
  188.             StreamingPartitionReader->m_header.importCount);
  189.           fb::endianSwapInplace(
  190.             StreamingPartitionReader->m_fieldDescriptors,
  191.             StreamingPartitionReader->m_header.fieldDescriptorCount);
  192.           fb::endianSwapInplace(
  193.             StreamingPartitionReader->m_typeDescriptors,
  194.             StreamingPartitionReader->m_header.typeDescriptorCount);
  195.           fb::endianSwapInplace(
  196.             StreamingPartitionReader->m_instanceEntries,
  197.             StreamingPartitionReader->m_header.typeCount);
  198.           fb::endianSwapInplace(StreamingPartitionReader->m_arrayEntries, StreamingPartitionReader->m_header.arrayCount);
  199.         }
  200.         fb::StreamingPartitionReader::resolveImports(StreamingPartitionReader);
  201.         StreamingPartitionReader->m_currentState = 5;
  202.         continue;
  203.       case 5:
  204.         fb::StreamingPartitionReader::handleLayout(StreamingPartitionReader);
  205.         StreamingPartitionReader->m_currentState = 3;
  206.         continue;
  207.       case 3:
  208.         isMetaDataLeft = StreamingPartitionReader->m_payloadOutstanding < bytesToEOF;
  209.         payLoadLeft = (int)&StreamingPartitionReader->m_payloadOutstanding;
  210.         pPayLoadLeft = &StreamingPartitionReader->m_payloadOutstanding;
  211.         if ( !isMetaDataLeft )
  212.           pPayLoadLeft = &byteCount;
  213.         realPayLoadLeft = *pPayLoadLeft;
  214.         if ( complete_3 )
  215.         {
  216.           payLoadPos = cursor;
  217.         }
  218.         else
  219.         {
  220.           memcpy(
  221.             &StreamingPartitionReader->m_payloadBuffer[StreamingPartitionReader->m_payloadInputCursor],
  222.             cursor,
  223.             realPayLoadLeft);
  224.           *(_DWORD *)payLoadLeft -= realPayLoadLeft;
  225.           v36 = *(_DWORD *)payLoadLeft;
  226.           StreamingPartitionReader->m_payloadInputCursor += realPayLoadLeft;
  227.           if ( v36 )
  228.             goto LABEL_46;
  229.           payLoadPos = StreamingPartitionReader->m_payloadBuffer;
  230.         }
  231.         StreamingPartitionReader->m_payload = payLoadPos;
  232.         StreamingPartitionReader->m_currentState = 4;
  233. LABEL_46:
  234.         cursor += realPayLoadLeft;
  235.         break;
  236.       case 4:
  237.         pPayload = StreamingPartitionReader->m_payload;
  238.         stringTableSize = StreamingPartitionReader->m_header.stringTableSize;
  239.         StreamingPartitionReader->m_sourceStringBlock = pPayload;
  240.         StreamingPartitionReader->m_sourceInstanceBlock = &pPayload[stringTableSize];
  241.         StreamingPartitionReader->m_currentState = 6;
  242.         return;
  243.       case 6:
  244.         fb::StreamingPartitionReader::handleFixup(StreamingPartitionReader);
  245.         StreamingPartitionReader->m_currentState = 7;
  246.         return;
  247.       case 7:
  248.         return;
  249.       default:
  250.         continue;
  251.     }
  252.   }
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement