Guest User

Untitled

a guest
Jul 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.27 KB | None | 0 0
  1. signed int __usercall sub_8057D00<eax>(int a1<eax>, void *a2<edx>)
  2. {
  3.   signed int result; // eax@1
  4.   __off_t v3; // eax@1
  5.   char v4; // zf@1
  6.   int v5; // eax@4
  7.   int v6; // esi@4
  8.   int v7; // eax@6
  9.   int v8; // edx@6
  10.   void *v9; // edx@7
  11.   char v10; // zf@8
  12.   __off_t v11; // eax@16
  13.   void *v12; // edi@19
  14.   __off_t v13; // eax@19
  15.   int v14; // eax@22
  16.   int v15; // edx@22
  17.   void *v16; // edx@23
  18.   __off_t v17; // ecx@24
  19.   int v18; // eax@26
  20.   const char *v19; // eax@27
  21.   ssize_t v20; // eax@30
  22.   ssize_t v21; // eax@32
  23.   char v22; // zf@33
  24.   size_t v23; // ecx@33
  25.   void *v24; // esi@33
  26.   int v25; // eax@41
  27.   int v26; // eax@43
  28.   int v27; // edx@43
  29.   void *v28; // eax@43
  30.   int v29; // ecx@43
  31.   int v30; // eax@44
  32.   int v31; // edx@44
  33.   void *v32; // eax@44
  34.   int v33; // ecx@44
  35.   int *v34; // eax@47
  36.   int *v35; // edi@47
  37.   char v36; // [sp-28h] [bp-88h]@14
  38.   int v37; // [sp-24h] [bp-84h]@43
  39.   __off_t v38; // [sp-20h] [bp-80h]@4
  40.   int v39; // [sp-1Ch] [bp-7Ch]@17
  41.   char *v40; // [sp-18h] [bp-78h]@17
  42.   char v41; // [sp-5h] [bp-65h]@19
  43.   void *buf; // [sp+0h] [bp-60h]@1
  44.   size_t v43; // [sp+4h] [bp-5Ch]@2
  45.   char *format; // [sp+8h] [bp-58h]@13
  46.   char *v45; // [sp+Ch] [bp-54h]@14
  47.   __off_t v46; // [sp+10h] [bp-50h]@4
  48.   __off_t v47; // [sp+14h] [bp-4Ch]@4
  49.   int v48; // [sp+1Ch] [bp-44h]@1
  50.   size_t nbytes; // [sp+20h] [bp-40h]@2
  51.   int v50; // [sp+24h] [bp-3Ch]@13
  52.   int *v51; // [sp+28h] [bp-38h]@13
  53.   int v52; // [sp+2Ch] [bp-34h]@1
  54.   int fd; // [sp+30h] [bp-30h]@1
  55.   __off_t offset; // [sp+34h] [bp-2Ch]@1
  56.   __off_t v55; // [sp+38h] [bp-28h]@13
  57.   size_t v56; // [sp+3Ch] [bp-24h]@13
  58.   __off_t v57; // [sp+40h] [bp-20h]@4
  59.   __off_t v58; // [sp+44h] [bp-1Ch]@4
  60.  
  61.   v52 = a1;
  62.   buf = a2;
  63.   v48 = *(_DWORD *)a1;
  64.   fd = *(_DWORD *)(a1 + 12);
  65.   v3 = lseek(fd, 0, 1);
  66.   offset = v3;
  67.   v4 = v3 == -1;
  68.   result = 1;
  69.   if ( v4 )
  70.     return result;
  71.   nbytes = *(_DWORD *)(v48 + 8);
  72.   v43 = (nbytes + 30) & 0xFFFFFFF0;
  73.   while ( 2 )
  74.   {
  75.     if ( (signed int)(nbytes + offset) > *(_DWORD *)(v48 + 4) )
  76.     {
  77. LABEL_10:
  78.       *__errno_location() = 28;
  79.       return -1;
  80.     }
  81.     while ( 1 )
  82.     {
  83.       v46 = offset;
  84.       v57 = offset;
  85.       v47 = offset >> 31;
  86.       v58 = offset >> 31;
  87.       v38 = (__off_t)&v57;
  88.       v5 = ioctl(fd, 0x40084D0Bu, &v57);
  89.       v6 = v5;
  90.       if ( !v5 )
  91.         break;
  92.       if ( v5 == -1 && *__errno_location() == 95 )
  93.         break;
  94.       v7 = *(_DWORD *)(v52 + 24);
  95.       v8 = *(_DWORD *)(v52 + 20);
  96.       if ( v7 >= v8 )
  97.       {
  98.         v30 = 2 * v8 + 1;
  99.         v31 = v52;
  100.         *(_DWORD *)(v52 + 20) = v30;
  101.         v37 = 4 * v30;
  102.         *(_DWORD *)&v36 = *(_DWORD *)(v31 + 16);
  103.         v32 = realloc(*(void **)&v36, 4 * v30);
  104.         v33 = v52;
  105.         v9 = v32;
  106.         *(_DWORD *)(v52 + 16) = v32;
  107.         v7 = *(_DWORD *)(v33 + 24);
  108.       }
  109.       else
  110.       {
  111.         v9 = *(void **)(v52 + 16);
  112.       }
  113.       *((_DWORD *)v9 + v7) = offset;
  114.       v10 = *(_DWORD *)(v52 + 28) == 1;
  115.       *(_DWORD *)(v52 + 24) = v7 + 1;
  116.       if ( v10 )
  117.       {
  118.         v34 = __errno_location();
  119.         v35 = v34;
  120.         v40 = (char *)*v34;
  121.         v39 = v6;
  122.         v38 = offset;
  123.         fprintf(stderr, "mtd: not writing bad block at 0x%08lx (ret %d errno %d)\n", offset, v6, v40);
  124.         *v35 = 5;
  125.         return -1;
  126.       }
  127.       v38 = offset;
  128.       fprintf(stderr, "mtd: not writing bad block at 0x%08lx\n", offset);
  129.       offset += *(_DWORD *)(v48 + 8);
  130.       if ( (signed int)(nbytes + offset) > *(_DWORD *)(v48 + 4) )
  131.         goto LABEL_10;
  132.     }
  133.     v55 = offset;
  134.     v56 = nbytes;
  135.     v50 = 0;
  136.     v51 = (int *)&v55;
  137.     format = "mtd: re-read error at 0x%08lx (%s)\n";
  138.     do
  139.     {
  140.       v45 = &v36;
  141.       v38 = (__off_t)v51;
  142.       if ( ioctl(fd, 0x40084D06u, v51) < 0 )
  143.       {
  144.         v18 = *__errno_location();
  145.         if ( v18 != 95 )
  146.         {
  147.           v39 = (int)strerror(v18);
  148.           v38 = offset;
  149.           v19 = "mtd: unlock failure at 0x%08lx (%s)\n";
  150. LABEL_28:
  151.           fprintf(stderr, v19, v38, v39, v40);
  152.           goto LABEL_21;
  153.         }
  154.       }
  155.       v38 = (__off_t)v51;
  156.       if ( ioctl(fd, 0x40084D02u, v51) >= 0 )
  157.       {
  158.         v11 = lseek(fd, offset, 0);
  159.         if ( v11 != offset || (v20 = write(fd, buf, nbytes), v20 != nbytes) )
  160.         {
  161.           *(_DWORD *)&v36 = *__errno_location();
  162.           v40 = strerror(*(int *)&v36);
  163.           v39 = nbytes;
  164.           v38 = offset;
  165.           fprintf(stderr, "mtd: write error at 0x%08lx size=%08x (%s)\n", offset, nbytes, v40);
  166.         }
  167.         v38 = (__off_t)v51;
  168.         if ( ioctl(fd, 0x40084D05u, v51) < 0 )
  169.         {
  170.           v25 = *__errno_location();
  171.           if ( v25 != 95 )
  172.           {
  173.             v39 = (int)strerror(v25);
  174.             v38 = offset;
  175.             fprintf(stderr, "mtd: lock failure at 0x%08lx (%s)\n", offset, v39, v40);
  176.           }
  177.         }
  178.         v13 = lseek(fd, offset, 0);
  179.         v12 = (void *)((unsigned int)&v41 & 0xFFFFFFF0);
  180.         if ( v13 != offset || (v21 = read(fd, v12, nbytes), v21 != nbytes) )
  181.         {
  182.           *(_DWORD *)&v36 = *__errno_location();
  183.           v39 = (int)strerror(*(int *)&v36);
  184.           v38 = offset;
  185.           fprintf(stderr, format, offset, v39, v40);
  186.           goto LABEL_21;
  187.         }
  188.         v23 = nbytes;
  189.         v24 = buf;
  190.         v22 = 1;
  191.         do
  192.         {
  193.           if ( !v23 )
  194.             break;
  195.           v22 = *(_BYTE *)v24 == *(_BYTE *)v12;
  196.           v24 = (char *)v24 + 1;
  197.           v12 = (char *)v12 + 1;
  198.           --v23;
  199.         }
  200.         while ( v22 );
  201.         if ( v22 )
  202.         {
  203.           if ( v50 == 1 )
  204.           {
  205.             v38 = 1;
  206.             fprintf(stderr, "mtd: wrote block after %d retries\n", 1);
  207.           }
  208.           v39 = v47;
  209.           v38 = v46;
  210.           fprintf(stderr, "mtd: successfully wrote block at %llx\n", v46, v47, v40);
  211.           return 0;
  212.         }
  213.         *(_DWORD *)&v36 = *__errno_location();
  214.         v39 = (int)strerror(*(int *)&v36);
  215.         v38 = offset;
  216.         v19 = "mtd: verification error at 0x%08lx (%s)\n";
  217.         goto LABEL_28;
  218.       }
  219.       *(_DWORD *)&v36 = *__errno_location();
  220.       v39 = (int)strerror(*(int *)&v36);
  221.       v38 = offset;
  222.       fprintf(stderr, "mtd: erase failure at 0x%08lx (%s)\n", offset, v39, v40);
  223. LABEL_21:
  224.       ++v50;
  225.     }
  226.     while ( v50 != 2 );
  227.     v14 = *(_DWORD *)(v52 + 24);
  228.     v15 = *(_DWORD *)(v52 + 20);
  229.     if ( v14 >= v15 )
  230.     {
  231.       v26 = 2 * v15 + 1;
  232.       v27 = v52;
  233.       *(_DWORD *)(v52 + 20) = v26;
  234.       v37 = 4 * v26;
  235.       *(_DWORD *)&v36 = *(_DWORD *)(v27 + 16);
  236.       v28 = realloc(*(void **)&v36, 4 * v26);
  237.       v29 = v52;
  238.       v16 = v28;
  239.       *(_DWORD *)(v52 + 16) = v28;
  240.       v14 = *(_DWORD *)(v29 + 24);
  241.     }
  242.     else
  243.     {
  244.       v16 = *(void **)(v52 + 16);
  245.     }
  246.     v17 = offset;
  247.     *((_DWORD *)v16 + v14) = offset;
  248.     *(_DWORD *)(v52 + 24) = v14 + 1;
  249.     v38 = v17;
  250.     fprintf(stderr, "mtd: skipping write block at 0x%08lx\n", v17);
  251.     v38 = (__off_t)v51;
  252.     ioctl(fd, 0x40084D06u, v51);
  253.     v38 = (__off_t)v51;
  254.     ioctl(fd, 0x40084D02u, v51);
  255.     v38 = (__off_t)v51;
  256.     ioctl(fd, 0x40084D05u, v51);
  257.     if ( *(_DWORD *)(v52 + 28) != 1 )
  258.     {
  259.       offset += *(_DWORD *)(v48 + 8);
  260.       continue;
  261.     }
  262.     break;
  263.   }
  264.   *__errno_location() = 5;
  265.   return -1;
  266. }
Add Comment
Please, Sign In to add comment