void directconnection::xNonceToBin(UUID* nonce) { size_t len = strlen(xNonce); char *p = (char*)alloca(len); strcpy(p, xNonce + 1); p[len-2] = 0; UuidFromStringA((BYTE*)p, nonce); }
static int core_IsPluginLoaded(lua_State *L) { const char *value = lua_tostring(L, 1); MUUID uuid = { 0 }; bool res = UuidFromStringA((RPC_CSTR)value, (UUID*)&uuid) == RPC_S_OK; if (res) res = IsPluginLoaded(uuid) > 0; lua_pushboolean(L, res); return 1; }
int main(int argc, char** argv) { if (argc != 2) { printf("Please use VMID as argument\n"); return -1; } const char *msg = "***Hello! This message is from the host!***\n"; WSADATA wsaData; SOCKADDR_HV remoteAddr; SOCKET fd; int ret; // Initialize Winsock ret = WSAStartup(MAKEWORD(2, 2), &wsaData); if (ret != NO_ERROR) { printf("WSAStartup() failed with error: %d\n", ret); return -1; } memset(&remoteAddr, 0, sizeof(SOCKADDR_HV)); remoteAddr.Family = AF_HYPERV; // The Linux VM is listening in Vsock port 0x808 TryConvertVsockPortToServiceId(0x808, &remoteAddr.ServiceId); // This is the "remote" VM's VMID got by the PowerShell command // "Get-VM -Name <the_VM_name> | ft id". if (UuidFromStringA((RPC_CSTR)argv[1], &remoteAddr.VmId) != RPC_S_OK) { printf("Failed to parse the remote VMID: %d\n", GetLastError()); ret = -1; goto out; } if (ConnectToVM(&remoteAddr, &fd) < 0) { printf("Failed to connect to the VM!\n"); ret = -1; goto out; } ret = send(fd, msg, strlen(msg), 0); printf("Sent a msg to the VM: msg_len = %d.\nExited.\n", ret); closesocket(fd); WSACleanup(); return 0; out: WSACleanup(); return ret; }
RTDECL(int) RTUuidFromStr(PRTUUID pUuid, const char *pszString) { /* check params */ AssertPtrReturn(pUuid, VERR_INVALID_POINTER); AssertPtrReturn(pszString, VERR_INVALID_POINTER); RPC_STATUS rc; #ifdef RPC_UNICODE_SUPPORTED /* always use ASCII version! */ rc = UuidFromStringA((unsigned char *)pszString, (UUID *)pUuid); #else rc = UuidFromString((unsigned char *)pszString, (UUID *)pUuid); #endif return RTErrConvertFromWin32(rc); }
int ustring_Uuid(lua_State* L) { UUID uuid; if(lua_gettop(L) == 0 || !lua_toboolean(L, 1)) { // generate new UUID if(UuidCreate(&uuid) == RPC_S_OK) { lua_pushlstring(L, (const char*)&uuid, sizeof(UUID)); return 1; } } else { size_t len; const char* arg1 = luaL_checklstring(L, 1, &len); if(len == sizeof(UUID)) { // convert given UUID to string unsigned char* p; if(UuidToStringA((UUID*)arg1, &p) == RPC_S_OK) { lua_pushstring(L, (char*)p); RpcStringFreeA(&p); return 1; } } else { // convert string UUID representation to UUID if(UuidFromStringA((unsigned char*)arg1, &uuid) == RPC_S_OK) { lua_pushlstring(L, (const char*)&uuid, sizeof(UUID)); return 1; } } } lua_pushnil(L); return 1; }
static void UuidConversionAndComparison(void) { CHAR strx[100], x; LPSTR str = strx; WCHAR wstrx[100], wx; LPWSTR wstr = wstrx; UUID Uuid1, Uuid2, *PUuid1, *PUuid2; RPC_STATUS rslt; int i1,i2; /* Uuid Equality */ for (i1 = 0; i1 < 11; i1++) for (i2 = 0; i2 < 11; i2++) { if (i1 < 10) { Uuid1 = Uuid_Table[i1]; PUuid1 = &Uuid1; } else { PUuid1 = NULL; } if (i2 < 10) { Uuid2 = Uuid_Table[i2]; PUuid2 = &Uuid2; } else { PUuid2 = NULL; } ok( (UuidEqual(PUuid1, PUuid2, &rslt) == Uuid_Comparison_Grid[i1][i2]), "UUID Equality\n" ); } /* Uuid to String to Uuid (char) */ for (i1 = 0; i1 < 10; i1++) { Uuid1 = Uuid_Table[i1]; ok( (UuidToStringA(&Uuid1, (unsigned char**)&str) == RPC_S_OK), "Simple UUID->String copy\n" ); ok( (UuidFromStringA((unsigned char*)str, &Uuid2) == RPC_S_OK), "Simple String->UUID copy from generated UUID String\n" ); ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> String -> Uuid transform\n" ); /* invalid uuid tests -- size of valid UUID string=36 */ for (i2 = 0; i2 < 36; i2++) { x = str[i2]; str[i2] = 'g'; /* whatever, but "g" is a good boundary condition */ ok( (UuidFromStringA((unsigned char*)str, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID String\n" ); str[i2] = x; /* change it back so remaining tests are interesting. */ } RpcStringFreeA((unsigned char **)&str); } /* Uuid to String to Uuid (wchar) */ for (i1 = 0; i1 < 10; i1++) { Uuid1 = Uuid_Table[i1]; rslt=UuidToStringW(&Uuid1, &wstr); ok( (rslt == RPC_S_OK), "Simple UUID->WString copy\n" ); ok( (UuidFromStringW(wstr, &Uuid2) == RPC_S_OK), "Simple WString->UUID copy from generated UUID String\n" ); ok( UuidEqual(&Uuid1, &Uuid2, &rslt), "Uuid -> WString -> Uuid transform\n" ); /* invalid uuid tests -- size of valid UUID string=36 */ for (i2 = 0; i2 < 36; i2++) { wx = wstr[i2]; wstr[i2] = 'g'; /* whatever, but "g" is a good boundary condition */ ok( (UuidFromStringW(wstr, &Uuid1) == RPC_S_INVALID_STRING_UUID), "Invalid UUID WString\n" ); wstr[i2] = wx; /* change it back so remaining tests are interesting. */ } RpcStringFreeW(&wstr); } }