~ubuntu-branches/ubuntu/feisty/clamav/feisty

« back to all changes in this revision

Viewing changes to libclamav/upack.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-20 10:33:44 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20070220103344-zgcu2psnx9d98fpa
Tags: upstream-0.90
ImportĀ upstreamĀ versionĀ 0.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2007-2008 Sourcefire, Inc.
3
 
 *
4
 
 *  Authors: Michal 'GiM' Spadlinski
 
2
 *  Copyright (C) 2006 Michal 'GiM' Spadlinski http://gim.org.pl/
5
3
 *
6
4
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License version 2 as
8
 
 *  published by the Free Software Foundation.
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
9
8
 *
10
9
 *  This program is distributed in the hope that it will be useful,
11
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
17
 *  MA 02110-1301, USA.
19
18
 */
20
19
 
 
20
/*
 
21
 * upack.c
 
22
 *
 
23
 *
 
24
 */
 
25
 
21
26
#if HAVE_CONFIG_H
22
27
#include "clamav-config.h"
23
28
#endif
56
61
int unupack(int upack, char *dest, uint32_t dsize, char *buff, uint32_t vma, uint32_t ep, uint32_t base, uint32_t va, int file)
57
62
{
58
63
        int j, searchval;
59
 
        char *loc_esi, *loc_edi = NULL, *loc_ebx, *end_edi, *save_edi, *alvalue;
 
64
        char *loc_esi, *loc_edi, *loc_ebx, *end_edi, *save_edi, *rpeb, *alvalue;
60
65
        char *paddr, *pushed_esi, *save2;
61
66
        uint32_t save1, save3, loc_ecx, count, shlsize, original_ep, ret, loc_ebx_u;
62
67
        struct cli_exe_section section;
277
282
                        if (!CLI_ISCONTAINED(dest, dsize, loc_esi, 12))
278
283
                                return -1;
279
284
 
280
 
                        cli_dbgmsg("Upack: %p %p %08x %08x\n", loc_esi, dest, cli_readint32(loc_esi), base);
 
285
                        cli_dbgmsg("Upack: %08x %08x %08x %08x\n", loc_esi, dest, cli_readint32(loc_esi), base);
281
286
                        loc_ebx_u = loc_esi - (dest + cli_readint32(loc_esi) - base);
282
287
                        cli_dbgmsg("Upack: EBX: %08x\n", loc_ebx_u);
283
288
                        loc_esi += 4;
396
401
        while(save3) {
397
402
                if (!CLI_ISCONTAINED(dest, dsize, pushed_esi + loc_ecx, 1))
398
403
                {
399
 
                        cli_dbgmsg("Upack: callfixerr %p %08x = %p, %p\n", dest, dsize, dest+dsize, pushed_esi+loc_ecx);
 
404
                        cli_dbgmsg("Upack: callfixerr %08x %08x = %08x, %08x\n", dest, dsize, dest+dsize, pushed_esi+loc_ecx);
400
405
                        return -1;
401
406
                }
402
407
                if (pushed_esi[loc_ecx] == '\xe8' || pushed_esi[loc_ecx] == '\xe9')
440
445
        p.p1 = cli_readint32(init_ebx);
441
446
        p.p2 = cli_readint32(init_ebx + 4);
442
447
 
443
 
        cli_dbgmsg("\n\tp0: %p\n\tp1: %08x\n\tp2: %08x\n", p.p0, p.p1, p.p2);
444
 
        for (i = 0; i<6; i++) {
445
 
                state[i] = cli_readint32(loc_ebx + (i<<2));
 
448
        cli_dbgmsg("\n\tp0: %08x\n\tp1: %08x\n\tp2: %08x\n", p.p0, p.p1, p.p2);
 
449
        for (i = 0; i<6; i++)
 
450
                state[i] = cli_readint32(loc_ebx + (i<<2)),
446
451
                cli_dbgmsg("state[%d] = %08x\n", i, state[i]);
447
 
        }
448
452
        do {
449
453
                loc_eax = eax_copy;
450
454
                loc_edx = loc_ebx + (loc_eax<<2) + 0x58;
539
543
                                                return -1;
540
544
                                        /* cdq, loc_edx = (loc_eax&0x80000000)?0xffffffff:0; */
541
545
                                        loc_ecx = temp_ebp;
542
 
                                        temp_ebp = CLI_SRS((int32_t)loc_eax, 31); /* thx, desp */
 
546
                                        temp_ebp = (int32_t)loc_eax >> 31; /* thx, desp */
543
547
                                        /* loc_483a00 */
544
548
                                        do {
545
549
                                                temp_ebp += temp_ebp;