svf-lib 1.0.1049 → 1.0.1052
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SVF-linux/Release-build/lib/libSvf.a +0 -0
- package/SVF-linux/include/SVF-FE/BasicTypes.h +1 -0
- package/SVF-linux/include/Util/BasicTypes.h +0 -1
- package/SVF-osx/Release-build/lib/CUDD/libCudd.a +0 -0
- package/SVF-osx/Release-build/lib/libSvf.a +0 -0
- package/SVF-osx/include/MTA/LockResultValidator.h +1 -2
- package/SVF-osx/include/MTA/MTAAnnotator.h +1 -1
- package/SVF-osx/include/MTA/MTAResultValidator.h +2 -2
- package/SVF-osx/include/SVF-FE/BasicTypes.h +1 -0
- package/SVF-osx/include/SVF-FE/SVFIRBuilder.h +3 -0
- package/SVF-osx/include/Util/BasicTypes.h +0 -1
- package/SVF-osx/include/Util/ExtAPI.h +198 -174
- package/SVF-osx/include/Util/SVFUtil.h +0 -6
- package/SVF-osx/include/Util/SymState.h +118 -0
- package/SVF-osx/include/Util/cJSON.h +300 -0
- package/SVF-osx/include/Util/config.h +6 -0
- package/package.json +1 -1
|
Binary file
|
|
@@ -58,6 +58,7 @@ typedef llvm::ConstantExpr ConstantExpr;
|
|
|
58
58
|
typedef llvm::ConstantDataArray ConstantDataArray;
|
|
59
59
|
typedef llvm::ConstantData ConstantData;
|
|
60
60
|
typedef llvm::ConstantArray ConstantArray;
|
|
61
|
+
typedef llvm::Constant Constant;
|
|
61
62
|
|
|
62
63
|
// LLVM Instructions
|
|
63
64
|
typedef llvm::AllocaInst AllocaInst;
|
|
@@ -91,7 +91,6 @@ typedef llvm::FunctionType FunctionType;
|
|
|
91
91
|
|
|
92
92
|
/// LLVM Aliases and constants
|
|
93
93
|
typedef llvm::Argument Argument;
|
|
94
|
-
typedef llvm::Constant Constant;
|
|
95
94
|
typedef llvm::ConstantInt ConstantInt;
|
|
96
95
|
typedef llvm::ConstantPointerNull ConstantPointerNull;
|
|
97
96
|
typedef llvm::GlobalAlias GlobalAlias;
|
|
Binary file
|
|
Binary file
|
|
@@ -70,8 +70,7 @@ private:
|
|
|
70
70
|
|
|
71
71
|
if (callee)
|
|
72
72
|
{
|
|
73
|
-
if (
|
|
74
|
-
|| callee->getName().find("llvm.memset") != std::string::npos)
|
|
73
|
+
if (callee->getName().find("llvm.memset") != std::string::npos)
|
|
75
74
|
return I;
|
|
76
75
|
}
|
|
77
76
|
I = I->getPrevNode();
|
|
@@ -78,7 +78,7 @@ public:
|
|
|
78
78
|
inline bool isMemcpy(const Instruction *I)
|
|
79
79
|
{
|
|
80
80
|
const SVFFunction* F =SVFUtil::getCallee(I);
|
|
81
|
-
return F &&
|
|
81
|
+
return F && F->getName().find("llvm.memcpy") != std::string::npos;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
private:
|
|
@@ -416,9 +416,9 @@ private:
|
|
|
416
416
|
|
|
417
417
|
if (const SVFFunction *callee = SVFUtil::getCallee(I))
|
|
418
418
|
{
|
|
419
|
-
if (
|
|
420
|
-
|| callee->getName().find("llvm.memset") != std::string::npos)
|
|
419
|
+
if (callee->getName().find("llvm.memset") != std::string::npos)
|
|
421
420
|
return I;
|
|
421
|
+
|
|
422
422
|
}
|
|
423
423
|
I = I->getPrevNode();
|
|
424
424
|
}
|
|
@@ -58,6 +58,7 @@ typedef llvm::ConstantExpr ConstantExpr;
|
|
|
58
58
|
typedef llvm::ConstantDataArray ConstantDataArray;
|
|
59
59
|
typedef llvm::ConstantData ConstantData;
|
|
60
60
|
typedef llvm::ConstantArray ConstantArray;
|
|
61
|
+
typedef llvm::Constant Constant;
|
|
61
62
|
|
|
62
63
|
// LLVM Instructions
|
|
63
64
|
typedef llvm::AllocaInst AllocaInst;
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
#include "Util/ExtAPI.h"
|
|
35
35
|
#include "SVF-FE/BasicTypes.h"
|
|
36
36
|
#include "SVF-FE/ICFGBuilder.h"
|
|
37
|
+
#include "Util/cJSON.h"
|
|
37
38
|
|
|
38
39
|
namespace SVF
|
|
39
40
|
{
|
|
@@ -240,6 +241,8 @@ protected:
|
|
|
240
241
|
|
|
241
242
|
/// Handle external call
|
|
242
243
|
//@{
|
|
244
|
+
virtual u32_t getArgIndex(std::string s);
|
|
245
|
+
virtual NodeID parseNode(std::string s, CallSite cs, const Instruction *inst);
|
|
243
246
|
virtual void handleExtCall(CallSite cs, const SVFFunction *F);
|
|
244
247
|
void addComplexConsForExt(Value *D, Value *S, const Value* sz);
|
|
245
248
|
//@}
|
|
@@ -91,7 +91,6 @@ typedef llvm::FunctionType FunctionType;
|
|
|
91
91
|
|
|
92
92
|
/// LLVM Aliases and constants
|
|
93
93
|
typedef llvm::Argument Argument;
|
|
94
|
-
typedef llvm::Constant Constant;
|
|
95
94
|
typedef llvm::ConstantInt ConstantInt;
|
|
96
95
|
typedef llvm::ConstantPointerNull ConstantPointerNull;
|
|
97
96
|
typedef llvm::GlobalAlias GlobalAlias;
|
|
@@ -28,218 +28,242 @@
|
|
|
28
28
|
|
|
29
29
|
/*
|
|
30
30
|
* Modified by Yulei Sui 2013
|
|
31
|
-
*/
|
|
31
|
+
*/
|
|
32
32
|
|
|
33
33
|
#ifndef __ExtAPI_H
|
|
34
34
|
#define __ExtAPI_H
|
|
35
35
|
|
|
36
36
|
#include "Util/BasicTypes.h"
|
|
37
|
-
#include
|
|
38
|
-
#include
|
|
37
|
+
#include "Util/cJSON.h"
|
|
38
|
+
#include "Util/config.h"
|
|
39
39
|
#include <string>
|
|
40
|
+
#include <map>
|
|
41
|
+
|
|
42
|
+
#define EXTAPI_JSON_PATH "/lib/Util/ExtAPI.json"
|
|
40
43
|
|
|
41
44
|
namespace SVF
|
|
42
45
|
{
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
/*
|
|
48
|
+
|
|
49
|
+
Specifications in ExtAPI.json
|
|
50
|
+
|
|
51
|
+
Specification language: The specification language of external function includes:
|
|
52
|
+
1. the name of the function,
|
|
53
|
+
2. the type of the function,
|
|
54
|
+
3. the operations of the function.
|
|
55
|
+
|
|
56
|
+
Funtion type: Funtion type represents some property of the function.
|
|
57
|
+
For example,
|
|
58
|
+
”EFT_ALLOC“, represents if this external function allocates a new object and assigns it to one of its arguments,
|
|
59
|
+
For the selection of Function type and a more detailed explanation, please refer to enum extf_t in ExtAPI.h.
|
|
60
|
+
|
|
61
|
+
Function operations: Function operations indicates the relationship between input and output,
|
|
62
|
+
mainly the relationship between function parameters, or between parameters and return values after function is executed.
|
|
63
|
+
For example,
|
|
64
|
+
"copy": ["A2", "L"], indicates that after this external function is executed, the value of the 2th parameter is copied into the return value.
|
|
65
|
+
For the selection of Function type and a more detailed explanation, please refer to enum extType in ExtAPI.h.
|
|
66
|
+
|
|
67
|
+
For operands of function operation, e.g., "A2", "L", there are the following options:
|
|
68
|
+
"A": represents an parameter;
|
|
69
|
+
"N": represents a number;
|
|
70
|
+
"R": represents a reference;
|
|
71
|
+
"L": represents a return value;
|
|
72
|
+
"V": represents a dummy node;
|
|
73
|
+
|
|
74
|
+
Among them, parameter may have multiple forms, because there may be multiple parameters, and parameter may be a reference or complex structure,
|
|
75
|
+
|
|
76
|
+
Here we use regular expressions "(AN)(R|RN)^*" to represent parameter, for example,
|
|
77
|
+
"A0": represents the 1th parameter;
|
|
78
|
+
"A2R": represents that the 3th parameter is a reference;
|
|
79
|
+
"A1R2": represents the 3th substructure of 2th parameter "A1R", where "A1R" is a complex structure;
|
|
80
|
+
"A2R3R": represents the 4th substructure of 3th parameter "A2R" is a reference, where "A2R" is a complex structure;
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Specification format:
|
|
84
|
+
"functionName": {
|
|
85
|
+
"type": "functional type",
|
|
86
|
+
"function operation_1": [ operand_1, operand_2, ... , operand_n],
|
|
87
|
+
"function operation_2": [ operand_1, operand_2, ... , operand_n],
|
|
88
|
+
...
|
|
89
|
+
"function operation_n": [ operand_1, operand_2, ... , operand_n]
|
|
90
|
+
}
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
|
|
45
94
|
class ExtAPI
|
|
46
95
|
{
|
|
47
96
|
public:
|
|
48
|
-
//External Function types
|
|
49
|
-
//Assume a call in the form LHS= F(arg0, arg1, arg2, arg3).
|
|
50
97
|
enum extf_t
|
|
51
98
|
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
EXT_ADDR = 0, // Handle addr edge
|
|
100
|
+
EXT_COPY, // Handle copy edge
|
|
101
|
+
EXT_LOAD, // Handle load edge
|
|
102
|
+
EXT_STORE, // Handle store edge
|
|
103
|
+
EXT_LOADSTORE, // Handle load and store edges, and add a dummy node
|
|
104
|
+
EXT_COPY_N, // Copy the character c (an unsigned char) to the first n characters of the string pointed to, by the argument str
|
|
105
|
+
EXT_COPY_MN, // Copies n characters from memory area src to memory area dest.
|
|
106
|
+
EXT_FUNPTR, // Handle function void *dlsym(void *handle, const char *symbol)
|
|
107
|
+
EXT_COMPLEX, // Handle function _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
|
|
108
|
+
EXT_OTHER
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// External Function types
|
|
112
|
+
// Assume a call in the form LHS= F(arg0, arg1, arg2, arg3).
|
|
113
|
+
enum extType
|
|
114
|
+
{
|
|
115
|
+
EFT_NOOP = 0, // no effect on pointers
|
|
116
|
+
EFT_ALLOC, // returns a ptr to a newly allocated object
|
|
117
|
+
EFT_REALLOC, // like L_A0 if arg0 is a non-null ptr, else ALLOC
|
|
118
|
+
EFT_FREE, // free memory arg0 and all pointers passing into free function
|
|
119
|
+
EFT_FREE_MULTILEVEL, // any argument with 2-level pointer passing too a free wrapper function e.g., XFree(void**) which frees memory for void* and void**
|
|
120
|
+
EFT_NOSTRUCT_ALLOC, // like ALLOC but only allocates non-struct data
|
|
121
|
+
EFT_STAT, // retval points to an unknown static var X
|
|
122
|
+
EFT_STAT2, // ret -> X -> Y (X, Y - external static vars)
|
|
123
|
+
EFT_L_A0, // copies arg0, arg1, or arg2 into LHS
|
|
61
124
|
EFT_L_A1,
|
|
62
125
|
EFT_L_A2,
|
|
63
126
|
EFT_L_A8,
|
|
64
|
-
EFT_L_A0__A0R_A1,
|
|
65
|
-
EFT_L_A0__A0R_A1R,
|
|
66
|
-
EFT_L_A1__FunPtr, //obtain the address of a symbol based on the arg1 (char*) and parse a function to LHS (e.g., void *dlsym(void *handle, char *funname);)
|
|
127
|
+
EFT_L_A0__A0R_A1, // stores arg1 into *arg0 and returns arg0 (currently only for memset)
|
|
128
|
+
EFT_L_A0__A0R_A1R, // copies the data that arg1 points to into the location
|
|
129
|
+
EFT_L_A1__FunPtr, // obtain the address of a symbol based on the arg1 (char*) and parse a function to LHS (e.g., void *dlsym(void *handle, char *funname);)
|
|
67
130
|
// arg0 points to; note that several fields may be
|
|
68
131
|
// copied at once if both point to structs.
|
|
69
132
|
// Returns arg0.
|
|
70
|
-
EFT_A1R_A0R, //copies *arg0 into *arg1, with non-ptr return
|
|
71
|
-
EFT_A3R_A1R_NS, //copies *arg1 into *arg3 (non-struct copy only)
|
|
72
|
-
EFT_A1R_A0, //stores arg0 into *arg1
|
|
73
|
-
EFT_A2R_A1, //stores arg1 into *arg2
|
|
74
|
-
EFT_A4R_A1, //stores arg1 into *arg4
|
|
75
|
-
EFT_L_A0__A2R_A0, //stores arg0 into *arg2 and returns it
|
|
76
|
-
EFT_L_A0__A1_A0, //store arg1 into arg0's base and returns arg0
|
|
77
|
-
EFT_A0R_NEW, //stores a pointer to an allocated object in *arg0
|
|
78
|
-
EFT_A1R_NEW, //as above, into *arg1, etc.
|
|
133
|
+
EFT_A1R_A0R, // copies *arg0 into *arg1, with non-ptr return
|
|
134
|
+
EFT_A3R_A1R_NS, // copies *arg1 into *arg3 (non-struct copy only)
|
|
135
|
+
EFT_A1R_A0, // stores arg0 into *arg1
|
|
136
|
+
EFT_A2R_A1, // stores arg1 into *arg2
|
|
137
|
+
EFT_A4R_A1, // stores arg1 into *arg4
|
|
138
|
+
EFT_L_A0__A2R_A0, // stores arg0 into *arg2 and returns it
|
|
139
|
+
EFT_L_A0__A1_A0, // store arg1 into arg0's base and returns arg0
|
|
140
|
+
EFT_A0R_NEW, // stores a pointer to an allocated object in *arg0
|
|
141
|
+
EFT_A1R_NEW, // as above, into *arg1, etc.
|
|
79
142
|
EFT_A2R_NEW,
|
|
80
143
|
EFT_A4R_NEW,
|
|
81
144
|
EFT_A11R_NEW,
|
|
82
|
-
EFT_STD_RB_TREE_INSERT_AND_REBALANCE,
|
|
83
|
-
EFT_STD_RB_TREE_INCREMENT,
|
|
84
|
-
EFT_STD_LIST_HOOK,
|
|
145
|
+
EFT_STD_RB_TREE_INSERT_AND_REBALANCE, // Some complex effects
|
|
146
|
+
EFT_STD_RB_TREE_INCREMENT, // Some complex effects
|
|
147
|
+
EFT_STD_LIST_HOOK, // Some complex effects
|
|
85
148
|
|
|
86
|
-
CPP_EFT_A0R_A1,
|
|
87
|
-
CPP_EFT_A0R_A1R,
|
|
88
|
-
CPP_EFT_A1R,
|
|
149
|
+
CPP_EFT_A0R_A1, // stores arg1 into *arg0
|
|
150
|
+
CPP_EFT_A0R_A1R, // copies *arg1 into *arg0
|
|
151
|
+
CPP_EFT_A1R, // load arg1
|
|
89
152
|
EFT_CXA_BEGIN_CATCH, //__cxa_begin_catch
|
|
90
153
|
CPP_EFT_DYNAMIC_CAST, // dynamic_cast
|
|
91
|
-
|
|
154
|
+
EFT_NULL // not found in the list
|
|
92
155
|
};
|
|
93
|
-
private:
|
|
94
156
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
157
|
+
private:
|
|
158
|
+
std::map<std::string, extf_t> op_pair =
|
|
159
|
+
{
|
|
160
|
+
{"addr", EXT_ADDR},
|
|
161
|
+
{"copy", EXT_COPY},
|
|
162
|
+
{"load", EXT_LOAD},
|
|
163
|
+
{"store", EXT_STORE},
|
|
164
|
+
{"load_store", EXT_LOADSTORE},
|
|
165
|
+
{"copy_n", EXT_COPY_N},
|
|
166
|
+
{"copy_mn", EXT_COPY_MN},
|
|
167
|
+
{"complex", EXT_COMPLEX},
|
|
168
|
+
{"funptr", EXT_FUNPTR}
|
|
169
|
+
};
|
|
101
170
|
|
|
102
|
-
|
|
171
|
+
std::map<std::string, extType> type_pair =
|
|
103
172
|
{
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
173
|
+
{"EFT_NOOP", EFT_NOOP},
|
|
174
|
+
{"EFT_ALLOC", EFT_ALLOC},
|
|
175
|
+
{"EFT_REALLOC", EFT_REALLOC},
|
|
176
|
+
{"EFT_FREE", EFT_FREE},
|
|
177
|
+
{"EFT_FREE_MULTILEVEL", EFT_FREE_MULTILEVEL},
|
|
178
|
+
{"EFT_NOSTRUCT_ALLOC", EFT_NOSTRUCT_ALLOC},
|
|
179
|
+
{"EFT_STAT", EFT_STAT},
|
|
180
|
+
{"EFT_STAT2", EFT_STAT2},
|
|
181
|
+
{"EFT_L_A0", EFT_L_A0},
|
|
182
|
+
{"EFT_L_A1", EFT_L_A1},
|
|
183
|
+
{"EFT_L_A2", EFT_L_A2},
|
|
184
|
+
{"EFT_L_A8", EFT_L_A8},
|
|
185
|
+
{"EFT_L_A0__A0R_A1", EFT_L_A0__A0R_A1},
|
|
186
|
+
{"EFT_L_A0__A0R_A1R", EFT_L_A0__A0R_A1R},
|
|
187
|
+
{"EFT_L_A1__FunPtr", EFT_L_A1__FunPtr},
|
|
188
|
+
{"EFT_A1R_A0R", EFT_A1R_A0R},
|
|
189
|
+
{"EFT_A3R_A1R_NS", EFT_A3R_A1R_NS},
|
|
190
|
+
{"EFT_A1R_A0", EFT_A1R_A0},
|
|
191
|
+
{"EFT_A2R_A1", EFT_A2R_A1},
|
|
192
|
+
{"EFT_A4R_A1", EFT_A4R_A1},
|
|
193
|
+
{"EFT_L_A0__A2R_A0", EFT_L_A0__A2R_A0},
|
|
194
|
+
{"EFT_L_A0__A1_A0", EFT_L_A0__A1_A0},
|
|
195
|
+
{"EFT_A0R_NEW", EFT_A0R_NEW},
|
|
196
|
+
{"EFT_A1R_NEW", EFT_A1R_NEW},
|
|
197
|
+
{"EFT_A2R_NEW", EFT_A2R_NEW},
|
|
198
|
+
{"EFT_A4R_NEW", EFT_A4R_NEW},
|
|
199
|
+
{"EFT_A11R_NEW", EFT_A11R_NEW},
|
|
200
|
+
{"EFT_STD_RB_TREE_INSERT_AND_REBALANCE", EFT_STD_RB_TREE_INSERT_AND_REBALANCE},
|
|
201
|
+
{"EFT_STD_RB_TREE_INCREMENT", EFT_STD_RB_TREE_INCREMENT},
|
|
202
|
+
{"EFT_STD_LIST_HOOK", EFT_STD_LIST_HOOK},
|
|
203
|
+
{"CPP_EFT_A0R_A1R", CPP_EFT_A0R_A1R},
|
|
204
|
+
{"CPP_EFT_A1R", CPP_EFT_A1R},
|
|
205
|
+
{"EFT_CXA_BEGIN_CATCH", EFT_CXA_BEGIN_CATCH},
|
|
206
|
+
{"CPP_EFT_DYNAMIC_CAST", CPP_EFT_DYNAMIC_CAST},
|
|
207
|
+
{"", EFT_NULL}
|
|
208
|
+
};
|
|
107
209
|
|
|
108
|
-
|
|
109
|
-
|
|
210
|
+
static ExtAPI *extOp;
|
|
211
|
+
|
|
212
|
+
// Store specifications of external functions in ExtAPI.json file
|
|
213
|
+
static cJSON *root;
|
|
110
214
|
|
|
111
215
|
public:
|
|
216
|
+
static ExtAPI *getExtAPI();
|
|
112
217
|
|
|
113
|
-
|
|
114
|
-
static ExtAPI* getExtAPI()
|
|
115
|
-
{
|
|
116
|
-
if (extAPI == nullptr)
|
|
117
|
-
{
|
|
118
|
-
extAPI = new ExtAPI();
|
|
119
|
-
}
|
|
120
|
-
return extAPI;
|
|
121
|
-
}
|
|
218
|
+
static void destory();
|
|
122
219
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (extAPI != nullptr)
|
|
126
|
-
{
|
|
127
|
-
delete extAPI;
|
|
128
|
-
extAPI = nullptr;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
220
|
+
// Get the corresponding name in ext_t, e.g. "EXT_ADDR" in {"addr", EXT_ADDR},
|
|
221
|
+
extf_t get_opName(std::string s);
|
|
131
222
|
|
|
132
|
-
//Return the extf_t of (F).
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
assert(F);
|
|
136
|
-
std::string funName = F->getName();
|
|
137
|
-
if(F->isIntrinsic())
|
|
138
|
-
{
|
|
139
|
-
unsigned start = funName.find('.');
|
|
140
|
-
unsigned end = funName.substr(start + 1).find('.');
|
|
141
|
-
funName = "llvm." + funName.substr(start + 1, end);
|
|
142
|
-
}
|
|
143
|
-
Map<std::string, extf_t>::const_iterator it= info.find(funName);
|
|
144
|
-
if(it == info.end())
|
|
145
|
-
return EFT_OTHER;
|
|
146
|
-
else
|
|
147
|
-
return it->second;
|
|
148
|
-
}
|
|
223
|
+
// Return the extf_t of (F).
|
|
224
|
+
// Get external function name, e.g "memcpy"
|
|
225
|
+
std::string get_name(const SVFFunction *F);
|
|
149
226
|
|
|
150
|
-
//
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
extf_t t= get_type(F);
|
|
165
|
-
return t==EFT_ALLOC || t==EFT_NOSTRUCT_ALLOC;
|
|
166
|
-
}
|
|
167
|
-
//Does (F) allocate a new object and assign it to one of its arguments?
|
|
168
|
-
bool is_arg_alloc(const SVFFunction* F) const
|
|
169
|
-
{
|
|
170
|
-
extf_t t= get_type(F);
|
|
171
|
-
return t>=EFT_A0R_NEW && t<=EFT_A11R_NEW;
|
|
172
|
-
}
|
|
173
|
-
//Get the position of argument which holds the new object
|
|
174
|
-
int get_alloc_arg_pos(const SVFFunction* F) const
|
|
175
|
-
{
|
|
176
|
-
extf_t t= get_type(F);
|
|
177
|
-
switch(t)
|
|
178
|
-
{
|
|
179
|
-
case EFT_A0R_NEW:
|
|
180
|
-
return 0;
|
|
181
|
-
case EFT_A1R_NEW:
|
|
182
|
-
return 1;
|
|
183
|
-
case EFT_A2R_NEW:
|
|
184
|
-
return 2;
|
|
185
|
-
case EFT_A4R_NEW:
|
|
186
|
-
return 4;
|
|
187
|
-
case EFT_A11R_NEW:
|
|
188
|
-
return 11;
|
|
189
|
-
default:
|
|
190
|
-
assert(false && "Not an alloc call via argument.");
|
|
191
|
-
return -1;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
//Does (F) allocate only non-struct objects?
|
|
195
|
-
bool no_struct_alloc(const SVFFunction* F) const
|
|
196
|
-
{
|
|
197
|
-
return get_type(F) == EFT_NOSTRUCT_ALLOC;
|
|
198
|
-
}
|
|
199
|
-
//Does (F) not free/release any memory?
|
|
200
|
-
bool is_dealloc(const SVFFunction* F) const
|
|
201
|
-
{
|
|
202
|
-
extf_t t= get_type(F);
|
|
203
|
-
return t == EFT_FREE;
|
|
204
|
-
}
|
|
205
|
-
//Does (F) not do anything with the known pointers?
|
|
206
|
-
bool is_noop(const SVFFunction* F) const
|
|
207
|
-
{
|
|
208
|
-
extf_t t= get_type(F);
|
|
209
|
-
return t == EFT_NOOP || t == EFT_FREE;
|
|
210
|
-
}
|
|
211
|
-
//Does (F) reallocate a new object?
|
|
212
|
-
bool is_realloc(const SVFFunction* F) const
|
|
213
|
-
{
|
|
214
|
-
extf_t t= get_type(F);
|
|
215
|
-
return t==EFT_REALLOC;
|
|
216
|
-
}
|
|
217
|
-
//Should (F) be considered "external" (either not defined in the program
|
|
218
|
-
// or a user-defined version of a known alloc or no-op)?
|
|
219
|
-
bool is_ext(const SVFFunction* F)
|
|
220
|
-
{
|
|
221
|
-
assert(F);
|
|
222
|
-
//Check the cache first; everything below is slower.
|
|
223
|
-
Map<const SVFFunction*, bool>::iterator i_iec= isext_cache.find(F);
|
|
224
|
-
if(i_iec != isext_cache.end())
|
|
225
|
-
return i_iec->second;
|
|
226
|
-
|
|
227
|
-
bool res;
|
|
228
|
-
if(F->isDeclaration() || F->isIntrinsic())
|
|
229
|
-
{
|
|
230
|
-
res= 1;
|
|
231
|
-
}
|
|
232
|
-
else
|
|
233
|
-
{
|
|
234
|
-
extf_t t= get_type(F);
|
|
235
|
-
res= t==EFT_ALLOC || t==EFT_REALLOC || t==EFT_NOSTRUCT_ALLOC
|
|
236
|
-
|| t==EFT_NOOP || t==EFT_FREE;
|
|
237
|
-
}
|
|
238
|
-
isext_cache[F]= res;
|
|
239
|
-
return res;
|
|
240
|
-
}
|
|
241
|
-
};
|
|
227
|
+
// Get arguments of the operation, e.g. ["A1R", "A0", "A2"]
|
|
228
|
+
std::vector<std::string> get_opArgs(const cJSON *value);
|
|
229
|
+
|
|
230
|
+
// Get specifications of external functions in ExtAPI.json file
|
|
231
|
+
cJSON *get_FunJson(const std::string funName);
|
|
232
|
+
|
|
233
|
+
// Get property of the operation, e.g. "EFT_A1R_A0R"
|
|
234
|
+
extType get_type(const SVF::SVFFunction *callee);
|
|
235
|
+
|
|
236
|
+
// Does (F) have a static var X (unavailable to us) that its return points to?
|
|
237
|
+
bool has_static(const SVFFunction *F);
|
|
238
|
+
|
|
239
|
+
// Assuming hasStatic(F), does (F) have a second static Y where X -> Y?
|
|
240
|
+
bool has_static2(const SVFFunction *F);
|
|
242
241
|
|
|
242
|
+
// Does (F) allocate a new object and return it?
|
|
243
|
+
bool is_alloc(const SVFFunction *F);
|
|
244
|
+
|
|
245
|
+
// Does (F) allocate a new object and assign it to one of its arguments?
|
|
246
|
+
bool is_arg_alloc(const SVFFunction *F);
|
|
247
|
+
|
|
248
|
+
// Get the position of argument which holds the new object
|
|
249
|
+
s32_t get_alloc_arg_pos(const SVFFunction *F);
|
|
250
|
+
|
|
251
|
+
// Does (F) allocate only non-struct objects?
|
|
252
|
+
bool no_struct_alloc(const SVFFunction *F);
|
|
253
|
+
|
|
254
|
+
// Does (F) not free/release any memory?
|
|
255
|
+
bool is_dealloc(const SVFFunction *F);
|
|
256
|
+
|
|
257
|
+
// Does (F) not do anything with the known pointers?
|
|
258
|
+
bool is_noop(const SVFFunction *F);
|
|
259
|
+
|
|
260
|
+
// Does (F) reallocate a new object?
|
|
261
|
+
bool is_realloc(const SVFFunction *F);
|
|
262
|
+
|
|
263
|
+
// Should (F) be considered "external" (either not defined in the program
|
|
264
|
+
// or a user-defined version of a known alloc or no-op)?
|
|
265
|
+
bool is_ext(const SVFFunction *F);
|
|
266
|
+
};
|
|
243
267
|
} // End namespace SVF
|
|
244
268
|
|
|
245
|
-
#endif
|
|
269
|
+
#endif
|
|
@@ -405,12 +405,6 @@ inline bool isStaticExtFun(const SVFFunction* fun)
|
|
|
405
405
|
return fun && ExtAPI::getExtAPI()->has_static(fun);
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
/// Return external call type
|
|
409
|
-
inline ExtAPI::extf_t extCallTy(const SVFFunction* fun)
|
|
410
|
-
{
|
|
411
|
-
return ExtAPI::getExtAPI()->get_type(fun);
|
|
412
|
-
}
|
|
413
|
-
|
|
414
408
|
/// Program entry function e.g. main
|
|
415
409
|
//@{
|
|
416
410
|
/// Return true if this is a program entry function (e.g. main)
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//===- SymState.h -- Symbolic State----------------------------//
|
|
2
|
+
//
|
|
3
|
+
// SVF: Static Value-Flow Analysis
|
|
4
|
+
//
|
|
5
|
+
// Copyright (C) <2013-2017> <Yulei Sui>
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
// This program is free software: you can redistribute it and/or modify
|
|
9
|
+
// it under the terms of the GNU General Public License as published by
|
|
10
|
+
// the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
// (at your option) any later version.
|
|
12
|
+
|
|
13
|
+
// This program is distributed in the hope that it will be useful,
|
|
14
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
// GNU General Public License for more details.
|
|
17
|
+
|
|
18
|
+
// You should have received a copy of the GNU General Public License
|
|
19
|
+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
//
|
|
21
|
+
//===----------------------------------------------------------------------===//
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* SymState.h
|
|
25
|
+
*
|
|
26
|
+
* Created on: 2022/6/21
|
|
27
|
+
* Author: Xiao Cheng
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef SVF_SYMSTATE_H
|
|
31
|
+
#define SVF_SYMSTATE_H
|
|
32
|
+
|
|
33
|
+
#include "ExeState.h"
|
|
34
|
+
|
|
35
|
+
namespace SVF
|
|
36
|
+
{
|
|
37
|
+
class SymState
|
|
38
|
+
{
|
|
39
|
+
public:
|
|
40
|
+
typedef std::string AbstractState;
|
|
41
|
+
|
|
42
|
+
SymState(const ExeState &_es, const AbstractState &_as) : exeState(_es), absState(_as)
|
|
43
|
+
{
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
virtual ~SymState()
|
|
48
|
+
{
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
SymState(const SymState &symState) : absState(symState.getAbstractState()),
|
|
53
|
+
exeState(symState.getExecutionState())
|
|
54
|
+
{
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
const AbstractState& getAbstractState() const
|
|
59
|
+
{
|
|
60
|
+
return absState;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const ExeState& getExecutionState() const
|
|
64
|
+
{
|
|
65
|
+
return exeState;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
SymState &operator=(const SymState &rhs)
|
|
69
|
+
{
|
|
70
|
+
if (*this != rhs)
|
|
71
|
+
{
|
|
72
|
+
exeState = rhs.getExecutionState();
|
|
73
|
+
absState = rhs.getAbstractState();
|
|
74
|
+
}
|
|
75
|
+
return *this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// Overloading Operator==
|
|
79
|
+
inline bool operator==(const SymState &rhs) const
|
|
80
|
+
{
|
|
81
|
+
return absState == rhs.getAbstractState() && exeState = rhs.getExecutionState();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// Overloading Operator!=
|
|
85
|
+
inline bool operator!=(const SymState &rhs) const
|
|
86
|
+
{
|
|
87
|
+
return !(*this == rhs);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// Overloading Operator==
|
|
91
|
+
inline bool operator<(const SymState &rhs) const
|
|
92
|
+
{
|
|
93
|
+
if (absState != rhs.getAbstractState())
|
|
94
|
+
return absState < rhs.getAbstractState();
|
|
95
|
+
if (exeState != rhs.getExecutionState())
|
|
96
|
+
return exeState < rhs.getExecutionState();
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private:
|
|
101
|
+
ExeState exeState;
|
|
102
|
+
AbstractState absState;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
template<>
|
|
107
|
+
struct std::hash<SVF::SymState>
|
|
108
|
+
{
|
|
109
|
+
size_t operator()(const SVF::SymState &symState) const
|
|
110
|
+
{
|
|
111
|
+
|
|
112
|
+
SVF::Hash<std::pair<SVF::AbstractState, SVF::ExeState>> pairH;
|
|
113
|
+
|
|
114
|
+
return pairH(make_pair(symState.getAbstractState(), symState.getExecutionState()));
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
#endif //SVF_SYMSTATE_H
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#ifndef cJSON__h
|
|
24
|
+
#define cJSON__h
|
|
25
|
+
|
|
26
|
+
#ifdef __cplusplus
|
|
27
|
+
extern "C"
|
|
28
|
+
{
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
|
32
|
+
#define __WINDOWS__
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#ifdef __WINDOWS__
|
|
36
|
+
|
|
37
|
+
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
|
38
|
+
|
|
39
|
+
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
|
40
|
+
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
|
41
|
+
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
|
42
|
+
|
|
43
|
+
For *nix builds that support visibility attribute, you can define similar behavior by
|
|
44
|
+
|
|
45
|
+
setting default visibility to hidden by adding
|
|
46
|
+
-fvisibility=hidden (for gcc)
|
|
47
|
+
or
|
|
48
|
+
-xldscope=hidden (for sun cc)
|
|
49
|
+
to CFLAGS
|
|
50
|
+
|
|
51
|
+
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
|
52
|
+
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
#define CJSON_CDECL __cdecl
|
|
56
|
+
#define CJSON_STDCALL __stdcall
|
|
57
|
+
|
|
58
|
+
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
|
59
|
+
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
|
60
|
+
#define CJSON_EXPORT_SYMBOLS
|
|
61
|
+
#endif
|
|
62
|
+
|
|
63
|
+
#if defined(CJSON_HIDE_SYMBOLS)
|
|
64
|
+
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
|
65
|
+
#elif defined(CJSON_EXPORT_SYMBOLS)
|
|
66
|
+
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
|
67
|
+
#elif defined(CJSON_IMPORT_SYMBOLS)
|
|
68
|
+
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
|
69
|
+
#endif
|
|
70
|
+
#else /* !__WINDOWS__ */
|
|
71
|
+
#define CJSON_CDECL
|
|
72
|
+
#define CJSON_STDCALL
|
|
73
|
+
|
|
74
|
+
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
|
75
|
+
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
|
76
|
+
#else
|
|
77
|
+
#define CJSON_PUBLIC(type) type
|
|
78
|
+
#endif
|
|
79
|
+
#endif
|
|
80
|
+
|
|
81
|
+
/* project version */
|
|
82
|
+
#define CJSON_VERSION_MAJOR 1
|
|
83
|
+
#define CJSON_VERSION_MINOR 7
|
|
84
|
+
#define CJSON_VERSION_PATCH 15
|
|
85
|
+
|
|
86
|
+
#include <stddef.h>
|
|
87
|
+
|
|
88
|
+
/* cJSON Types: */
|
|
89
|
+
#define cJSON_Invalid (0)
|
|
90
|
+
#define cJSON_False (1 << 0)
|
|
91
|
+
#define cJSON_True (1 << 1)
|
|
92
|
+
#define cJSON_NULL (1 << 2)
|
|
93
|
+
#define cJSON_Number (1 << 3)
|
|
94
|
+
#define cJSON_String (1 << 4)
|
|
95
|
+
#define cJSON_Array (1 << 5)
|
|
96
|
+
#define cJSON_Object (1 << 6)
|
|
97
|
+
#define cJSON_Raw (1 << 7) /* raw json */
|
|
98
|
+
|
|
99
|
+
#define cJSON_IsReference 256
|
|
100
|
+
#define cJSON_StringIsConst 512
|
|
101
|
+
|
|
102
|
+
/* The cJSON structure: */
|
|
103
|
+
typedef struct cJSON
|
|
104
|
+
{
|
|
105
|
+
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
|
106
|
+
struct cJSON *next;
|
|
107
|
+
struct cJSON *prev;
|
|
108
|
+
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
|
109
|
+
struct cJSON *child;
|
|
110
|
+
|
|
111
|
+
/* The type of the item, as above. */
|
|
112
|
+
int type;
|
|
113
|
+
|
|
114
|
+
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
|
115
|
+
char *valuestring;
|
|
116
|
+
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
|
117
|
+
int valueint;
|
|
118
|
+
/* The item's number, if type==cJSON_Number */
|
|
119
|
+
double valuedouble;
|
|
120
|
+
|
|
121
|
+
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
|
122
|
+
char *string;
|
|
123
|
+
} cJSON;
|
|
124
|
+
|
|
125
|
+
typedef struct cJSON_Hooks
|
|
126
|
+
{
|
|
127
|
+
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
|
128
|
+
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
|
129
|
+
void (CJSON_CDECL *free_fn)(void *ptr);
|
|
130
|
+
} cJSON_Hooks;
|
|
131
|
+
|
|
132
|
+
typedef int cJSON_bool;
|
|
133
|
+
|
|
134
|
+
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
|
135
|
+
* This is to prevent stack overflows. */
|
|
136
|
+
#ifndef CJSON_NESTING_LIMIT
|
|
137
|
+
#define CJSON_NESTING_LIMIT 1000
|
|
138
|
+
#endif
|
|
139
|
+
|
|
140
|
+
/* returns the version of cJSON as a string */
|
|
141
|
+
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
|
142
|
+
|
|
143
|
+
/* Supply malloc, realloc and free functions to cJSON */
|
|
144
|
+
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
|
145
|
+
|
|
146
|
+
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
|
147
|
+
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
|
148
|
+
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
|
149
|
+
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
|
150
|
+
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
|
151
|
+
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
|
152
|
+
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
|
153
|
+
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
|
154
|
+
|
|
155
|
+
/* Render a cJSON entity to text for transfer/storage. */
|
|
156
|
+
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
|
157
|
+
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
|
158
|
+
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
|
159
|
+
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
|
160
|
+
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
|
161
|
+
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
|
162
|
+
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
|
163
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
|
164
|
+
/* Delete a cJSON entity and all subentities. */
|
|
165
|
+
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
|
166
|
+
|
|
167
|
+
/* Returns the number of items in an array (or object). */
|
|
168
|
+
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
|
169
|
+
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
|
170
|
+
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
|
171
|
+
/* Get item "string" from object. Case insensitive. */
|
|
172
|
+
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
|
173
|
+
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
|
174
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
|
175
|
+
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
|
176
|
+
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
|
177
|
+
|
|
178
|
+
/* Check item type and return its value */
|
|
179
|
+
CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item);
|
|
180
|
+
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item);
|
|
181
|
+
|
|
182
|
+
/* These functions check the type of an item */
|
|
183
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
|
184
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
|
185
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
|
186
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
|
187
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
|
188
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
|
189
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
|
190
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
|
191
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
|
192
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
|
193
|
+
|
|
194
|
+
/* These calls create a cJSON item of the appropriate type. */
|
|
195
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
|
196
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
|
197
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
|
198
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
|
199
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
|
200
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
|
201
|
+
/* raw json */
|
|
202
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
|
203
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
|
204
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
|
205
|
+
|
|
206
|
+
/* Create a string where valuestring references a string so
|
|
207
|
+
* it will not be freed by cJSON_Delete */
|
|
208
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
|
209
|
+
/* Create an object/array that only references it's elements so
|
|
210
|
+
* they will not be freed by cJSON_Delete */
|
|
211
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
|
212
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
|
213
|
+
|
|
214
|
+
/* These utilities create an Array of count items.
|
|
215
|
+
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
|
216
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
|
217
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
|
218
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
|
219
|
+
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
|
220
|
+
|
|
221
|
+
/* Append item to the specified array/object. */
|
|
222
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
|
223
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
|
224
|
+
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
|
225
|
+
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
|
226
|
+
* writing to `item->string` */
|
|
227
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
|
228
|
+
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
|
229
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
|
230
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
|
231
|
+
|
|
232
|
+
/* Remove/Detach items from Arrays/Objects. */
|
|
233
|
+
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
|
234
|
+
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
|
235
|
+
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
|
236
|
+
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
|
237
|
+
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
|
238
|
+
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
|
239
|
+
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
|
240
|
+
|
|
241
|
+
/* Update array items. */
|
|
242
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
|
243
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
|
244
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
|
245
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
|
246
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
|
247
|
+
|
|
248
|
+
/* Duplicate a cJSON item */
|
|
249
|
+
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
|
250
|
+
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
|
251
|
+
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
|
252
|
+
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
|
253
|
+
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
|
254
|
+
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
|
255
|
+
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
|
256
|
+
|
|
257
|
+
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
|
258
|
+
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
|
259
|
+
* but should point to a readable and writable address area. */
|
|
260
|
+
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
|
261
|
+
|
|
262
|
+
/* Helper functions for creating and adding items to an object at the same time.
|
|
263
|
+
* They return the added item or NULL on failure. */
|
|
264
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
|
265
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
|
266
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
|
267
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
|
268
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
|
269
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
|
270
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
|
271
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
|
272
|
+
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
|
273
|
+
|
|
274
|
+
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
|
275
|
+
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
|
276
|
+
/* helper for the cJSON_SetNumberValue macro */
|
|
277
|
+
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
|
278
|
+
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
|
279
|
+
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
|
280
|
+
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
|
281
|
+
|
|
282
|
+
/* If the object is not a boolean type this does nothing and returns cJSON_Invalid else it returns the new type*/
|
|
283
|
+
#define cJSON_SetBoolValue(object, boolValue) ( \
|
|
284
|
+
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
|
285
|
+
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
|
286
|
+
cJSON_Invalid\
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
/* Macro for iterating over an array or object */
|
|
290
|
+
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
|
291
|
+
|
|
292
|
+
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
|
293
|
+
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
|
294
|
+
CJSON_PUBLIC(void) cJSON_free(void *object);
|
|
295
|
+
|
|
296
|
+
#ifdef __cplusplus
|
|
297
|
+
}
|
|
298
|
+
#endif
|
|
299
|
+
|
|
300
|
+
#endif
|