Ejemplo n.º 1
0
int UnwrapKey(const char *pin, int keyid, const char* filename)
{
	uint16 sw1sw2;
	uint8 *pWrapped;
	int len;
	int rc = SC_Open(pin, 0);
	if (rc < 0)
		return rc;
	if (!(1 <= keyid && keyid <= 127)) {
		printf("keyid (%d) must be between 1 and 127\n", keyid);
		return ERR_INVALID;
	}
	ReadFromFile(filename, pWrapped, len);
	if (pWrapped == NULL) {
		printf("file '%s' not found\n", filename);
		return ERR_INVALID;
	}
	if (len <= 0) {
		free(pWrapped);
		printf("file '%s' empty\n", filename);
		return ERR_INVALID;
	}
	/* - SmartCard-HSM: UNWRAP KEY */
	rc = SC_ProcessAPDU(
		0, 0x80,0x74,keyid,0x93,
		pWrapped, len,
		NULL, 0,
		&sw1sw2);
	free(pWrapped);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 2
0
int ChangeSoPin(const char *oldsopin, const char *newsopin)
{
	uint16 sw1sw2;
	int rc;
	uint8 so_pin_so_pin[8 + 8];
	if (strlen(oldsopin) != 16) {
		printf("old SO_PIN must have 16 hex-digits\n");
		return ERR_INVALID;
	}
	rc = Hex2Bin(oldsopin, 16, so_pin_so_pin);
	if (rc)
		return rc;
	if (strlen(newsopin) != 16) {
		printf("new SO_PIN must have 16 hex-digits\n");
		return ERR_INVALID;
	}
	rc = Hex2Bin(newsopin, 16, so_pin_so_pin + 8);
	if (rc)
		return rc;
	rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: CHANGE REFERENCE DATA */
	rc = SC_ProcessAPDU(
		0, 0x00,0x24,0x00,0x88,
		so_pin_so_pin, 8 + 8,
		NULL, 0,
		&sw1sw2);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 3
0
int ChangePin(const char *oldpin, const char *newpin)
{
	uint16 sw1sw2;
	int rc, old_len, new_len;
	uint8 pins[32];
	old_len = strlen(oldpin);
	if (!(6 <= old_len && old_len <= 16)) {
		printf("old PIN must have 6 - 16 chars\n");
		return ERR_INVALID;
	}
	new_len = strlen(newpin);
	if (new_len != old_len) {
		printf("new PIN must have same size as old pin\n");
		return ERR_INVALID;
	}
	memcpy(pins,           oldpin, old_len); /* no 0 terminator */
	memcpy(pins + old_len, newpin, new_len); /* no 0 terminator */
	rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: CHANGE REFERENCE DATA */
	rc = SC_ProcessAPDU(
		0, 0x00,0x24,0x00,0x81,
		pins, old_len + new_len,
		NULL, 0,
		&sw1sw2);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 4
0
int UnlockPin(const char *sopin)
{
	uint16 sw1sw2;
	int rc;
	uint8 so_pin[8];
	if (strlen(sopin) != 16) {
		printf("SO_PIN must have 16 hex-digits\n");
		return ERR_INVALID;
	}
	rc = Hex2Bin(sopin, 16, so_pin);
	if (rc)
		return rc;
	rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: RESET RETRY COUNTER */
	rc = SC_ProcessAPDU(
		0, 0x00,0x2C,0x01,0x81,
		so_pin, 8,
		NULL, 0,
		&sw1sw2);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 5
0
int DumpAllFiles(const char *pin)
{
	uint8 list[2 * 128];
	uint16 sw1sw2;
	int rc, i;
	rc = SC_Open(pin, 0);
	if (rc < 0)
		return rc;

	/* - SmartCard-HSM: ENUMERATE OBJECTS */
	rc = SC_ProcessAPDU(
		0, 0x00,0x58,0x00,0x00,
		NULL, 0,
		list, sizeof(list),
		&sw1sw2);
	if (rc < 0) {
		SC_Close();
		return rc;
	}
	/* save dir and all files */
	printf("write 'dir.hsm'\n");
	SaveToFile("dir.hsm", list, rc);
	for (i = 0; i < rc; i += 2) {
		uint8 buf[8192], *p;
		char name[10];
		int rc, off;
		uint16 fid = list[i] << 8 | list[i + 1];
		if (list[i] == 0xcc) /* never readable */
			continue;
		for (p = buf, off = 0; off < sizeof(buf); p += rc) {
			int l = sizeof(buf) - off;
			if (l > MAX_OUT_IN)
				l = MAX_OUT_IN;
			rc = SC_ReadFile(fid, off, p, l);
			if (rc < 0)
				break;
			off += rc;
			if (rc < l)
				break;
		}
		if (rc >= 0) {
			sprintf(name, "%04X.asn", fid);
			printf("write '%s'\n", name);
			SaveToFile(name, buf, off);
		}
	}
	SC_Close();
	return 0;
}
Ejemplo n.º 6
0
int GetPinStatus()
{
	uint16 sw1sw2;
	int rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: VERIFY */
	rc = SC_ProcessAPDU(
		0, 0x00,0x20,0x00,0x81,
		NULL, 0,
		NULL, 0,
		&sw1sw2);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 7
0
int WrapKey(const char *pin, int keyid, const char* filename)
{
	uint16 sw1sw2;
	uint8 wrapped[1024];
	int rc;
	if (!(1 <= keyid && keyid <= 127)) {
		printf("keyid (%d) must be between 1 and 127\n", keyid);
		return ERR_INVALID;
	}
	rc = SC_Open(pin, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: WRAP KEY */
	rc = SC_ProcessAPDU(
		0, 0x80,0x72,keyid,0x92,
		NULL, 0,
		wrapped, sizeof(wrapped),
		&sw1sw2);
	SC_Close();
	if (rc <= 0)
		return rc;
	SaveToFile(filename, wrapped, rc);
	return sw1sw2;
}
Ejemplo n.º 8
0
int SetPin(const char *pin, const char *sopin)
{
	uint16 sw1sw2;
	int rc;
	uint8 so_pin_pin[8 + 16];
	int pin_len = strlen(pin);
	if (!(6 <= pin_len && pin_len <= 16)) {
		printf("PIN must have 6 - 16 chars\n");
		return ERR_INVALID;
	}
	if (sopin == 0) {
		memcpy(so_pin_pin, "\x35\x37\x36\x32\x31\x38\x38\x30", 8);
	} else {
		if (strlen(sopin) != 16) {
			printf("SO_PIN must have 16 hex-digits\n");
			return ERR_INVALID;
		}
		rc = Hex2Bin(sopin, 16, so_pin_pin);
		if (rc)
			return rc;
	}
	memcpy(so_pin_pin + 8, pin, pin_len); /* no 0 terminator */
	rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: RESET RETRY COUNTER */
	rc = SC_ProcessAPDU(
		0, 0x00,0x2C,0x00,0x81,
		so_pin_pin, 8 + pin_len,
		NULL, 0,
		&sw1sw2);
	SC_Close();
	if (rc < 0)
		return rc;
	return sw1sw2;
}
Ejemplo n.º 9
0
static void InitMapInfo(void)
{
    int map;
    int mapMax;
    int mcmdValue;
    mapInfo_t *info;
    char songMulch[10];

    mapMax = 1;

    // Put defaults into MapInfo[0]
    info = MapInfo;
    info->cluster = 0;
    info->warpTrans = 0;
    info->nextMap = 1;          // Always go to map 1 if not specified
    info->cdTrack = 1;
    info->sky1Texture = R_TextureNumForName(DEFAULT_SKY_NAME);
    info->sky2Texture = info->sky1Texture;
    info->sky1ScrollDelta = 0;
    info->sky2ScrollDelta = 0;
    info->doubleSky = false;
    info->lightning = false;
    info->fadetable = W_GetNumForName(DEFAULT_FADE_TABLE);
    strcpy(info->name, UNKNOWN_MAP_NAME);

//      strcpy(info->songLump, DEFAULT_SONG_LUMP);
    SC_Open(MAPINFO_SCRIPT_NAME);
    while (SC_GetString())
    {
        if (SC_Compare("MAP") == false)
        {
            SC_ScriptError(NULL);
        }
        SC_MustGetNumber();
        if (sc_Number < 1 || sc_Number > 99)
        {                       // 
            SC_ScriptError(NULL);
        }
        map = sc_Number;

        info = &MapInfo[map];

        // Save song lump name
        strcpy(songMulch, info->songLump);

        // Copy defaults to current map definition
        memcpy(info, &MapInfo[0], sizeof(*info));

        // Restore song lump name
        strcpy(info->songLump, songMulch);

        // The warp translation defaults to the map number
        info->warpTrans = map;

        // Map name must follow the number
        SC_MustGetString();
        strcpy(info->name, sc_String);

        // Process optional tokens
        while (SC_GetString())
        {
            if (SC_Compare("MAP"))
            {                   // Start next map definition
                SC_UnGet();
                break;
            }
            mcmdValue = MapCmdIDs[SC_MustMatchString(MapCmdNames)];
            switch (mcmdValue)
            {
                case MCMD_CLUSTER:
                    SC_MustGetNumber();
                    info->cluster = sc_Number;
                    break;
                case MCMD_WARPTRANS:
                    SC_MustGetNumber();
                    info->warpTrans = sc_Number;
                    break;
                case MCMD_NEXT:
                    SC_MustGetNumber();
                    info->nextMap = sc_Number;
                    break;
                case MCMD_CDTRACK:
                    SC_MustGetNumber();
                    info->cdTrack = sc_Number;
                    break;
                case MCMD_SKY1:
                    SC_MustGetString();
                    info->sky1Texture = R_TextureNumForName(sc_String);
                    SC_MustGetNumber();
                    info->sky1ScrollDelta = sc_Number << 8;
                    break;
                case MCMD_SKY2:
                    SC_MustGetString();
                    info->sky2Texture = R_TextureNumForName(sc_String);
                    SC_MustGetNumber();
                    info->sky2ScrollDelta = sc_Number << 8;
                    break;
                case MCMD_DOUBLESKY:
                    info->doubleSky = true;
                    break;
                case MCMD_LIGHTNING:
                    info->lightning = true;
                    break;
                case MCMD_FADETABLE:
                    SC_MustGetString();
                    info->fadetable = W_GetNumForName(sc_String);
                    break;
                case MCMD_CD_STARTTRACK:
                case MCMD_CD_END1TRACK:
                case MCMD_CD_END2TRACK:
                case MCMD_CD_END3TRACK:
                case MCMD_CD_INTERTRACK:
                case MCMD_CD_TITLETRACK:
                    SC_MustGetNumber();
                    cd_NonLevelTracks[mcmdValue - MCMD_CD_STARTTRACK] =
                        sc_Number;
                    break;
            }
        }
        mapMax = map > mapMax ? map : mapMax;
    }
    SC_Close();
    MapCount = mapMax;
}
Ejemplo n.º 10
0
void SN_InitSequenceScript(void)
{
	int i, j;
	int inSequence;
	int *tempDataStart;
	int *tempDataPtr;

	inSequence = -1;
	ActiveSequences = 0;
	for(i = 0; i < SS_MAX_SCRIPTS; i++)
	{
		SequenceData[i] = NULL;
	} 

	SC_Open(SS_SCRIPT_NAME);
	while(SC_GetString())
	{
		if(*sc_String == ':')
		{
			if(inSequence != -1)
			{
				SC_ScriptError("SN_InitSequenceScript:  Nested Script Error");
			}
			tempDataStart = (int *)Z_Malloc(SS_TEMPBUFFER_SIZE, 
				PU_STATIC, NULL);
			memset(tempDataStart, 0, SS_TEMPBUFFER_SIZE);
			tempDataPtr = tempDataStart;
			for(i = 0; i < SS_MAX_SCRIPTS; i++)
			{
				if(SequenceData[i] == NULL)
				{
					break;
				}
			}
			if(i == SS_MAX_SCRIPTS)
			{
				I_Error("Number of SS Scripts >= SS_MAX_SCRIPTS");
			}
			for(j = 0; j < SEQ_NUMSEQ; j++)
			{
				if(!strcasecmp(SequenceTranslate[j].name, sc_String+1))
				{
					SequenceTranslate[j].scriptNum = i;
					inSequence = j;
					break;
				}
			}					
			continue; // parse the next command
		}
		if(inSequence == -1)
		{
			continue;
		}
		if(SC_Compare(SS_STRING_PLAYUNTILDONE))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			SC_MustGetString();
			*tempDataPtr++ = SS_CMD_PLAY;
			*tempDataPtr++ = GetSoundOffset(sc_String);
			*tempDataPtr++ = SS_CMD_WAITUNTILDONE;		
		}
		else if(SC_Compare(SS_STRING_PLAY))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			SC_MustGetString();
			*tempDataPtr++ = SS_CMD_PLAY;
			*tempDataPtr++ = GetSoundOffset(sc_String);
		}
		else if(SC_Compare(SS_STRING_PLAYTIME))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			SC_MustGetString();
			*tempDataPtr++ = SS_CMD_PLAY;
			*tempDataPtr++ = GetSoundOffset(sc_String);
			SC_MustGetNumber();
			*tempDataPtr++ = SS_CMD_DELAY;	
			*tempDataPtr++ = sc_Number;
		}
		else if(SC_Compare(SS_STRING_PLAYREPEAT))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			SC_MustGetString();
			*tempDataPtr++ = SS_CMD_PLAYREPEAT;
			*tempDataPtr++ = GetSoundOffset(sc_String);
		}
		else if(SC_Compare(SS_STRING_DELAY))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			*tempDataPtr++ = SS_CMD_DELAY;
			SC_MustGetNumber();
			*tempDataPtr++ = sc_Number;
		}
		else if(SC_Compare(SS_STRING_DELAYRAND))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			*tempDataPtr++ = SS_CMD_DELAYRAND;
			SC_MustGetNumber();
			*tempDataPtr++ = sc_Number;
			SC_MustGetNumber();
			*tempDataPtr++ = sc_Number;
		}
		else if(SC_Compare(SS_STRING_VOLUME))
		{
			VerifySequencePtr(tempDataStart, tempDataPtr);
			*tempDataPtr++ = SS_CMD_VOLUME;
			SC_MustGetNumber();
			*tempDataPtr++ = sc_Number;
		}
		else if(SC_Compare(SS_STRING_END))
		{
			int dataSize;

			*tempDataPtr++ = SS_CMD_END;
			dataSize = (tempDataPtr-tempDataStart)*sizeof(int);
			SequenceData[i] = (int *)Z_Malloc(dataSize, PU_STATIC,
				NULL);
			memcpy(SequenceData[i], tempDataStart, dataSize);
			Z_Free(tempDataStart);
			inSequence = -1;
		}
		else if(SC_Compare(SS_STRING_STOPSOUND))
		{
			SC_MustGetString();
			SequenceTranslate[inSequence].stopSound =
				GetSoundOffset(sc_String);
			*tempDataPtr++ = SS_CMD_STOPSOUND;
		}
		else
		{
			SC_ScriptError("SN_InitSequenceScript:  Unknown commmand.\n");
		}
	}
}
Ejemplo n.º 11
0
void P_InitFTAnims(void)
{
	int     base;
	boolean ignore;
	boolean done;
	int     AnimDefCount = 0;
	int     groupNumber, picBase;
	int     type, index;

	SC_Open(ANIM_SCRIPT_NAME);
	while(SC_GetString())
	{
		if(AnimDefCount == MAX_ANIM_DEFS)
		{
			Con_Error("P_InitFTAnims: too many AnimDefs.");
		}
		if(SC_Compare(SCI_FLAT))
		{
			type = ANIM_FLAT;
		}
		else if(SC_Compare(SCI_TEXTURE))
		{
			type = ANIM_TEXTURE;
		}
		else
		{
			SC_ScriptError(NULL);
		}
		SC_MustGetString();		// Name
		ignore = false;
		if(type == ANIM_FLAT)
		{
			if(W_CheckNumForName(sc_String) == -1)
			{
				ignore = true;
			}
			else
			{
				picBase = R_FlatNumForName(sc_String);
				groupNumber =
					R_CreateAnimGroup(DD_FLAT, AGF_SMOOTH | AGF_FIRST_ONLY);
			}
		}
		else
		{						// Texture
			if(R_CheckTextureNumForName(sc_String) == -1)
			{
				ignore = true;
			}
			else
			{
				picBase = R_TextureNumForName(sc_String);
				groupNumber =
					R_CreateAnimGroup(DD_TEXTURE, AGF_SMOOTH | AGF_FIRST_ONLY);
			}
		}

		done = false;
		while(done == false)
		{
			if(SC_GetString())
			{
				if(SC_Compare(SCI_PIC))
				{
					SC_MustGetNumber();
					if(ignore == false)
					{
						index = picBase + sc_Number - 1;
					}
					SC_MustGetString();
					if(SC_Compare(SCI_TICS))
					{
						SC_MustGetNumber();
						if(ignore == false)
						{
							R_AddToAnimGroup(groupNumber, index, sc_Number, 0);
						}
					}
					else if(SC_Compare(SCI_RAND))
					{
						SC_MustGetNumber();
						base = sc_Number;
						SC_MustGetNumber();
						if(ignore == false)
						{
							R_AddToAnimGroup(groupNumber, index, base,
											 sc_Number - base);
						}
					}
					else
					{
						SC_ScriptError(NULL);
					}
				}
				else
				{
					SC_UnGet();
					done = true;
				}
			}
			else
			{
				done = true;
			}
		}
	}
	SC_Close();
}
Ejemplo n.º 12
0
int main(int argc, char** argv)
{
    FILE *f = fopen("dgl.h", "w");
    int i = 0;

    SC_Open("GL.H");

    while(SC_ReadTokens())
    {
        SC_Find(false);

        if(!stricmp(sc_parser.token, "WINGDIAPI"))
        {
            GetGLType(&gldata[i].header);
            SC_Find(false);

            if(!stricmp(sc_parser.token, "APIENTRY"))
            {
                SC_Find(false);
                if(sc_parser.token[0] == 'g' && sc_parser.token[1] == 'l')
                {
                    int j = 0;

                    strcpy(gldata[i].name, sc_parser.token);

                    while(!strrchr(sc_parser.token, ';'))
                    {
                        if(GetGLType(&gldata[i].args[j]))
                            GetGLArg(&gldata[i].args[j]);
                        j++;
                    }

                    i++;
                }
            }
        }
    }

    fprintf(f, "//\n// Generated by dglmake\n//\n");
    fprintf(f, "#ifndef USE_DEBUG_GLFUNCS\n\n");

    SlapGLStuffToFile(f, i, false);
    fprintf(f, "\n#endif // USE_DEBUG_GLFUNCS\n\n");

    SC_Close();

    SlapGLExtensionsToFile(f, "GL_ARB_multitexture");
    SlapGLExtensionsToFile(f, "GL_EXT_compiled_vertex_array");
    SlapGLExtensionsToFile(f, "GL_EXT_multi_draw_arrays");
    SlapGLExtensionsToFile(f, "GL_EXT_fog_coord");
    SlapGLExtensionsToFile(f, "GL_ARB_vertex_buffer_object");
    SlapGLExtensionsToFile(f, "GL_ARB_texture_non_power_of_two");
    SlapGLExtensionsToFile(f, "GL_ARB_texture_env_combine");
    SlapGLExtensionsToFile(f, "GL_EXT_texture_env_combine");
    SlapGLExtensionsToFile(f, "GL_EXT_texture_filter_anisotropic");
    SlapGLExtensionsToFile(f, "GL_ARB_shader_objects");
    SlapGLExtensionsToFile(f, "GL_ARB_framebuffer_object");
    SlapGLExtensionsToFile(f, "GL_ARB_occlusion_query");
    SlapGLExtensionsToFile(f, "GL_EXT_texture_array");

    fclose(f);

    return 1;
}
Ejemplo n.º 13
0
void SlapGLExtensionsToFile(FILE* f, char* arbstring)
{
    int i = 0;
    int a = 0;
    int j;

    SC_Open("SDL_opengl.h");

    fprintf(f, "//\n// %s\n//\n", arbstring);

    while(SC_ReadTokens())
    {
        SC_Find(false);

        if(!strcmp(sc_parser.token, arbstring))
        {
            SC_Find(false);

            if(strcmp(sc_parser.token, "1"))
                continue;

            while(SC_ReadTokens())
            {
                SC_Find(false);

                if(!strcmp(sc_parser.token, "#endif"))
                {
                    int count;

                    count = i;
                    i = 0;

                    while(i < count)
                    {
                        SC_Find(false);

                        if(!strcmp(sc_parser.token, "(APIENTRYP"))
                        {
                            int j = 0;
                            int len;

                            SC_Find(false);

                            strcpy(gldata[i].extname, sc_parser.token);

                            len = strlen(gldata[i].extname);
                            gldata[i].extname[len - 1] = 0;

                            while(!strrchr(sc_parser.token, ';'))
                            {
                                if(GetGLType(&gldata[i].args[j]))
                                    GetGLArg(&gldata[i].args[j]);
                                j++;
                            }

                            i++;
                        }
                    }

                    break;
                }
                else
                {
                    if(!strcmp(sc_parser.token, "GLAPI"))
                    {
                        GetGLType(&gldata[i].header);
                        SC_Find(false);
                        SC_Find(false);

                        if(sc_parser.token[0] == 'g' && sc_parser.token[1] == 'l')
                        {
                            strcpy(gldata[i].name, sc_parser.token);
                            i++;
                        }
                    }
                }
            }
        }
    }

    fprintf(f, "extern bool has_%s;\n", arbstring);

    if(i > 0)
        fprintf(f, "\n");

    if(i > 0)
        fprintf(f, "#ifndef __IPHONEOS__\n");
    for(j = 0; j < i; j++)
    {
        fprintf(f, "typedef %s ", ReturnGLType(&gldata[j].header));
        if(gldata[j].header.pointer)
            fprintf(f, "*");

        fprintf(f, "(APIENTRYP %s) (", gldata[j].extname);

        a = 0;

        if(gldata[j].args[a].name[0] == 0)
            fprintf(f, "void");
        else
        {
            while(gldata[j].args[a].name[0] != 0)
            {
                if(a > 0)
                    fprintf(f, ", ");

                if(gldata[j].args[a].isconst)
                    fprintf(f, "const ");

                fprintf(f, "%s", ReturnGLType(&gldata[j].args[a]));
                if(gldata[j].args[a].pointer)
                    fprintf(f, "*");

                fprintf(f, " %s", gldata[j].args[a++].name);
            }
        }

        fprintf(f, ");\n");
    }
    if(i > 0)
        fprintf(f, "#endif // __IPHONEOS__\n");

    if(i > 0)
        fprintf(f, "\n");

    if(i > 0)
        fprintf(f, "#ifndef __IPHONEOS__\n");
    for(j = 0; j < i; j++)
    {
        fprintf(f, "extern %s _%s;\n", gldata[j].extname, gldata[j].name);
    }
    if(i > 0)
        fprintf(f, "#endif // __IPHONEOS__\n");

    fprintf(f, "\n");

    fprintf(f, "#ifndef __IPHONEOS__\n");
    fprintf(f, "#define %s_Define() \\\n", arbstring);
    fprintf(f, "bool has_%s = false;", arbstring);
    if(i > 0)
        fprintf(f, " \\\n");
    else
        fprintf(f, "\n");

    for(j = 0; j < i; j++)
    {
        fprintf(f, "%s _%s = NULL", gldata[j].extname, gldata[j].name);
        if(j < (i - 1))
            fprintf(f, "; \\\n");
        else
            fprintf(f, "\n");
    }
    fprintf(f, "#else\n");
    fprintf(f, "#define %s_Define() bool has_%s = false;\n", arbstring, arbstring);
    fprintf(f, "#endif // __IPHONEOS__\n");

    fprintf(f, "\n");

    fprintf(f, "#ifndef __IPHONEOS__\n");
    fprintf(f, "#define %s_Init() \\\n", arbstring);
    fprintf(f, "has_%s = GL_CheckExtension(\"%s\");", arbstring, arbstring);

    if(i > 0)
        fprintf(f, " \\\n");
    else
        fprintf(f, "\n");

    for(j = 0; j < i; j++)
    {
        fprintf(f, "_%s = (%s)GL_RegisterProc(\"%s\")", gldata[j].name, gldata[j].extname, gldata[j].name);
        if(j < (i - 1))
            fprintf(f, "; \\\n");
        else
            fprintf(f, "\n");
    }
    fprintf(f, "#else\n");
    fprintf(f, "#define %s_Init() has_%s = true;\n", arbstring, arbstring);
    fprintf(f, "#endif // __IPHONEOS__\n");

    fprintf(f, "\n");

    if(i > 0)
    {
        fprintf(f, "#ifndef USE_DEBUG_GLFUNCS\n\n");

        SlapGLStuffToFile(f, i, true);
        fprintf(f, "\n#endif // USE_DEBUG_GLFUNCS\n\n");
    }

    SC_Close();
}
Ejemplo n.º 14
0
static void PS_ParseOuter(void)
{
    while(SC_ReadTokens())
    {
        SC_Find();

        switch(sc_parser->tokentype)
        {
        case TK_NONE:
            break;
        case TK_EOF:
            return;
        case TK_IDENIFIER:
            PS_ParseIdentifier();
            break;
        case TK_POUND:
            {
                SC_Find();
                switch(sc_parser->tokentype)
                {
                case TK_INCLUDE:
                    {
                        static char includepath[256];

                        SC_GetString();
                        SC_PushParser();

                        sprintf(includepath, "%s%s",
                            ps_userdirectory, sc_stringbuffer);

                        SC_Open(includepath);
                        PS_ParseOuter();
                        SC_Close();
                    }
                    break;
                case TK_DEFINE:
                    SC_ExpectNextToken(TK_IDENIFIER);
                    SC_AddIdentifier();
                    break;
                case TK_UNDEF:
                    SC_ExpectNextToken(TK_IDENIFIER);
                    SC_RemoveIdentifier();
                    break;
                case TK_SETDIR:
                    SC_GetString();
                    sprintf(ps_userdirectory, "%s", sc_parser->token);
                    break;
                default:
                    break;
                }
            }
            break;
        case TK_MACRO:
            SC_ExpectNextToken(TK_NUMBER);
            M_NewMacro(SC_GetNumber());
            SC_ExpectNextToken(TK_LBRACK);
            PS_ParseInner();
            M_FinishMacro();
            break;
        default:
            SC_Error("Unknown token in outer block: %s", sc_parser->token);
            break;
        }
    }
}
Ejemplo n.º 15
0
int InitializeToken(const char *pin, const char *sopin, int dkeksCount, uint8 *dkeks)
{
	uint16 sw1sw2;
	int rc, i;
	uint8 data[2 + 2 + 18 + 18 + 2 + 2];
	uint8 *p = data;
	int pin_len = strlen(pin);
	if (!(6 <= pin_len && pin_len <= 16)) {
		printf("PIN must have 6 - 16 chars\n");
		return ERR_INVALID;
	}
	/* Configuration Options (currently '0001') */
	*p++ = 0x80; *p++ = 0x02; *p++ = 0x00; *p++ = 0x01;
	/* Initial PIN value */
	*p++ = 0x81; *p++ = (uint8)pin_len; memcpy(p, pin, pin_len); p += pin_len;
	/* Initialization Code (== SO_PIN) */
	*p++ = 0x82; *p++ = 0x08;
	if (sopin == 0) {
		memcpy(p, "\x35\x37\x36\x32\x31\x38\x38\x30", 8);
	} else {
		if (strlen(sopin) != 16) {
			printf("SO_PIN must have 16 hex-digits\n");
			return ERR_INVALID;
		}
		rc = Hex2Bin(sopin, 16, p);
		if (rc)
			return rc;
	}
	p += 8;
	/* Retry Counter Initial Value */
	*p++ = 0x91; *p++ = 0x01; *p++ = 3;
	/* Number of Device Encryption Key shares */
	if (dkeksCount) {
		*p++ = 0x92; *p++ = 0x01; *p++ = dkeksCount;
	}

	rc = SC_Open(0, 0);
	if (rc < 0)
		return rc;
	/* - SmartCard-HSM: INITIALIZE DEVICE */
	rc = SC_ProcessAPDU(
		0, 0x80,0x50,0x00,0x00,
		data, (int)(p - data),
		NULL, 0,
		&sw1sw2);
	if (rc < 0) {
		SC_Close();
		return rc;
	}
	if (sw1sw2 != 0x9000) {
		SC_Close();
		return sw1sw2;
	}
	for (i = 0, p = dkeks; i < dkeksCount; i++, p += 0x20) {
		uint8 buf[10];
		/* - SmartCard-HSM: IMPORT DKEK SHARE */
		rc = SC_ProcessAPDU(
			0, 0x80,0x52,0x00,0x00,
			p, 0x20,
			buf, 10,
			&sw1sw2);
		if (rc < 0) {
			SC_Close();
			return rc;
		}
		if (sw1sw2 != 0x9000) {
			SC_Close();
			return sw1sw2;
		}
		printf("total shares: %d, outstanding shares: %d, key check value: %02x%02x%02x%02x%02x%02x%02x%02x\n",
			buf[0],
			buf[1],
			buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9]);
	}
	SC_Close();
	return sw1sw2;
}
Ejemplo n.º 16
0
int main(int argc, char **argv)
{
	int i, rc;
#if defined(_WIN32) && defined(_DEBUG)
	atexit((void(*)(void))_CrtDumpMemoryLeaks);
#endif
	if (argc < 2)
		return Usage();

	if (strcmp(argv[1], "--get-pin-status") == 0) {
		rc = GetPinStatus();
		printf("get-pin-status returns: 0x%4x\n", rc);
		return 0;
	}
	if (strcmp(argv[1], "--save-files") == 0) {
		DumpAllFiles(argc >= 3 ? argv[2] : 0);
		return 0;
	}
	if (argc < 3)
		return Usage();

	if (strcmp(argv[1], "--restore-files") == 0) {
		int rc = SC_Open(argv[2], 0);
		if (rc < 0)
			return rc;
		for (i = 3; i < argc; i++) {
			const char *name = argv[i];
			int dataLen, off;
			uint8 *pData;
			uint8 afid[2];
			uint16 fid;
			if (strlen(name) != 8 || strcmp(name + 4, ".asn") || Hex2Bin(name, 4, afid)) {
				printf("filename '%s' must be 'abcd.asn' where abcd is a valid hex number\n", name);
				continue;
			}
			fid = afid[0] << 8 | afid[1];
			if (fid == 0x2f02) {
				printf("filename '%s' skipped, EF_DevAut is readonly\n", name);
				continue;
			}
			ReadFromFile(name, pData, dataLen);
			if (pData == NULL) {
				printf("cant read file '%s'\n", name);
				continue;
			}
			if (dataLen == 0) {
				free(pData);
				printf("file '%s' empty\n", name);
				continue;
			}
			rc = 0;
			for (off = 0; off < dataLen;) {
				int len = dataLen - off;
				if (len > MAX_OUT_IN - 6)
					len = MAX_OUT_IN - 6;
				rc = SC_WriteFile(fid, off, pData + off, len);
				if (rc < 0)
					break;
				off += len;
			}
			free(pData);
			if (rc < 0) {
				printf("write error %d file '%s'\n", rc, name);
				continue;
			}
			printf("file '%s' successfully restored\n", name);
		}
		SC_Close();
		return 0;
	}
	if (strcmp(argv[1], "--init-token") == 0) {
		int len;
		uint8* buf;
		switch (argc) {
		default:
			return Usage();
		case 3:
			rc = InitializeToken(argv[2], NULL, 0, NULL);
			break;
		case 4:
			rc = InitializeToken(argv[2], argv[3], 0, NULL);
			break;
		case 5:
			ReadFromFile(argv[4], buf, len);
			if (buf == NULL) {
				printf("file '%s' not found\n", argv[4]);
				return ERR_INVALID;
			}
			if (len < 32 || (len & 31)) {
				free(buf);
				printf("file length of '%s' must be a positive multiple of 32\n", argv[4]);
				return ERR_INVALID;
			}
			rc = InitializeToken(argv[2], argv[3], len / 32, buf);
			free(buf);
			break;
		}
		printf("init-token returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--unlock-pin") == 0) {
		if (!(3 <= argc && argc <= 3))
			return Usage();
		rc = UnlockPin(argv[2]);
		printf("unlock-pin returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--set-pin") == 0) {
		if (!(3 <= argc && argc <= 4))
			return Usage();
		rc = SetPin(argv[2], argc == 3 ? NULL : argv[3]);
		printf("set-pin returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--change-pin") == 0) {
		if (!(4 <= argc && argc <= 4))
			return Usage();
		rc = ChangePin(argv[2], argv[3]);
		printf("change-pin returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--change-so-pin") == 0) {
		if (!(4 <= argc && argc <= 4))
			return Usage();
		rc = ChangeSoPin(argv[2], argv[3]);
		printf("change-pin returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--wrap-key") == 0) {
		if (!(5 <= argc && argc <= 5))
			return Usage();
		rc = WrapKey(argv[2], atoi(argv[3]), argv[4]);
		printf("wrap-key returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	if (strcmp(argv[1], "--unwrap-key") == 0) {
		if (!(5 <= argc && argc <= 5))
			return Usage();
		rc = UnwrapKey(argv[2], atoi(argv[3]), argv[4]);
		printf("unwrap-key returns: 0x%4x\n", rc);
		return rc == 0x9000 ? 0 : rc;
	}
	return Usage();
}