~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/disasm.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  MA 02110-1301, USA.
19
19
 */
20
20
 
 
21
#if HAVE_CONFIG_H
 
22
#include "clamav-config.h"
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
#include <string.h>
 
27
#include <assert.h>
 
28
 
 
29
#include "others.h"
 
30
 
21
31
#include "disasmpriv.h"
22
32
#include "disasm.h"
23
33
 
1244
1254
#define GETSIZE(X) (x86ops[table][s->table_op].X!=SIZE_WD?x86ops[table][s->table_op].X:((s->opsize)?SIZE_WORD:SIZE_DWORD))
1245
1255
 
1246
1256
 
1247
 
static uint8_t *disasm_x86(uint8_t *command, unsigned int len, struct DISASMED *s) {
 
1257
static const uint8_t *disasm_x86(const uint8_t *command, unsigned int len, struct DISASMED *s) {
1248
1258
  unsigned int reversed=0, i;
1249
1259
  uint8_t b;
1250
1260
  unsigned int table = 0;
1535
1545
            GETBYTE(b);
1536
1546
            shiftme+=b<<(i*8);
1537
1547
          }
1538
 
          shiftme<<=((8-mod)*8);
1539
 
          s->args[reversed].arg.marg.disp=shiftme>>((8-mod)*8);
 
1548
          if(mod) {
 
1549
              shiftme<<=((8-mod)*8);
 
1550
              s->args[reversed].arg.marg.disp=shiftme>>((8-mod)*8);
 
1551
          } else s->args[reversed].arg.marg.disp=0;
1540
1552
        } else {
1541
1553
          if (mod==0 && rm==6) {
1542
1554
            s->args[reversed].arg.marg.r1=REG_INVALID;
1669
1681
  }
1670
1682
}
1671
1683
 
1672
 
 
1673
 
void disasmbuf(uint8_t *buff, unsigned int len, int fd) {
1674
 
  uint8_t *next = buff;
1675
 
  unsigned int counter=0;
 
1684
const uint8_t* cli_disasm_one(const uint8_t* buff, unsigned int len,
 
1685
                              struct DISASM_RESULT *w, int spam)
 
1686
{
1676
1687
  struct DISASMED s;
1677
 
  struct MARIO {
1678
 
    uint16_t real_op;
1679
 
    uint8_t opsize;
1680
 
    uint8_t adsize;
1681
 
    uint8_t segment;
1682
 
 
1683
 
    uint8_t arg[3][10];
1684
 
 
1685
 
    uint8_t extra[29];
1686
 
  } w;
1687
 
 
1688
 
  memset(&w.extra[0], 0, sizeof(w.extra));
1689
 
 
1690
 
  while(len && counter++<200) {
1691
 
    int i;
1692
 
    if(!(next = disasm_x86(next, len, &s))) {
1693
 
      /* TODO: invd opcode or buff over */
1694
 
      return;
1695
 
    }
1696
 
    if(cli_debug_flag) {
 
1688
  int i;
 
1689
 
 
1690
  memset(&w->extra[0], 0, sizeof(w->extra));
 
1691
  buff = disasm_x86(buff, len, &s);
 
1692
  if (!buff)
 
1693
      return NULL;
 
1694
  if (spam) {
1697
1695
      char hr[128];
1698
1696
      spam_x86(&s, hr);
1699
1697
      cli_dbgmsg("%s\n", hr);
1700
 
    }
1701
 
    
1702
 
    len -= next-buff;
1703
 
    buff=next;
1704
 
 
1705
 
    w.real_op = le16_to_host(s.real_op);
1706
 
    w.opsize = s.opsize;
1707
 
    w.adsize = s.adsize;
1708
 
    w.segment = s.segment;
1709
 
 
1710
 
    for (i=0; i<3; i++) {
1711
 
      w.arg[i][0] = s.args[i].access;
1712
 
      w.arg[i][1] = s.args[i].size;
 
1698
  }
 
1699
  w->real_op = le16_to_host(s.real_op);
 
1700
  w->opsize = s.opsize;
 
1701
  w->adsize = s.adsize;
 
1702
  w->segment = s.segment;
 
1703
 
 
1704
  for (i=0; i<3; i++) {
 
1705
      w->arg[i][0] = s.args[i].access;
 
1706
      w->arg[i][1] = s.args[i].size;
1713
1707
      switch(s.args[i].access) {
1714
1708
      case ACCESS_MEM:
1715
 
        w.arg[i][2]=s.args[i].arg.marg.r1;
1716
 
        w.arg[i][3]=s.args[i].arg.marg.r2;
1717
 
        w.arg[i][4]=s.args[i].arg.marg.scale;
1718
 
        w.arg[i][5]=0;
1719
 
        cli_writeint32(&w.arg[i][6], s.args[i].arg.marg.disp);
 
1709
        w->arg[i][2]=s.args[i].arg.marg.r1;
 
1710
        w->arg[i][3]=s.args[i].arg.marg.r2;
 
1711
        w->arg[i][4]=s.args[i].arg.marg.scale;
 
1712
        w->arg[i][5]=0;
 
1713
        cli_writeint32(&w->arg[i][6], s.args[i].arg.marg.disp);
1720
1714
        break;
1721
1715
      case ACCESS_REG:
1722
 
        w.arg[i][1] = s.args[i].reg;
 
1716
        w->arg[i][1] = s.args[i].reg;
1723
1717
      default:
1724
 
        cli_writeint32(&w.arg[i][2], s.args[i].arg.q);
1725
 
        cli_writeint32(&w.arg[i][6], s.args[i].arg.q>>32);
 
1718
        cli_writeint32(&w->arg[i][2], s.args[i].arg.q);
 
1719
        cli_writeint32(&w->arg[i][6], s.args[i].arg.q>>32);
1726
1720
      }
 
1721
  }
 
1722
  return buff;
 
1723
}
 
1724
 
 
1725
int disasmbuf(const uint8_t *buff, unsigned int len, int fd) {
 
1726
  const uint8_t *next = buff;
 
1727
  unsigned int counter=0;
 
1728
  int gotsome=0;
 
1729
  struct DISASM_RESULT w;
 
1730
  memset(&w.extra[0], 0, sizeof(w.extra));
 
1731
 
 
1732
  while(len && counter++<200) {
 
1733
    if(!(next = cli_disasm_one(next, len, &w, cli_debug_flag))) {
 
1734
      /* TODO: invd opcode or buff over */
 
1735
      return gotsome;
1727
1736
    }
 
1737
    
 
1738
    len -= next-buff;
 
1739
    buff=next;
 
1740
 
1728
1741
    cli_writen(fd, &w, sizeof(w));
 
1742
    gotsome = 1;
1729
1743
  }
 
1744
  return gotsome;
1730
1745
}
1731
1746