-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathida_settings.cpp
78 lines (71 loc) · 1.27 KB
/
ida_settings.cpp
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
#pragma once
#include "ida_settings.h"
#include <fstream>
#include <pro.h>
CIDASettings::CIDASettings()
{
if(resolveHomePath())
{
LoadJson();
}
}
bool CIDASettings::isLoaded()
{
return _isLoaded;
}
bool CIDASettings::resolveHomePath()
{
qstring qhome_path;
#ifdef __UNIX__
if(qgetenv("HOME", &qhome_path))
{
configpath = std::string(qhome_path.c_str()) + "/.idapro/ps4nidconfig.json";
return true;
}
#elif defined(_WIN32)
if(qgetenv("APPDATA", &qhome_path))
{
configpath = std::string(qhome_path.c_str()) + "/Hex-Rays/IDA Pro/ps4nidconfig.json";
return true;
}
#else
#error unsupported platform
#endif
return false;
}
void CIDASettings::Save()
{
std::ofstream config_doc(configpath.c_str() , std::ofstream::out);
config_doc << root << std::endl;
config_doc.close();
}
void CIDASettings::LoadJson()
{
std::ifstream config_doc(configpath.c_str(), std::ifstream::binary);
if(config_doc.is_open())
{
config_doc >> root;
config_doc.close();
_isLoaded = true;
}
else
{
_isLoaded = false;
}
}
std::string CIDASettings::getAsString(char* name)
{
if(isLoaded())
{
return root.get(name, "").asString();
}
return "";
}
bool CIDASettings::getAsBool(char* name, bool defVal)
{
if(isLoaded())
{
return root.get(name, defVal).asBool();
}
return defVal;
}