-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.c
149 lines (122 loc) · 2.64 KB
/
main.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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "procmodlib.h"
#include "unicode.h"
void args() {
printf("ProcMod - v0.1\n\
-p PROCID -- Process ID to work on\n\
-f -- Text to find in the process\n\
-r -- Text to replace in the proces\n\
-u -- Convert find/replace parameters to UTF-16 (for JVM)\n\
-d FILE -- dumps process to file\n\
-l NUM -- Lower bound of search\n\
-t NUM -- Top bound of search\n\
-h -- Hexadecimal find/replace strings\n");
}
int main(int argc, char **argv) {
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
opterr = 0;
if (argc == 1) {
args();
return;
}
int procid = -1;
char *dump = NULL;
char *find = NULL;
char *replace = NULL;
char utf16 = 0;
WORD lbound = 0;
WORD ubound = WORDMAX;
int hex = 0;
while ((c = getopt(argc, argv, "d:b:c:p:f:ur:l:t:h")) != -1)
switch (c) {
case 'd':
dump = optarg;
break;
case 'b':
bflag = 1;
break;
case 'c':
cvalue = optarg;
break;
case 'p':
procid = atoi(optarg);
break;
case 'f':
find = optarg;
break;
case 'r':
replace = optarg;
break;
case 'u':
utf16 = 1;
break;
case 'l':
lbound = TOWORD(optarg);
break;
case 't':
ubound = TOWORD(optarg);
break;
case 'h':
hex = 1;
break;
default:
args();
abort();
}
if (procid == -1) {
args();
return;
}
if (dump) {
dumpprocess(procid, dump);
}
if (find != NULL && replace != NULL) {
if (!utf16 && !hex) {
procreplace(procid, find, strlen(find), replace,
strlen(replace), lbound, ubound);
} else if (hex) {
char *f_ = tobytes(find);
char *r_ = tobytes(replace);
if (!f_ || !r_) {
printf
("Hexadecimal must be even number of characters\n");
return;
}
int fl = strlen(find) / 2;
if (fl == 0)
fl = 1;
int rl = strlen(replace) / 2;
if (rl == 0)
rl = 1;
procreplace(procid, f_, fl, r_, rl, lbound, ubound);
} else {
char *f_ = asciitou16(find);
char *r_ = asciitou16(replace);;
procreplace(procid, f_, u16bytes(f_), r_,
u16bytes(r_), lbound, ubound);
}
} else if (find) {
if (!utf16 && !hex) {
procreplace(procid, find, strlen(find), NULL, 0, lbound,
ubound);
} else if (hex) {
unsigned char *f_ = tobytes(find);
if (!f_) {
printf
("Hexadecimal must be even number of characters\n");
return;
}
int div2 = strlen(find) / 2;
if (div2 == 0)
div2 = 1;
procreplace(procid, f_, div2, NULL, 0, lbound, ubound);
} else {
char *f_ = asciitou16(find);
procreplace(procid, f_, u16bytes(f_), NULL, 0, lbound,
ubound);
}
}
}