/*********************************************************************** * UuidFromStringW (RPCRT4.@) */ RPC_STATUS WINAPI UuidFromStringW(RPC_WSTR s, UUID *uuid) { int i; if (!s) return UuidCreateNil( uuid ); if (strlenW(s) != 36) return RPC_S_INVALID_STRING_UUID; if ((s[8]!='-') || (s[13]!='-') || (s[18]!='-') || (s[23]!='-')) return RPC_S_INVALID_STRING_UUID; for (i=0; i<36; i++) { if ((i == 8)||(i == 13)||(i == 18)||(i == 23)) continue; if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0')) return RPC_S_INVALID_STRING_UUID; } /* in form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ uuid->Data1 = (hex2bin[s[0]] << 28 | hex2bin[s[1]] << 24 | hex2bin[s[2]] << 20 | hex2bin[s[3]] << 16 | hex2bin[s[4]] << 12 | hex2bin[s[5]] << 8 | hex2bin[s[6]] << 4 | hex2bin[s[7]]); uuid->Data2 = hex2bin[s[9]] << 12 | hex2bin[s[10]] << 8 | hex2bin[s[11]] << 4 | hex2bin[s[12]]; uuid->Data3 = hex2bin[s[14]] << 12 | hex2bin[s[15]] << 8 | hex2bin[s[16]] << 4 | hex2bin[s[17]]; /* these are just sequential bytes */ uuid->Data4[0] = hex2bin[s[19]] << 4 | hex2bin[s[20]]; uuid->Data4[1] = hex2bin[s[21]] << 4 | hex2bin[s[22]]; uuid->Data4[2] = hex2bin[s[24]] << 4 | hex2bin[s[25]]; uuid->Data4[3] = hex2bin[s[26]] << 4 | hex2bin[s[27]]; uuid->Data4[4] = hex2bin[s[28]] << 4 | hex2bin[s[29]]; uuid->Data4[5] = hex2bin[s[30]] << 4 | hex2bin[s[31]]; uuid->Data4[6] = hex2bin[s[32]] << 4 | hex2bin[s[33]]; uuid->Data4[7] = hex2bin[s[34]] << 4 | hex2bin[s[35]]; return RPC_S_OK; }
static void _uuuid_create(struct uuuid_t** uuuid, int* status, int nil) { struct uuuid_t* u; RPC_STATUS st; u = uuuid_new(); if (!u) { *status = UUUID_ERR; return; } if (nil) st = UuidCreateNil(&u->uuid); else st = UuidCreate(&u->uuid); if (st != RPC_S_OK) { uuuid_free(u); *status = UUUID_ERR; return; } *uuuid = u; *status = UUUID_OK; }
RTDECL(int) RTUuidClear(PRTUUID pUuid) { /* check params */ AssertPtrReturn(pUuid, VERR_INVALID_POINTER); return RTErrConvertFromWin32(UuidCreateNil((UUID *)pUuid)); }
void uuid_generate_time_safe(uuid_t out){ UUID uuid; UuidCreateNil(&uuid); UuidCreateSequential(&uuid); uuid.Data1 = htonl(uuid.Data1); uuid.Data2 = htons(uuid.Data2); uuid.Data3 = htons(uuid.Data3); memcpy(out, &uuid, UUID_T_LENGTH); }
void uuid_generate_random(uuid_t out){ UUID uuid; UuidCreateNil(&uuid); UuidCreate(&uuid); uuid.Data1 = htonl(uuid.Data1); uuid.Data2 = htons(uuid.Data2); uuid.Data3 = htons(uuid.Data3); memcpy(out, &uuid, UUID_T_LENGTH); }
RPC_STATUS UuidFromStringA(RPC_CSTR StringUuid, UUID* Uuid) { int index; BYTE bin[36]; if (!StringUuid) return UuidCreateNil(Uuid); if (strlen((char*) StringUuid) != 36) return RPC_S_INVALID_STRING_UUID; if ((StringUuid[8] != '-') || (StringUuid[13] != '-') || (StringUuid[18] != '-') || (StringUuid[23] != '-')) { return RPC_S_INVALID_STRING_UUID; } for (index = 0; index < 36; index++) { if ((index == 8) || (index == 13) || (index == 18) || (index == 23)) continue; if ((StringUuid[index] >= '0') && (StringUuid[index] <= '9')) bin[index] = StringUuid[index] - '0'; else if ((StringUuid[index] >= 'a') && (StringUuid[index] <= 'f')) bin[index] = StringUuid[index] - 'a' + 10; else if ((StringUuid[index] >= 'A') && (StringUuid[index] <= 'F')) bin[index] = StringUuid[index] - 'A' + 10; else return RPC_S_INVALID_STRING_UUID; } Uuid->Data1 = ((bin[0] << 28) | (bin[1] << 24) | (bin[2] << 20) | (bin[3] << 16) | (bin[4] << 12) | (bin[5] << 8) | (bin[6] << 4) | bin[7]); Uuid->Data2 = ((bin[9] << 12) | (bin[10] << 8) | (bin[11] << 4) | bin[12]); Uuid->Data3 = ((bin[14] << 12) | (bin[15] << 8) | (bin[16] << 4) | bin[17]); Uuid->Data4[0] = ((bin[19] << 4) | bin[20]); Uuid->Data4[1] = ((bin[21] << 4) | bin[22]); Uuid->Data4[2] = ((bin[24] << 4) | bin[25]); Uuid->Data4[3] = ((bin[26] << 4) | bin[27]); Uuid->Data4[4] = ((bin[28] << 4) | bin[29]); Uuid->Data4[5] = ((bin[30] << 4) | bin[31]); Uuid->Data4[6] = ((bin[32] << 4) | bin[33]); Uuid->Data4[7] = ((bin[34] << 4) | bin[35]); return RPC_S_OK; }
void uuid_clear (uuid_t uu) { // all zeros, no change between GUID and UUID UuidCreateNil (reinterpret_cast<UUID*>(uu)); }
/* clear.c */ void uuid_clear(uuid_t uu){ UuidCreateNil((UUID*)uu); }
int _tmain(int argc, _TCHAR* argv[]) { int i; char buf[MAX_PATH]; #ifdef _DEBUG _crtBreakAlloc = -1; // break on Nth memory allocation #endif #if defined(TRACE) System::Diagnostics::Trace::Listeners->Add( gcnew System::Diagnostics::TextWriterTraceListener( System::Console::Out ) ); System::Diagnostics::Trace::AutoFlush = true; #endif WSADATA wsaData; int iResult; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { printf_s( "WSAStartup failed: %d\n", iResult ); goto returnFail; } else { printf_s( "WSAStartup succeeded\n" ); } // -- select agent and playback file -- char *logPath = "..\\data\\"; WCHAR logDirName[TOP_LOG_DIRS][256]; int logDirCount; WCHAR logDirPath[MAX_PATH]; WCHAR logName[10][256]; int logCount; FILE *logF; FILE *settingsF; char AT_name[256]; char UUIDString[256]; int breakOnAlloc = -1; int optionNum; // get crt break val or use last settings printf( "0) Use last settings\n1) _crtBreakAlloc = -1 (disabled)\n2) Enter _crtBreakAlloc\n\nNOTE: To properly use _crtBreakAlloc you should:\n a) ensure the desired log file is selected (e.g. run once with option 2)\n b) run once with option 0 to determine the desired break value (because \n selecting things in this menu unfortunately changes the allocation\n count)\n c) use option 2 to set the _crtDebugAlloc value\n d) run with option 0 again so that the correct allocation count is used\n from step b)\n\n" ); do { printf( "Select an option: " ); *buf = getchar(); while( getchar() != '\n' ); // clear until return } while ( buf[0] - '0' < 0 || buf[0] - '0' >= 3 ); optionNum = buf[0] - '0'; if ( optionNum == 0 ) { // use last settings if ( fopen_s( &settingsF, "settings.txt", "r" ) ) { printf( "Couldn't open settings file\n" ); goto returnFail; } fscanf_s( settingsF, "%d\n", &breakOnAlloc ); #ifdef _DEBUG _crtBreakAlloc = breakOnAlloc; #endif fgetws( logDirPath, MAX_PATH, settingsF ); logDirPath[wcslen(logDirPath)-1] = '\0'; // strip \n fgets( AT_name, 256, settingsF ); AT_name[strlen(AT_name)-1] = '\0'; // strip \n fgets( UUIDString, 256, settingsF ); // no \n here fclose( settingsF ); } else { if ( optionNum == 2 ) { // get _crtBreakAlloc printf( "Enter value for _crtBreakAlloc: " ); while( 1 != scanf_s( "%d", &breakOnAlloc ) ) { while( getchar() != '\n' ); // clear until return } while( getchar() != '\n' ); // clear until return } #ifdef _DEBUG _crtBreakAlloc = breakOnAlloc; #endif // enumerate log directories enumerateLogDirectories( logPath, logDirName, &logDirCount ); printf( "0) Use last settings\n" ); for ( i=0; i<logDirCount; i++ ) { printf( "%d) %ls\n", i+1, logDirName[i] ); } do { printf( "Select a directory: " ); *buf = getchar(); while( getchar() != '\n' ); // clear until return } while ( buf[0] - '0' < 0 || buf[0] - '0' >= logDirCount+1 ); i = buf[0] - '0'; // use i to store selection if ( i == 0 ) { // use last settings if ( fopen_s( &settingsF, "settings.txt", "r" ) ) { printf( "Couldn't open settings file\n" ); goto returnFail; } fscanf_s( settingsF, "%d\n", &i ); // throw away fgetws( logDirPath, MAX_PATH, settingsF ); logDirPath[wcslen(logDirPath)-1] = '\0'; // strip \n fgets( AT_name, 256, settingsF ); AT_name[strlen(AT_name)-1] = '\0'; // strip \n fgets( UUIDString, 256, settingsF ); // no \n here fclose( settingsF ); } else { i--; // set i to the name index swprintf_s( logDirPath, MAX_PATH, L"%hs%s\\", logPath, logDirName[i] ); // enumerate logs int page = 0; int moreLogs; do { enumerateLogs( logDirPath, page, logName, &logCount, &moreLogs ); system("cls"); printf( "Page %d\n", page ); for ( i=0; i<logCount; i++ ) { printf( "%d) %.64ls\n", i, logName[i] ); } if ( page != 0 ) printf( "p) previous page\n" ); if ( moreLogs ) printf( "n) next page\n" ); do { printf( "Select a log: " ); *buf = getchar(); while( getchar() != '\n' ); // clear until return } while ( (buf[0] - '0' < 0 || buf[0] - '0' >= logCount) && (buf[0] != 'p' || page == 0) && (buf[0] != 'n' || !moreLogs) ); if ( buf[0] == 'p' ) { page--; } else if ( buf[0] == 'n' ) { page++; } else { break; } } while (1); i = buf[0] - '0'; // this is the log we want // open the log to parse the agent id sprintf_s( buf, MAX_PATH, "%ls%ls", logDirPath, logName[i] ); if ( fopen_s( &logF, buf, "r" ) ) { printf( "Failed to open log file! %s\n", buf ); goto returnFail; } // clear first line fgets( buf, MAX_PATH, logF ); // get agent type if ( 5 != fscanf_s( logF, "[%d:%d:%d.%d] %s\n", &i, &i, &i, &i, AT_name, 256 ) ) { printf( "Expected agent name\n" ); goto returnFail; } // finish line fgets( buf, MAX_PATH, logF ); // clear agent UUID line fgets( buf, MAX_PATH, logF ); // get playbackfile UUID if ( 5 != fscanf_s( logF, "[%d:%d:%d.%d] AgentPlayback UUID %s\n", &i, &i, &i, &i, UUIDString, 256 ) ) { printf( "Expected agentplayback UUID\n" ); goto returnFail; } fclose( logF ); } // save settings for next time if ( fopen_s( &settingsF, "settings.txt", "w" ) ) { printf( "Couldn't save settings file\n" ); goto returnFail; } fprintf_s( settingsF, "%d\n%ls\n%s\n%s", breakOnAlloc, logDirPath, AT_name, UUIDString ); fclose( settingsF ); } if ( optionNum == 2 ) { printf( "\nSettings saved, restart and run with option 0\n\n" ); goto returnFail; } // -- Startup info -- char *libraryPath = "library\\"; // library path sAddressPort ap; sprintf_s( ap.address, sizeof(ap.address), "127.0.0.1" ); sprintf_s( ap.port, sizeof(ap.port), "50000" ); UUID ticket; UuidCreateNil( &ticket ); int logLevel = 9; char logDirectory[MAX_PATH]; WCHAR baseDirectory[512]; GetCurrentDirectory( 512, baseDirectory ); sprintf_s( logDirectory, MAX_PATH, "%ls", baseDirectory ); // strip last directory to reach base path i = (int)wcslen(baseDirectory); while ( baseDirectory[i] != '\\' ) i--; baseDirectory[i] = '\0'; SetCurrentDirectory( baseDirectory ); char playbackFile[256]; sprintf_s( playbackFile, 256, "%lsx %s.apb", logDirPath+1, UUIDString ); // strip off the leading . of ..\\ if ( strcmp( AT_name, "AgentHost" ) != 0 ) { // regular agent WCHAR wbuf[512]; char AT_object[256]; // agent template object sprintf_s( AT_object, 256, "%s.dll", AT_name ); // -- Load agent DLL -- HINSTANCE library = NULL; // set the current directory to the library path in case they need their own dlls SetCurrentDirectory( baseDirectory ); wsprintf( wbuf, _T(".\\%hs%hs\\"), libraryPath, AT_name ); SetCurrentDirectory( wbuf ); // load the library wsprintf( wbuf, _T("%hs"), AT_object ); library = LoadLibrary( wbuf ); SetCurrentDirectory( baseDirectory ); // set the directory back if ( library == NULL ) { printf_s( "LoadLibrary failed for %ls\n", wbuf ); goto returnFail; } // -- Spawn Agent -- SpawnFuncPtr sfp; sfp = (SpawnFuncPtr)GetProcAddress( library, "Playback" ); if ( sfp( &ap, &ticket, logLevel, logDirectory, PLAYBACKMODE_PLAYBACK, playbackFile ) ) { printf_s( "Failed to spawn agent\n" ); goto returnFail; } // -- Clean up -- FreeLibrary( library ); } else { // host int steps = 0; AgentHost *pHOST; SetCurrentDirectory( baseDirectory ); pHOST = new AgentHost( ".\\library\\", LOG_LEVEL_ALL, logDirectory, PLAYBACKMODE_PLAYBACK, playbackFile ); pHOST->configure(); pHOST->start( NULL, NULL ); while ( !pHOST->step() ) steps++; pHOST->stop(); delete pHOST; } // Clean up Winsock WSACleanup(); #if defined(TRACE) System::Diagnostics::Trace::WriteLine( "--- Exit _tmain() for startup thread: AutonomicPlayback ---" ); _CrtDumpMemoryLeaks(); #endif printf( "Finished. Press ENTER to exit..." ); getchar(); return 0; returnFail: printf( "Finished. Press ENTER to exit..." ); getchar(); return 1; }
void uuid_clear (uuid_t uu) { UuidCreateNil (reinterpret_cast<UUID*>(uu)); }