Exemplo n.º 1
0
void TypeConfig::ResolveTags(const std::map<TagId,std::string>& map,
                             std::vector<Tag>& tags) const
{
    tags.clear();

    for (std::map<TagId,std::string>::const_iterator t=map.begin();
            t!=map.end();
            ++t) {
        if (GetTagInfo(t->first).IsInternalOnly()) {
            continue;
        }

        Tag tag;

        tag.key=t->first;
        tag.value=t->second;

        tags.push_back(tag);
    }
}
int CMediaLibrary::SetExtendedFileInfo(const wchar_t *fn, const wchar_t *Metadata, const wchar_t *val)
{

	bool FindTag = false;
	int RetCode = 0;

	::EnterCriticalSection(&CriticalSection);

	if (std::wstring(fn) != FileName)
	{
		FileName = std::wstring(fn);
		FindTag = GetTagInfo(FileName);
	}
	else
	{
		FindTag = true;
	}

	if (FindTag) {
		const char *MetaData = reinterpret_cast<const char*>(Metadata);

		if (_stricmp(MetaData, "title") == 0) {
			TagDataW.Title = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "artist") == 0) {
			TagDataW.Artist = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "albumartist") == 0) {
			TagDataW.AlbumArtist = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "comment") == 0) {
			TagDataW.Comment = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "album") == 0) {
			TagDataW.Album = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "year") == 0) {
			TagDataW.Year = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "genre") == 0) {
			TagDataW.Genre = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "track") == 0) {
			TagDataW.Track = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "composer") == 0) {
			TagDataW.Composer = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "publisher") == 0) {
			TagDataW.Publisher = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "disc") == 0) {
			TagDataW.Disc = val;
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "bpm") == 0) {
			TagDataW.BPM = val;
			RetCode = 1;
		}
		else {
			RetCode = 0;
		}

	}
	else {
//		FileName = L"";
		RetCode = 0;
	}

	::LeaveCriticalSection(&CriticalSection);
	return RetCode;
}
Exemplo n.º 3
0
static int DecryptPRX1(const u8* pbIn, u8* pbOut, int cbTotal, u32 tag)
{
	int i;
	s32_le retsize;
	u8 bD0[0x80], b80[0x50], b00[0x80], bB0[0x20];

	const TAG_INFO *pti = GetTagInfo(tag);
	if (pti == NULL)
	{
		return -1;
	}
	if (!HasKey(pti->code) || 
		(pti->codeExtra != 0 && !HasKey(pti->codeExtra)))
	{
		return MISSING_KEY;
	}

	retsize = *(s32_le*)&pbIn[0xB0];

	for (i = 0; i < 0x14; i++)
	{
		if (pti->key[i] != 0)
			break;
	}

	// Scramble the key (!)
	//
	// NOTE: I can't make much sense out of this code. Scramble seems really odd, appears
	// to write to stuff that should be before the actual key.
	u8 key[0x90];
	memcpy(key, pti->key, 0x90);
	if (i == 0x14)
	{
		Scramble((u32_le *)key, 0x90, pti->code);
	}

	// build conversion into pbOut

	if (pbIn != pbOut)
		memcpy(pbOut, pbIn, cbTotal);

	memcpy(bD0, pbIn+0xD0, 0x80);
	memcpy(b80, pbIn+0x80, 0x50);
	memcpy(b00, pbIn+0x00, 0x80);
	memcpy(bB0, pbIn+0xB0, 0x20);

	memset(pbOut, 0, 0x150);
	memset(pbOut, 0x55, 0x40); // first $40 bytes ignored

	// step3 demangle in place
	u32_le* pl = (u32_le*)(pbOut+0x2C);
	pl[0] = 5; // number of ulongs in the header
	pl[1] = pl[2] = 0;
	pl[3] = pti->code; // initial seed for PRX
	pl[4] = 0x70;   // size

	// redo part of the SIG check (step2)
	u8 buffer1[0x150];
	memcpy(buffer1+0x00, bD0, 0x80);
	memcpy(buffer1+0x80, b80, 0x50);
	memcpy(buffer1+0xD0, b00, 0x80);
	if (pti->codeExtra != 0)
		ExtraV2Mangle(buffer1+0x10, pti->codeExtra);
	memcpy(pbOut+0x40, buffer1+0x40, 0x40);

	int ret;
	int iXOR;
	for (iXOR = 0; iXOR < 0x70; iXOR++)
#ifdef COMMON_BIG_ENDIAN
		pbOut[0x40+iXOR] = pbOut[0x40+iXOR] ^ key[(0x14+iXOR) ^3];
#else
		pbOut[0x40+iXOR] = pbOut[0x40+iXOR] ^ key[0x14+iXOR];
#endif

	ret = sceUtilsBufferCopyWithRange(pbOut+0x2C, 20+0x70, pbOut+0x2C, 20+0x70, 7);
	if (ret != 0)
	{
		return -1;
	}

	for (iXOR = 0x6F; iXOR >= 0; iXOR--)
#ifdef COMMON_BIG_ENDIAN
		pbOut[0x40+iXOR] = pbOut[0x2C+iXOR] ^ key[(0x20+iXOR) ^ 3];
#else
		pbOut[0x40+iXOR] = pbOut[0x2C+iXOR] ^ key[0x20+iXOR];
#endif

	memset(pbOut+0x80, 0, 0x30); // $40 bytes kept, clean up
	pbOut[0xA0] = 1;
	// copy unscrambled parts from header
	memcpy(pbOut+0xB0, bB0, 0x20); // file size + lots of zeros
	memcpy(pbOut+0xD0, b00, 0x80); // ~PSP header

	// step4: do the actual decryption of code block
	//  point 0x40 bytes into the buffer to key info
	ret = sceUtilsBufferCopyWithRange(pbOut, cbTotal, pbOut+0x40, cbTotal-0x40, 0x1);
	if (ret != 0)
	{
		return -1;
	}

	// return cbTotal - 0x150; // rounded up size
	return retsize;
}
int CMediaLibrary::GetExtendedFileInfo(const wchar_t *fn, const wchar_t *Metadata, wchar_t *dest, size_t destlen)
{

	bool FindTag;
	int RetCode;

	::EnterCriticalSection(&CriticalSection);

	if (std::wstring(fn) != FileName)
	{
		FindTag = GetTagInfo(fn);
	}
	else
	{
		FindTag = true;
	}

	if (FindTag) {
		wchar_t	Buff[MAX_MUSICTEXT];
		const char *MetaData = reinterpret_cast<const char*>(Metadata);

		if (_stricmp(MetaData, "length") == 0) {
			_ultow_s(TagDataW.Length, dest, destlen, 10);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "formatinformation") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Format.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "type") == 0) {
			Buff[0] = '0';
			Buff[1] = 0;
			wcsncpy_s(dest, destlen, Buff, _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "family") == 0) {
			wcsncpy_s(dest, destlen, L"The True Audio File", _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "lossless") == 0) {
			Buff[0] = '1';
			wcsncpy_s(dest, destlen, Buff, _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "title") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Title.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "artist") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Artist.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "albumartist") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.AlbumArtist.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "comment") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Comment.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "album") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Album.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "year") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Year.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "genre") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Genre.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "track") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Track.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "composer") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Composer.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "publisher") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Publisher.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "disc") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.Disc.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else if (_stricmp(MetaData, "bpm") == 0) {
			wcsncpy_s(dest, destlen, TagDataW.BPM.c_str(), _TRUNCATE);
			RetCode = 1;
		}
		else {
			RetCode = 0;
		}

	}
	else {
		FileName = L"";
		RetCode = 0;
	}

	::LeaveCriticalSection(&CriticalSection);
	return RetCode;
}