-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern.c
More file actions
136 lines (96 loc) · 3.11 KB
/
pattern.c
File metadata and controls
136 lines (96 loc) · 3.11 KB
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
#include<stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
void create_pattern(uint64_t sayi, char* bul, int flag);
void help();
int main(int argc,char *argv[]){
if(argc < 3){
help();
return 0;
}
else if(strcmp(("-p"),argv[1]) == 0 ){
create_pattern(atoi(argv[2]),NULL,0);
}
else if(strcmp(("-f"),argv[1]) == 0){
char *bul = argv[2];
create_pattern(atoi(argv[3]),bul,1);
}
else if(strcmp(("-x"),argv[1]) == 0){
char *bul = argv[2];
create_pattern(atoi(argv[3]),bul,2);
}else{
printf("Usage ./pattern [options] value1 value2\n");
return -1;
}
return 0;
}
void create_pattern(uint64_t sayi,char* bul,int flag){
char bigA = 65;
char smallA = 97;
char num = 48;
char output[sayi];
for(int i=0;i<sayi;i++){
output[i] = bigA;
output[i+1] = smallA;
output[i+2] =num;
i = i+2 ;
num++;
if(num == 58){
smallA++;
num = 48;
}
if(smallA == 123){
bigA++;
smallA = 97;
num = 48;
}
}
if(flag == 1){
bul[4] = '\0';
output[sayi] = '\0';
for(int i=0;i<=sayi;i++){
if(bul[0] == output[i]){
if(bul[1] == output[i+1]){
if(bul[2] == output[i+2]){
if(bul[3] == output[i+3]){
printf("offset:%d\n",i);
return;
}
}
}
}
}
}else if(flag == 2){
int *deger = malloc(4 *sizeof(int));
int counter = 0;
for(int i=0;i<8;i+=2){
int head = (bul[i] -'0')*16;
int tail = (bul[i+1] - '0');
deger[counter] = head + tail;
counter++;
}
for(int i=0;i<=sayi;i++){
if(deger[3] == output[i]){
if(deger[2] == output[i+1]){
if(deger[1] == output[i+2]){
if(deger[0] == output[i+3]){
printf("offset:%d\n",i);
return;
}
}
}
}
}
printf("No matches!\n");
return;
}
output[sayi] = '\0';
printf("###Pattern###\n%s\n",output);
}
void help(){
printf("\nPattern Generator [64] v1.0 Dogan Duran: 2023-07-19\n");
printf("The purpose of the Pattern Generator is to create patterns in order to find overflow offsets in memory and calculate those offsets.\n\n");
printf("Usage ./pattern [options] value1 value2 \n\nExample uses\n./pattern -p 100\n./pattern -f 0Aj1 300 \n./pattern -x 41386141 300\n\n");
printf("[options]\n -p : Create pattern\n -f : Find the offset within the pattern\n -x : Find the offset within the pattern in hexadecimal format\n");
}