-
Notifications
You must be signed in to change notification settings - Fork 0
/
cstring.c
54 lines (44 loc) · 865 Bytes
/
cstring.c
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
#include "lich.h"
#include <string.h>
#include <strings.h>
#include <unistd.h>
/*
* Simple (reversable) stand-in for strfry(). This is in no way
* cryptographically sound and is useful only for obfuscation.
*
*/
static VALUE
strfry_thunk(VALUE self)
{
char *ptr, c;
int i, len;
ptr = RSTRING(self)->ptr;
len = RSTRING(self)->len;
swab(ptr);
for (i = 0; i < len; i++)
{
c = ptr[i];
ptr[i] = ptr[len - i];
ptr[len - i] = c;
}
return self;
}
/*
* The limitations above are fully applicable here as well.
* Ruby-wrapper for the memfrob() func.
*
*/
static VALUE
memfrob_thunk(VALUE self)
{
Check_Type(self, T_STRING);
memfrob(RSTRING(self)->ptr);
return self;
}
void
Init_cstring()
{
extern VALUE rb_cString;
rb_define_method(rb_cString, "strfry", strfry_thunk, 0);
rb_define_method(rb_cString, "memfrob", memfrob_thunk, 0);
}