forked from scanmem/scanmem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanmem.h
132 lines (114 loc) · 4.28 KB
/
scanmem.h
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
#ifndef _SCANMEM_INC
#define _SCANMEM_INC /* include guard */
/*lint +libh(config.h) */
#include "config.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h> /*lint !e537 */
#include "scanroutines.h"
#include "list.h"
#include "value.h"
#include "target_memory_info_array.h"
/* list of functions where i dont want to be warned about ignored return value */
/*lint -esym(534,detach,printversion,strftime,fflush,sleep) */
#ifndef PACKAGE_VERSION
# define PACKAGE_VERSION "(unknown)"
#endif
/*
#ifndef NDEBUG
# define eprintf(x, y...) fprintf(stderr, x, ## y)
#else
# define eprintf(x, y...)
#endif
*/
/* from string.h in glibc */
#ifndef strdupa
#define strdupa(s) \
({ \
const char *__old = (s); \
size_t __len = strlen(__old) + 1; \
char *__new = (char *) alloca(__len); \
(char *) memcpy(__new, __old, __len); \
})
#endif
#ifndef strndupa
#define strndupa(s, n) \
({ \
const char *__old = (s); \
size_t __len = strnlen(__old, (n)); \
char *__new = (char *) alloca(__len + 1); \
__new[__len] = '\0'; \
(char *) memcpy(__new, __old, __len); \
})
#endif
#ifdef _lint
/*lint -save -e652 -e683 -e547 */
# define snprintf(a, b, c...) (((void) b), sprintf(a, ## c))
# define strtoll(a,b,c) ((long long) strtol(a,b,c))
# define WIFSTOPPED
# define sighandler_t _sigfunc_t
/*lint -restore */
/*lint -save -esym(526,getline,strdupa,strdup,strndupa,strtoll,pread) */
ssize_t getline(char **lineptr, size_t * n, FILE * stream);
char *strndupa(const char *s, size_t n);
char *strdupa(const char *s);
char *strdup(const char *s);
ssize_t pread(int fd, void *buf, size_t count, off_t offset);
/*lint -restore */
#endif
#ifdef __CSURF__
# define waitpid(x,y,z) ((*(y)=0),-rand())
# define WIFSTOPPED(x) (rand())
# define ptrace(w,x,y,z) ((errno=rand()),(ptrace(w,x,y,z)))
#endif
#ifndef MIN
# define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/* global settings */
typedef struct {
unsigned exit:1;
pid_t target;
matches_and_old_values_array *matches;
long num_matches;
double scan_progress;
list_t *regions;
list_t *commands; /* command handlers */
const char *current_cmdline; /* the command being executed */
struct {
unsigned short alignment;
unsigned short debug;
unsigned short backend; /* if 1, scanmem will work as a backend, and output would be more machine-readable */
/* options that can be changed during runtime */
scan_data_type_t scan_data_type;
region_scan_level_t region_scan_level;
unsigned short detect_reverse_change;
unsigned short dump_with_ascii;
unsigned short reverse_endianness;
} options;
} globals_t;
/* this structure represents one known match, its address and type. */
#if 0
typedef struct {
void *address; /* address of variable */
region_t *region; /* region it belongs to */
value_t lvalue; /* last seen value */
unsigned matchid; /* unique identifier */
} match_t;
#endif
/* global settings */
extern globals_t globals;
bool init();
/* ptrace.c */
bool detach(pid_t target);
bool setaddr(pid_t target, void *addr, const value_t * to);
bool checkmatches(globals_t * vars, scan_match_type_t match_type, const uservalue_t *uservalue);
bool searchregions(globals_t * vars, scan_match_type_t match_type, const uservalue_t *uservalue);
bool peekdata(pid_t pid, void *addr, value_t * result);
bool attach(pid_t target);
bool read_array(pid_t target, void *addr, char *buf, int len);
bool write_array(pid_t target, void *addr, const void *data, int len);
/* menu.c */
bool getcommand(globals_t * vars, char **line);
void printversion();
#endif