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

« back to all changes in this revision

Viewing changes to libclamav/mew.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
387
386
                var28 = cli_readint32 (source);
388
387
                source += 4;
389
388
                temp = cli_readint32 (source) - vma;
390
 
                var18 = (uint8_t *)(orgsource + temp);
 
389
                var18 = orgsource + temp;
391
390
                if (special) pushed_esi = orgsource + temp;
392
391
                source += 4;
393
392
                temp = cli_readint32 (source);
563
562
                                break;
564
563
                        } else {
565
564
                                var0C += 2;
566
 
                                new_ecx = (char *)var18;
 
565
                                new_ecx = var18;
567
566
                                new_edx = new_eax = var08;
568
567
                                new_eax -= loc_edi;
569
568
                                if ( ((var0C < var28 - new_edx) &&
694
693
        if (!CLI_ISCONTAINED(bb, bl, old_ecx, 4) || !CLI_ISCONTAINED(bb, bl, p->p0, 4))
695
694
        {
696
695
                if (!CLI_ISCONTAINED(bb, bl, old_ecx, 4))
697
 
                        cli_dbgmsg("contain error! %p %08x ecx: %p [%p]\n", bb, bl, old_ecx,bb+bl);
 
696
                        cli_dbgmsg("contain error! %08x %08x ecx: %08x [%08x]\n", bb, bl, old_ecx,bb+bl);
698
697
                else
699
 
                        cli_dbgmsg("contain error! %p %08x p0: %p [%p]\n", bb, bl, p->p0,bb+bl);
 
698
                        cli_dbgmsg("contain error! %08x %08x p0: %08x [%08x]\n", bb, bl, p->p0,bb+bl);
700
699
                return 0xffffffff;
701
700
        }
702
701
        ret = cli_readint32(old_ecx);
731
730
 */
732
731
uint32_t lzma_upack_esi_50(struct lzmastate *p, uint32_t old_eax, uint32_t old_ecx, char **old_edx, char *old_ebp, uint32_t *retval, char *bs, uint32_t bl)
733
732
{
734
 
        uint32_t loc_eax = old_eax, ret;
 
733
        uint32_t loc_eax = old_eax, original = old_eax, ret;
735
734
 
736
735
        do {
737
736
                *old_edx = old_ebp + (loc_eax<<2);
741
740
                loc_eax += ret;
742
741
        } while (loc_eax < old_ecx);
743
742
 
 
743
/*      cli_dbgmsg("loc_eax: %08x - ecx: %08x = %08x || original: %08x\n", loc_eax, old_ecx, loc_eax - old_ecx, original); */
744
744
        *retval = loc_eax - old_ecx;
745
745
        return 0;
746
746
}
772
772
}
773
773
 
774
774
 
775
 
int unmew11(char *src, int off, int ssize, int dsize, uint32_t base, uint32_t vadd, int uselzma, int filedesc)
 
775
int unmew11(int sectnum, char *src, int off, int ssize, int dsize, uint32_t base, uint32_t vadd, int uselzma, char **endsrc, char **enddst, int filedesc)
776
776
{
777
777
        uint32_t entry_point, newedi, loc_ds=dsize, loc_ss=ssize;
778
 
        char *source = src + dsize + off;
 
778
        char *source = src + dsize + off; /*EC32(section_hdr[sectnum].VirtualSize) + off;*/
779
779
        char *lesi = source + 12, *ledi;
780
780
        char *f1, *f2;
781
781
        int i;
785
785
        entry_point  = cli_readint32(source + 4);
786
786
        newedi = cli_readint32(source + 8);
787
787
        ledi = src + (newedi - vma);
788
 
        loc_ds = size_sum - (newedi - vma);
789
788
 
790
789
        i = 0;
791
 
        loc_ss -= 12;
792
 
        loc_ss -= off;
 
790
        ssize -= 12;
793
791
        while (1)
794
792
        {
795
 
                cli_dbgmsg("MEW unpacking section %d (%p->%p)\n", i, lesi, ledi);
796
 
                if (!CLI_ISCONTAINED(src, size_sum, lesi, loc_ss) || !CLI_ISCONTAINED(src, size_sum, ledi, loc_ds))
 
793
                cli_dbgmsg("MEW unpacking section %d (%08x->%08x)\n", i, lesi, ledi);
 
794
                if (!CLI_ISCONTAINED(src, size_sum, lesi, 4) || !CLI_ISCONTAINED(src, size_sum, ledi, 4))
797
795
                {
798
796
                        cli_dbgmsg("Possibly programmer error or hand-crafted PE file, report to clamav team\n");
799
797
                        return -1;
813
811
 
814
812
                /* XXX */
815
813
                loc_ss -= (f1+4-lesi);
 
814
                loc_ds -= (f2-ledi);
 
815
                ledi = src + (cli_readint32(f1) - vma);
816
816
                lesi = f1+4;
817
817
 
818
 
                ledi = src + (cli_readint32(f1) - vma);
819
 
                loc_ds = size_sum - (cli_readint32(f1) - vma);
820
 
 
821
818
                if (!uselzma)
822
819
                {
823
820
                        uint32_t val = PESALIGN(f2 - src, 0x1000);