コード例 #1
0
	std::list<TextCounter> FreqAnalyser::getPriorities(Text text, int keylen, int column){
		std::list<TextCounter> result;
		std::map<Text, int> counter;
		std::map<Text, int>::iterator countIt;
		int i;
		for (i=0; i<text.size();  i += keylen) {
			Text letter;
			letter.push_back(text[i+column]);
			if (counter.find(letter) == counter.end()){
				counter[letter] = 1;
			} else {
				counter[letter] = counter[letter] + 1;
			}
		}
		// on relit le map et on crée la liste...
		pDEBUG("FreqAnaliser","Column %d\n", column);
		for (countIt = counter.begin(); countIt != counter.end(); countIt++){
			TextCounter tc;

			tc.setText(countIt->first);
			tc.setCount(countIt->second);
			pDEBUG("FreqAnalyser","    Letter %s found %d times\n",tc.getText().toString().c_str(), tc.getCount());
			result.push_back(tc);
		}
		result.sort();
		result.reverse();
		return result;
	}
コード例 #2
0
ファイル: Credential.cpp プロジェクト: leoayt/pgina
		IFACEMETHODIMP Credential::GetBitmapValue(__in DWORD dwFieldID, __out HBITMAP* phbmp)
		{
			if(!m_fields || dwFieldID >= m_fields->fieldCount || !phbmp)
				return E_INVALIDARG;

			if(m_fields->fields[dwFieldID].fieldDescriptor.cpft != CPFT_TILE_IMAGE)
				return E_INVALIDARG;

			HBITMAP bitmap = NULL;
			std::wstring tileImage = pGina::Registry::GetString(L"TileImage", L"");
			if(tileImage.empty() || tileImage.length() == 1)
			{
				// Use builtin
				bitmap = LoadBitmap(GetMyInstance(), MAKEINTRESOURCE(IDB_LOGO_MONOCHROME_200));
			}
			else
			{
				pDEBUG(L"Credential::GetBitmapValue: Loading image from: %s", tileImage.c_str());
				bitmap = (HBITMAP) LoadImageW((HINSTANCE) NULL, tileImage.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);			
			}
			
			if(!bitmap)
				return HRESULT_FROM_WIN32(GetLastError());
			
			*phbmp = bitmap;
			return S_OK;
		}
コード例 #3
0
ファイル: GinaChain.cpp プロジェクト: ExcelsiorGmbH/pgina
		bool GinaChain::GetConsoleSwitchCredentials(PVOID pCredInfo)
		{
			bool retval = m_wrappedGina->GetConsoleSwitchCredentials(pCredInfo);
			PWLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0 pInfo = (PWLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0) pCredInfo;
			pDEBUG(L"GetConsoleSwitchCredentials: CredInfo=%p PrivateDataLen: 0x%08x PrivateData: %p", pCredInfo, pInfo->PrivateDataLen, pInfo->PrivateData);
			return retval;
		}
コード例 #4
0
/**
	Winlogon calls this function when an SAS event is received and noone is logged on. This indicates
		that a logon attempt should be made.

	@param pWlxContext (IN parameter) Context value associated with this window station that GINA returned in the
		WlxInitialize() call.
	@param dwSasType (IN parameter) A value indicating what type of secure attentionsequence was entered. Values below
		WLX_SAS_TYPE_MAX_MSFT_VALUE are used to define Microsoft standard secure attention
		sequences. Values above this value are for definition by GINA developers.
	@param pAuthenticationId (IN parameter) The AuthenticationID associated with this logon.The GINA DLL should pass this
		value as the LogonId parameter to the LsaLogonUser() call. The pointer is good only until this
		routine returns. To keep the LUID value longer than that, the GINA DLL should copy it before
		returning.
	@param pLogonSid (IN parameter) This parameter contains a pointer to a SID. This sid is unique to this logon session.
		Winlogon uses this SID to change the protection on the window station and application desktop so
		that the newly logged on user can access them. To ensure proper user shell access to these objects,
		the GINA DLL should include this SID in theLocalGroups parameter passed to LsaLogonUser().
		Winlogon frees this SID upon return from thiscall, so if it is required by GINA after returning, a copy
		must be made in this routine.
	@param pdwOptions (OUT parameter) Receives a set of logon options. These options are defined by the manifest
		constants named WLX_LOGON_OPT_xxx.
	@param phToken (OUT parameter) Upon completion of a successful logon,receives a handle that must be filled in
		upon return if a logon was successfully performed. This handle value is typically receivedfrom
		LsaLogonUser(). Winlogon closes this handle when it isdone with it, so if the GINA DLL should be
		able to access the token, it should make a duplicate of this handle.
	@param pMprNotifyInfo (OUT parameter) This parameter contains a pointer to a structure for returning password information
		to other network providers. A GINA is not required to return this information. If a GINA returns
		password information, then it should fill in the pointers inthe structure. Any NULL field in the
		structure will be ignored byWinlogon. The strings should be allocated individually by theGINA, and
		they will be freed by Winlogon.
	@param pProfile (OUT parameter) Upon return from a successful authentication, this field must point to one of the
		WLX_PROFILE_xxx structures. The first DWORD in the profile structure is used to indicate which
		of the WLX_PROFILE_xxx structures is beingreturned. The information in this structure is used by
		Winlogon to load the logged on user's profile. This structure, and any strings orbuffers pointed to
		from withing this structure are freed byWinlogon when no longer needed.

	<strong>Thread Desktop:</strong> Winlogon Desktop\n
	<strong>Workstation:</strong> Locked\n

	@return WLX_SAS_ACTION_LOGON - A user has logged on.\n
			WLX_SAS_ACTION_NONE - A logon attempt was unsuccessful or cancelled.\n
			WLX_SAS_ACTION_SHUTDOWN - The user requested the system be shut down.\n
			WLX_SAS_ACTION_SHUTDOWN_REBOOT - The user requested the system be rebooted.\n
            WLX_SAS_ACTION_SHUTDOWN_POWER_OFF - The user requested that the system be turned off\n
*/
int WINAPI WlxLoggedOutSAS(PVOID pWlxContext, DWORD dwSasType, PLUID pAuthenticationId, PSID pLogonSid,
						   PDWORD pdwOptions, PHANDLE phToken, PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, PVOID *pProfile)
{
	pDEBUG(L"WlxLoggedOutSAS");
	pGINA_FROM_CTX(pWlxContext);
	return pGina->LoggedOutSAS(dwSasType, pAuthenticationId, pLogonSid, pdwOptions, phToken, pMprNotifyInfo, pProfile);
}
コード例 #5
0
		/* static */
		INT_PTR HookedLoggedOutSAS::MicrosoftDialogProcWrapper(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
		{
			if(s_hookedDlgProc == 0)
			{
				pERROR(L"HookedLoggedOutSAS::MicrosoftDialogProcWrapper: Dialog wrapper called before we know who we're hooking!");
				return 0;	// Nothin we can do!
			}

			// Fall through if hooking is not enabled
			if(!s_hookingEnabled)
				return s_hookedDlgProc(hwnd, msg, wparam, lparam);

			// Hooking is on, so we let msgina do its thing
			INT_PTR msginaResult = s_hookedDlgProc(hwnd, msg, wparam, lparam);

			// If we're init'ing, then we set username, password and queue a message to login
			if(msg == WM_INITDIALOG)
			{
				std::wstring domainUsername = s_loginResult.Domain();
				domainUsername += L"\\";
				domainUsername += s_loginResult.Username();

				pDEBUG(L"HookedLoggedOutSAS::MicrosoftDialogProcWrapper: Hooked dialog, setting username/password and submitting for user: %s", domainUsername.c_str());
				SetDlgItemText(hwnd, IDC_MSGINA_USERNAME, domainUsername.c_str());
				SetDlgItemText(hwnd, IDC_MSGINA_PASSWORD, s_loginResult.Password().c_str());			
				SendMessage(hwnd, WM_COMMAND, 1, 1);
			}

			return msginaResult;
		}
コード例 #6
0
ファイル: nodeset.c プロジェクト: glenux/alobe
NodeSetList_t nodesetlist_merge(NodeSetList_t one, NodeSetList_t two){
	NodeSetList_t result = nodesetlist_create();

	NodeSetItem_t * curptr;

	if (DEBUG_MERGE){
		pDEBUG("MERGING NODESETLIST\n");
		nodesetlist_display(one);
	}

	curptr = one;
	while (curptr != NULL){
		/* 
		 * str = nodesetitem_tostr(curptr);
		 * printf("Copying... %s\n", str);
		 * free(str);
		 */
		result = nodesetlist_insert_item (result, curptr);
		curptr = curptr->next;
	}

	if (DEBUG_MERGE){
		pDEBUG("AND\n");
		nodesetlist_display(two);
	}

	curptr = two;
	while (curptr != NULL){
		/* 
		 * str = nodesetitem_tostr(curptr);
		 * printf("Copying... %s\n", str);
		 * free(str);
		 */
		result = nodesetlist_insert_item (result, curptr);
		curptr = curptr->next;
	}

	if (DEBUG_MERGE){
		pDEBUG("GIVES\n");
		nodesetlist_display(result);
	}
	return result;
}
コード例 #7
0
ファイル: Provider.cpp プロジェクト: autojie/pgina
		IFACEMETHODIMP Provider::UnAdvise()
		{
			if(m_logonUiCallbackEvents)
			{
				pDEBUG(L"Provider::UnAdvise() - provider events callback reference released");
				m_logonUiCallbackEvents->Release();
				m_logonUiCallbackEvents = NULL;
				m_logonUiCallbackContext = 0;
			}

			return S_OK;
		}
コード例 #8
0
/**
  Winlogon and a GINA DLL use this function to determine which version of the interface each
  	was written for.

  <strong>Thread Desktop:</strong> Winlogon Desktop\n
  <strong>Workstation:</strong> Locked\n

  @return TRUE - The GINA DLL can operate with this version of Winlogon.Continue initializing Winlogon. \n
   FALSE - The GINA DLL can not operate with this version of Winlogon.Winlogon (and the system) will not boot.
 */
BOOL WINAPI WlxNegotiate(DWORD dwWinlogonVersion, DWORD *pdwDllVersion)
{
	pDEBUG(L"WlxNegotiate(%d (0x%08x), ...)", dwWinlogonVersion, dwWinlogonVersion);
	// We support all versions from 1.3 up
	if(dwWinlogonVersion < WLX_VERSION_1_3)
		return FALSE;

	// We'll support what winlogon does
	*pdwDllVersion = dwWinlogonVersion;

	// Record winlogon version
	pGina::GINA::WinlogonInterface::Version(dwWinlogonVersion);
	return true;
}
コード例 #9
0
ファイル: Provider.cpp プロジェクト: autojie/pgina
		IFACEMETHODIMP Provider::Advise(__in ICredentialProviderEvents* pcpe, __in UINT_PTR upAdviseContext)
		{
			// If we already have a callback handle, release our reference to it
			UnAdvise();

			// Store what we've been given
			m_logonUiCallbackEvents = pcpe;
			m_logonUiCallbackContext = upAdviseContext;

			// Up ref count as we hold a pointer to this guy
			if(m_logonUiCallbackEvents)
			{
				pDEBUG(L"Provider::Advise(%p, %p) - provider events callback reference added", pcpe, upAdviseContext);
				m_logonUiCallbackEvents->AddRef();
			}

			return S_OK;
		}
コード例 #10
0
ファイル: math_tools.cpp プロジェクト: glenux/cryptaffinity
	int MathTools::pgcd(int a, int b){
		int fa = a;
		int fb = b;
		int pgcd;
		int rest;
		int tmp;

		while(b > 0){
			if (a<b){ tmp = a; a=b; b=tmp; }

			rest = a%b;
			//pDEBUG("MathTools::pgcd","%d - %d -> %d\n", a,b,rest);
			a = b;
			b = rest;
		}
			pDEBUG("MathTools::pgcd","%d - %d -> %d\n", fa,fb,a);
		return a;
	}
コード例 #11
0
ファイル: math_tools.cpp プロジェクト: glenux/cryptaffinity
	int MathTools::inverse(int a, int modulo){ 
		std::vector<int> pgcd_vec;
		int ca, cm, cpgcd;
		pgcd_vec = this->pgcd_mod(a, modulo);

		ca = pgcd_vec[1];
		cm = pgcd_vec[2];
		cpgcd = pgcd_vec[0];
		
		if (cpgcd != 1) {
			// crash
			pDEBUG("MathTools::inverse","CRASHHHHHH");	
		} else {
			while (ca < 0){
				ca = (ca + modulo);
			}
			// ca est positif;
			ca = ca % modulo;
		}
		return ca;
	}
コード例 #12
0
		void DialogLoggedOutSAS::ApplyLogoImage()
		{
			if(m_bitmap == NULL)
			{
				std::wstring tileImage = pGina::Registry::GetString(L"TileImage", L"");
				if(tileImage.empty() || tileImage.length() == 1)
				{
					// Use builtin
					m_bitmap = LoadBitmap(GetMyInstance(), MAKEINTRESOURCE(IDB_PGINA_LOGO));
				}
				else
				{
					pDEBUG(L"Credential::GetBitmapValue: Loading image from: %s", tileImage.c_str());
					m_bitmap = (HBITMAP) LoadImageW((HINSTANCE) NULL, tileImage.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);			
				}				
			}

			if(m_bitmap)
			{
				SetItemBitmap(IDC_LOGO, m_bitmap);
			}
		}
コード例 #13
0
ファイル: GinaChain.cpp プロジェクト: ExcelsiorGmbH/pgina
		GinaChain::GinaChain(WinlogonInterface *pWinLogonIface) : 
			Gina(pWinLogonIface), WinlogonProxy(pWinLogonIface), m_passthru(false)
		{
			// Are we in passthru mode?
			m_passthru = pGina::Registry::GetBool(L"GinaPassthru", false);

			// When we use the winlogon router table, we want it to 
			//	direct all winlogon calls to us (via our WinlogonProxy 
			//	implementation).  We sit between winlogon and a real
			//	GINA, so our Gina interface let's us have first shot
			//	at Winlogon->Gina direction calls, and WinlogonRouter+
			//	WinlogonProxy let's us have first shot at Gina->Winlogon
			//	direction traffic.
			WinlogonRouter::Interface(this);

			// Init and load our chained/wrapped gina
			std::wstring ginaName = pGina::Registry::GetString(L"ChainedGinaPath", L"MSGINA.DLL");
			pDEBUG(L"Wrapping gina: %s", ginaName.c_str());

			m_wrappedGina = new GinaWrapper(ginaName.c_str());
			if(!m_wrappedGina->Load())
			{
				pERROR(L"Failed to load wrapped gina: 0x%08x", GetLastError());
				return;
			}

			// Now negotiate and initialize our wrapped gina			
			if(!m_wrappedGina->Negotiate(WinlogonInterface::Version()))
			{	
				pERROR(L"Failed to negotiate with wrapped gina using version: %d (0x%08x)", WinlogonInterface::Version(), WinlogonInterface::Version());
				return;
			}

			if(!m_wrappedGina->Initialize(L"Winsta0", WinlogonRouter::Interface(), NULL, WinlogonRouter::DispatchTable()))
			{
				pERROR(L"Failed to initialize wrapped gina");
				return;
			}
		}
コード例 #14
0
ファイル: degenerator.c プロジェクト: glenux/alobe
void degenerator_compute (Degenerator_t * degenerator){
	int cur_iter;
	

	pDEBUG("Iterating %d times\n", degenerator->_iterations);
	for (cur_iter = 0; cur_iter < degenerator->_iterations; cur_iter++){
		if ((cur_iter % degenerator->_iterations_offset) == 0){
			// faire des calculs (nombre de composantes connexes)
			store_reset (degenerator->_store, STORE_RESET_ALL ^ STORE_RESET_DEGREE);

			Fifo_t * fifo_idx = fifo_create(degenerator->_size);
			store_connexity (degenerator->_store, fifo_idx);

			fprintf(degenerator->_io->output, "%d %ld\n", cur_iter, fifo_get_size (fifo_idx));
			fifo_destroy(fifo_idx);
			// afficher la courbe...
		}
		// Choisir un noeud selon une certaine méthode...
		nodeindex_t selected_node = (degenerator_select_mode_table[degenerator->_select_mode])(degenerator);
		printf("Node %ld\n", selected_node);

		store_del_node(degenerator->_store, selected_node);
	}
}
コード例 #15
0
/**
	Winlogon calls this function before locking the workstation, if, forexample, a screen saver is marked
		as secure.

	@param pWlxContext IN parameter) Context value associated with this window station that GINA returned in the
		wlxInitialize() call.

	@return True - Indicates it is OK to lock the workstation.\n
			False - Indicates it is not OK to lock the workstation.\n
*/
BOOL WINAPI WlxIsLockOk(PVOID pWlxContext)
{
	pDEBUG(L"WlxIsLockOk");
	pGINA_FROM_CTX(pWlxContext);
	return (pGina->IsLockOk() ? TRUE : FALSE);
}
コード例 #16
0
/**
	Winlogon calls this function when it receives an SAS and theworkstation is locked. GINA may return
		indicating the workstation is to remain locked, the workstation is to be unlocked, or the logged­on
		user is being forced to log off (whichleaves the workstation locked until the logoff is completed).

	@param pWlxContext (IN parameter) Context value associated with this window station that GINA returned in the
		WlxInitialize() call.
	@param dwSasType (IN parameter) A value indicating what type of secure attentionsequence was entered. Values below
		WLX_SAS_TYPE_MAX_MSFT_VALUE are used to define Microsoft standard secure attention
		sequences. Values above this value are for definition by GINA developers.

	<strong>Thread Desktop:</strong> Winlogon Desktop\n
	<strong>Workstation:</strong> Locked\n

	@return WLX_SAS_ACTION_NONE - Workstation remains locked.\n
			WLX_SAS_ACTION_UNLOCK_WKSTA - Unlock the workstation.\n
			WLX_SAS_ACTION_FORCE_LOGOFF - Force the user to log off.\n
*/
int WINAPI WlxWkstaLockedSAS(PVOID pWlxContext, DWORD dwSasType)
{
	pDEBUG(L"WlxWkstaLockedSAS");
	pGINA_FROM_CTX(pWlxContext);
	return pGina->WkstaLockedSAS(dwSasType);
}
コード例 #17
0
/**
	Winlogon calls this function when an SAS event is received, andthere is a user logged on. This
		indicates that the user needs to talk to the security system. Note, this is distinguished from when the
		workstation is locked; see below.

	This function is used generally when the logged on user wishes to shut down, log out, or lock the
		workstation. The extension DLL can lock the workstation by returning WLX_LOCK_WKSTA.
		Winlogon locks the workstation, and calls WlxWkstaLockedSAS the next time an SAS is received.
		The extension DLL can use the profile to determine any information needed about the system.

	@param pWlxContext (IN parameter) Context value associated with this window station that GINA returned in the
		WlxInitialize() call.
	@param dwSasType (IN parameter) A value indicating what type of secure attentionsequence was entered. Values below
		WLX_SAS_TYPE_MAX_MSFT_VALUE are used to define Microsoft standard secure attention
		sequences. Values above this value are for definition by GINA developers.
	@param pReserved (IN parameter) Reserved.

	<strong>Thread Desktop:</strong> Winlogon Desktop\n
	<strong>Workstation:</strong> Locked\n

	@return WLX_SAS_ACTION_NONE - Return to the default desktop.\n
			WLX_SAS_ACTION_LOCK_WKSTA - Lock the workstation, wait for next SAS.\n
            WLX_SAS_ACTION_LOGOFF - Log the user off of the workstation.\n
			WLX_SAS_ACTION_SHUTDOWN - Log the user off and shutdown the machine.\n
			WLX_SAS_ACTION_SHUTDOWN_REBOOT - Shut down and reboot the machine.\n
			WLX_SAS_ACTION_SHUTDOWN_POWER_OFF - Shut down and turn off the machine, if hardware allows.
			WLX_SAS_ACTION_PWD_CHANGED - Indicates that the user changed their password. Notify network providers.
			WLX_SAS_ACTION_TASKLIST - Invoke the task list.
*/
int WINAPI WlxLoggedOnSAS(PVOID pWlxContext, DWORD dwSasType, PVOID pReserved)
{
	pDEBUG(L"WlxLoggedOnSAS");
	pGINA_FROM_CTX(pWlxContext);
	return pGina->LoggedOnSAS(dwSasType, pReserved);
}
コード例 #18
0
/**
	Winlogon calls this function when the workstation is placed in thelocked state. This allows the GINA
		to display information aboutthe lock, such as who locked the workstation and when. The GINA
		should display a dialog box that will be interrupted by a WLX_WM_SAS message, much like the
		WlxDisplaySASNotice function. This function should display a notice that describes the machine as locked.

	@param pWlxContext (IN parameter) Context value associated with this window station that GINA returned in the
		WlxInitialize() call.
	@return None
*/
VOID WINAPI WlxDisplayLockedNotice(PVOID pWlxContext)
{
	pDEBUG(L"WlxDisplayLockedNotice");
	pGINA_FROM_CTX(pWlxContext);
	pGina->DisplayLockedNotice();
}
コード例 #19
0
ファイル: ba_vigenere.cpp プロジェクト: glenux/cryptaffinity
void BreakAffinity::runVigenere() {
    MathTools mt;
    CodecVigenere codec;
    FreqAnalyser fa;
    Text cypherText = this->_config.getText();
    Text plainText;
    std::list<TextCounter> tc;
    cypherText.setAlphabet(this->_config.getAlphabet());
    int alpha_size = this->_config.getAlphabet().size();

    // 1 - repérer les mots qui se répentent
    pDEBUG("BreakAffinity::run","analysing %s\n",cypherText.toString().c_str());
    KeyVigenere key;
    TextCounter fst;
    TextCounter sec;
    int dist1, dist2;
    int fst_idx1, fst_idx2;
    int sec_idx1, sec_idx2;
    int key_len;
    int key_idx;

    tc = cypherText.getRepeatedPatterns();

    fst = tc.front();
    tc.pop_front();
    sec = tc.front();

    std::list<int> fst_idx = fst.getParam();
    std::list<int> sec_idx = sec.getParam();

    fst_idx1 = fst_idx.front();
    fst_idx.pop_front();
    fst_idx2 = fst_idx.front();

    sec_idx1 = sec_idx.front();
    sec_idx.pop_front();
    sec_idx2 = sec_idx.front();

    dist1 = fst_idx2 - fst_idx1;
    dist2 = sec_idx2 - sec_idx1;

    // 2 - on en déduit la longueur de la clef
    key_len = mt.pgcd(dist1,dist2);
    pDEBUG("BreakAffinity::run","PGCD(%d, %d) = %d\n", dist1, dist2, key_len);

    // 3 - on calcule le décalage par colonne
    std::list<TextCounter>::iterator pI;
    std::vector<int> prio_conf = this->_config.getPriorities();

    for (int i=0; i< prio_conf.size(); i++) {
        printf("%d - ",prio_conf[i]);
    }
    printf("\n");
    std::list<KeyVigenere> keyList;
    std::list<KeyVigenere>::iterator lI;

    for (key_idx = 0; key_idx < key_len; key_idx++) {
        std::list<TextCounter> prio_list;
        TextCounter firstCypherTC, firstPlainTC;
        int firstCypher, firstPlain;
        int shift;
        prio_list = fa.getPriorities(cypherText, key_len, key_idx);

        firstCypherTC = prio_list.front();
        firstCypher = firstCypherTC.getText()[0];

        std::list<KeyVigenere> nList;
        for (int i=0; i<2; i++) {
            firstPlain = prio_conf[i];
            //printf("Shift column %d from %d to %d\n",
            //key_idx,
            //firstCypher,
            //firstPlain);
            //
            // on fixe le décalage a partir de la premiere priorité...
            shift = (alpha_size + firstCypher - firstPlain) % alpha_size;
            // Cypher = Plain + Key => Key = Cypher - Plain
            if(key_idx==0) {
                KeyVigenere kv;
                kv.push_back(shift);
                nList.push_back(kv);
            } else {
                for (lI=keyList.begin(); lI!=keyList.end(); lI++) {
                    KeyVigenere kv=*lI;
                    //printf("From %s ",kv.toString().c_str());
                    kv.push_back(shift);
                    //printf("creating %s\n",kv.toString().c_str());
                    nList.push_back(kv);
                }
            }
        }
        keyList.clear();
        for (lI=nList.begin(); lI!=nList.end(); lI++) {
            keyList.push_back((*lI));
        }
    }
    // on filtre en fonction des 70%...
    for (lI=keyList.begin(); lI!=keyList.end(); lI++) {
        float score = 0;
        key = (*lI);
        printf("Trying key %s\n", key.toString().c_str());

        plainText = codec.decode(cypherText, key);
        plainText.setAlphabet(this->_config.getAlphabet());
        for (int i=0; i<9; i++) {
            score += plainText.getCountOf(prio_conf[i]);
        }
        score = score / plainText.size();
        if (fabs(score - this->_config.getFrequencies()) < this->_config.getEpsilon()) {
            key.setAlphabet(this->_config.getAlphabet());
            printf("   KEY = %s\n",key.toAlphabet().c_str());
            printf("   PLAIN TEXT(%f) = %s\n",fabs(score-0.7),plainText.toAlphabet().c_str());
        }

    }
    return ;
}
コード例 #20
0
/**
	Winlogon calls this function following a successful logon. Itspurpose is to request GINA to activate
		the user shell program(s). Note that the user shell should be activated in this routine ratherthan in
		WlxLoggedOffSas() so that Winlogon has a chance to update its state, including setting workstation
		and desktop protections, before any logged­on user processes are allowed to run. The pszDesktop parameter
		should be passed to the CreateProcess API through the field lpDesktop in the STARTUPINFO structure. This
		field is designated "Reserved forfuture use. Must be NULL." in the Win32 documentation, but pass this parameter in.

	@param pWlxContext (IN parameter) Context value associated with this window station that GINA returned in the
		WlxInitialize() call.
	@param pszDesktopName (IN parameter) Name of the desktop on which to start the shell. This should be supplied to
		CreateProcess() in the lpStartupInfo­>lpDesktop field (q.v).
	@param pszMprLogonScripts (IN parameter) Script names returned from the provider DLLs. Provider DLLs may return scripts to
		be executed during logon. The GINA may reject these, but Winlogon will provide them ifthey are
		there.
	@param pEnvironment (IN parameter) Initial environment for the process. Winlogoncreates this environment and hands it
		off to the GINA. The GINA can modify this environment before using it to initialize the user'sshell.

	<strong>Thread Desktop:</strong> Application Desktop\n
	<strong>Workstation:</strong> Not Locked\n

	@return	TRUE - Indicates that the shell processes were started by the GINA DLL.\n
			FALSE - Indicates that the GINA could not start the shell, and that the logon session should be terminated by
					Winlogon.
	@Notes
*/
BOOL WINAPI WlxActivateUserShell(PVOID pWlxContext, PWSTR pszDesktopName, PWSTR pszMprLogonScript, PVOID pEnvironment)
{
	pDEBUG(L"WlxActivateUserShell");
	pGINA_FROM_CTX(pWlxContext);
	return (pGina->ActivateUserShell(pszDesktopName, pszMprLogonScript, pEnvironment) ? TRUE : FALSE);
}
コード例 #21
0
ファイル: GinaChain.cpp プロジェクト: ExcelsiorGmbH/pgina
		// SAS handling
		int  GinaChain::LoggedOutSAS(DWORD dwSasType, PLUID pAuthenticationId, PSID pLogonSid, PDWORD pdwOptions, 
									 PHANDLE phToken, PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, PVOID *pProfile)
		{
			// If configured to pass through to MS GINA, or auto-logon is enabled, we 
			// pass through, and let the MS GINA handle the logon.
			if(m_passthru || IsAutoLogonEnabled())
			{
				return m_wrappedGina->LoggedOutSAS(dwSasType, pAuthenticationId, pLogonSid, pdwOptions, phToken, pMprNotifyInfo, pProfile);				
			}

			// We auth'd in another session - this session is the real one though, need to tell the service to add!
			if(dwSasType == WLX_SAS_TYPE_AUTHENTICATED)
			{
				// We could do this, but we don't get password (without additional wrapping of our own in WlxGetConsoleSwitchCredentials
				//  So instead we grab it post SAS processing via msgina.				
				WLX_CONSOLESWITCH_CREDENTIALS_INFO_V1_0 credInfo;
				if(m_winlogon->WlxQueryConsoleSwitchCredentials(&credInfo))
				{
					pDEBUG(L"LoggedOutSAS: CredInfo=%p PrivateDataLen: 0x%08x PrivateData: %p", &credInfo, credInfo.PrivateDataLen, credInfo.PrivateData);
				}				
				
				int msresult = m_wrappedGina->LoggedOutSAS(dwSasType, pAuthenticationId, pLogonSid, pdwOptions, phToken, pMprNotifyInfo, pProfile);
				//pGina::Transactions::LoginInfo::Add(pMprNotifyInfo->pszUserName, pMprNotifyInfo->pszDomain, pMprNotifyInfo->pszPassword);
				return msresult;
			}

			// Gather username/password from user.  If remote, we get it from rdp client if provided,
			//  otherwise show the logged out sas dialog to get it.
			std::wstring username;
			std::wstring password;
			std::wstring domain;
						
			bool showDialog = true;

			if(pGina::Helpers::UserIsRemote())
			{
				WLX_CLIENT_CREDENTIALS_INFO_V2_0 creds;
				creds.dwType = WLX_CREDENTIAL_TYPE_V2_0;				
				if(m_winlogon->WlxQueryTsLogonCredentials(&creds))
				{
					if(creds.pszUserName) username = creds.pszUserName;
					if(creds.pszPassword) password = creds.pszPassword;
					if(creds.pszDomain) domain = creds.pszDomain;
					if(!creds.fPromptForPassword) showDialog = false;

					pDEBUG(L"fPromptForPassword: %s", creds.fPromptForPassword ? L"TRUE" : L"FALSE");
					pDEBUG(L"fDisconnectOnLogonFailure: %s", creds.fDisconnectOnLogonFailure ? L"TRUE" : L"FALSE");
				}				
			}
			
			if(showDialog)
			{
				DialogLoggedOutSAS dialog(m_winlogon);						
				dialog.Username(username);
				dialog.Password(password);

				int dialogResult = dialog.ShowDialog();
				if(dialogResult == DialogLoggedOutSAS::SAS_ACTION_LOGON)
				{
					// Harvest u/p for passing along to msgina
					username = dialog.Username();
					password = dialog.Password();
				}
				else if(dialogResult >= DialogLoggedOutSAS::SAS_ACTION_MIN && dialogResult <= DialogLoggedOutSAS::SAS_ACTION_MAX)
				{
					// Just do as told
					return dialogResult;
				}
				else
				{
					// Unknown ret value, default to no action
					return DialogLoggedOutSAS::SAS_ACTION_NONE;
				}
			}

			// We now have the login info, let's give it a shot!
			pDEBUG(L"GinaChain::LoggedOutSAS: Processing login for %s", username.c_str());
			pGina::Transactions::User::LoginResult result = pGina::Transactions::User::ProcessLoginForUser(username.c_str(), NULL, password.c_str(), pGina::Protocol::LoginRequestMessage::Login);
			if(!result.Result())
			{
				std::wstring failureMsg = result.Message();
				pERROR(L"GinaChain::LoggedOutSAS: %s", failureMsg.c_str());
				m_winlogon->WlxMessageBox(NULL, const_cast<wchar_t *>(failureMsg.c_str()), L"Login Failure", MB_ICONEXCLAMATION | MB_OK);
				return WLX_SAS_ACTION_NONE;					
			}			

			pDEBUG(L"inaChain::LoggedOutSAS: Successful, resulting username: %s", result.Username().c_str());						

			// Invoke the msgina logged out sas dialog, intercept it, set username/password, and hit ok!
			HookedLoggedOutSAS::Enabled(true);
			HookedLoggedOutSAS::SetLoginInfo(result);
			int msresult = m_wrappedGina->LoggedOutSAS(dwSasType, pAuthenticationId, pLogonSid, pdwOptions, phToken, pMprNotifyInfo, pProfile);
			HookedLoggedOutSAS::Enabled(false);				
			return msresult;			
		}
コード例 #22
0
ファイル: serialdevices.cpp プロジェクト: AndyA/beebem
bool TouchScreenPoll(void)
{
unsigned char data;
static int mode = 0;

	if (ts_delay > 0)
	{
		ts_delay--;
		return false;
	}
	
	if (ts_outlen > 0)		// Process data waiting to be received by BeebEm straight away
	{
		return true;
	}

	if (ts_inlen > 0)
	{
		data = ts_inbuff[ts_inhead];
		ts_inhead = (ts_inhead + 1) % TS_BUFF_SIZE;
		ts_inlen--;
		
		switch (data)
		{
			case 'M' :
				mode = 0;
				break;

			case '0' :
			case '1' :
			case '2' :
			case '3' :
			case '4' :
			case '5' :
			case '6' :
			case '7' :
			case '8' :
			case '9' :
				mode = mode * 10 + data - '0';
				break;

			case '.' :

/*
 * Mode 1 seems to be polled, sends a '?' and we reply with data
 * Mode 129 seems to be send current values all time
 */
				
//->				WriteLog("Setting touch screen mode to %d\n", mode);
//++
				pDEBUG(dL"Setting touch screen mode to %d", dR, mode);
//<-
				break;

			case '?' :

				if (mode == 1)		// polled mode
				{
					TouchScreenReadScreen(false);
				}
				break;
		}
	}
	
	if (mode == 129)		// real time mode
	{
		TouchScreenReadScreen(true);
	}
		
	if (mode == 130)		// area mode - seems to be pressing with two fingers which we can't really do ??
	{
		TouchScreenReadScreen(true);
	}
	
	
	return false;
}
コード例 #23
0
ファイル: nodeset.c プロジェクト: glenux/alobe
NodeSetList_t nodesetlist_insert_item(NodeSetList_t root, 
		NodeSetItem_t * item)
{
	bool action_done = false;
	NodeSetList_t head = root;
	// on insere de façon triée...
	NodeSetItem_t * prevptr = NULL;	
	NodeSetItem_t * curptr = root;	
	char * curstr = NULL;
	char * itemstr = nodesetitem_tostr(item);

	while(curptr != NULL){

		curstr = nodesetitem_tostr(curptr);

		if (nodesetitem_is_overlap(curptr, item)){
			pDEBUG("OVERLAP %s vs %s\n", curstr, itemstr);
			/* on fusionne les deux... cf SNAP*/
			NodeSetItem_t * newptr = 
				nodesetitem_create_from_bounds(curptr, item);

			curptr->minimum = newptr->minimum;
			curptr->maximum = newptr->maximum;

			/* 
			 * char * str = nodesetitem_tostr(curptr);
			 * printf("=> %s\n",str);
			 * free(str);
			 */

			nodesetitem_destroy(newptr);

			action_done = true;
			break;
		} 
		else if (nodesetitem_is_snap(curptr, item))
		{
			pDEBUG("SNAP %s vs %s\n", curstr, itemstr);
			/* on fusionne les deux... cf OVERLAP*/
			NodeSetItem_t * newptr = 
				nodesetitem_create_from_bounds(curptr, item);

			curptr->minimum = newptr->minimum;
			curptr->maximum = newptr->maximum;

			/* 
			 * char * str = nodesetitem_tostr(curptr);
			 * printf("=> %s\n",str);
			 * free(str);
 			 */

			nodesetitem_destroy(newptr);

			action_done = true;
			break;
		} 
		else if (curptr->minimum > item->maximum) {
			/* alors on insère le noeud ici... */
			NodeSetItem_t * newptr = nodesetitem_copy(item);
			if (NULL == curptr->prev) 
			{ /* on est en tete de liste */
				newptr->next = head;
				if (head){ head->prev = newptr; }
				head = newptr;
			} 
			else 
			{ /* on est en milieu de liste */
				prevptr->next = newptr;
				newptr->prev = prevptr;
				newptr->next = curptr;
				curptr->prev = newptr;
			}

			action_done = true;
			break;
		} else {
			pDEBUG("Rien en commun : %s vs %s\n", curstr, itemstr);
			// on va ajouter à la fin ?
		}

		prevptr = curptr;	
		curptr = curptr->next;	

		free(curstr);
		curstr = NULL;
	}
	if (head == NULL){
		NodeSetItem_t * newptr = nodesetitem_copy(item);
		head = newptr;
		action_done = true;
	}

	if (!action_done){
		pDEBUG("On ajoute %s a la fin de la nodesetlist\n",itemstr);
		NodeSetItem_t * newptr = nodesetitem_copy(item);
		if (NULL != prevptr) {	prevptr->next = newptr; } // n'arrive jamais 
		newptr->prev = prevptr;
	}

	if (NULL != curstr) { free(curstr); }
	if (NULL != itemstr) { free(itemstr); }

	return head;
}
コード例 #24
0
ファイル: csw.cpp プロジェクト: Wren6991/Arcade-Machine
void LoadCSW(char *file)
{
    int end;
    int sourcesize;

//	csw_file = fopen("/Users/jonwelch/MyProjects/csw/AticAtac.csw", "rb");

    CloseCSW();

    csw_file = fopen(file, "rb");

    if (csw_file == NULL)
    {
//->		WriteLog("Failed to open file\n");
//++
        qERROR("Failed to open file.");
//<-
        return;
    }

    /* Read header */
    if (fread(file_buf, 1, 0x34, csw_file) != 0x34 ||
            strncmp((const char*)file_buf, "Compressed Square Wave", 0x16) != 0 ||
            file_buf[0x16] != 0x1a)
    {
//->		WriteLog("Not a valid CSW file\n");
//++
        qERROR("Not a valid CSW file.");
//<-
        fclose(csw_file);
        return;
    }

//->	WriteLog("CSW version: %d.%d\n", (int)file_buf[0x17], (int)file_buf[0x18]);
//++
    pDEBUG(dL"CSW version: %d,%d", dR, (int)file_buf[0x17], (int)file_buf[0x18]);
//<-

    int sample_rate = file_buf[0x19] + (file_buf[0x1a] << 8) + (file_buf[0x1b] << 16) + (file_buf[0x1c] << 24);
    int total_samples = file_buf[0x1d] + (file_buf[0x1e] << 8) + (file_buf[0x1f] << 16) + (file_buf[0x20] << 24);
    int compression_type = file_buf[0x21];
    int flags = file_buf[0x22];
    unsigned int header_ext = file_buf[0x23];

//->	WriteLog("Sample rate: %d\n", sample_rate);
//--	WriteLog("Total Samples: %d\n", total_samples);
//--	WriteLog("Compressing: %d\n", compression_type);
//--	WriteLog("Flags: %x\n", flags);
//--	WriteLog("Header ext: %d\n", header_ext);
//++
    pDEBUG(dL"Sample rate: %d", dR, sample_rate);
    pDEBUG(dL"Total Samples: %d", dR, total_samples);
    pDEBUG(dL"Compressing: %d", dR, compression_type);
    pDEBUG(dL"Header ext: %d", dR, header_ext);
//<-

    file_buf[0x33] = 0;
//->	WriteLog("Enc appl: %s\n", &file_buf[0x24]);
//++
    pDEBUG(dL"Enc appl: %s", dR, &file_buf[0x24]);
//<-

    /* Read header extension bytes */
    if (fread(file_buf, 1, header_ext, csw_file) != header_ext)
    {
//->		WriteLog("Failed to read header extension\n");
//++
        qERROR("Failed to read header extension.");
//<-
        fclose(csw_file);
        return;
    }

    end = ftell(csw_file);
    fseek(csw_file, 0, SEEK_END);
    sourcesize = ftell(csw_file) - end + 1;
    fseek(csw_file, end, SEEK_SET);

    csw_bufflen = 8 * 1024 * 1024;
    csw_buff = (unsigned char *) malloc(csw_bufflen);
    sourcebuff = (unsigned char *) malloc(sourcesize);

    fread(sourcebuff, 1, sourcesize, csw_file);
    fclose(csw_file);

    uncompress(csw_buff, &csw_bufflen, sourcebuff, sourcesize);

    free(sourcebuff);

//->	WriteLog("Source Size = %d\n", sourcesize);
//--	WriteLog("Uncompressed Size = %d\n", csw_bufflen);
//++
    pDEBUG(dL"Source Size = %d.", dR, sourcesize);
    pDEBUG(dL"Uncompressed Size = %d.", dR, csw_bufflen);
//<-

    CSW_CYCLES = 2000000 / sample_rate - 1;
    csw_state = 0;
    csw_bit = 0;
    csw_pulselen = 0;
    csw_ptr = 0;
    csw_pulsecount = -1;
    csw_tonecount = 0;
    bit_count = -1;

    strcpy(UEFTapeName, file);

    CSWOpen = 1;
    CSW_BUF = 0;
    TxD = 0;
    RxD = 0;
    TapeClock = 0;
    OldClock = 0;
    TapeTrigger = TotalCycles + CSW_CYCLES;
}
コード例 #25
0
ファイル: csw.cpp プロジェクト: Wren6991/Arcade-Machine
int csw_poll(int clock)
{
    int ret;

    ret = -1;

    if (bit_count == -1)
    {
        bit_count = csw_data();
        if (bit_count == -1)
        {
            CloseCSW();
            return ret;
        }
    }

    if (bit_count > 0)
    {
        bit_count--;
        return ret;
    }

    //	WriteLog("csw_pulsecount %d, csw_bit %d\n", csw_pulsecount, csw_bit);

    switch (csw_state)
    {
    case 0 :			// Waiting for tone

        if (csw_pulselen < 0x0d)					/* Count tone pulses */
        {
            csw_tonecount++;
            if (csw_tonecount > 20)					/* Arbitary figure */
            {
//->					WriteLog("Detected tone at %d\n", csw_pulsecount);
//++
                pDEBUG(dL"Detected tone at %d.", dR, csw_pulsecount);
//<-
                csw_state = 1;
            }
        }
        break;

    case 1 :			// In tone

        if (csw_pulselen > 0x14)					/* Noise so reset back to wait for tone again */
        {
            csw_state = 0;
            csw_tonecount = 0;
        } else if ( (csw_pulselen > 0x0d) && (csw_pulselen < 0x14) )			/* Not in tone any more - data start bit */
        {
//->				WriteLog("Entered data at %d\n", csw_pulsecount);
//++
            pDEBUG(dL"Entered data at %d.", dR, csw_pulsecount);
//<-
            bit_count = csw_data();					/* Skip next half of wave */
            csw_state = 2;
            csw_bit = 0;
            csw_byte = 0;
            csw_datastate = 0;
        }
        break;

    case 2 :			// In data

        switch (csw_datastate)
        {
        case 0 :		// Receiving data

            bit_count = csw_data();				/* Skip next half of wave */
            csw_byte >>= 1;

            if (csw_pulselen > 0x14)
            {
                csw_state = 0;					/* Noisy pulse so reset to tone */
                csw_tonecount = 0;
                break;
            }

            if (csw_pulselen <= 0x0d)
            {
                bit_count += csw_data();
                bit_count += csw_data();
                csw_byte |= 0x80;
            }
            csw_bit++;
            if (csw_bit == 8)
            {
                ret = csw_byte;
                csw_datastate = 1;				/* Stop bits */
            }
            break;

        case 1 :		// Stop bits

            bit_count = csw_data();

            if (csw_pulselen > 0x14)
            {
                csw_state = 0;					/* Noisy pulse so reset to tone */
                csw_tonecount = 0;
                break;
            }

            if (csw_pulselen <= 0x0d)
            {
                bit_count += csw_data();
                bit_count += csw_data();
            }
            csw_datastate = 2;					/* tone/start bit */
            break;

        case 2 :

            if (csw_pulselen > 0x14)
            {
                csw_state = 0;					/* Noisy pulse so reset to tone */
                csw_tonecount = 0;
                break;
            }

            if (csw_pulselen <= 0x0d)			/* Back in tone again */
            {
//->						WriteLog("Back in tone again at %d\n", csw_pulsecount);
//++
                pDEBUG(dL"Back in tone again at %d.", dR, csw_pulsecount);
//<-
                csw_state = 0;
                csw_tonecount = 0;
                csw_bit = 0;
            }
            else /* Start bit */
            {
                bit_count = csw_data();			/* Skip next half of wave */
                csw_bit = 0;
                csw_byte = 0;
                csw_datastate = 0;				/* receiving data */
            }
            break;
        }
        break;
    }

    bit_count += csw_data();		/* Get next bit */

    return ret;
}
コード例 #26
0
/**
	Winlogon calls this function once for each window station present on the machine. (Note that
	 Windows NT 3.5 supports only one window station. This window station is called "Winsta0".
	 Additional physical window stations may be supported in futurereleases.) This allows the DLL to
	 initialize itself, including obtainingaddresses of Winlogon support functions used by this DLL.
	 The DLL can return a context pointer that will be passed in allfuture interactions from Winlogon to
	 GINA. This allows GINA to keep global context associated with this window station.

	We've added the calls necessary to ensure the theme service is started and working before we go any
     further, as explained in http://support.microsoft.com/default.aspx?scid=kb;en-us;322047

	@param lpWinsta Points to the name of the window station being initialized.
	@param hWlx Handle to Winlogon that must be provided in future calls related tothis window station.
	@param pwReserved Reserved
	@param pWinlogonFunctions Receives a pointer to a Winlogon function dispatch table. Thecontents of the table is dependent upon
		the GINA DLL version returned from the WlxNegotiate() call. The table does not change, so the
		GINA DLL can reference the table rather than copying it.
	@param pWlxContext This is an OUT parameter. It allows GINA to return a 32­bit context value that will be provided in all
		future calls related to this window station. Generally the value returned will be something likea
		pointer to a context structure allocated by GINA for this window station.

	<strong>Thread Desktop:</strong> Winlogon Desktop\n
	<strong>Workstation:</strong> Locked\n
   	@return True - Indicates the Gina DLL successfully initialized.\n
			False - Indicates the Gina could not successfully initialize.\n
			<i>Note that If the DLL could not initialize, then the system will not boot.<i>
 */
BOOL WINAPI WlxInitialize(LPWSTR lpWinsta, HANDLE hWlx, PVOID pvReserved, PVOID pWinlogonFunctions, PVOID * pWlxContext)
{
	pDEBUG(L"WlxInitialize(%s, 0x%08x, 0x%08x, 0x%08x, ...)", lpWinsta, hWlx, pvReserved, pWinlogonFunctions);
	pGina::GINA::Themes::Init();
	return (pGina::GINA::Gina::InitializeFactory(hWlx, pWinlogonFunctions, (pGina::GINA::Gina **) pWlxContext) ? TRUE : FALSE);
}
コード例 #27
0
ファイル: alobe.c プロジェクト: glenux/alobe
int main(int argc, char ** argv){
	srand(time(NULL));

	Config_t * config = config_create (argc, argv);
	if (!config_is_valid (config)) { config_usage (config); exit(-1); }
    pDEBUG("Got config from command line\n");

	config_set (config);
    pDEBUG("Config set\n");

	// en fonction de la commande 
	switch (config->command){
		case COMMAND_TP1_FILTER_EX2:
			{
				Filter_t * filter = filter_create(&(config->io), 
						config->filter_size,
						config->filter_offset);
				filter_run (filter);
				filter_destroy (filter);
			}
			break;

		case COMMAND_TP1_DEGREE_EX3:
			{	
				Degree_t * degree = degree_create (&(config->io),	
						config->nodecount,						
						MODE_DEGREE);
				degree_set_output (degree, true);
				degree_fill_from_input_graph (degree);
				degree_destroy (degree);
			}
			break;

		case COMMAND_TP1_STORE_GRAPH_EX4:
			{
				Store_t * store = store_create(&(config->io), 
						config->nodecount);
				store_fill_from_input_graph (store);
				store_destroy (store);
			}
			break;

		case COMMAND_TP1_DENSITY_AVGDEGREE_MAXDEGREE_EX5:
			{
				Degree_t * degree = degree_create (&(config->io),	
						config->nodecount,						
						MODE_DEGSTATS);
				degree_set_output (degree, true);
				degree_fill_from_input_graph (degree);
				degree_destroy (degree);
			}
			break;

		case COMMAND_TP1_CONNEXITY_EX6:
			{
				Store_t * store = store_create(&(config->io), 
						config->nodecount);
				store_fill_from_input_graph (store);
				store_connexity (store, NULL);
				store_destroy (store);
			}
			break;

		case COMMAND_TP1_CONNEXITY_DEFI:
			{
				Defi_t * defi = defi_create(&(config->io),
						config->nodecount);
				defi_run (defi);
				defi_destroy (defi);
			}
			break;

		case COMMAND_TP2_DISTANCE_ONE_TO_OTHER_EX1:
			{
				fprintf(stderr,"Exercice 1 - Ecrire un  programme qui,  étant  donné un\n");
				fprintf(stderr," graphe et un de ses noeud,  calcule la distance  de ce\n");
				fprintf(stderr," noeud  a tous  les  autres,  ainsi que  la moyenne  de\n");
				fprintf(stderr," toutes ces distances.\n\n");

				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_MAX_AND_AVERAGE);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, 1);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;

		case COMMAND_TP2_PLOT_DISTRIB_DISTANCES_EX2:
			{
				fprintf(stderr,"Exercice 2 - Tracer la  distribution des  distances à un\n");
				fprintf(stderr," noeud donné, c'est à dire pour chaque entier  i le nom-\n");
				fprintf(stderr," bre de noeuds à distance i du noeud donné.\n\n");
				
				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_MAX_DISTRIBUTION);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, 1);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;
		case COMMAND_TP2_EVOL_OF_DISTS_FNC_NB_PARCOURS_EX3:
			{
				fprintf(stderr, "Exercice 3 - Ecrire un  programme  qui permet  de tracer\n");
				fprintf(stderr, " l'évolution de  l'estimation de  la distance moyenne en\n");
				fprintf(stderr, " fonction du nombre de parcours effectués.\n");
				fprintf(stderr, "A chaque étape, le programme calcule la distance moyenne\n");
				fprintf(stderr, " d'un noeud à tous les autres, puis fait la moyenne avec\n");
				fprintf(stderr, " toutes les valeurs précédentes.\n\n");
						
				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_EVOLUTION);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, config->iterations);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;
		case COMMAND_TP2_LIMIT_INFERIOR_EX4:
			{
				fprintf(stderr, "Exercice 4 - Ecrire un  programme qui  calcule une borne\n");
				fprintf(stderr, " inférieure du diamètre, en prenant la distance maximale\n");
				fprintf(stderr, " d'un noeud donné à tous les autres.\n\n");

				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_SHOW_LIMIT_INF);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, config->iterations);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;
		case COMMAND_TP2_LIMIT_SUPERIOR_EX5:
			{
				fprintf(stderr, "Exercice 5 - Ecrire un programme  qui calcule  une borne\n");
				fprintf(stderr, " supérieure du diamètre, en prenant la distance maximale\n");
				fprintf(stderr, " dans l'arbre du parcours en largeur.\n\n");

				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_SHOW_LIMIT_SUP);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, config->iterations);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;
		case COMMAND_TP2_EVOLUTION_AND_LIMITS_DEFI:
			{
				fprintf(stderr, "Défi - Ecrire un  programme qui  donne un  encadrement de\n");
				fprintf(stderr, " plus en plus fin  du diamètre d'un graphe.  Le programme\n");
				fprintf(stderr, " effectue à  chaque étape  un parcours  en largeur et  en\n");
				fprintf(stderr, " déduit une borne inférieure et une borne supérieure pour\n");
				fprintf(stderr, " le diamètre.  Si elle  améliorent le résultat  elle sont\n");
				fprintf(stderr, " conservées  à la  place des meilleures  valeurs trouvées\n");
				fprintf(stderr, " lors des étapes précédentes.\n\n");
				
				Distance_t * distance = distance_create((&config->io),
						config->nodecount);
				distance_set_mode (distance, MODE_DEFI);

				distance_set_root (distance, config->root_index);
				distance_set_iterations (distance, config->iterations);

				distance_compute (distance);
				distance_destroy (distance);
			}
			break;

		case COMMAND_TP3_DISTRIB_DEG_EX1:
			{
				fprintf(stderr, "Exercice 1 - Ecrire un programme qui calcule la distribu-\n");
				fprintf(stderr, " tion des degrés d'un graphe.\n");

				Degree_t * degree = degree_create (&(config->io),	
						config->nodecount,						
						MODE_DEGREE);
				degree_set_output (degree, false);
				degree_fill_from_input_graph (degree);

				degree_output_distribution (degree);
				degree_destroy (degree);

			}
			break;

		case COMMAND_TP3_EVOL_AVG_DEG_EX2:
			{
				Store_t * store = store_create(&(config->io), 
						config->nodecount);
				store_fill_from_input_graph (store);

				store_compute_avg_degree(store, config->iterations);

				store_destroy (store);

			}
			break;

		case COMMAND_TP3_GENERATE_EX3:
			{

				fprintf(stderr, "Generating a random graph\n");

				Generator_t * generator = generator_create(&(config->io),
						config->nodecount,
						config->filter_size);

				generator_run (generator);
				generator_destroy (generator); 
			}
			break;
			
		case COMMAND_TP3_DEGENERATE_EX5:
			{
				fprintf(stderr, "Degenerating input graph\n");
				Degenerator_t * degen = degenerator_create (&(config->io),
						config->nodecount, config->iterations);						
				degenerator_set_select_mode (degen, DEGENERATOR_SELECT_RANDOM);

				degenerator_compute (degen);
				degenerator_destroy (degen);
			}
			break;
	
		case COMMAND_TP3_DEGENERATE_MAX_DEG_EX7:
			{
				fprintf(stderr, "Degenerating input graph with max degrees first\n");
				Degenerator_t * degen = degenerator_create (&(config->io),
						config->nodecount, config->iterations);						
				degenerator_set_select_mode (degen, DEGENERATOR_SELECT_MAX_DEG);

				degenerator_compute (degen);
				degenerator_destroy (degen);
			}
			break;

		default:
			{
				printf("Undefined mode\n");
			}
			break;
	}

	config_destroy (config);

	return EXIT_SUCCESS;
}