-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.c
67 lines (64 loc) · 1.27 KB
/
test.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
#define _CRT_SECURE_NO_WARNINGS
#include "dovzhyna.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
static long fsize(FILE* f)
{
long old = ftell(f);
fseek(f, 0, SEEK_END);
long size = ftell(f);
fseek(f, old, SEEK_SET);
return size;
}
static void printhex(uint8_t* data, size_t sz)
{
for (size_t i = 0; i < sz; i++) {
if (i) printf(" ");
printf("%.2X", (unsigned)data[i]);
}
}
int main(int argc, char **argv)
{
if (argc != 2) return -1;
FILE* f = fopen(argv[1], "rb");
if (!f) return -1;
long filesize = fsize(f);
char* text = (char*)malloc(filesize+15);
fread(text, filesize, 1, f);
memset(text + filesize, 0xCC, 15);
fclose(f);
struct OpState os;
int lastop = 0;
for (int i = 0; i < filesize+15;) {
int status = dovzhyna_decode(&os, (uint8_t*)text + i, 1);
if (status) {
printf("error %.8X\n", i);
i++;
continue;
}
if ((i & 15) == 0) {
switch (lastop) {
case 0xCC:
printf("sub %.8X\n", i);
break;
case 0xE9:
case 0xEA:
case 0xC2:
case 0xC3:
case 0xFF:
printf("maybe %.8X\n", i);
break;
}
if(i==0) printf("maybe %.8X\n", i);
}
//printf("%.8X: ",i);
//printhex(os.data, os.index);
//printf("\n");
assert(os.index);
i += os.index;
lastop = os.opcode;
}
free(text);
}