forked from scanmem/scanmem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarget_memory_info_array.h
119 lines (102 loc) · 4.71 KB
/
target_memory_info_array.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
/*
target_memory_info_array.h
Copyright (C) 2009 Eli Dupree <elidupree(a)charter.net>
Copyright (C) 2010 WANG Lu <coolwanglu(a)gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SEOIGROIYIOOBKOB_INC
#define _SEOIGROIYIOOBKOB_INC /* include guard */
#include <inttypes.h>
#include "value.h"
#include "maps.h"
/* These two structs are not used; pointers to them are used to refer to arrays containing copied_data_swaths / matches_swaths, in the following ormat:
- the array begins with the first_byte_in_child pointer; immediately after that is the number_of_bytes, and then the struct's data describing that many bytes. (Note that the number refers to the number of bytes in the child process's memory that are covered, not the number of bytes the struct takes up.)
- in the first position after each such block is another such block (first byte pointer and number of bytes), or a null pointer and a 0 number of bytes to terminate the data.
(The first_byte_in_child pointers refer to locations in the child - they cannot be followed except using ptrace())*/
typedef struct {
uint8_t old_value;
match_flags match_info;
} old_value_and_match_info;
/*
typedef struct {
void *first_byte_in_child;
unsigned long number_of_bytes;
} unknown_type_of_swath;
typedef struct {
void *first_byte_in_child;
unsigned long number_of_bytes;
uint8_t copied_bytes[0];
} copied_data_swath;
typedef struct {
void *first_byte_in_child;
unsigned long number_of_bytes;
match_flags match_info[0];
} matches_swath;
*/
typedef struct {
void *first_byte_in_child;
unsigned long number_of_bytes;
old_value_and_match_info data[0];
} matches_and_old_values_swath;
/*
typedef struct {
unsigned long bytes_allocated;
unsigned long max_needed_bytes;
} unknown_type_of_array;
typedef struct {
unsigned long bytes_allocated;
unsigned long max_needed_bytes;
copied_data_swath swaths[0];
} copied_data_array;
typedef struct {
unsigned long bytes_allocated;
unsigned long max_needed_bytes;
matches_swath swaths[0];
} matches_array;
*/
typedef struct {
unsigned long bytes_allocated;
unsigned long max_needed_bytes;
matches_and_old_values_swath swaths[0];
} matches_and_old_values_array;
/*
* now we use MATCHES_AND_VALUES only
*
typedef enum {
MATCHES,
MATCHES_AND_VALUES,
VALUES
} data_array_type_t;
*/
typedef struct {
matches_and_old_values_swath *swath;
long index;
} match_location;
matches_and_old_values_array * allocate_array(matches_and_old_values_array *array, unsigned long max_bytes);
matches_and_old_values_array * allocate_enough_to_reach(matches_and_old_values_array *array, void *last_byte_to_reach_plus_one, matches_and_old_values_swath **swath_pointer_to_correct);
matches_and_old_values_swath * add_element(matches_and_old_values_array **array, matches_and_old_values_swath *swath, void *remote_address, void *new_element);
matches_and_old_values_array * null_terminate(matches_and_old_values_array *array, matches_and_old_values_swath *swath);
/* only at most sizeof(int64_t) bytes will be readed, if more bytes needed (e.g. bytearray), read it separatedly (for performance) */
value_t data_to_val_aux(matches_and_old_values_swath *swath, long index, long swath_length);
value_t data_to_val(matches_and_old_values_swath *swath, long index);
/* for printable text representation */
void data_to_printable_string(char *buf, int buf_length, matches_and_old_values_swath *swath, long index, int string_length);
/* for bytearray representation */
void data_to_bytearray_text(char *buf, int buf_length, matches_and_old_values_swath *swath, long index, int bytearray_length);
void * remote_address_of_nth_element(matches_and_old_values_swath *swath, long n);
void * remote_address_of_last_element(matches_and_old_values_swath *swath);
void * local_address_beyond_nth_element(matches_and_old_values_swath *swath, long n);
void * local_address_beyond_last_element(matches_and_old_values_swath *swath);
match_location nth_match(matches_and_old_values_array *matches, unsigned n);
matches_and_old_values_array * delete_by_region(matches_and_old_values_array *array, long *num_matches, region_t *which, bool invert);
#endif