svf-tools 1.0.704 → 1.0.706

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svf-tools",
3
- "version": "1.0.704",
3
+ "version": "1.0.706",
4
4
  "description": "* <b>[TypeClone](https://github.com/SVF-tools/SVF/wiki/TypeClone) published in our [ECOOP paper](https://yuleisui.github.io/publications/ecoop20.pdf) is now available in SVF </b> * <b>SVF now uses a single script for its build. Just type [`source ./build.sh`](https://github.com/SVF-tools/SVF/blob/master/build.sh) in your terminal, that's it!</b> * <b>SVF now supports LLVM-10.0.0! </b> * <b>We thank [bsauce](https://github.com/bsauce) for writing a user manual of SVF ([link1](https://www.jianshu.com/p/068a08ec749c) and [link2](https://www.jianshu.com/p/777c30d4240e)) in Chinese </b> * <b>SVF now supports LLVM-9.0.0 (Thank [Byoungyoung Lee](https://github.com/SVF-tools/SVF/issues/142) for his help!). </b> * <b>SVF now supports a set of [field-sensitive pointer analyses](https://yuleisui.github.io/publications/sas2019a.pdf). </b> * <b>[Use SVF as an external lib](https://github.com/SVF-tools/SVF/wiki/Using-SVF-as-a-lib-in-your-own-tool) for your own project (Contributed by [Hongxu Chen](https://github.com/HongxuChen)). </b> * <b>SVF now supports LLVM-7.0.0. </b> * <b>SVF now supports Docker. [Try SVF in Docker](https://github.com/SVF-tools/SVF/wiki/Try-SVF-in-Docker)! </b> * <b>SVF now supports [LLVM-6.0.0](https://github.com/svf-tools/SVF/pull/38) (Contributed by [Jack Anthony](https://github.com/jackanth)). </b> * <b>SVF now supports [LLVM-4.0.0](https://github.com/svf-tools/SVF/pull/23) (Contributed by Jared Carlson. Thank [Jared](https://github.com/jcarlson23) and [Will](https://github.com/dtzWill) for their in-depth [discussions](https://github.com/svf-tools/SVF/pull/18) about updating SVF!) </b> * <b>SVF now supports analysis for C++ programs.</b> <br />",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,8 +31,8 @@
31
31
  #define __ExtAPI_H
32
32
 
33
33
  #include "SVFIR/SVFValue.h"
34
- #include "Util/cJSON.h"
35
- #include "Util/config.h"
34
+ #include <Util/cJSON.h>
35
+ #include <Util/config.h>
36
36
  #include <string>
37
37
  #include <map>
38
38
 
@@ -261,7 +261,9 @@ public:
261
261
  static void destory();
262
262
 
263
263
  // Add an entry with the specified fields to the ExtAPI, which will be reflected immediately by further ExtAPI queries
264
- void add_entry(const char* funName, extType type, bool overwrite_app_function);
264
+ void add_entry(const char* funName, const char* returnType,
265
+ std::vector<const char*> argTypes, extType type,
266
+ bool overwrite_app_function);
265
267
 
266
268
  // Get numeric index of the argument in external function
267
269
  u32_t getArgPos(const std::string& s);
@@ -299,6 +301,9 @@ public:
299
301
  // 0: Apply user-defined functions
300
302
  // 1: Apply function specification in ExtAPI.json
301
303
  u32_t isOverwrittenAppFunction(const SVF::SVFFunction *callee);
304
+ u32_t isOverwrittenAppFunction(const std::string& funcName);
305
+ // set priority of the function
306
+ void setOverWrittenAppFunction(const std::string& funcName, u32_t overwrite_app_function);
302
307
 
303
308
  // Does (F) have a static var X (unavailable to us) that its return points to?
304
309
  bool has_static(const SVFFunction *F);
@@ -185,13 +185,30 @@ void ExtAPI::destory()
185
185
  }
186
186
  }
187
187
 
188
- void ExtAPI::add_entry(const char* funName, extType type,
188
+ void ExtAPI::add_entry(const char* funName, const char* returnType,
189
+ std::vector<const char*> argTypes, extType type,
189
190
  bool overwrite_app_function)
190
191
  {
191
- assert(root);
192
- assert(get_type(funName) == EFT_NULL);
192
+ assert(root && "Parse the json before adding additional entries");
193
+ assert(get_type(funName) == EFT_NULL && "Do not add entries that already exist");
193
194
  auto entry = cJSON_CreateObject();
194
195
 
196
+ // add the signature fields
197
+ auto returnTypeString = cJSON_CreateString(returnType);
198
+ cJSON_AddItemToObject(entry, "return", returnTypeString);
199
+
200
+ std::stringstream ss;
201
+ ss << "(";
202
+ for (auto str : argTypes)
203
+ ss << str << ",";
204
+ std::string formattedArgs = ss.str();
205
+ if (formattedArgs.back() == ',')
206
+ formattedArgs.back() = ')';
207
+ else
208
+ formattedArgs.append(")");
209
+ auto argsString = cJSON_CreateString(formattedArgs.c_str());
210
+ cJSON_AddItemToObject(entry, "argument", argsString);
211
+
195
212
  // add the type field
196
213
  auto typeString = cJSON_CreateString(extType_toString(type).c_str());
197
214
  cJSON_AddItemToObject(entry, JSON_OPT_FUNCTIONTYPE, typeString);
@@ -200,8 +217,8 @@ void ExtAPI::add_entry(const char* funName, extType type,
200
217
  auto overwriteBool = cJSON_CreateNumber(overwrite_app_function ? 1 : 0);
201
218
  cJSON_AddItemToObject(entry, JSON_OPT_OVERWRITE, overwriteBool);
202
219
 
203
- // we don't know where the `funName` comes from, so copy it just in case
204
- cJSON_AddItemToObject(root, strdup(funName), entry);
220
+ // add object to root
221
+ cJSON_AddItemToObject(root, funName, entry);
205
222
  }
206
223
 
207
224
  // Get the corresponding name in ext_t, e.g. "EXT_ADDR" in {"addr", EXT_ADDR},
@@ -416,6 +433,11 @@ ExtAPI::extType ExtAPI::get_type(const SVF::SVFFunction* F)
416
433
  u32_t ExtAPI::isOverwrittenAppFunction(const SVF::SVFFunction* callee)
417
434
  {
418
435
  std::string funName = get_name(callee);
436
+ return isOverwrittenAppFunction(funName);
437
+ }
438
+
439
+ u32_t ExtAPI::isOverwrittenAppFunction(const std::string& funName)
440
+ {
419
441
  cJSON* item = get_FunJson(funName);
420
442
  if (item != nullptr)
421
443
  {
@@ -429,6 +451,16 @@ u32_t ExtAPI::isOverwrittenAppFunction(const SVF::SVFFunction* callee)
429
451
  return 0;
430
452
  }
431
453
 
454
+ void ExtAPI::setOverWrittenAppFunction(const std::string& funcName, u32_t overwrite_app_function)
455
+ {
456
+ auto item = get_FunJson(funcName);
457
+ assert(item && "Do not set fields for ExtAPI funcs that don't exist!");
458
+ auto overwrite_obj = item->child->next->next->next;
459
+ assert(overwrite_obj);
460
+ assert(strcmp(overwrite_obj->string, JSON_OPT_OVERWRITE) == 0);
461
+ cJSON_SetIntValue(overwrite_obj, overwrite_app_function);
462
+ }
463
+
432
464
  // Does (F) have a static var X (unavailable to us) that its return points to?
433
465
  bool ExtAPI::has_static(const SVFFunction* F)
434
466
  {
@@ -1224,6 +1224,7 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1224
1224
  else
1225
1225
  {
1226
1226
  s32_t nodeIDType = ExtAPI::getExtAPI()->getNodeIDType(s);
1227
+ // return value >= 0 is an argument node
1227
1228
  if (nodeIDType >= 0)
1228
1229
  {
1229
1230
  if( svfcall->arg_size() <= (u32_t) nodeIDType)
@@ -1239,29 +1240,41 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1239
1240
  nodeIDMap[s] = pag->getValueNode(svfcall->getArgOperand(nodeIDType));
1240
1241
  }
1241
1242
  }
1243
+ // return value = -1 is an inst node
1242
1244
  else if (nodeIDType == -1)
1243
1245
  {
1244
1246
  operands.push_back(pag->getValueNode(svfcall));
1245
1247
  nodeIDMap[s] = pag->getValueNode(svfcall);
1246
1248
  }
1249
+ // return value = -2 is a Dummy node
1247
1250
  else if (nodeIDType == -2)
1248
1251
  {
1249
1252
  operands.push_back(pag->addDummyValNode());
1250
1253
  nodeIDMap[s] = operands[operands.size() - 1];
1251
1254
  }
1255
+ // return value = -3 is an object node
1252
1256
  else if (nodeIDType == -3)
1253
1257
  {
1254
1258
  if (svfcall->getType()->isPointerTy())
1255
1259
  {
1256
- operands.push_back(pag->getObjectNode(svfcall));
1257
- nodeIDMap[s] = pag->getObjectNode(svfcall);
1260
+ NodeID objId;
1261
+ // Indirect call
1262
+ if (getCallee(svfcall) == nullptr)
1263
+ objId = pag->addDummyObjNode(svfcall->getType());
1264
+ else // Direct call
1265
+ objId = pag->getObjectNode(svfcall);
1266
+
1267
+ operands.push_back(objId);
1268
+ nodeIDMap[s] = objId;
1258
1269
  }
1259
1270
  }
1271
+ // return value = -4 is a nullptr node
1260
1272
  else if (nodeIDType == -4)
1261
1273
  {
1262
1274
  operands.push_back(pag->getNullPtr());
1263
1275
  nodeIDMap[s] = operands[operands.size() - 1];
1264
1276
  }
1277
+ // return value = -5 is an offset
1265
1278
  else if (nodeIDType == -5)
1266
1279
  {
1267
1280
  for (char const &c : s)
@@ -1272,6 +1285,7 @@ void SVFIRBuilder::parseOperations(std::vector<ExtAPI::Operation> &operations,
1272
1285
  operands.push_back(atoi(s.c_str()));
1273
1286
  nodeIDMap[s] = atoi(s.c_str());
1274
1287
  }
1288
+ // return value = -6 is an illegal operand format
1275
1289
  else
1276
1290
  assert(false && "The operand format of function operation is illegal!");
1277
1291
  }