1 // Copyright (c) 2012- PPSSPP Project.
2
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
11
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18 #include "zlib.h"
19 #include <stdio.h>
20
21 #include "Core/MemMap.h"
22 #include "Core/System.h"
23 #include "Core/ELF/PrxDecrypter.h"
24 #include "Core/FileSystems/MetaFileSystem.h"
25 #include "Core/HLE/scePauth.h"
26 #include "Core/HLE/HLE.h"
27 #include "Core/HLE/FunctionWrappers.h"
28 #include "Common/File/FileUtil.h"
29
scePauth_F7AA47F6(u32 srcPtr,int srcLength,u32 destLengthPtr,u32 workArea)30 static int scePauth_F7AA47F6(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
31 {
32 auto src = Memory::GetPointer(srcPtr);
33 auto key = Memory::GetPointer(workArea);
34
35 const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);
36
37 if (decryptResult < 0)
38 {
39 ERROR_LOG(HLE, "Pauth decryption failed 0x%08X", decryptResult);
40 return decryptResult;
41 }
42
43 Memory::Write_U32(decryptResult, destLengthPtr);
44 return 0;
45 }
46
scePauth_98B83B5D(u32 srcPtr,int srcLength,u32 destLengthPtr,u32 workArea)47 static int scePauth_98B83B5D(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
48 {
49 auto src = Memory::GetPointer(srcPtr);
50 auto key = Memory::GetPointer(workArea);
51
52 const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);
53
54 if (decryptResult < 0)
55 {
56 ERROR_LOG(HLE, "Pauth decryption failed 0x%08X", decryptResult);
57 return decryptResult;
58 }
59
60 Memory::Write_U32(decryptResult, destLengthPtr);
61 return 0;
62 }
63
64 const HLEFunction scePauth[] = {
65 {0XF7AA47F6, &WrapI_UIUU<scePauth_F7AA47F6>, "scePauth_F7AA47F6", 'i', "xixx"},
66 {0X98B83B5D, &WrapI_UIUU<scePauth_98B83B5D>, "scePauth_98B83B5D", 'i', "xixx"},
67 };
68
Register_scePauth()69 void Register_scePauth()
70 {
71 RegisterModule("scePauth", ARRAY_SIZE(scePauth), scePauth);
72 }
73