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
|
/* Xamine - X Protocol Analyzer
* Copyright (C) 2004-2005 Josh Triplett
*
* This package is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.
*
* This package 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 Lesser General Public
* License for more details.
*/
#ifndef XAMINE_H
#define XAMINE_H
typedef enum
{
XAMINE_BOOLEAN,
XAMINE_CHAR,
XAMINE_SIGNED,
XAMINE_UNSIGNED,
XAMINE_STRUCT,
XAMINE_UNION,
XAMINE_TYPEDEF
} XamineType;
typedef enum
{
XAMINE_REQUEST,
XAMINE_RESPONSE
} XamineDirection;
typedef struct XamineDefinition
{
char *name;
XamineType type;
union
{
unsigned int size; /* base types */
struct XamineFieldDefinition *fields; /* struct, union */
struct XamineDefinition *ref; /* typedef */
};
struct XamineDefinition *next;
} XamineDefinition;
typedef enum XamineExpressionType
{
XAMINE_FIELDREF,
XAMINE_VALUE,
XAMINE_OP
} XamineExpressionType;
typedef enum XamineOp
{
XAMINE_ADD,
XAMINE_SUBTRACT,
XAMINE_MULTIPLY,
XAMINE_DIVIDE,
XAMINE_LEFT_SHIFT,
XAMINE_BITWISE_AND
} XamineOp;
typedef struct XamineExpression
{
XamineExpressionType type;
union
{
char *field; /* Field name for XAMINE_FIELDREF */
unsigned long value; /* Value for XAMINE_VALUE */
struct /* Operator and operands for XAMINE_OP */
{
XamineOp op;
struct XamineExpression *left;
struct XamineExpression *right;
};
};
} XamineExpression;
typedef struct XamineFieldDefinition
{
char *name;
XamineDefinition *definition;
XamineExpression *length; /* List length; NULL for non-list */
struct XamineFieldDefinition *next;
} XamineFieldDefinition;
typedef struct XaminedItem
{
char *name;
XamineDefinition *definition;
unsigned int offset;
union
{
unsigned char bool_value;
char char_value;
signed long signed_value;
unsigned long unsigned_value;
};
struct XaminedItem *child;
struct XaminedItem *next;
} XaminedItem;
/* Opaque types for an Xamine library state and a conversation-specific
* state. */
typedef struct XamineState XamineState;
typedef struct XamineConversation XamineConversation;
/* Initialization and cleanup */
extern XamineState * xamine_init();
extern void xamine_cleanup(XamineState *state);
/* Retrieval of the type definitions. */
extern XamineDefinition * xamine_get_definitions(XamineState *state);
/* Creation and destruction of conversations. */
extern XamineConversation * xamine_create_conversation(XamineState *state);
extern void xamine_free_conversation(XamineConversation *conversation);
/* Analysis */
extern XaminedItem * xamine(XamineConversation *conversation,
XamineDirection dir,
void *data, unsigned int size);
extern void xamine_free(XaminedItem *item);
#endif /* XAMINE_H */
|