JSON::JSON() : _json(NULL) { if (!initialized) { json_set_alloc_funcs(jsonAlloc, jsonFree); initialized = true; } }
static void * json_open(uschar *filename, uschar **errmsg) { FILE * f; json_set_alloc_funcs(json_malloc, json_free); if (!(f = Ufopen(filename, "rb"))) { int save_errno = errno; *errmsg = string_open_failed(errno, "%s for json search", filename); errno = save_errno; return NULL; } return f; }
DrachtioController::DrachtioController( int argc, char* argv[] ) : m_bDaemonize(false), m_bLoggingInitialized(false), m_configFilename(DEFAULT_CONFIG_FILENAME) { if( !parseCmdArgs( argc, argv ) ) { usage() ; exit(-1) ; } m_Config = boost::make_shared<DrachtioConfig>( m_configFilename.c_str() ) ; if( !m_Config->isValid() ) { exit(-1) ; } this->installConfig() ; #ifdef DEBUG json_set_alloc_funcs(my_json_malloc, my_json_free); #endif }
void sqlbox_configure_redis(Cfg* cfg) { CfgGroup *grp; Octstr *sql; if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: Redis: group 'sqlbox' is not specified!"); sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table")); if (sqlbox_logtable == NULL) { panic(0, "'sql-log-table' is not configured in the group 'sqlbox'."); } sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table")); if (sqlbox_insert_table == NULL) { panic(0, "'sql-insert-table' is not configured in the group 'sqlbox'."); } sqlbox_inflight_table = cfg_get(grp, octstr_imm("sql-inflight-table")); json_set_alloc_funcs(gw_malloc_json, gw_free_json); /* no need to create tables on redis */ }
static void test_chaos() { json_malloc_t orig_malloc; json_free_t orig_free; json_t *json = NULL; json_t *obj = json_object(); json_t *arr1 = json_array(); json_t *arr2 = json_array(); json_t *txt = json_string("test"); json_t *intnum = json_integer(1); json_t *dblnum = json_real(0.5); char *dumptxt = NULL; json_t *dumpobj = json_pack("{s:[iiis], s:s}", "key1", 1, 2, 3, "txt", "key2", "v2"); int keyno; if (!obj || !arr1 || !arr2 || !txt || !intnum || !dblnum || !dumpobj) fail("failed to allocate basic objects"); json_get_alloc_funcs(&orig_malloc, &orig_free); json_set_alloc_funcs(chaos_malloc, chaos_free); chaos_loop_new_value(json, json_pack("{s:s}", "key", "value")); chaos_loop_new_value(json, json_pack("{s:[]}", "key")); chaos_loop_new_value(json, json_pack("[biIf]", 1, 1, (json_int_t)1, 1.0)); chaos_loop_new_value(json, json_pack("[s*,s*]", "v1", "v2")); chaos_loop_new_value(json, json_pack("o", json_incref(txt))); chaos_loop_new_value(json, json_pack("O", txt)); chaos_loop_new_value(json, json_pack("s++", "a", "long string to force realloc", "another long string to force yet another reallocation of the string because " "that's what we are testing.")); chaos_loop(test_unpack(),,); chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1)),,); chaos_loop(json_dump_callback(dumpobj, dump_chaos_callback, NULL, JSON_INDENT(1) | JSON_SORT_KEYS),,); chaos_loop(!dumptxt, dumptxt = json_dumps(dumpobj, JSON_COMPACT);, free(dumptxt); dumptxt = NULL;);
void Json::init() { json_set_alloc_funcs( sized_malloc, sized_free ); }
void sqon_init (void) { json_set_alloc_funcs (sqon_malloc, sqon_free); }
extern "C" DLL_EXPORT const char* _dbg_dbginit() { if(!EngineCheckStructAlignment(UE_STRUCT_TITAN_ENGINE_CONTEXT, sizeof(TITAN_ENGINE_CONTEXT_t))) return "Invalid TITAN_ENGINE_CONTEXT_t alignment!"; if(sizeof(TITAN_ENGINE_CONTEXT_t) != sizeof(REGISTERCONTEXT)) return "Invalid REGISTERCONTEXT alignment!"; dputs("Initializing wait objects..."); waitinitialize(); dputs("Initializing debugger..."); dbginit(); dputs("Initializing debugger functions..."); dbgfunctionsinit(); dputs("Setting JSON memory management functions..."); json_set_alloc_funcs(json_malloc, json_free); dputs("Initializing capstone..."); Capstone::GlobalInitialize(); dputs("Initializing Yara..."); if(yr_initialize() != ERROR_SUCCESS) return "Failed to initialize Yara!"; dputs("Getting directory information..."); wchar_t wszDir[deflen] = L""; if(!GetModuleFileNameW(hInst, wszDir, deflen)) return "GetModuleFileNameW failed!"; char dir[deflen] = ""; strcpy_s(dir, StringUtils::Utf16ToUtf8(wszDir).c_str()); int len = (int)strlen(dir); while(dir[len] != '\\') len--; dir[len] = 0; strcpy_s(alloctrace, dir); strcat_s(alloctrace, "\\alloctrace.txt"); DeleteFileW(StringUtils::Utf8ToUtf16(alloctrace).c_str()); setalloctrace(alloctrace); strcpy_s(dbbasepath, dir); //debug directory strcat_s(dbbasepath, "\\db"); CreateDirectoryW(StringUtils::Utf8ToUtf16(dbbasepath).c_str(), 0); //create database directory char szLocalSymbolPath[MAX_PATH] = ""; strcpy_s(szLocalSymbolPath, dir); strcat_s(szLocalSymbolPath, "\\symbols"); char cachePath[MAX_SETTING_SIZE]; if(!BridgeSettingGet("Symbols", "CachePath", cachePath) || !*cachePath) { strcpy_s(szSymbolCachePath, szLocalSymbolPath); BridgeSettingSet("Symbols", "CachePath", ".\\symbols"); } else { if (_strnicmp(cachePath, ".\\", 2) == 0) { strncpy_s(szSymbolCachePath, dir, _TRUNCATE); strncat_s(szSymbolCachePath, cachePath + 1, _TRUNCATE); } else { // Trim the buffer to fit inside MAX_PATH strncpy_s(szSymbolCachePath, cachePath, _TRUNCATE); } if(strstr(szSymbolCachePath, "http://") || strstr(szSymbolCachePath, "https://")) { if(Script::Gui::MessageYesNo("It is strongly discouraged to use symbol servers in your path directly (use the store option instead).\n\nDo you want me to fix this?")) { strcpy_s(szSymbolCachePath, szLocalSymbolPath); BridgeSettingSet("Symbols", "CachePath", ".\\symbols"); } } } dputs(szSymbolCachePath); SetCurrentDirectoryW(StringUtils::Utf8ToUtf16(dir).c_str()); dputs("Allocating message stack..."); gMsgStack = MsgAllocStack(); if(!gMsgStack) return "Could not allocate message stack!"; dputs("Initializing global script variables..."); varinit(); dputs("Registering debugger commands..."); registercommands(); dputs("Starting command loop..."); hCommandLoopThread = CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0); char plugindir[deflen] = ""; strcpy_s(plugindir, dir); strcat_s(plugindir, "\\plugins"); CreateDirectoryW(StringUtils::Utf8ToUtf16(plugindir).c_str(), 0); dputs("Loading plugins..."); pluginload(plugindir); dputs("Handling command line..."); //handle command line int argc = 0; wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc); if(argc == 2) //we have an argument { String str = "init \""; str += StringUtils::Utf16ToUtf8(argv[1]); str += "\""; DbgCmdExec(str.c_str()); } else if(argc == 5) //4 arguments (JIT) { if(_wcsicmp(argv[1], L"-a") == 0 && !_wcsicmp(argv[3], L"-e")) { String str = "attach ."; str += StringUtils::Utf16ToUtf8(argv[2]); str += ", ."; str += StringUtils::Utf16ToUtf8(argv[4]); DbgCmdExec(str.c_str()); } } LocalFree(argv); dputs("Initialization successful!"); bIsStopped = false; return nullptr; }
void cxJsonInit() { json_set_alloc_funcs((json_malloc_t)allocator->malloc, (json_free_t)allocator->free); convertFuncs = CX_ALLOC(cxHash); cxSetConvert("formatConvert", cxStrFormatConvert); }
void ast_json_reset_alloc_funcs(void) { json_set_alloc_funcs(ast_json_malloc, ast_json_free); }
void ast_json_set_alloc_funcs(void *(*malloc_fn)(size_t), void (*free_fn)(void*)) { json_set_alloc_funcs(malloc_fn, free_fn); }
extern "C" DLL_EXPORT const char* _dbg_dbginit() { if(!EngineCheckStructAlignment(UE_STRUCT_TITAN_ENGINE_CONTEXT, sizeof(TITAN_ENGINE_CONTEXT_t))) return "Invalid TITAN_ENGINE_CONTEXT_t alignment!"; if(sizeof(TITAN_ENGINE_CONTEXT_t) != sizeof(REGISTERCONTEXT)) return "Invalid REGISTERCONTEXT alignment!"; dputs("Initializing locks..."); SectionLockerGlobal::Initialize(); dputs("Initializing wait objects..."); waitinitialize(); dputs("Initializing debugger..."); dbginit(); dputs("Initializing debugger functions..."); dbgfunctionsinit(); dputs("Setting JSON memory management functions..."); json_set_alloc_funcs(json_malloc, json_free); dputs("Initializing capstone..."); Capstone::GlobalInitialize(); dputs("Initializing Yara..."); if(yr_initialize() != ERROR_SUCCESS) return "Failed to initialize Yara!"; dputs("Getting directory information..."); wchar_t wszDir[deflen] = L""; if(!GetModuleFileNameW(hInst, wszDir, deflen)) return "GetModuleFileNameW failed!"; char dir[deflen] = ""; strcpy_s(dir, StringUtils::Utf16ToUtf8(wszDir).c_str()); int len = (int)strlen(dir); while(dir[len] != '\\') len--; dir[len] = 0; strcpy_s(alloctrace, dir); strcat_s(alloctrace, "\\alloctrace.txt"); DeleteFileW(StringUtils::Utf8ToUtf16(alloctrace).c_str()); setalloctrace(alloctrace); strcpy_s(dbbasepath, dir); //debug directory strcat_s(dbbasepath, "\\db"); CreateDirectoryW(StringUtils::Utf8ToUtf16(dbbasepath).c_str(), 0); //create database directory strcpy_s(szSymbolCachePath, dir); strcat_s(szSymbolCachePath, "\\symbols"); SetCurrentDirectoryW(StringUtils::Utf8ToUtf16(dir).c_str()); dputs("Allocating message stack..."); gMsgStack = MsgAllocStack(); if(!gMsgStack) return "Could not allocate message stack!"; dputs("Initializing global script variables..."); varinit(); dputs("Registering debugger commands..."); registercommands(); dputs("Starting command loop..."); hCommandLoopThread = CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0); char plugindir[deflen] = ""; strcpy_s(plugindir, dir); strcat_s(plugindir, "\\plugins"); CreateDirectoryW(StringUtils::Utf8ToUtf16(plugindir).c_str(), 0); dputs("Loading plugins..."); pluginload(plugindir); dputs("Handling command line..."); //handle command line int argc = 0; wchar_t** argv = CommandLineToArgvW(GetCommandLineW(), &argc); if(argc == 2) //we have an argument { String str = "init \""; str += StringUtils::Utf16ToUtf8(argv[1]); str += "\""; DbgCmdExec(str.c_str()); } else if(argc == 5) //4 arguments (JIT) { if(_wcsicmp(argv[1], L"-a") == 0 && !_wcsicmp(argv[3], L"-e")) { String str = "attach ."; str += StringUtils::Utf16ToUtf8(argv[2]); str += ", ."; str += StringUtils::Utf16ToUtf8(argv[4]); DbgCmdExec(str.c_str()); } } LocalFree(argv); dputs("Initialization successful!"); return 0; }