This repository has been archived by the owner on Sep 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 82
/
example.c
74 lines (61 loc) · 1.99 KB
/
example.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
#include "wintools.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
FILE* dfile;
__attribute__((constructor))
void init()
{
FILE* out = stdout;
pid_t pid;
#if (LMODE() == MODE_EXTERNAL())
FILE* pipe = popen("pidof qemu-system-x86_64", "r");
fscanf(pipe, "%d", &pid);
pclose(pipe);
#else
out = fopen("/tmp/testr.txt", "w");
pid = getpid();
#endif
fprintf(out, "Using Mode: %s\n", TOSTRING(LMODE));
dfile = out;
WinCtx ctx;
int ret = InitializeContext(&ctx, pid);
fprintf(out, "Initialization status: %d\n", ret);
if (!ret) {
if (0) {
fprintf(out, "Kernel Export Table:\n");
for (size_t i = 0; i < ctx.ntExports.size; i++) {
char* c = (char*)ctx.ntExports.list[i].name;
while (*c != '\0')
putc(*c++, out);
for (size_t o = (c - ctx.ntExports.list[i].name); o < 64; o++)
putc(' ', out);
fprintf(out, "%lx\n", ctx.ntExports.list[i].address);
}
}
WinProcList processList = GenerateProcessList(&ctx);
fprintf(out, "\nProcess List:\nPID\tVIRT\t\t\tPHYS\t\tBASE\t\tNAME\n");
for (size_t i = 0; i < processList.size; i++)
fprintf(out, "%lu\t%.16lx\t%.9lx\t%.9lx\t%s\n", processList.list[i].pid, processList.list[i].process, processList.list[i].physProcess, processList.list[i].dirBase, processList.list[i].name);
for (size_t i = 0; i < processList.size; i++)
if (!strcmp(processList.list[i].name, "csgo.exe")) {
WinModuleList list = GenerateModuleList(&ctx, processList.list + i);
fprintf(out, "Module List for %s:\nBASEADDR\tENTRY_POINT\tMOD_SIZE\tLOAD\tNAME\n", processList.list[i].name);
for (int o = 0; o < list.size; o++)
fprintf(out, "%.8lx\t%.8lx\t%.8lx\t%hx\t%s\n", list.list[o].baseAddress, list.list[o].entryPoint, list.list[o].sizeOfModule, list.list[o].loadCount, list.list[o].name);
FreeModuleList(list);
break;
}
FreeProcessList(processList);
}
FreeContext(&ctx);
fclose(out);
}
int main()
{
return 0;
}