...
|
...
|
@@ -163,7 +163,7 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
163
|
163
|
{
|
164
|
164
|
if (!CLI_ISCONTAINED(dest, dsize, loc_esi+6, 10) || *(loc_esi+6) != '\xbe' || *(loc_esi+11) != '\xbf')
|
165
|
165
|
return -1;
|
166
|
|
- if (cli_readint32(loc_esi + 7) < base || cli_readint32(loc_esi+7) > vma)
|
|
166
|
+ if ((uint32_t)cli_readint32(loc_esi + 7) < base || (uint32_t)cli_readint32(loc_esi+7) > vma)
|
167
|
167
|
return -1;
|
168
|
168
|
loc_edi = dest + (cli_readint32(loc_esi + 12) - vma);
|
169
|
169
|
loc_esi = dest + (cli_readint32(loc_esi + 7) - base);
|
...
|
...
|
@@ -199,7 +199,7 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
199
|
199
|
for (j=0; j<4; j++, loc_edi+=4)
|
200
|
200
|
cli_writeint32(loc_edi, (1));
|
201
|
201
|
|
202
|
|
- for (j=0; j<count; j++, loc_edi+=4)
|
|
202
|
+ for (j=0; (unsigned int)j<count; j++, loc_edi+=4)
|
203
|
203
|
cli_writeint32(loc_edi, 0x400);
|
204
|
204
|
|
205
|
205
|
loc_edi = dest + cli_readint32(loc_esi + 0xc) - vma;
|
...
|
...
|
@@ -214,8 +214,8 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
214
|
214
|
save3 = cli_readint32(loc_esi + 0x40);
|
215
|
215
|
}
|
216
|
216
|
/* begin end */
|
217
|
|
- cli_dbgmsg("data initialized, before upack lzma call!\n");
|
218
|
|
- if ((ret = unupack399(dest, dsize, 0, loc_ebx, 0, loc_edi, end_edi, shlsize, paddr)) == -1)
|
|
217
|
+ cli_dbgmsg("Upack: data initialized, before upack lzma call!\n");
|
|
218
|
+ if ((ret = (uint32_t)unupack399(dest, dsize, 0, loc_ebx, 0, loc_edi, end_edi, shlsize, paddr)) == 0xffffffff)
|
219
|
219
|
return -1;
|
220
|
220
|
/* alternative begin */
|
221
|
221
|
} else {
|
...
|
...
|
@@ -272,12 +272,12 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
272
|
272
|
if (!CLI_ISCONTAINED(dest, dsize, loc_esi, 12))
|
273
|
273
|
return -1;
|
274
|
274
|
|
275
|
|
- cli_dbgmsg("%08x %08x %08x %08x\n", loc_esi, dest, cli_readint32(loc_esi), base);
|
|
275
|
+ cli_dbgmsg("Upack: %08x %08x %08x %08x\n", loc_esi, dest, cli_readint32(loc_esi), base);
|
276
|
276
|
loc_ebx_u = loc_esi - (dest + cli_readint32(loc_esi) - base);
|
277
|
|
- cli_dbgmsg("EBX: %08x\n", loc_ebx_u);
|
|
277
|
+ cli_dbgmsg("Upack: EBX: %08x\n", loc_ebx_u);
|
278
|
278
|
loc_esi += 4;
|
279
|
279
|
save2 = loc_edi = dest + cli_readint32(loc_esi) - base;
|
280
|
|
- cli_dbgmsg("DEST: %08x, %08x\n", cli_readint32(loc_esi), cli_readint32(loc_esi) - base);
|
|
280
|
+ cli_dbgmsg("Upack: DEST: %08x, %08x\n", cli_readint32(loc_esi), cli_readint32(loc_esi) - base);
|
281
|
281
|
loc_esi += 4;
|
282
|
282
|
/* 2vGiM: j is signed. Is that really what you want? Will it cause problems with the following checks?
|
283
|
283
|
* yes! this is wrong! how did you notice that?!
|
...
|
...
|
@@ -289,7 +289,7 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
289
|
289
|
return -1;
|
290
|
290
|
}
|
291
|
291
|
loc_esi += 4;
|
292
|
|
- cli_dbgmsg("ecx counter: %08x\n", j);
|
|
292
|
+ cli_dbgmsg("Upack: ecx counter: %08x\n", j);
|
293
|
293
|
|
294
|
294
|
if (!CLI_ISCONTAINED(dest, dsize, loc_esi, (j*4)) || !CLI_ISCONTAINED(dest, dsize, loc_edi, ((j+count)*4)))
|
295
|
295
|
return -1;
|
...
|
...
|
@@ -324,7 +324,7 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
324
|
324
|
/* checked above, (...save2, 8) */
|
325
|
325
|
save_edi = loc_edi = dest + ((uint32_t)cli_readint32(loc_esi) - base);
|
326
|
326
|
loc_esi +=4;
|
327
|
|
- cli_dbgmsg("before_fixing\n");
|
|
327
|
+ cli_dbgmsg("Upack: before_fixing\n");
|
328
|
328
|
/* fix values */
|
329
|
329
|
if (!CLI_ISCONTAINED(dest, dsize, loc_ebx-4, (12 + 4*4)) || !CLI_ISCONTAINED(dest, dsize, loc_esi+0x24, 4) || !CLI_ISCONTAINED(dest, dsize, loc_esi+0x40, 4))
|
330
|
330
|
return -1;
|
...
|
...
|
@@ -370,8 +370,8 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
370
|
370
|
end_edi = dest + cli_readint32(loc_esi-0x28) - base; /* read checked above */
|
371
|
371
|
loc_esi = save_edi;
|
372
|
372
|
}
|
373
|
|
- cli_dbgmsg("data initialized, before upack lzma call!\n");
|
374
|
|
- if ((ret = unupack399(dest, dsize, loc_ecx, loc_ebx, loc_ecx, loc_edi, end_edi, shlsize, paddr)) == -1)
|
|
373
|
+ cli_dbgmsg("Upack: data initialized, before upack lzma call!\n");
|
|
374
|
+ if ((ret = (uint32_t)unupack399(dest, dsize, loc_ecx, loc_ebx, loc_ecx, loc_edi, end_edi, shlsize, paddr)) == 0xffffffff)
|
375
|
375
|
return -1;
|
376
|
376
|
if (upack_version == UPACK_399)
|
377
|
377
|
save3 = cli_readint32(loc_esi + 0x40);
|
...
|
...
|
@@ -381,12 +381,17 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
381
|
381
|
|
382
|
382
|
/* let's fix calls */
|
383
|
383
|
loc_ecx = 0;
|
|
384
|
+ if (!CLI_ISCONTAINED(dest, dsize, alvalue, 1)) {
|
|
385
|
+ cli_dbgmsg("Upack: alvalue out of bounds\n");
|
|
386
|
+ return -1;
|
|
387
|
+ }
|
|
388
|
+
|
384
|
389
|
searchval = *alvalue&0xff;
|
385
|
390
|
cli_dbgmsg("Upack: loops: %08x search value: %02x\n", save3, searchval);
|
386
|
391
|
while(save3) {
|
387
|
392
|
if (!CLI_ISCONTAINED(dest, dsize, pushed_esi + loc_ecx, 1))
|
388
|
393
|
{
|
389
|
|
- cli_dbgmsg("callfixerr %08x %08x = %08x, %08x\n", dest, dsize, dest+dsize, pushed_esi+loc_ecx);
|
|
394
|
+ cli_dbgmsg("Upack: callfixerr %08x %08x = %08x, %08x\n", dest, dsize, dest+dsize, pushed_esi+loc_ecx);
|
390
|
395
|
return -1;
|
391
|
396
|
}
|
392
|
397
|
if (pushed_esi[loc_ecx] == '\xe8' || pushed_esi[loc_ecx] == '\xe9')
|
...
|
...
|
@@ -395,7 +400,7 @@ int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uin
|
395
|
395
|
loc_ecx++;
|
396
|
396
|
if (!CLI_ISCONTAINED(dest, dsize, adr, 4))
|
397
|
397
|
{
|
398
|
|
- cli_dbgmsg("callfixerr\n");
|
|
398
|
+ cli_dbgmsg("Upack: callfixerr\n");
|
399
|
399
|
return -1;
|
400
|
400
|
}
|
401
|
401
|
if ((cli_readint32(adr)&0xff) != searchval)
|
...
|
...
|
@@ -462,7 +467,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
462
|
462
|
eax_copy = loc_eax;
|
463
|
463
|
loc_edx = loc_ebx + 0xbc0;
|
464
|
464
|
state[5] = loc_ebp;
|
465
|
|
- if (lzma_upack_esi_54(&p, loc_eax, &loc_ecx, &loc_edx, &temp, bs, bl) == -1)
|
|
465
|
+ if (lzma_upack_esi_54(&p, loc_eax, &loc_ecx, &loc_edx, &temp, bs, bl) == 0xffffffff)
|
466
|
466
|
return -1;
|
467
|
467
|
loc_ecx = 3;
|
468
|
468
|
jakas_kopia = temp;
|
...
|
...
|
@@ -472,7 +477,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
472
|
472
|
loc_ecx = 0x40;
|
473
|
473
|
loc_eax <<= 6; /* ecx=0x40, mul cl */
|
474
|
474
|
loc_ebp8 = loc_ebx + ((loc_eax<<2) + 0x378);
|
475
|
|
- if (lzma_upack_esi_50(&p, 1, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == -1)
|
|
475
|
+ if (lzma_upack_esi_50(&p, 1, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == 0xffffffff)
|
476
|
476
|
return -1;
|
477
|
477
|
loc_ebp = loc_eax;
|
478
|
478
|
if ((loc_eax&0xff) >= 4)
|
...
|
...
|
@@ -524,7 +529,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
524
|
524
|
loc_eax <<= (loc_ecx&0xff);
|
525
|
525
|
loc_ebp8 = loc_edx;
|
526
|
526
|
temp_ebp = loc_ecx; loc_ecx = loc_eax; loc_eax = temp_ebp;
|
527
|
|
- if (lzma_upack_esi_50(&p, 1, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == -1)
|
|
527
|
+ if (lzma_upack_esi_50(&p, 1, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == 0xffffffff)
|
528
|
528
|
return -1;
|
529
|
529
|
/* cdq, loc_edx = (loc_eax&0x80000000)?0xffffffff:0; */
|
530
|
530
|
loc_ecx = temp_ebp;
|
...
|
...
|
@@ -586,7 +591,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
586
|
586
|
/* loc_48396a */
|
587
|
587
|
eax_copy = loc_eax;
|
588
|
588
|
loc_edx = loc_ebx + 0x778;
|
589
|
|
- if (lzma_upack_esi_54(&p, loc_eax, &loc_ecx, &loc_edx, &temp, bs, bl) == -1)
|
|
589
|
+ if (lzma_upack_esi_54(&p, loc_eax, &loc_ecx, &loc_edx, &temp, bs, bl) == 0xffffffff)
|
590
|
590
|
return -1;
|
591
|
591
|
loc_eax = loc_ecx;
|
592
|
592
|
loc_ecx = temp;
|
...
|
...
|
@@ -646,7 +651,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
646
|
646
|
{
|
647
|
647
|
loc_eax = (loc_eax&0xffff0000)|(loc_ah<<8)|loc_al;
|
648
|
648
|
/* loc_483918, loc_48391a */
|
649
|
|
- if (lzma_upack_esi_50(&p, loc_eax, 0x100, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == -1)
|
|
649
|
+ if (lzma_upack_esi_50(&p, loc_eax, 0x100, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == 0xffffffff)
|
650
|
650
|
return -1;
|
651
|
651
|
break;
|
652
|
652
|
}
|
...
|
...
|
@@ -656,7 +661,7 @@ int unupack399(char *bs, uint32_t bl, uint32_t init_eax, char *init_ebx, uint32_
|
656
|
656
|
} else {
|
657
|
657
|
/* loc_48391a */
|
658
|
658
|
loc_ecx = (loc_ecx&0xffff00ff)|0x100;
|
659
|
|
- if (lzma_upack_esi_50(&p, loc_eax, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == -1)
|
|
659
|
+ if (lzma_upack_esi_50(&p, loc_eax, loc_ecx, &loc_edx, loc_ebp8, &loc_eax, bs, bl) == 0xffffffff)
|
660
|
660
|
return -1;
|
661
|
661
|
}
|
662
|
662
|
/* loc_48391f */
|