コード例 #1
0
ファイル: Alarm.c プロジェクト: CapujAgg/Router-CNC---Info-II
/*
 * Retorna el estado del pin de direccion del eje enviado en t
 * 0->CW; 1->CCW
 */
uint8_t get_dir (uint8_t t){

	if (t==0)
		return (GetPIN(XDIR,TRUE));
	if (t==1)
		return (GetPIN(YDIR,TRUE));
	if (t==2)
		return (GetPIN(ZDIR,TRUE));
	return 0;
}
コード例 #2
0
void Debounce(void)
{
	uint8_t cambios,j = 0;

	static uint8_t ContadorEstados[ ENTRADAS ];

	//--- En 'j', almaceno el estado actual de las entradas. Un bit x cada entrada => 8 entradas para
	//--- este ejemplo. Es aquí donde defino QUE bit de 'BufferEntradas' corresponde a QUE entrada.
	j = GetPIN(KEY4_RC, ACTIVO_BAJO);		//KEY4_RC: cont++
	if ( GetPIN(KEY3_RC, ACTIVO_BAJO) )		//KEY3_RC: cont--
		j |= 0x02;
	//----------------------

	cambios = ( BufferEntradas ^ j ); /*Si cambios vale 0 => no hubo cambios respecto de todos los
	estados anteriores de todas las entradas. Si cambios es distinto de cero => alguna entrada cambio
	de estado, con lo que se procederá a su análisis-----*/

	if( cambios )	//Si el if es verdadero, es que hubo algún cambio=>analizo.
	{
		for( j = 0 ; j < ENTRADAS ; j++ )
		{
			if( cambios & (0x01 << j) )
			{
				ContadorEstados[ j ] ++;

				if(ContadorEstados[ j ] == ACEPTAReSTADO)
				{
					ContadorEstados[ j ] = 0;
					BufferEntradas = BufferEntradas ^ (0x01 << j);
				}
			}
			else
				ContadorEstados[ j ] = 0;
		}
	}
	else	/*Si cambios vale cero puede ser por dos causas :
	a) Porque efectivamente las entradas estan estables y no se registraron cambios de estados (lo mas probable)
	b) Porque las entradas que estaban siendo analizadas rebotaron y hacen parecer que no hubo cambio de
		estados en ninguna. Es poco probable que se de con varias, entradas pero puede pasar.
	Si lo que paso es b) tengo que poner todos los contadores a cero, porque no se cual rebotó.
	Si lo que paso fue a) y pongo los contadores a cero	no pasa nada.*/
	{
		for( j = 0 ; j < ENTRADAS ; j++ )
			ContadorEstados[ j ] = 0;
	}
}
コード例 #3
0
ファイル: emvproc.c プロジェクト: x-lugoo/pos
/* Online processing.
    steps:
	(1) Dial. If dial failed, return ONLINE_FAILED
	(2) Use EMVGetTLVData() to retrieve data from core, pack to ISO8583.
	(3) Save reversal data and flag, then send request to host
	(4) Receive from host, then do accordingly:
	   A. If host approved, copy RspCode,AuthCode,AuthCodeLen or so, and return ONLINE_APPROVE
	   B. If host denial, copy RspCode or so, return ONLINE_DENIAL
	   C. If host require voice referral, copy RspCode or so.,return ONLINE_REFER.
	       Note that if not support, needn't return ONLINE_REFER but directly ONLINE_DENIAL

	Reversal flag can only be cleared after all EMV processing, NOT immediately after online.
*/
int  cEMVOnlineProc(uchar *psRspCode,  uchar *psAuthCode, int *piAuthCodeLen,
					uchar *psAuthData, int *piAuthDataLen,
					uchar *psScript,   int *piScriptLen)
{
	int		iRet, iLength, iRetryPIN;
	ulong	ulICCDataLen;
	uchar	*psICCData, *psTemp;

	// initialize output parameters
	*psRspCode      = 0;
	*piAuthCodeLen  = 0;
	*piAuthDataLen  = 0;
	*piScriptLen    = 0;
	SaveTVRTSI(TRUE);
	glProcInfo.bIsFirstGAC = FALSE;

    //add begin. fixed bug about not pack F52 when use chip card. linzhao 20160510
    if (glProcInfo.stTranLog.uiEntryMode & MODE_PIN_INPUT)
    {
       if(memcmp(glProcInfo.sPinBlock,"\x00\x00\x00\x00\x00\x00\x00\x00",8) !=0)
       {
           PubLong2Char((ulong)LEN_PIN_DATA, 2, glSendPack.sPINData);
           memcpy(&glSendPack.sPINData[2], glProcInfo.sPinBlock, LEN_PIN_DATA);
       }

    }
    //add end.linzhao 20160510

	UpdateEntryModeForOfflinePIN();

	// prepare online DE55 data
	iRet = SetDE55(DE55_SALE, &glSendPack.sICCData[2], &iLength);
	if( iRet!=0 )
	{
		glProcInfo.ucOnlineStatus = ST_ONLINE_FAIL;
		return ONLINE_FAILED;
	}
	PubASSERT( iLength<LEN_ICC_DATA );
	PubLong2Char((ulong)iLength, 2, glSendPack.sICCData);
	memcpy(glProcInfo.stTranLog.sIccData, &glSendPack.sICCData[2], iLength);	// save for batch upload
	glProcInfo.stTranLog.uiIccDataLen = (ushort)iLength;

	if( !ChkIfAmex() )
	{
		if( !(ChkIfDah() || ChkIfCiti() || ChkIfScb()) &&
            ChkIfAcqNeedDE56() )
		{
			if ( glProcInfo.stTranLog.ucTranType!=AUTH && glProcInfo.stTranLog.ucTranType!=PREAUTH )
			{
				iLength = glSysCtrl.stField56[glCurAcq.ucIndex].uiLength;
				PubASSERT(iLength<LEN_ICC_DATA);
				if( iLength>0 )
				{
					memcpy(&glSendPack.sICCData2[2], glSysCtrl.stField56[glCurAcq.ucIndex].sData, iLength);
				}
				else
				{
					SetStdEmptyDE56(&glSendPack.sICCData2[2], &iLength);
				}
				PubLong2Char((ulong)iLength, 2, glSendPack.sICCData2);
			}
		}
	}

	// 冲正交易处理 & 离线交易上送
	// 判断上次交易是否需要进行冲正等
	// send reversal here. If required by bank, also send offline here
	iRet = TranReversal();
	if( iRet!=0 )
	{
		glProcInfo.ucOnlineStatus = ST_ONLINE_FAIL;
		return ONLINE_FAILED;
	}

	iRetryPIN = 0;
	while( 1 )
	{
		if (ChkIfAmex() || ChkCurAcqName("AMEX", FALSE))
		{
			GetNewInvoiceNo();
		}

		iRet = SendRecvPacket();
		if( iRet!=0 )
		{
			glProcInfo.ucOnlineStatus = ST_ONLINE_FAIL;
			return ONLINE_FAILED;
		}

		if( memcmp(glRecvPack.szRspCode, "55", 2)!=0 || ++iRetryPIN>3 || !ChkIfNeedPIN() )
		{
			break;
		}

		// retry EMV online PIN
		iRet = GetPIN(GETPIN_RETRY);
		if( iRet!=0 )
		{
			return ONLINE_DENIAL;
		}
		sprintf((char *)glSendPack.szSTAN, "%06lu", glSysCtrl.ulSTAN);
		memcpy(&glSendPack.sPINData[0], "\x00\x08", 2);
		memcpy(&glSendPack.sPINData[2], glProcInfo.sPinBlock, 8);
	}

	// set response code
	memcpy(psRspCode,  glRecvPack.szRspCode,  LEN_RSP_CODE);
	glProcInfo.ucOnlineStatus = ST_ONLINE_APPV;

	// get response issuer data
	sgAuthDataLen = sgScriptLen = 0;

	ulICCDataLen = PubChar2Long(glRecvPack.sICCData, 2);
	psICCData = &glRecvPack.sICCData[2];
	if (ChkIfAmex())
	{
		iRet = GetDE55Amex(glSendPack.sICCData+2, psICCData, ulICCDataLen);
		if( iRet<0 )
		{
			// if analyze response ICC data failed, return fail
			glProcInfo.ucOnlineStatus = ST_ONLINE_FAIL;
			return ONLINE_FAILED;
		}
	}
	else
	{
		for(psTemp=psICCData; psTemp<psICCData+ulICCDataLen; )
		{
			// version 1.00.0016 change by Jolie Yang at 2013-08-16
			// due to the application just only get contents of 71\72, and transfer it to EMV kernal.
			iRet = GetTLVItem(&psTemp, psICCData+ulICCDataLen-psTemp, SaveRspICCData, FALSE);
			//iRet = GetTLVItem(&psTemp, psICCData+ulICCDataLen-psTemp, SaveRspICCData, TRUE);
			//if( iRet<0 )
			//{	// if analyze response ICC data failed, return fail
			//	glProcInfo.ucOnlineStatus = ST_ONLINE_FAIL;
			//	return ONLINE_FAILED;
			//}
		}
	}


	memcpy(psAuthData, sAuthData, sgAuthDataLen);
	*piAuthDataLen = sgAuthDataLen;
	
	// version 1.00.0016 change by Jolie Yang at 2013-08-16
	// due to the application need not extract the sub-tag of 71/72, just get contents of 71\72, and transfer to EMV kernal
	// AdjustIssuerScript();
	memcpy(psScript, sIssuerScript, sgScriptLen);
	*piScriptLen = sgScriptLen;

	if( memcmp(glRecvPack.szRspCode, "00", LEN_RSP_CODE)!=0 )
	{
		return ONLINE_DENIAL;
	}
	// set authorize code only if txn approved
	memcpy(psAuthCode, glRecvPack.szAuthCode, LEN_AUTH_CODE);
	*piAuthCodeLen = strlen((char *)glRecvPack.szAuthCode);

	return ONLINE_APPROVE;
}
コード例 #4
0
ファイル: emvproc.c プロジェクト: x-lugoo/pos
// Callback function required by EMV core.
// Wait holder enter PIN.
// developer customized.
// Modified by Kim_LinHB 2014-6-8 v1.01.0000
int cEMVGetHolderPwd(int iTryFlag, int iRemainCnt, uchar *pszPlainPin)
{
	int		iResult;
	uchar	ucRet, szBuff[30], szAmount[15];

	// online PIN
	if( pszPlainPin==NULL )
	{
		iResult = GetPIN(GETPIN_EMV);
		if( iResult==0 )
		{
			if( glProcInfo.stTranLog.uiEntryMode & MODE_PIN_INPUT )
			{
				return EMV_OK;
			}
			else
			{
				return EMV_NO_PASSWORD;
			}
		}
		else if( iResult==ERR_USERCANCEL )
		{
			return EMV_USER_CANCEL;
		}
		else
		{
			return EMV_NO_PINPAD;
		}
	}

	// Offline plain/enciphered PIN processing below
	Gui_ClearScr();
	if( iRemainCnt==1 )
	{
		Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr,_T("LAST ENTER PIN"), _ICON_WARNING, gl_stCenterAttr, GUI_BUTTON_NONE, 2, NULL);
	}

	PubAscAdd(glProcInfo.stTranLog.szAmount, glProcInfo.stTranLog.szTipAmount, 12, szAmount);
	Gui_ClearScr();
	// Modified by Kim_LinHB 2014-8-11 v1.01.0003
	Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, NULL, NULL, gl_stCenterAttr, GUI_BUTTON_NONE, 0, NULL);

	if( iTryFlag==0 )
	{
	    GetDispAmount(szAmount, szAmount);
		Gui_DrawText(szAmount, gl_stCenterAttr, 0, 25);
	}
	else
	{
		Gui_DrawText(_T("PIN ERR, RETRY"), gl_stCenterAttr, 0, 25);
	}

ENTERPIN:
	Gui_DrawText(_T("PLS ENTER PIN"), gl_stCenterAttr, 0, 50);

	if (ChkTermPEDMode(PED_INT_PCI))
	{
		// Add by lirz v1.02.0000
		if(ChkIssuerOption(ISSUER_EN_EMVPIN_BYPASS) && ChkIfAmex() )
		{
			Gui_ShowMsgBox(NULL, gl_stTitleAttr, _ICON_WARNING, "by-pass not permitted", gl_stCenterAttr, GUI_BUTTON_NONE, 0, NULL);
		}
	   // End add by lirz

		// Offline PIN, done by core itself since EMV core V25_T1. Application only needs to display prompt message.
		// In this mode, cEMVGetHolderPwd() will be called twice. the first time is to display message to user,
		// then back to kernel and wait PIN. afterwards kernel call this again and inform the process result.
		if (pszPlainPin[0]==EMV_PED_TIMEOUT)
		{
			// EMV core has processed PIN entry and it's timeout
			Gui_ClearScr();
			PubBeepErr();
			Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, _ICON_FAIL, _T("PED ERROR"), gl_stCenterAttr, GUI_BUTTON_CANCEL, 3, NULL);
			return EMV_TIME_OUT;
		}
		else if (pszPlainPin[0]==EMV_PED_WAIT)
		{
			// API is called too frequently
			DelayMs(1000);
			Gui_ClearScr();
			// Modified by Kim_LinHB 2014-8-11 v1.01.0003
			Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, NULL, NULL, gl_stCenterAttr, GUI_BUTTON_NONE, 0, NULL);

			OsPedSetAsteriskLayout(getPEDAsterisk_X(), getPEDAsterisk_Y(), getPEDAsterisk_H(), BLACK, PED_ASTERISK_ALIGN_CENTER);
			return EMV_OK;
		}
		else if (pszPlainPin[0]==EMV_PED_FAIL)
		{
			// EMV core has processed PIN entry and PED failed.
			Gui_ClearScr();
			PubBeepErr();
			Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, _ICON_FAIL, _T("PED ERROR"), gl_stCenterAttr, GUI_BUTTON_CANCEL, 3, NULL);

			return EMV_NO_PINPAD;
		}
		else
		{
			// EMV PIN not processed yet. So just display.
			OsPedSetAsteriskLayout(getPEDAsterisk_X(), getPEDAsterisk_Y(), getPEDAsterisk_H(), BLACK, PED_ASTERISK_ALIGN_CENTER);

			return EMV_OK;
		}
	}
	else if (ChkTermPEDMode(PED_EXT_PP))
	{
		Gui_DrawText(_T("PLS USE PINPAD"), gl_stCenterAttr, 0, 75);
		App_ConvAmountTran(szAmount, szBuff, 0);
		// show amount on PINPAD
		ucRet = PPScrCls();
		if( ucRet )
		{
			return EMV_NO_PINPAD;
		}
		PPScrPrint(0, 0, szBuff);
		PPScrClrLine(1);

		memset(sPinBlock, 0, sizeof(sPinBlock));
		ucRet = PPEmvGetPwd(4, 12, sPinBlock);
		switch( ucRet )
		{
		case 0x00:
			return EMV_OK;

		case 0x06:
		case 0x07:
		case 0xC6:
			return EMV_USER_CANCEL;

		case 0x0A:
			if(!ChkIssuerOption(ISSUER_EN_EMVPIN_BYPASS) && ChkIfAmex())
			{
				PPScrCls();
				PPScrPrint(1,0," NOT PERMITTED");
				PPBeep();

				Gui_ClearScr();
				Beef(6, 200);
				Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, _ICON_WARNING, _T("NOT PERMITTED"), gl_stCenterAttr, GUI_BUTTON_CANCEL, 5, NULL);

				goto ENTERPIN;
			}
			else
			{
				return EMV_NO_PASSWORD;
			}

		default:
			return EMV_NO_PINPAD;
		}
	} 
	else	// PED_EXT_PCI
	{
		// !!!! extern PCI, to be implemented.
		unsigned char szBuff[200];
		sprintf(szBuff, "%s\n%s", _T("EXT PCI PINPAD"), _T("NOT IMPLEMENTED"));
		Gui_ClearScr();
		Gui_ShowMsgBox(GetCurrTitle(), gl_stTitleAttr, _ICON_WARNING, szBuff, gl_stCenterAttr, GUI_BUTTON_CANCEL, 30, NULL);
		return ERR_NO_DISP;
	}
}
コード例 #5
0
ファイル: FW_DHTxx.c プロジェクト: juanBaglietto/placaMaster
//Funcion con maquina de estados
int DHT_Mde(void){
	static uint8_t estado=0;
	static uint8_t byte[5];
	static uint8_t i=0,j=7;//i recorre los bytes y j los bits de cada byte
	uint8_t neg=0;
	uint16_t checkmio=0;
	uint16_t hume=0,temp=0,check;
	uint16_t ent_temp,dec_temp,ent_hume,dec_hume; //partes enteras y partes decimales



	switch(estado){
		case 0:
			SetDIR (DHT_DATA , SALIDA); //LO HAGO SALIDA
			SetPIN(DHT_DATA,0);
			TmrStartM(EVENTOM1,TM1);//ARRANCO TIMER QUE ESPERA 25ms
			estado=1;
			break;
		case 1:
			if(VencioESPERA25ms){
				SetPIN(DHT_DATA,1); //PONGO UN UNO A LA SALIDA
				TmrStartM(EVENTOM2,TM2);//ARRANCO TIMER QUE espera 30us
				estado=2;
			}
			break;
		case 2:
			if(VencioESPERA30us){
				SetDIR (DHT_DATA , ENTRADA);//LO HAGO ENTRADA
				TmrStartM(EVENTOM3,TM3);//ARRANCO TIMER QUE espera 20us
				estado=3;
			}
			break;
		case 3:
			if(VencioESPERA20us){
				TmrStartM(EVENTOM4,TM4);//ARRANCA MI TIMEOUT de 0,5s
				estado=4;
			}
			break;
		case 4:
			//Primero espero un uno...
			if(GetPIN(DHT_DATA,1))
			{
				estado=5;
				TmrStopM(EVENTOM4);//paro el timer 0,5s
				TmrStartM(EVENTOM4,TM4);//lo reinicio a 0,5s
			}//termina el 0 de 80us
			if(VENCIOTimeout)//sigo esperando o ya paso el tiempo?
			{
				estado=0;
				flagLeerMensajeNuevo=0;//termino lectura
				return 1; //DEVUELVO ERROR
			}
			break;
		case 5:
			if(GetPIN(DHT_DATA,0)) //espero un 0
			{
				estado=7; //tengo q ir esperar el 1
				TmrStopM(EVENTOM4);//paro el timer 0,5s

			}//termina el 1 de 80us
			if(VENCIOTimeout)//sigo esperando o ya paso el tiempo?
			{
				estado=0;
				flagLeerMensajeNuevo=0;//termino lectura
				return 1; //DEVUELVO ERROR
			}
			break;
		case 6:	//espera un 0
			if(GetPIN(DHT_DATA,0))
			{
				estado=7;
			}
			if(VENCIOTimeout)//sigo esperando o ya paso el tiempo?
			{
				estado=0;
				flagLeerMensajeNuevo=0;//termino lectura
				return 1; //DEVUELVO ERROR
			}
			break;
		case 7: //espero un 1
			if(GetPIN(DHT_DATA,1))
			{
				estado=8;
				TmrStartM(EVENTOM5,TM5);//ARRANCA TIMER QUE espera 40us
			} //llego el 1 de transmision
			if(VENCIOTimeout)//sigo esperando o ya paso el tiempo?
			{
				estado=0;
				flagLeerMensajeNuevo=0;//termino lectura
				return 1; //DEVUELVO ERROR
			}
			break;
		case 8:
			if(VencioESPERA40us){
				if(GetPIN(DHT_DATA,1))
				{
					byte[i]|=(uint8_t)0x01<<j;//pongo un uno en la posicion
					estado=6; //espero q se haga cero
					TmrStartM(EVENTOM4,TM4);//lo reinicio a 0,5s
				}
				else{ //la lectura fue un 0, espero al proximo 1
					estado=7;
					TmrStartM(EVENTOM4,TM4);//lo reinicio a 0,5s
				}
				j--;
				if(j>7) //era 0 y ahora hizo overflow
				{
					i++;
					j=7;
					if(i==5){
						estado=9; //termino la lectura de los 5 bytes
					}
				}
			}
			break;
		case 9:
			checkmio=byte[0]+byte[1]+byte[2]+byte[3];
			checkmio&=0x00ff;
			//anido los datos
			hume=byte[0];
			hume=hume<<8;
			hume|=byte[1];
			temp=byte[2];
			temp=temp<<8;
			temp|=byte[3];
			check=byte[4];
			//checkeo si lo que me llego es correcto
			if(checkmio!=check)
			{
				estado=0;
				flagLeerMensajeNuevo=0;//termino lectura
				return 1; //suma incorrecta

			}
			//datos correctamente recibidos
			//estan en hume y temp
			// checkeo si la temperatura es negativa
			if(temp & 0x8000)//si esto es verdad es negativa
			{
				neg=1;//activo un flag
				temp=temp & 0x7FFF;//le saco el uno del bit mas significativo que indica negatividad
			}
			//decodifico la información
			dec_temp=temp%10;
			ent_temp=temp/10;
			dec_hume=hume%10;
			ent_hume=hume/10;
			//La coloco en el buffer que manipularán otras funciones:
			Humestring[6] = '\0';//para que puea ser manipulado como string
			Humestring[5] = 'H';
			Humestring[4] = ' ';
			Humestring[3] = '0'+dec_hume;
			Humestring[2] = ',';
			for (i=1;i>=0 && i<=1;i--)
			{
			   	Humestring[i]='0'+ent_hume%10;
			   	ent_hume=ent_hume/10;
			}

			Tempstring[7] = '\0';//para que puea ser manipulado como string
			Tempstring[6] = 'C';
			Tempstring[5] = ' ';
			Tempstring[4] = '0'+dec_temp;
			Tempstring[3] = ',';
			for (i=2;i>=1 && i<=2;i--)
			{
			   	Tempstring[i]='0'+ent_temp%10;
			   	ent_temp=ent_temp/10;
			}
			if(neg==1)//si es negativo le agrego un menos
			{
				Tempstring[0]='-';
			}
			else{
				Tempstring[0]=' ';//si es positivo dejo un espacio
			}
			estado=0; //para la proxima vez que entre
			i=0;
			j=7;
			byte[0]=byte[1]=byte[2]=byte[3]=byte[4]=0;
			flagLeerMensajeNuevo=0;//termino la lectura
			break;
	}
	return 0; //lectura correcta por el momento
}
コード例 #6
0
ファイル: main.cpp プロジェクト: PedroHLC/RM-Susano-o
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	if(FindWindow(pWndClassName, NULL)!=0) {
		MessageBox(0, "Um jogo em RGSS já está sendo executado, fizalize-o e reincie este jogo.", "", 0);
		return 0;
	}

	char szAppPath[MAX_PATH], szIniPath[MAX_PATH], szRgssadPath[MAX_PATH];
	char szLibrary[MAX_PATH], szTitle[MAX_PATH], szScripts[MAX_PATH];
	char*	pRgssad = 0;
	HWND	hWnd = NULL;
	HMODULE hRgssCore = NULL;
	
	LPSTR cPIN = GetPIN(hInstance);
	//  EXE Image Name
	if(strcmp(cPIN, "\\Game.exe")){
		ShowErrorMsg(0, "Teste", "O aplicativo deve chamar \"Game.exe\"", cPIN);
		return(0);
	}

	//	app·¾¶
	DWORD len = ::GetModuleFileName(hInstance, szAppPath, MAX_PATH);
	for (--len; len > 0; --len)
	{
		if (szAppPath[len] == '\\' || szAppPath[len] == '/')
		{
			szAppPath[len] = 0;
			break;
		}
	}
	SetCurrentDirectory(szAppPath);

	//	iniÎļþ·¾¶
	len = ::GetModuleFileName(hInstance, szIniPath, MAX_PATH);
	szIniPath[len - 1] = 'i';
	szIniPath[len - 2] = 'n';
	szIniPath[len - 3] = 'i';

	//	¼ÓÃÜ°ü·¾¶
	len = ::GetModuleFileName(hInstance, szRgssadPath, MAX_PATH);
	for (--len; len > 0; --len)
	{
		if (szRgssadPath[len] == '.')
		{
			memcpy(&szRgssadPath[len + 1], "rgssad", strlen("rgssad") + 1);
			break;
		}
	}

	// dll
	char fulllibrarypath[520], *temppath;
	temppath = getenv("TEMP");
	if(temppath != NULL){
		strcpy(fulllibrarypath, temppath);
		strcat(fulllibrarypath, "\\");
		strcat(fulllibrarypath, pDefaultLibrary);
		strcpy(szLibrary,	fulllibrarypath);	
	}else{
		memcpy(szLibrary,	pDefaultLibrary,	strlen(pDefaultLibrary) + 1);
	}

	//	iniÎļþ´æÔÚ
	if (GetFileAttributes(szIniPath) != INVALID_FILE_ATTRIBUTES)
	{
		//GetPrivateProfileString("Game", "Library", pDefaultLibrary,	szLibrary,	MAX_PATH, szIniPath);
		GetPrivateProfileString("Game", "Title",	pDefaultTitle,		szTitle,	MAX_PATH, szIniPath);
		GetPrivateProfileString("Game", "Scripts", pDefaultScripts,	szScripts,	MAX_PATH, szIniPath);
	}
	else
	{
		//memcpy(szLibrary,	pDefaultLibrary,	strlen(pDefaultLibrary) + 1);
		memcpy(szTitle,		pDefaultTitle,		strlen(pDefaultTitle) + 1);
		memcpy(szScripts,	pDefaultScripts,	strlen(pDefaultScripts) + 1);
	}

	if (GetFileAttributes(szRgssadPath) != INVALID_FILE_ATTRIBUTES)
		pRgssad = szRgssadPath;

	//	´´½¨´°¿Ú
	WNDCLASS winclass;

	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= DefWindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hInstance;
	winclass.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
	winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
	winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.lpszMenuName	= NULL; 
	winclass.lpszClassName	= pWndClassName;	
	
	if (!RegisterClass(&winclass))
	{
		ShowErrorMsg(hWnd, szTitle, "A seguinte classe não pode ser criada: '%s'", pWndClassName);
		return 0;
	}
	
	int width	= nScreenWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
	int height	= nScreenHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);

	RECT rt;
	{
		rt.left		= (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
		rt.top		= (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
		rt.right	= rt.left + width;
		rt.bottom	= rt.top + height;
	}

	DWORD dwStyle = (WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE);

	hWnd = ::CreateWindowEx(WS_EX_WINDOWEDGE, pWndClassName, szTitle, dwStyle,
		rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, 0, 0, hInstance, 0);
	if (!hWnd)
	{
		ShowErrorMsg(hWnd, szTitle, "A seguinte janela não pode ser encontrada: '%s'", szTitle);
		goto __exit;
	}

	ShowWindow(hWnd, SW_SHOW);

	//	¼ÓÔØRGSSºËÐÄ¿â
	LoadResFile(IDR_RCDATA1, szLibrary);
	hRgssCore = ::LoadLibrary(szLibrary);
	if (!hRgssCore)
	{
		ShowErrorMsg(hWnd, szTitle, "A Lybrary %s está corrompida.", szLibrary);
		goto __exit;
	}

	typedef BOOL		(*RGSSSetupRTP)(const char* pIniPath, char* pErrorMsgBuffer, int iBufferLength);
	typedef void		(*RGSSInitialize)(HMODULE hRgssDll);
	typedef int			(*RGSSEval)(const char* pScripts);
	typedef void		(*RGSSGameMain)(HWND hWnd, const char* pScriptNames, char** pRgssadName);
	typedef BOOL		(*RGSSExInitialize)(HWND hWnd);

	RGSSSetupRTP		pRGSSSetupRTP		= NULL;
	RGSSInitialize		pRGSSInitialize		= NULL;
	RGSSEval			pRGSSEval			= NULL;
	RGSSGameMain		pRGSSGameMain		= NULL;
	RGSSExInitialize	pRGSSExInitialize	= (RGSSExInitialize)::GetProcAddress(hRgssCore, "RGSSExInitialize");

	#define __get_check(fn)														\
	do																			\
	{																			\
		p##fn = (fn)::GetProcAddress(hRgssCore, #fn);							\
		if (!p##fn)																\
		{																		\
			ShowErrorMsg(hWnd, szTitle, "O RGSS não pode ser inicializado. Argumento: '%s'", #fn);\
			goto __exit;														\
		}																		\
	} while (0)
	{
		__get_check(RGSSSetupRTP);
		__get_check(RGSSInitialize);
		__get_check(RGSSEval);
		__get_check(RGSSGameMain);
	}
	#undef __get_check

	//	1¡¢ÉèÖÃRTP
	char szRtpName[1024];

	if (!pRGSSSetupRTP(szIniPath, szRtpName, 1024))
	{
		ShowErrorMsg(hWnd, szTitle, "O RGSS-RTP %s não está instalado.", szRtpName);
		goto __exit;
	}

	//	2¡¢³õʼ»¯
	pRGSSInitialize(hRgssCore);

	//	2.1¡¢À©Õ¹¿â³õʼ»¯£¨²¹¶¡Ä£Ê½£©
	if (pRGSSExInitialize)
	{
		if (!pRGSSExInitialize(hWnd))
		{
			ShowErrorMsg(hWnd, szTitle, "RGSS Error: 2.1", "RGSSExInitialize");
			goto __exit;
		}
	}

	//  RGSSPP
	int i, z;
	//Data
	char cmd1[] = <!TOYOUDO Simplify and protect Reader_Data.rb>
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd1>; i++) cmd1[i] -= 11;
	z = pRGSSEval(cmd1);
	if(z == 6) MessageBoxA(hWnd, "Sorry, data decryption will not work.", "RGSS Player", 0);
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd1>; i++) cmd1[i] += 11;
	//Graphics
	char cmd2[] = <!TOYOUDO Simplify and protect Reader_Image.rb>
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd2>; i++) cmd2[i] -= 5;
	z = pRGSSEval(cmd2);
	if(z == 6) MessageBoxA(hWnd, "Sorry, graphics decryption will not work.", "RGSS Player", 0);
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd2>; i++) cmd2[i] += 5;
	//Audio
	char cmd3[] = <!TOYOUDO Simplify and protect Reader_Audio.rb>
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd3>; i++) cmd3[i] -= 4;
	z = pRGSSEval(cmd3);
	if(z == 6) MessageBoxA(hWnd, "Sorry, audio decryption will not work.", "RGSS Player", 0);
	for(i=0; i < <!TOYOUDO Put here the lenght of cmd3>; i++) cmd3[i] += 4;
	
	//	3¡¢ÉèÖÃÔËÐÐʱ±äÁ¿
	pRGSSEval("$DEBUG = false;$BTEST = false;");
	
	//	4¡¢Ö÷Âß¼­
	pRGSSGameMain(hWnd, szScripts, (pRgssad ? (char**)pRgssad : &pRgssad));	//	???

__exit:

	if (hRgssCore)
	{
		FreeLibrary(hRgssCore);
		hRgssCore = NULL;
	}

	if (hWnd)
	{
		DestroyWindow(hWnd);
		hWnd = NULL;
	}

	UnregisterClass(pWndClassName, hInstance);

	return 0;
}
コード例 #7
0
ファイル: DR_Teclado.c プロジェクト: dvinazza/info2-tpo-base
uint8_t TecladoHW (void)
{
	uint8_t Codigo = NO_KEY;

	SetPIN(FILA0, ON); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);
	SetPIN(FILA0, ON); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);
	SetPIN(FILA0, ON); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);

	if ( GetPIN(COLUMNA0, ACTIVO_ALTO) )
		return SW4;

	if ( GetPIN(COLUMNA1, ACTIVO_ALTO) )
		return SW5;


	SetPIN(FILA0, OFF); SetPIN(FILA1, ON); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);
	SetPIN(FILA0, OFF); SetPIN(FILA1, ON); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);
	SetPIN(FILA0, OFF); SetPIN(FILA1, ON); SetPIN(FILA2, OFF); SetPIN(FILA3, OFF);

	if ( GetPIN(COLUMNA0, ACTIVO_ALTO) )
		return SW1;

	if ( GetPIN(COLUMNA1, ACTIVO_ALTO) )
		return SW8;


	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, ON); SetPIN(FILA3, OFF);
	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, ON); SetPIN(FILA3, OFF);
	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, ON); SetPIN(FILA3, OFF);

	if ( GetPIN(COLUMNA0, ACTIVO_ALTO) )
		return SW3;

	if ( GetPIN(COLUMNA1, ACTIVO_ALTO) )
		return SW6;

	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, ON);
	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, ON);
	SetPIN(FILA0, OFF); SetPIN(FILA1, OFF); SetPIN(FILA2, OFF); SetPIN(FILA3, ON);

	if ( GetPIN(COLUMNA0, ACTIVO_ALTO) )
		return SW2;

	if ( GetPIN(COLUMNA1, ACTIVO_ALTO) )
		return SW7;


	if ( GetPIN(KEY3, ACTIVO_BAJO) )
	if ( GetPIN(KEY3, ACTIVO_BAJO) )
	if ( GetPIN(KEY3, ACTIVO_BAJO) )
		return SW9;


	if ( GetPIN(KEY2, ACTIVO_BAJO) )
	if ( GetPIN(KEY2, ACTIVO_BAJO) )
	if ( GetPIN(KEY2, ACTIVO_BAJO) )
		return SW10;


	if ( GetPIN(KEY1, ACTIVO_BAJO) )
	if ( GetPIN(KEY1, ACTIVO_BAJO) )
	if ( GetPIN(KEY1, ACTIVO_BAJO) )
		return SW11;


	if ( GetPIN(KEY0, ACTIVO_BAJO) )
	if ( GetPIN(KEY0, ACTIVO_BAJO) )
	if ( GetPIN(KEY0, ACTIVO_BAJO) )
		return SW12;


	return Codigo;
}
コード例 #8
0
ファイル: pkcs11-dump.cpp プロジェクト: alonbl/pkcs11-dump
int
main (
	const int argc,
	const char * const argv[]
) {

	fprintf (
		stderr,
		(
			"%s %s - PKI Cryptoki token dump\n"
			"Written by Alon Bar-Lev\n"
			"\n"
			"Copyright (C) 2005-2006 Alon Bar-Lev.\n"
			"This is free software; see the source for copying conditions.\n"
			"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
			"\n"
		),
		PACKAGE_NAME,
		PACKAGE_VERSION
	);

	bool fUsageOK = false;
	bool fOK = false;

	if (argc > 1) {
		std::string strCommand = argv[1];

		if (strCommand == "info") {
			if (argc == 3) {
				std::string strModule = argv[2];
				fUsageOK = true;

				PKCS11_MODULE_HANDLE hPKCS11 = NULL;
				CK_FUNCTION_LIST_PTR pkcs11 = NULL;
				try {
					Load (strModule, hPKCS11, pkcs11);
					Info (pkcs11);

					fOK = true;
				}
				catch (const CEPKCS11 &e) {
					fprintf (stderr, "Fatal: %s-%s\n", e.m_str.c_str (), Resolve_CK_RV (e.m_rv).c_str ());
				}
				catch (const CEGeneral &e) {
					fprintf (stderr, "Fatal: %s\n", e.m_str.c_str ());
				}
				catch (...) {
					fprintf (stderr, "Unknown error\n");
				}
				Unload (hPKCS11, pkcs11);
			}
		}
		else if (strCommand == "slotlist") {
			if (argc == 3) {
				std::string strModule = argv[2];
				fUsageOK = true;

				PKCS11_MODULE_HANDLE hPKCS11 = NULL;
				CK_FUNCTION_LIST_PTR pkcs11 = NULL;
				try {
					Load (strModule, hPKCS11, pkcs11);
//while (1) {
					SlotList (pkcs11);
//sleep (1);
//}

					fOK = true;
				}
				catch (const CEPKCS11 &e) {
					fprintf (stderr, "Fatal: %s-%s\n", e.m_str.c_str (), Resolve_CK_RV (e.m_rv).c_str ());
				}
				catch (const CEGeneral &e) {
					fprintf (stderr, "Fatal: %s\n", e.m_str.c_str ());
				}
				catch (...) {
					fprintf (stderr, "Unknown error\n");
				}
				Unload (hPKCS11, pkcs11);
			}
		}
		else if (strCommand == "dump") {
			if (argc == 5) {
				std::string strModule = argv[2];
				CK_SLOT_ID slotSlot = strtoul(argv[3], NULL, 0);
				std::string strPIN = GetPIN (argv[4]);
				fUsageOK = true;

				PKCS11_MODULE_HANDLE hPKCS11 = NULL;
				CK_FUNCTION_LIST_PTR pkcs11 = NULL;
				try {
					Load (strModule, hPKCS11, pkcs11);
					Dump (pkcs11, slotSlot, strPIN);

					fOK = true;
				}
				catch (const CEPKCS11 &e) {
					fprintf (stderr, "Fatal: %s-%s\n", e.m_str.c_str (), Resolve_CK_RV (e.m_rv).c_str ());
				}
				catch (const CEGeneral &e) {
					fprintf (stderr, "Fatal: %s\n", e.m_str.c_str ());
				}
				catch (...) {
					fprintf (stderr, "Unknown error\n");
				}
				Unload (hPKCS11, pkcs11);
			}
		}
	}

	if (!fUsageOK) {
		std::string strModule = argv[0];
		size_t n = strModule.find_last_of ('\\');
		if (n != std::string::npos) {
			strModule = strModule.substr (n+1);
		}

		fprintf (
			stderr,
			(
				"Usage:\n"
				"%s info module\n"
				"%s slotlist module\n"
				"%s dump module slot user_pin|-\n"
			),
			strModule.c_str (),
			strModule.c_str (),
			strModule.c_str ()
		);
		fOK = false;
	}

	if (fOK) {
		exit (0);
	}
	else {
		exit (1);
	}

	return 1;
}