Beispiel #1
0
/**
 * @fn int AppInit(void)

 * @return SUCC 成功
 			 FAIL 失败
 */
int AppInit (void)
{
	char PDOL_Value[256] ;//APDU数据域最大不能超过255字节(LC决定)
	char resp[256] ;//APDU的响应,最大为256字节,由(LE)决定
	int ret ;
	char trace[4];

	InitTVR() ; //初始化TVR
	InitTSI() ; //初始化TSI

	memset (PDOL_Value, 0, 256) ;
	if (DOLProcess (PDOL, PDOL_Value) == FAIL)//建立数据元列表失败
		return FAIL ;

	memset(resp, 0x00, 256) ;
	//PDOL_Value第一字节为后续字节的长度
	if( (ret = IC_GetProcessOptions(PDOL_Value + 1, PDOL_Value[0], resp)) < 0 )
	{	
		IC_GetLastSW (PDOL_Value, PDOL_Value+1) ;
		if (*PDOL_Value == 0x69 && *(PDOL_Value + 1) ==0x85)
		{
			//需考虑清除当前应用,并回到应用选择
			return QUIT ;
		}
		return FAIL ; 	
	}
	
	//分析处理选项命令的响应
	if(AnalyzeProcOp( resp,  ret) == FAIL)
 		return FAIL ;

	getvar((char * )&ret, TSC_OFF, TSC_LEN) ;
	ret ++ ;
	if (ret > 99999999)
		ret = 0 ;

	memset(trace, 0, sizeof(trace));
	IntToC4((unsigned char *)trace, (unsigned int)ret) ;
	SetAppData("\x9F\x41", trace, 4) ;
	savevar((char * )&ret, TSC_OFF, TSC_LEN) ;
	return SUCC ;
}
Beispiel #2
0
void command(char *line) {
    // remove the \n at the end from fgets
    line[strcspn(line, "\n")] = 0;
    char *line2;
    int i = 0, type = 0;
    
    line2 = strtok(line, " ");
    while(line2 != NULL) {
        if(line2[0] == '"') {
            line2++;
            type = 2;
            strcpy(line_words[i], "");
            while(line2 != NULL) {
                strcat(line_words[i], line2);
                strcat(line_words[i], " ");
                line2 = strtok(NULL, "\"");
            }
        } else {
            strcpy(line_words[i], line2);
            line2 = strtok(NULL, " ");
        }
        i++;
    }
    
    if(strcmp(line_words[0], "print") == 0) {
        print(line_words[1]);
    } else if(strcmp(line_words[0], "var") == 0) {
        savevar();
    } else {
        // no command found, maybe it's a variable operation
        var *vari = list_search(line_words[0]);
        if(vari) {
            variable_op(vari, type);
        }
    }
}