diff options
Diffstat (limited to 'other/Kermit/lib/DevMemPatt.cpp')
| -rw-r--r-- | other/Kermit/lib/DevMemPatt.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/other/Kermit/lib/DevMemPatt.cpp b/other/Kermit/lib/DevMemPatt.cpp new file mode 100644 index 0000000..81fd6e9 --- /dev/null +++ b/other/Kermit/lib/DevMemPatt.cpp | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* | ||
| 2 | * DevMemPatt.cpp: | ||
| 3 | * written by palmers / teso | ||
| 4 | */ | ||
| 5 | #include <DevMemPatt.hpp> | ||
| 6 | |||
| 7 | |||
| 8 | DevMemPatt::DevMemPatt () | ||
| 9 | { | ||
| 10 | rw = new rwKernel (); | ||
| 11 | } | ||
| 12 | |||
| 13 | |||
| 14 | DevMemPatt::DevMemPatt (rwKernel *a) | ||
| 15 | { | ||
| 16 | rw = a; | ||
| 17 | } | ||
| 18 | |||
| 19 | |||
| 20 | DevMemPatt::~DevMemPatt () | ||
| 21 | { | ||
| 22 | } | ||
| 23 | |||
| 24 | |||
| 25 | int DevMemPatt::compare_data_snippet (unsigned char *x, struct sfp *y) | ||
| 26 | { | ||
| 27 | bool i = false; | ||
| 28 | int ret = -1; | ||
| 29 | short a = 0, | ||
| 30 | b = 0; | ||
| 31 | |||
| 32 | while ((b < y->length) && (a < READ_BUFF_SIZE)) | ||
| 33 | { | ||
| 34 | if ((x[a] == y->fp[b].val) || (y->fp[b].type == WWCARD)) | ||
| 35 | { | ||
| 36 | if (i == false) | ||
| 37 | { | ||
| 38 | i = true; | ||
| 39 | ret = a; | ||
| 40 | } | ||
| 41 | b++; | ||
| 42 | } | ||
| 43 | else if (i == true) | ||
| 44 | { | ||
| 45 | i = false; | ||
| 46 | ret = -1; | ||
| 47 | b = 0; | ||
| 48 | } | ||
| 49 | a++; | ||
| 50 | } | ||
| 51 | return ret; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | unsigned int DevMemPatt::find_patt (unsigned int s, \ | ||
| 56 | unsigned int e, unsigned short l, unsigned char *snipp) | ||
| 57 | { | ||
| 58 | bool i = false; | ||
| 59 | int ret = -1; | ||
| 60 | unsigned short a = 0, | ||
| 61 | b = 0; | ||
| 62 | unsigned char *readBuff = NULL; | ||
| 63 | |||
| 64 | readBuff = new unsigned char[READ_BUFF_SIZE]; | ||
| 65 | |||
| 66 | while (s < e) | ||
| 67 | { | ||
| 68 | rw->read (readBuff, READ_BUFF_SIZE, s); | ||
| 69 | while ((b < l) && (a < READ_BUFF_SIZE)) | ||
| 70 | { | ||
| 71 | if (readBuff[a] == snipp[b]) | ||
| 72 | { | ||
| 73 | if (i == false) | ||
| 74 | { | ||
| 75 | i = true; | ||
| 76 | ret = a; | ||
| 77 | } | ||
| 78 | b++; | ||
| 79 | } | ||
| 80 | else if (i == true) | ||
| 81 | { | ||
| 82 | i = false; | ||
| 83 | ret = -1; | ||
| 84 | b = 0; | ||
| 85 | } | ||
| 86 | a++; | ||
| 87 | } | ||
| 88 | if (ret != -1) | ||
| 89 | { | ||
| 90 | if (ret == 0) | ||
| 91 | return s; | ||
| 92 | s = s + ret - READ_BUFF_SIZE; | ||
| 93 | } | ||
| 94 | s += READ_BUFF_SIZE; | ||
| 95 | } | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | unsigned int DevMemPatt::find_patt (struct sfp *a) | ||
| 101 | { | ||
| 102 | int x = -1; | ||
| 103 | unsigned int s = a->start_addr, | ||
| 104 | e = a->stop_addr; | ||
| 105 | unsigned char *readBuff = NULL; | ||
| 106 | |||
| 107 | readBuff = new unsigned char[READ_BUFF_SIZE]; | ||
| 108 | |||
| 109 | while (s < e) | ||
| 110 | { | ||
| 111 | rw->read (readBuff, READ_BUFF_SIZE, s); | ||
| 112 | if ((x = compare_data_snippet (readBuff, a)) != -1) | ||
| 113 | { | ||
| 114 | if (x == 0) | ||
| 115 | return s; | ||
| 116 | s = s + x - READ_BUFF_SIZE; | ||
| 117 | } | ||
| 118 | s += READ_BUFF_SIZE; | ||
| 119 | } | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
