added a generic _dump() function and put functions into its own C file...

This commit is contained in:
git@daemon.de
2014-02-05 13:08:34 +01:00
parent 192856446b
commit 5707ecbf9c
2 changed files with 75 additions and 36 deletions

View File

@@ -27,42 +27,13 @@
#include <ctype.h>
#include <wctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
// lowercase a string
static inline char *_lc(char *in) {
size_t len = strlen(in);
size_t i;
for(i=0; i<len; ++i)
in[i] = towlower(in[i]);
return in;
}
// find the offset of the beginning of a certain string within binary data
static inline size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hlen) {
size_t i;
size_t offset = 0;
int m = 0;
for(i=0; i<binlen-hlen; ++i) {
if(memcmp(&bin[i], sigstart, hlen) == 0) {
offset = i;
m = 1;
break;
}
}
if(m == 0)
offset = -1;
return offset;
}
static inline void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen) {
size_t i;
for (i = 0; i < xlen; ++i)
buf[i] = iv[i] ^ buf[i];
}
char *_lc(char *in);
size_t _findoffset(unsigned char *bin, size_t binlen, char *sigstart, size_t hlen);
void _xorbuf(unsigned char *iv, unsigned char *buf, size_t xlen);
void _dump(char *n, unsigned char *d, size_t s);
#endif // _HAVE_PCP_UTIL_H