Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- signed int __usercall sub_8057D00<eax>(int a1<eax>, void *a2<edx>)
- {
- signed int result; // eax@1
- __off_t v3; // eax@1
- char v4; // zf@1
- int v5; // eax@4
- int v6; // esi@4
- int v7; // eax@6
- int v8; // edx@6
- void *v9; // edx@7
- char v10; // zf@8
- __off_t v11; // eax@16
- void *v12; // edi@19
- __off_t v13; // eax@19
- int v14; // eax@22
- int v15; // edx@22
- void *v16; // edx@23
- __off_t v17; // ecx@24
- int v18; // eax@26
- const char *v19; // eax@27
- ssize_t v20; // eax@30
- ssize_t v21; // eax@32
- char v22; // zf@33
- size_t v23; // ecx@33
- void *v24; // esi@33
- int v25; // eax@41
- int v26; // eax@43
- int v27; // edx@43
- void *v28; // eax@43
- int v29; // ecx@43
- int v30; // eax@44
- int v31; // edx@44
- void *v32; // eax@44
- int v33; // ecx@44
- int *v34; // eax@47
- int *v35; // edi@47
- char v36; // [sp-28h] [bp-88h]@14
- int v37; // [sp-24h] [bp-84h]@43
- __off_t v38; // [sp-20h] [bp-80h]@4
- int v39; // [sp-1Ch] [bp-7Ch]@17
- char *v40; // [sp-18h] [bp-78h]@17
- char v41; // [sp-5h] [bp-65h]@19
- void *buf; // [sp+0h] [bp-60h]@1
- size_t v43; // [sp+4h] [bp-5Ch]@2
- char *format; // [sp+8h] [bp-58h]@13
- char *v45; // [sp+Ch] [bp-54h]@14
- __off_t v46; // [sp+10h] [bp-50h]@4
- __off_t v47; // [sp+14h] [bp-4Ch]@4
- int v48; // [sp+1Ch] [bp-44h]@1
- size_t nbytes; // [sp+20h] [bp-40h]@2
- int v50; // [sp+24h] [bp-3Ch]@13
- int *v51; // [sp+28h] [bp-38h]@13
- int v52; // [sp+2Ch] [bp-34h]@1
- int fd; // [sp+30h] [bp-30h]@1
- __off_t offset; // [sp+34h] [bp-2Ch]@1
- __off_t v55; // [sp+38h] [bp-28h]@13
- size_t v56; // [sp+3Ch] [bp-24h]@13
- __off_t v57; // [sp+40h] [bp-20h]@4
- __off_t v58; // [sp+44h] [bp-1Ch]@4
- v52 = a1;
- buf = a2;
- v48 = *(_DWORD *)a1;
- fd = *(_DWORD *)(a1 + 12);
- v3 = lseek(fd, 0, 1);
- offset = v3;
- v4 = v3 == -1;
- result = 1;
- if ( v4 )
- return result;
- nbytes = *(_DWORD *)(v48 + 8);
- v43 = (nbytes + 30) & 0xFFFFFFF0;
- while ( 2 )
- {
- if ( (signed int)(nbytes + offset) > *(_DWORD *)(v48 + 4) )
- {
- LABEL_10:
- *__errno_location() = 28;
- return -1;
- }
- while ( 1 )
- {
- v46 = offset;
- v57 = offset;
- v47 = offset >> 31;
- v58 = offset >> 31;
- v38 = (__off_t)&v57;
- v5 = ioctl(fd, 0x40084D0Bu, &v57);
- v6 = v5;
- if ( !v5 )
- break;
- if ( v5 == -1 && *__errno_location() == 95 )
- break;
- v7 = *(_DWORD *)(v52 + 24);
- v8 = *(_DWORD *)(v52 + 20);
- if ( v7 >= v8 )
- {
- v30 = 2 * v8 + 1;
- v31 = v52;
- *(_DWORD *)(v52 + 20) = v30;
- v37 = 4 * v30;
- *(_DWORD *)&v36 = *(_DWORD *)(v31 + 16);
- v32 = realloc(*(void **)&v36, 4 * v30);
- v33 = v52;
- v9 = v32;
- *(_DWORD *)(v52 + 16) = v32;
- v7 = *(_DWORD *)(v33 + 24);
- }
- else
- {
- v9 = *(void **)(v52 + 16);
- }
- *((_DWORD *)v9 + v7) = offset;
- v10 = *(_DWORD *)(v52 + 28) == 1;
- *(_DWORD *)(v52 + 24) = v7 + 1;
- if ( v10 )
- {
- v34 = __errno_location();
- v35 = v34;
- v40 = (char *)*v34;
- v39 = v6;
- v38 = offset;
- fprintf(stderr, "mtd: not writing bad block at 0x%08lx (ret %d errno %d)\n", offset, v6, v40);
- *v35 = 5;
- return -1;
- }
- v38 = offset;
- fprintf(stderr, "mtd: not writing bad block at 0x%08lx\n", offset);
- offset += *(_DWORD *)(v48 + 8);
- if ( (signed int)(nbytes + offset) > *(_DWORD *)(v48 + 4) )
- goto LABEL_10;
- }
- v55 = offset;
- v56 = nbytes;
- v50 = 0;
- v51 = (int *)&v55;
- format = "mtd: re-read error at 0x%08lx (%s)\n";
- do
- {
- v45 = &v36;
- v38 = (__off_t)v51;
- if ( ioctl(fd, 0x40084D06u, v51) < 0 )
- {
- v18 = *__errno_location();
- if ( v18 != 95 )
- {
- v39 = (int)strerror(v18);
- v38 = offset;
- v19 = "mtd: unlock failure at 0x%08lx (%s)\n";
- LABEL_28:
- fprintf(stderr, v19, v38, v39, v40);
- goto LABEL_21;
- }
- }
- v38 = (__off_t)v51;
- if ( ioctl(fd, 0x40084D02u, v51) >= 0 )
- {
- v11 = lseek(fd, offset, 0);
- if ( v11 != offset || (v20 = write(fd, buf, nbytes), v20 != nbytes) )
- {
- *(_DWORD *)&v36 = *__errno_location();
- v40 = strerror(*(int *)&v36);
- v39 = nbytes;
- v38 = offset;
- fprintf(stderr, "mtd: write error at 0x%08lx size=%08x (%s)\n", offset, nbytes, v40);
- }
- v38 = (__off_t)v51;
- if ( ioctl(fd, 0x40084D05u, v51) < 0 )
- {
- v25 = *__errno_location();
- if ( v25 != 95 )
- {
- v39 = (int)strerror(v25);
- v38 = offset;
- fprintf(stderr, "mtd: lock failure at 0x%08lx (%s)\n", offset, v39, v40);
- }
- }
- v13 = lseek(fd, offset, 0);
- v12 = (void *)((unsigned int)&v41 & 0xFFFFFFF0);
- if ( v13 != offset || (v21 = read(fd, v12, nbytes), v21 != nbytes) )
- {
- *(_DWORD *)&v36 = *__errno_location();
- v39 = (int)strerror(*(int *)&v36);
- v38 = offset;
- fprintf(stderr, format, offset, v39, v40);
- goto LABEL_21;
- }
- v23 = nbytes;
- v24 = buf;
- v22 = 1;
- do
- {
- if ( !v23 )
- break;
- v22 = *(_BYTE *)v24 == *(_BYTE *)v12;
- v24 = (char *)v24 + 1;
- v12 = (char *)v12 + 1;
- --v23;
- }
- while ( v22 );
- if ( v22 )
- {
- if ( v50 == 1 )
- {
- v38 = 1;
- fprintf(stderr, "mtd: wrote block after %d retries\n", 1);
- }
- v39 = v47;
- v38 = v46;
- fprintf(stderr, "mtd: successfully wrote block at %llx\n", v46, v47, v40);
- return 0;
- }
- *(_DWORD *)&v36 = *__errno_location();
- v39 = (int)strerror(*(int *)&v36);
- v38 = offset;
- v19 = "mtd: verification error at 0x%08lx (%s)\n";
- goto LABEL_28;
- }
- *(_DWORD *)&v36 = *__errno_location();
- v39 = (int)strerror(*(int *)&v36);
- v38 = offset;
- fprintf(stderr, "mtd: erase failure at 0x%08lx (%s)\n", offset, v39, v40);
- LABEL_21:
- ++v50;
- }
- while ( v50 != 2 );
- v14 = *(_DWORD *)(v52 + 24);
- v15 = *(_DWORD *)(v52 + 20);
- if ( v14 >= v15 )
- {
- v26 = 2 * v15 + 1;
- v27 = v52;
- *(_DWORD *)(v52 + 20) = v26;
- v37 = 4 * v26;
- *(_DWORD *)&v36 = *(_DWORD *)(v27 + 16);
- v28 = realloc(*(void **)&v36, 4 * v26);
- v29 = v52;
- v16 = v28;
- *(_DWORD *)(v52 + 16) = v28;
- v14 = *(_DWORD *)(v29 + 24);
- }
- else
- {
- v16 = *(void **)(v52 + 16);
- }
- v17 = offset;
- *((_DWORD *)v16 + v14) = offset;
- *(_DWORD *)(v52 + 24) = v14 + 1;
- v38 = v17;
- fprintf(stderr, "mtd: skipping write block at 0x%08lx\n", v17);
- v38 = (__off_t)v51;
- ioctl(fd, 0x40084D06u, v51);
- v38 = (__off_t)v51;
- ioctl(fd, 0x40084D02u, v51);
- v38 = (__off_t)v51;
- ioctl(fd, 0x40084D05u, v51);
- if ( *(_DWORD *)(v52 + 28) != 1 )
- {
- offset += *(_DWORD *)(v48 + 8);
- continue;
- }
- break;
- }
- *__errno_location() = 5;
- return -1;
- }
Add Comment
Please, Sign In to add comment