summaryrefslogtreecommitdiff
path: root/other/Kermit/lib/DevMemPatt.cpp
blob: 81fd6e942148ef2eadf0b209e2b750835ce846c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * DevMemPatt.cpp:
 * written by palmers / teso
 */
#include <DevMemPatt.hpp>


  DevMemPatt::DevMemPatt ()
  {
    rw = new rwKernel ();
  }


  DevMemPatt::DevMemPatt (rwKernel *a)
  {
    rw = a;
  }


  DevMemPatt::~DevMemPatt ()
  {
  }


  int DevMemPatt::compare_data_snippet (unsigned char *x, struct sfp *y)
  {
    bool		i = false;
    int			ret = -1;
    short		a = 0,
			b = 0;

  while ((b < y->length) && (a < READ_BUFF_SIZE))
    {
      if ((x[a] == y->fp[b].val) || (y->fp[b].type == WWCARD))
        {
          if (i == false)
            {
              i = true;
              ret = a;
            }
          b++;
        }
      else if (i == true)
        {
          i = false;
          ret = -1;
          b = 0;
        }
      a++;
    }
  return ret;
  }


  unsigned int DevMemPatt::find_patt (unsigned int s, \
		unsigned int e, unsigned short l, unsigned char *snipp)
  {
    bool		i = false;
    int			ret = -1;
    unsigned short	a = 0,
			b = 0;
    unsigned char	*readBuff = NULL;

    readBuff = new unsigned char[READ_BUFF_SIZE];

    while (s < e)
      {
        rw->read (readBuff, READ_BUFF_SIZE, s);
        while ((b < l) && (a < READ_BUFF_SIZE))
          {
            if (readBuff[a] == snipp[b])
              {
                if (i == false)
                  {
                    i = true;
                    ret = a;
                  }
                b++;
              }
            else if (i == true)
              {
                i = false;
                ret = -1;
                b = 0;
              }
            a++;
          }
        if (ret != -1)
	  {
	    if (ret == 0)
	      return s;
	    s = s + ret - READ_BUFF_SIZE;
	  }
        s += READ_BUFF_SIZE;
      }
    return 0;
  }


  unsigned int DevMemPatt::find_patt (struct sfp *a)
  {
    int			x = -1;
    unsigned int	s = a->start_addr,
			e = a->stop_addr;
    unsigned char	*readBuff = NULL;

    readBuff = new unsigned char[READ_BUFF_SIZE];

    while (s < e)
      {
        rw->read (readBuff, READ_BUFF_SIZE, s);
        if ((x = compare_data_snippet (readBuff, a)) != -1)
	  {
	    if (x == 0)
	      return s;
	    s = s + x - READ_BUFF_SIZE;
	  }
        s += READ_BUFF_SIZE;
      }
    return 0;
  }