Advertisement
xerpi

PSVita UDCD SceUdcdDriver check

Oct 20th, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.59 KB | None | 0 0
  1. /* SceUdcd module base: 0x01E10000, LOAD:01E142B4 udcd_check_driver */
  2. int __cdecl udcd_check_driver(const SceUdcdDriver *driver)
  3. {
  4.         SceUdcdDeviceDescriptor *device_descriptor; // r6@1
  5.         SceUdcdConfiguration *configuration; // r5@2
  6.         unsigned int bMaxPacketSize0; // r3@3
  7.         SceUdcdConfigDescriptor *config_descriptors; // r3@7
  8.         SceUdcdInterfaceSettings *interface_settings; // r2@8
  9.         int bNumInterfaces; // r4@9
  10.         int cnt; // r3@11
  11.         SceUdcdEndpointDescriptor *endpoint_descriptors; // r3@15
  12.         SceUdcdEndpointDescriptor *endpoint_ptr; // r3@17
  13.         signed int wMaxPacketSize; // r1@18
  14.         int bmAttributes; // r2@18
  15.         int bLength; // t1@25
  16.         SceUdcdDeviceDescriptor *device_descriptor_hi; // r3@26
  17.         SceUdcdConfiguration *configuration_hi; // r4@27
  18.         int result; // r0@29
  19.         SceUdcdConfigDescriptor *config_descriptors_hi; // r3@31
  20.         SceUdcdInterfaceSettings *interface_settings_hi; // r2@32
  21.         int bNumInterfaces_hi; // r0@33
  22.         int cnt_hi; // r3@35
  23.         SceUdcdEndpointDescriptor *endpoint_descriptors_hi; // r3@39
  24.         SceUdcdEndpointDescriptor *endpoint_ptr_hi; // r3@41
  25.         signed int wMaxPacketSize_hi; // r1@41
  26.         int bmAttributes_hi; // r2@41
  27.         int bLength_hi; // t1@45
  28.  
  29.         device_descriptor = driver->descriptor;
  30.         if ( !device_descriptor )
  31.                 return 0x80243306;
  32.         configuration = driver->configuration;
  33.         if ( !configuration )
  34.                 return 0x80243306;
  35.         bMaxPacketSize0 = device_descriptor->bMaxPacketSize0;
  36.         if ( bMaxPacketSize0 != 0x10 )
  37.         {
  38.                 if ( bMaxPacketSize0 <= 0x10 )
  39.                 {
  40.                         if ( bMaxPacketSize0 != 8 )
  41.                                 return 0x80243301;
  42.                 }
  43.                 else if ( bMaxPacketSize0 != 0x20 && bMaxPacketSize0 != 0x40 )
  44.                 {
  45.                         return 0x80243301;
  46.                 }
  47.         }
  48.         config_descriptors = configuration->configDescriptors;
  49.         if ( !configuration->configDescriptors )
  50.                 return 0x80243306;
  51.         interface_settings = configuration->settings;
  52.         if ( !interface_settings )
  53.                 return 0x80243306;
  54.         bNumInterfaces = config_descriptors->bNumInterfaces;
  55.         if ( config_descriptors->bNumInterfaces )
  56.         {
  57.                 if ( (signed int)interface_settings->numDescriptors > 2 )
  58.                         return 0x80243303;
  59.                 cnt = 0;
  60.                 while ( 1 )
  61.                 {
  62.                         ++cnt;
  63.                         ++interface_settings;
  64.                         if ( bNumInterfaces <= cnt )
  65.                                 break;
  66.                         if ( (signed int)interface_settings->numDescriptors > 2 )
  67.                                 return 0x80243303;
  68.                 }
  69.         }
  70.         if ( !configuration->interfaceDescriptors )
  71.                 return 0x80243306;
  72.         endpoint_descriptors = configuration->endpointDescriptors;
  73.         if ( endpoint_descriptors && endpoint_descriptors->bLength )
  74.         {
  75.                 endpoint_ptr = endpoint_descriptors + 1;
  76.                 do
  77.                 {
  78.                         wMaxPacketSize = endpoint_ptr[-1u].wMaxPacketSize;
  79.                         bmAttributes = endpoint_ptr[-1u].bmAttributes & 3;
  80.                         if ( bmAttributes != 2 )
  81.                         {
  82.                                 if ( bmAttributes == 3 )
  83.                                 {
  84.                                         if ( wMaxPacketSize > 0x40 )
  85.                                                 return 0x80243305;
  86.                                         goto LABEL_25;
  87.                                 }
  88.                                 if ( bmAttributes == 1 )
  89.                                 {
  90.                                         if ( wMaxPacketSize >= 0x400 )
  91.                                                 return 0x80243305;
  92.                                         goto LABEL_25;
  93.                                 }
  94.                         }
  95.                         if ( wMaxPacketSize != 0x10 )
  96.                         {
  97.                                 if ( (unsigned int)wMaxPacketSize <= 0x10 )
  98.                                 {
  99.                                         if ( wMaxPacketSize != 8 )
  100.                                                 return 0x80243305;
  101.                                 }
  102.                                 else if ( wMaxPacketSize != 0x20 && wMaxPacketSize != 0x40 )
  103.                                 {
  104.                                         return 0x80243305;
  105.                                 }
  106.                         }
  107. LABEL_25:
  108.                         bLength = endpoint_ptr->bLength;
  109.                         ++endpoint_ptr;
  110.                 }
  111.                 while ( bLength );
  112.         }
  113.         device_descriptor_hi = driver->descriptor_hi;
  114.         if ( !device_descriptor_hi )
  115.         {
  116.                 if ( driver->configuration_hi )
  117.                         result = 0x80243306;
  118.                 else
  119.                         result = 0;
  120.                 return result;
  121.         }
  122.         configuration_hi = driver->configuration_hi;
  123.         if ( !configuration_hi )
  124.                 return 0x80243306;
  125.         if ( (unsigned int)device_descriptor->bcdUSB < 0x200 )
  126.                 return 0;
  127.         if ( device_descriptor_hi->bMaxPacketSize0 != 0x40 )
  128.                 return 0x80243301;
  129.         config_descriptors_hi = configuration_hi->configDescriptors;
  130.         if ( !configuration_hi->configDescriptors )
  131.                 return 0x80243306;
  132.         interface_settings_hi = configuration_hi->settings;
  133.         if ( !interface_settings_hi )
  134.                 return 0x80243306;
  135.         bNumInterfaces_hi = config_descriptors_hi->bNumInterfaces;
  136.         if ( config_descriptors_hi->bNumInterfaces )
  137.         {
  138.                 if ( (signed int)interface_settings_hi->numDescriptors <= 2 )
  139.                 {
  140.                         cnt_hi = 0;
  141.                         while ( 1 )
  142.                         {
  143.                                 ++cnt_hi;
  144.                                 ++interface_settings_hi;
  145.                                 if ( cnt_hi >= bNumInterfaces_hi )
  146.                                         break;
  147.                                 if ( (signed int)interface_settings_hi->numDescriptors > 2 )
  148.                                         return 0x80243303;
  149.                         }
  150.                         goto LABEL_38;
  151.                 }
  152.                 return 0x80243303;
  153.         }
  154. LABEL_38:
  155.         if ( !configuration_hi->interfaceDescriptors )
  156.                 return 0x80243306;
  157.         endpoint_descriptors_hi = configuration_hi->endpointDescriptors;
  158.         result = (int)endpoint_descriptors_hi;
  159.         if ( endpoint_descriptors_hi )
  160.         {
  161.                 result = endpoint_descriptors_hi->bLength;
  162.                 if ( endpoint_descriptors_hi->bLength )
  163.                 {
  164.                         endpoint_ptr_hi = endpoint_descriptors_hi + 1;
  165.                         wMaxPacketSize_hi = endpoint_ptr_hi[-1u].wMaxPacketSize;
  166.                         bmAttributes_hi = endpoint_ptr_hi[-1u].bmAttributes & 3;
  167.                         if ( bmAttributes_hi == 2 )
  168.                                 goto LABEL_47;
  169. LABEL_42:
  170.                         if ( bmAttributes_hi != 3 && bmAttributes_hi != 1 )
  171.                         {
  172.                                 if ( wMaxPacketSize_hi == 0x40 )
  173.                                         goto LABEL_45;
  174.                                 return 0x80243305;
  175.                         }
  176.                         if ( wMaxPacketSize_hi > 0x400 )
  177.                                 return 0x80243305;
  178. LABEL_45:
  179.                         while ( 1 )
  180.                         {
  181.                                 bLength_hi = endpoint_ptr_hi->bLength;
  182.                                 ++endpoint_ptr_hi;
  183.                                 result = bLength_hi;
  184.                                 if ( !bLength_hi )
  185.                                         break;
  186.                                 wMaxPacketSize_hi = endpoint_ptr_hi[-1u].wMaxPacketSize;
  187.                                 bmAttributes_hi = endpoint_ptr_hi[-1u].bmAttributes & 3;
  188.                                 if ( bmAttributes_hi != 2 )
  189.                                         goto LABEL_42;
  190. LABEL_47:
  191.                                 if ( wMaxPacketSize_hi != 0x200 )
  192.                                         return 0x80243305;
  193.                         }
  194.                 }
  195.         }
  196.         return result;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement