diff --git a/appleauth/auth.cpp b/appleauth/auth.cpp index 0e3e7bf..999e3a6 100644 --- a/appleauth/auth.cpp +++ b/appleauth/auth.cpp @@ -1,9 +1,30 @@ #include "appleauth/iauth.h" -#include "tier2/fileformats/xml.h" +#include "tier2/fileformats/plist.h" #include "http/http.h" +#include "openssl/srp.h" +#include "openssl/sha.h" +#include "tier0/rand.h" IHTTPClientManager *g_pHttpClientMgr = NULL; +// autogenerated +#define APPLE_LOCAL_USER "e2e70285da39596ef06153b9c4e1e5dc8d2f983bc5cd63f5b1e292207060d931" +#define APPLE_HTTP_HEADER \ +{ \ + {"X-Apple-I-Client-Time", "2026-1-1T12:00:00"}, \ + {"X-Apple-Locale", "en_US"}, \ + {"X-Apple-I-TimeZone", "Europe/Kyiv"}, \ + {"X-Mme-Client-Info", " "}, \ + {"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, \ + {"X-Apple-I-MD-LU", APPLE_LOCAL_USER}, \ + {"X-Apple-I-MD-M", "0"}, \ + {"X-Apple-I-SRL-NO", "0"}, \ + {"X-Mme-Device-Id", "0"}, \ + {"Content-Type", "text/x-xml-plist"}, \ + {"Accept", "*/*"}, \ +}; + + class CAppleAuth: public IAppleAuth { public: @@ -12,47 +33,197 @@ public: virtual EAppleAuthStatus SubmitLoginData( const char *szEmail, const char *szPassword ) override; virtual EAppleAuthStatus Submit2FA( const char *szCode ) override; + CUtlString FetchADIPB(); + void FetchHeaders( CUtlString szAdiPb ); + IHTTPClient *m_pANIClient; IHTTPClient *m_pGrandSlamClient; - CUtlString m_szProvisionStart = "/"; - CUtlString m_szProvisionFinish = "/"; + CUtlString m_szProvisionStart = "/grandslam/MidService/startMachineProvisioning"; + CUtlString m_szProvisionFinish = "/grandslam/MidService/finishMachineProvisioning"; + IJSONObject *pHeader; + + CUtlString m_szAppleIMD; + CUtlString m_szAppleIMDM; + CUtlString m_szAppleIMDRINFO; + }; -void CAppleAuth::Init() +CUtlString CAppleAuth::FetchADIPB() { - CreateInterfaceFn fnHttpFactory = Sys_GetFactory("funnyhttp"); - g_pHttpClientMgr = (IHTTPClientManager*)fnHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL); - + CUtlString szProvisionExpectedInputRaw = NULL; + IJSONObject *pObject = NULL; + IJSONObject *pPlistObject = NULL; + CUtlString szProvisionExpectedInput = NULL; + CUtlString szAdiPb = NULL; + m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL); m_pGrandSlamClient = g_pHttpClientMgr->Connect("gsa.apple.com", true, NULL); { - HTTPHeaderParam_t params[] = { - {"X-Apple-I-Client-Time", "2026-1-1T12:00:00"}, - {"X-Apple-Locale", "en_US"}, - {"X-Apple-I-TimeZone", "Europe/Kyiv"}, - {"X-Mme-Client-Info", " "}, - {"User-Agent", "akd/1.0 CFNetwork/808.1.4"}, - {"X-Apple-I-MD-LU", "user"}, - {"X-Apple-I-MD-M", "0"}, - {"X-Apple-I-SRL-NO", "0"}, - {"X-Mme-Device-Id", "0"}, - {"Content-Type", "text/x-xml-plist"}, - {"Accept", "*/*"}, - }; + HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; HTTPHeader_t header = { sizeof(params)/sizeof(HTTPHeaderParam_t), params, }; m_pGrandSlamClient->Get("/grandslam/GsService2/lookup", &header); HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); - if (r.m_uCode == 200) + if ( r.m_uCode != 200 ) { - V_printf("%s\n",r.m_message.GetMemory()); + g_pHttpClientMgr->Disconnect(m_pANIClient); + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + return NULL; } } + + if ( !m_pANIClient->WebSocket_Connect("/v3/provisioning_session") ) + Plat_FatalErrorFunc("Failed to init AppleAuth websocket\n"); + + // Getting adipb + while ( ( szProvisionExpectedInputRaw = m_pANIClient->WebSocket_RecvText() ) != NULL ) + { + pObject = JSONManager()->ReadString(szProvisionExpectedInputRaw); + szProvisionExpectedInput = pObject->GetValue("result")->GetStringValue(); + V_printf("%s\n",szProvisionExpectedInput.GetString()); + if ( szProvisionExpectedInput == "GiveIdentifier" ) + { + m_pANIClient->WebSocket_SendText("{\"identifier\": \"" APPLE_LOCAL_USER "\"}"); + continue; + } + if ( szProvisionExpectedInput == "GiveStartProvisioningData" ) + { + const char *plist = + "\n" + "\n" + "\n" + "\n" + "\tHeader\n" + "\t\n" + "\tRequest\n" + "\t\n" + "\n" + "\n"; + + HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; + HTTPHeader_t header = { + sizeof(params)/sizeof(HTTPHeaderParam_t), + params, + }; + m_pGrandSlamClient->Post(m_szProvisionStart, &header, V_strlen(plist), plist); + HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); + if ( r.m_uCode != 200 ) + { + g_pHttpClientMgr->Disconnect(m_pANIClient); + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + return NULL; + } + IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message); + CUtlString spim = pObject->GetValue("Response")->GetObject()->GetValue("spim")->GetStringValue(); + m_pANIClient->WebSocket_SendText(CUtlString("{\"spim\": \"%s\"}", spim.GetString())); + + continue; + } + if ( szProvisionExpectedInput == "GiveEndProvisioningData" ) + { + CUtlString cpim = pObject->GetValue("cpim")->GetStringValue(); + + CUtlString plist = CUtlString( + "\n" + "\n" + "\n" + "\n" + "\tHeader\n" + "\t\n" + "\tRequest\n" + "\t\n" + "\tcpim\n" + "\t%s\n" + "\t\n" + "\n" + "\n", cpim.GetString()); + + HTTPHeaderParam_t params[] = APPLE_HTTP_HEADER; + HTTPHeader_t header = { + sizeof(params)/sizeof(HTTPHeaderParam_t), + params, + }; + m_pGrandSlamClient->Post(m_szProvisionFinish, &header, V_strlen(plist), plist); + HTTPResponse_t r = m_pGrandSlamClient->GetResponse(); + if ( r.m_uCode != 200 ) + { + g_pHttpClientMgr->Disconnect(m_pANIClient); + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + return NULL; + } + IJSONObject *pObject = PropertyListManager()->ReadString(r.m_message); + CUtlString tk = pObject->GetValue("Response")->GetObject()->GetValue("tk")->GetStringValue(); + CUtlString ptm = pObject->GetValue("Response")->GetObject()->GetValue("ptm")->GetStringValue(); + + V_printf("%s\n",CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString()).GetString()); + m_pANIClient->WebSocket_SendText(CUtlString("{\"tk\": \"%s\", \"ptm\": \"%s\"}", tk.GetString(), ptm.GetString())); + + continue; + } + if ( szProvisionExpectedInput == "ProvisioningSuccess" ) + { + szAdiPb = pObject->GetValue("adi_pb")->GetStringValue(); + g_pHttpClientMgr->Disconnect(m_pANIClient); + break; + } + if ( szProvisionExpectedInput == "Timeout" ) + { + break; + } + g_pHttpClientMgr->Disconnect(m_pANIClient); + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + return NULL; + } + g_pHttpClientMgr->Disconnect(m_pANIClient); + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + return szAdiPb; +} +void CAppleAuth::FetchHeaders( CUtlString szAdiPb ) +{ + // Get header + HTTPHeaderParam_t params[] = { + "Content-Type", "application/json", + }; + HTTPHeader_t header = { + sizeof(params)/sizeof(HTTPHeaderParam_t), + params, + }; + m_pANIClient = g_pHttpClientMgr->Connect("ani.sidestore.io", true, NULL); + CUtlString szPostData = CUtlString("{\"identifier\": \"" APPLE_LOCAL_USER "\", \"adi_pb\": \"%s\"}", szAdiPb.GetString()); + V_printf("%s\n",szPostData.GetString()); + m_pANIClient->Post("/v3/get_headers", &header, V_strlen(szPostData), szPostData); + HTTPResponse_t r = m_pANIClient->GetResponse(); + V_printf("%i\n",r.m_uCode); + if ( r.m_uCode == 200 ) + { + V_printf("%s\n",r.m_message.GetMemory()); + pHeader = JSONManager()->ReadString(r.m_message); + m_szAppleIMD = pHeader->GetValue("X-Apple-I-MD")->GetStringValue(); + m_szAppleIMDM = pHeader->GetValue("X-Apple-I-MD-M")->GetStringValue(); + m_szAppleIMDRINFO = pHeader->GetValue("X-Apple-I-MD-RINFO")->GetStringValue(); + JSONManager()->FreeObject(pHeader); + } + g_pHttpClientMgr->Disconnect(m_pANIClient); +} + +void CAppleAuth::Init() +{ + CreateInterfaceFn fnHttpFactory = Sys_GetFactory("funnyhttp"); + + g_pHttpClientMgr = (IHTTPClientManager*)fnHttpFactory(HTTP_CLIENT_INTERFACE_VERSION, NULL); + + + CUtlString szAdiPb = FetchADIPB(); + FetchHeaders(szAdiPb); + + } void CAppleAuth::Shutdown() @@ -62,7 +233,118 @@ void CAppleAuth::Shutdown() EAppleAuthStatus CAppleAuth::SubmitLoginData( const char *szEmail, const char *szPassword ) { + const char *pszUser = "your_username"; + const char *pszPass = ""; + SRP_gN *pstGN = SRP_get_default_gN("2048"); + if (!pstGN) return APPLE_AUTH_FAILURE; + + const BIGNUM *pN = pstGN->N; + const BIGNUM *pG = pstGN->g; + + unsigned char aucSalt[16]; + Plat_URandom(sizeof(aucSalt), aucSalt); + + unsigned char aucHash[SHA256_DIGEST_LENGTH]; + SHA256_CTX stCtx; + SHA256_Init(&stCtx); + SHA256_Update(&stCtx, aucSalt, sizeof(aucSalt)); + SHA256_Update(&stCtx, pszUser, strlen(pszUser)); + SHA256_Update(&stCtx, ":", 1); + SHA256_Update(&stCtx, pszPass, strlen(pszPass)); + SHA256_Final(aucHash, &stCtx); + BIGNUM *pX = BN_bin2bn(aucHash, SHA256_DIGEST_LENGTH, NULL); + BIGNUM *pV = BN_new(); + BN_CTX *pstCtx = BN_CTX_new(); + if (!BN_mod_exp(pV, pG, pX, pN, pstCtx)) return APPLE_AUTH_FAILURE; + BN_free(pX); + + BIGNUM *pA = BN_new(); + BIGNUM *pApriv = BN_new(); + if (!BN_rand(pApriv, 256, BN_RAND_TOP_ANY, BN_RAND_BOTTOM_ANY)) return APPLE_AUTH_FAILURE; + if (!BN_mod_exp(pA, pG, pApriv, pN, pstCtx)) return APPLE_AUTH_FAILURE; + + char *pszA = BN_bn2hex(pA); + V_printf("A: %s\n",pszA); + CUtlString plist = CUtlString( + "\n" + "\n" + "\n" + "\n" + "\tHeader\n" + "\t\n" + + "\tRequest\n" + "\t\n" + "\tA2k\n" + "\t%s\n" + "\tps\n" + "\ts2ks2k_fo\n" + "\t%s\n" + "\to\n" + "\tcomplete\n" + + "\tcpd\n" + "\t\n" + "\tbootstrap\n" + "\t\n" + "\tcapp\n" + "\tAppStore\n" + "\tckgen\n" + "\t\n" + "\tdc\n" + "\t#d4c5b3\n" + "\tdec\n" + "\t#e1e4e3\n" + "\tloc\n" + "\ten_US\n" + "\tpbe\n" + "\t\n" + "\tprtn\n" + "\tME349\n" + "\tsvct\n" + "\tiTunes\n" + + "\tX-Apple-I-MD\n" + "\t%s\n" + + "\tX-Apple-I-MD-M\n" + "\t%s\n" + + "\tX-Apple-I-MD-RINFO\n" + "\t%s\n" + "\t\n" + + "\t\n" + "\n" + "\n", pszA, szEmail, m_szAppleIMD.GetString(), m_szAppleIMDM.GetString(), m_szAppleIMDRINFO.GetString()); + m_pGrandSlamClient = g_pHttpClientMgr->Connect("gsa.apple.com", true, NULL); + HTTPHeaderParam_t params[] = { + {"Content-Type", "text/x-xml-plist"}, + {"Accept", "*/*"}, + }; + HTTPHeader_t header = { + sizeof(params)/sizeof(HTTPHeaderParam_t), + params, + }; + V_printf("%s\n",plist.GetString()); + m_pGrandSlamClient->Post("/grandslam/GsService2", &header, plist.GetLenght(), plist); + HTTPResponse_t stResponse = m_pGrandSlamClient->GetResponse(); + V_printf("%i\n", stResponse.m_uCode); + if (stResponse.m_uCode == 200) + { + V_printf("%s\n",stResponse.m_message.GetMemory()); + + } + g_pHttpClientMgr->Disconnect(m_pGrandSlamClient); + + OPENSSL_free(pszA); + BN_free(pApriv); + BN_free(pA); + BN_free(pV); + BN_CTX_free(pstCtx); + return APPLE_AUTH_SUCCESS; } EAppleAuthStatus CAppleAuth::Submit2FA( const char *szCode ) diff --git a/appleauth/build.cpp b/appleauth/build.cpp index 4a08be5..be90437 100644 --- a/appleauth/build.cpp +++ b/appleauth/build.cpp @@ -2,7 +2,6 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" ADD_DEPENDENCY_BUILD_FILE(tier0, "../tier0/build.cpp") ADD_DEPENDENCY_BUILD_FILE(tier1, "../tier1/build.cpp") @@ -23,6 +22,9 @@ DECLARE_BUILD_STAGE(appleauth) ldProject = ccompiler->Compile(&compileProject); ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")}); ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")}); + ldProject.libraries = { + "crypto", + }; ldProject.linkType = ELINK_DYNAMIC_LIBRARY; CUtlString szOutputProject = linker->Link(&ldProject); diff --git a/fpc/Makefile b/fpc/Makefile index 5887059..a5a8cfc 100644 --- a/fpc/Makefile +++ b/fpc/Makefile @@ -1,5 +1,5 @@ # We want to build just enough to use other stuff -TIER0_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier0/commandline.cpp +TIER0_FILES := ../tier0/lib.cpp ../tier0/mem.cpp ../tier0/platform.cpp ../tier0/commandline.cpp ../tier0/rand.cpp TIER1_FILES := ../tier1/utlbuffer.cpp ../tier1/interface.cpp ../tier1/utlstring.cpp ../tier1/utlvector.cpp ../tier1/utlmap.cpp TIER2_FILES := ../tier2/filesystem.cpp ../tier2/fileformats/ini.cpp FILESYSTEM_FILES := ../stdfilesystems/filesystem_libc.cpp @@ -20,7 +20,7 @@ recompile: ../build/tools/fpc build/fpc build install: ../build/tools/fpc libfpcbuild.a libfpc.so libtier0.so libtier1.a libtier2.a libfilesystem_std.so install_temp builddir - $(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc libtier0.so build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN' + $(CC) -fPIC main.cpp library/helper.cpp library/target.cpp library/builder.cpp -lc -lstdc++ $(CCFLAGS) -o build/fpc -ltier0 -Lbuild build/libtier1.a build/libtier2.a -Wl,--disable-new-dtags -Wl,-rpath,'$$ORIGIN' build/fpc build mv build/fpc_temp build/fpc mv build/libfpc_temp.so build/libfpc.so diff --git a/fpc/build.cpp b/fpc/build.cpp index 2b45ba2..3877124 100644 --- a/fpc/build.cpp +++ b/fpc/build.cpp @@ -87,7 +87,7 @@ DECLARE_BUILD_STAGE(libfpc) ldProject = ccompiler->Compile(&compileProject); ldProject.linkType = ELINK_DYNAMIC_LIBRARY; ldProject.libraryObjects = { - "libtier0.so", + GET_PROJECT_LIBRARY(tier0, "tier0"), GET_PROJECT_LIBRARY(tier1, "tier1"), GET_PROJECT_LIBRARY(tier2, "tier2"), }; @@ -114,7 +114,7 @@ DECLARE_BUILD_STAGE(fpc) compileProject.includeDirectories = g_IncludeDirectories; ldProject = ccompiler->Compile(&compileProject); ldProject.libraryObjects = { - "libtier0.so", + GET_PROJECT_LIBRARY(tier0, "tier0"), GET_PROJECT_LIBRARY(tier1, "tier1"), GET_PROJECT_LIBRARY(tier2, "tier2"), }; diff --git a/fpc/fpc_temp b/fpc/fpc_temp deleted file mode 100644 index 319fbbb..0000000 Binary files a/fpc/fpc_temp and /dev/null differ diff --git a/fpc/libfpc.so b/fpc/libfpc.so deleted file mode 100644 index 58a02bb..0000000 Binary files a/fpc/libfpc.so and /dev/null differ diff --git a/fpc/library/android/apktool.cpp b/fpc/library/android/apktool.cpp index c961e88..63904b3 100644 --- a/fpc/library/android/apktool.cpp +++ b/fpc/library/android/apktool.cpp @@ -2,7 +2,7 @@ #include "helper.h" #include "tier0/lib.h" #include "tier0/platform.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier1/interface.h" #include "runner.h" #include "tier1/utlstring.h" diff --git a/fpc/library/apple/appletool.cpp b/fpc/library/apple/appletool.cpp index fe78323..5cad9cf 100644 --- a/fpc/library/apple/appletool.cpp +++ b/fpc/library/apple/appletool.cpp @@ -88,6 +88,7 @@ CUtlString CAppleTool::SignPackage( const char *szIpa, const char *szPassword ) Plat_FatalErrorFunc("Couldn't get xtool\n"); g_pAppleAuth = (IAppleAuth*)fnFactory(APPLE_AUTH_INTERFACE_VERSION, NULL); g_pAppleAuth->Init(); + g_pAppleAuth->SubmitLoginData("bratelllo@icloud.com", ""); return szIpa; } diff --git a/fpc/library/clang/c.cpp b/fpc/library/clang/c.cpp index 6401c80..79ca81e 100644 --- a/fpc/library/clang/c.cpp +++ b/fpc/library/clang/c.cpp @@ -5,7 +5,7 @@ #include "target.h" #include "tier0/lib.h" #include "tier0/platform.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier1/interface.h" #include "tier1/utlstring.h" #include "tier1/utlvector.h" diff --git a/fpc/library/clang/ld.cpp b/fpc/library/clang/ld.cpp index 621a57f..ed44353 100644 --- a/fpc/library/clang/ld.cpp +++ b/fpc/library/clang/ld.cpp @@ -161,7 +161,18 @@ void CClangLinker::LinkFile( CUtlVector &cmd, const char *szName ) void CClangLinker::LinkLibraryObject( CUtlVector &cmd, const char *szName ) { - cmd.AppendTail(szName); + CUtlString szDir = CUtlString(szName).GetDirectory(); + CUtlString szFileName = CUtlString(szName).GetFileName(); + if (!V_strncmp(szFileName, "lib",3)) + szFileName.RemoveHead(3); + if (!V_strncmp(szFileName.GetFileExtension(), "so",2)) + szFileName.RemoveTail(3); + if (!V_strncmp(szFileName.GetFileExtension(), "a",1)) + szFileName.RemoveTail(2); + cmd.AppendTail("-L"); + cmd.AppendTail(szDir); + cmd.AppendTail("-l"); + cmd.AppendTail(szFileName); } void CClangLinker::LinkLibrary( CUtlVector &cmd, const char *szName ) diff --git a/fpc/library/runner.cpp b/fpc/library/runner.cpp index 76d3841..ef31573 100644 --- a/fpc/library/runner.cpp +++ b/fpc/library/runner.cpp @@ -5,7 +5,7 @@ #include "tier1/utlvector.h" #include "unistd.h" #include "sys/wait.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "winerunner.h" diff --git a/fpc/library/target.cpp b/fpc/library/target.cpp index ff5916c..618d1fd 100644 --- a/fpc/library/target.cpp +++ b/fpc/library/target.cpp @@ -1,5 +1,5 @@ #include "target.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier1/utlstring.h" //----------------------------------------------------------------------------- diff --git a/fpc/library/windows/c.cpp b/fpc/library/windows/c.cpp index c2ccc72..8e4395f 100644 --- a/fpc/library/windows/c.cpp +++ b/fpc/library/windows/c.cpp @@ -7,7 +7,7 @@ #include "tier0/lib.h" #include "tier0/mem.h" #include "tier0/platform.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier1/interface.h" #include "tier1/utlstring.h" #include "tier1/utlvector.h" diff --git a/fpc/library/windows/runner.cpp b/fpc/library/windows/runner.cpp index 693dfbd..3eeeb50 100644 --- a/fpc/library/windows/runner.cpp +++ b/fpc/library/windows/runner.cpp @@ -1,9 +1,9 @@ #include "runner.h" #include "tier0/platform.h" +#include "tier0/commandline.h" #include "tier1/interface.h" #include "tier1/utlstring.h" #include "tier1/utlvector.h" -#include "tier1/commandline.h" #include "windows.h" diff --git a/fpc/library/winerunner.cpp b/fpc/library/winerunner.cpp index a8d12ed..7602f0a 100644 --- a/fpc/library/winerunner.cpp +++ b/fpc/library/winerunner.cpp @@ -6,7 +6,7 @@ #include "tier1/utlvector.h" #include "unistd.h" #include "sys/wait.h" -#include "tier1/commandline.h" +#include "tier0/commandline.h" class CWineRunner: public IWineRunner { diff --git a/fpc/libtier0.so b/fpc/libtier0.so deleted file mode 100644 index 6764bc9..0000000 Binary files a/fpc/libtier0.so and /dev/null differ diff --git a/fpc/main.cpp b/fpc/main.cpp index 5cc7176..7814527 100644 --- a/fpc/main.cpp +++ b/fpc/main.cpp @@ -1,5 +1,6 @@ #include "tier0/platform.h" -#include "tier1/commandline.h" +#include "tier0/rand.h" +#include "tier0/commandline.h" #include "tier1/interface.h" #include "tier1/utlvector.h" #include "tier2/ifilesystem.h" @@ -153,12 +154,10 @@ findbuild: *ppConfig = g_pConfig; CommandLine()->CreateCommandLine(c, v); + Plat_InitRandom(); if (CommandLine()->CheckParam("build")) return build(); const char *szDeployDevice = CommandLine()->ParamValue("deploy"); - if (szDeployDevice) - { - - } + Plat_ShutdownRandom(); return 0; }; diff --git a/fpc/public/target.h b/fpc/public/target.h index 6c90285..d3b209b 100644 --- a/fpc/public/target.h +++ b/fpc/public/target.h @@ -5,20 +5,21 @@ #ifndef TARGET_T #define TARGET_T +#include "tier0/commandline.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" enum ETargetKernel { TARGET_KERNEL_UNKNOWN = 0, - TARGET_KERNEL_LINUX, TARGET_KERNEL_WINDOWS_DEVICES = 0x100, TARGET_KERNEL_WINDOWS_MSVC, TARGET_KERNEL_WINDOWS_GNU, TARGET_KERNEL_WINDOWS = TARGET_KERNEL_WINDOWS_GNU, - TARGET_KERNEL_APPLE_DEVICES = 0x200, + TARGET_KERNEL_POSIX = 0x10000, + TARGET_KERNEL_LINUX, + TARGET_KERNEL_APPLE_DEVICES = TARGET_KERNEL_POSIX | 0x200, TARGET_KERNEL_DARWIN, TARGET_KERNEL_IOS, TARGET_KERNEL_ANDROID, diff --git a/http/client.cpp b/http/client.cpp index e9d217a..f299d32 100644 --- a/http/client.cpp +++ b/http/client.cpp @@ -70,6 +70,7 @@ void CHTTPClient::Post( const char *szResource, HTTPHeader_t *pHeader, uint32_t szCombined = szMessage; szCombined.AppendTail(szHeader); szCombined.AppendTail("\r\n"); + V_printf("%s\n",szCombined.GetString()); Write(szCombined.GetString(), szCombined.GetLenght()); Write((void*)data, uDataSize); @@ -209,7 +210,6 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData { if ( !V_stricmp( headers[i].m_szParamName, "Content-Length" ) ) { - V_printf("%s\n",headers[i].m_szValue.GetString()); uBodySize = atoll(headers[i].m_szValue); bParseInChunks = false; }; @@ -302,7 +302,6 @@ void CHTTPClient::ConnectToServer() { struct hostent *pServerHostName = NULL; struct sockaddr_in serverAddress; - int fd = 0; int err; SSL_CTX *ctx; SSL *ssl; @@ -314,9 +313,6 @@ void CHTTPClient::ConnectToServer() return; } - fd = socket(AF_INET, SOCK_STREAM, 0); - if ( fd < 0 ) - return; V_memset(&serverAddress, 0, sizeof(serverAddress)); serverAddress.sin_family = AF_INET; @@ -328,7 +324,7 @@ void CHTTPClient::ConnectToServer() // https serverAddress.sin_port = htons(m_uPort); - err = connect(fd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)); + err = connect(m_iFileDescriptor, (struct sockaddr *)&serverAddress, sizeof(serverAddress)); if (err < 0) return; @@ -341,7 +337,7 @@ void CHTTPClient::ConnectToServer() if (!ssl) return; - SSL_set_fd(ssl, fd); + SSL_set_fd(ssl, m_iFileDescriptor); SSL_set_tlsext_host_name(ssl, m_szHostName); int r = SSL_connect(ssl); @@ -354,7 +350,6 @@ void CHTTPClient::ConnectToServer() } }; - m_iFileDescriptor = fd; if (m_bIsSecure) { m_pSSL = ssl; @@ -524,6 +519,8 @@ public: IHTTPClient *CHTTPClientManager::Connect( const char *szUrl, bool bSecure, uint16_t *pPort ) { CHTTPClient *pClient; + int fd = 0; + pClient = new CHTTPClient(); if (pPort) pClient->m_uPort = *pPort; @@ -534,6 +531,13 @@ IHTTPClient *CHTTPClientManager::Connect( const char *szUrl, bool bSecure, uint1 else pClient->m_uPort = 80; } + + fd = socket(AF_INET, SOCK_STREAM, 0); + if ( fd < 0 ) + return NULL; + + pClient->m_iFileDescriptor = fd; + pClient->m_szHostName = szUrl; pClient->m_bIsSecure = bSecure; return pClient; diff --git a/public/appleauth/iauth.h b/public/appleauth/iauth.h index 628746e..1d8c068 100644 --- a/public/appleauth/iauth.h +++ b/public/appleauth/iauth.h @@ -7,6 +7,7 @@ enum EAppleAuthStatus { + APPLE_AUTH_FAILURE, APPLE_AUTH_SUCCESS, APPLE_AUTH_NEED_2FA, APPLE_AUTH_NEED_SMS_2FA, diff --git a/public/tier1/commandline.h b/public/commandline.h similarity index 100% rename from public/tier1/commandline.h rename to public/commandline.h diff --git a/public/tier0/commandline.h b/public/tier0/commandline.h new file mode 100644 index 0000000..c41dbbe --- /dev/null +++ b/public/tier0/commandline.h @@ -0,0 +1,30 @@ +//================= Copyright kotofyt, All rights reserved ==================// +// Purpose: Command line handler for argc and argv. It also allows to find +// parameters and push your own. +//===========================================================================// + +#ifndef TIER0_COMMANDLINE_H +#define TIER0_COMMANDLINE_H + + +#include "tier0/platform.h" + +abstract_class ICommandLine +{ +public: + virtual void CreateCommandLine( int argc, char **argv ) = 0; + + virtual bool CheckParam( const char *psz ) = 0; + virtual char *ParamValue( const char* psz, const char *szDefaultValue = 0 ) = 0; + + virtual void AddParam( char *psz ) = 0; + virtual void RemoveParam( char *psz ) = 0; + + virtual int ParamCount() = 0; + virtual int FindParam( const char *psz ) = 0; + virtual const char *GetParam(int nIndex) = 0; +}; + +ICommandLine *CommandLine(); + +#endif diff --git a/public/tier0/rand.h b/public/tier0/rand.h new file mode 100644 index 0000000..a2eec79 --- /dev/null +++ b/public/tier0/rand.h @@ -0,0 +1,10 @@ +#ifndef TIER0_RAND_H +#define TIER0_RAND_H + +#include "tier0/platform.h" + +PLATFORM_INTERFACE void Plat_InitRandom(); +PLATFORM_INTERFACE void Plat_ShutdownRandom(); +PLATFORM_INTERFACE void Plat_URandom( size_t uBufferSize, uint8_t *szBuffer ); + +#endif diff --git a/public/tier1/utlstring.h b/public/tier1/utlstring.h index 320c9b1..66bba5e 100644 --- a/public/tier1/utlstring.h +++ b/public/tier1/utlstring.h @@ -26,6 +26,7 @@ public: void RemoveAt( size_t nPosition, size_t nCount ); CUtlString GetFileName(); + CUtlString GetFileExtension(); CUtlString GetDirectory(); CUtlString RemoveHeadFile(); @@ -126,13 +127,35 @@ inline CUtlString CUtlString::GetFileName() while (pLast != m_data.GetData()) { if (*pLast=='/') + { + pLast++; break; + } pLast--; } return pLast; } +inline CUtlString CUtlString::GetFileExtension() +{ + CUtlString szFileName = GetString(); + + char *pLast = &m_data[GetLenght()-1]; + while (pLast != m_data.GetData()) + { + if (*pLast=='.') + break; + if (*pLast=='/') + return NULL; + pLast--; + } + + return pLast+1; +} + + + inline CUtlString CUtlString::GetDirectory() { if (GetLenght() == 0) diff --git a/tests/ini/main.cpp b/tests/ini/main.cpp index 5516b08..4dbf0fe 100644 --- a/tests/ini/main.cpp +++ b/tests/ini/main.cpp @@ -1,7 +1,6 @@ #include "tier0/lib.h" #include "tier0/mem.h" #include "tier1/utlbuffer.h" -#include "tier1/commandline.h" #include "tier2/fileformats/ini.h" #include "tier2/ifilesystem.h" diff --git a/tier0/build.cpp b/tier0/build.cpp index e8cca35..5c7ea99 100644 --- a/tier0/build.cpp +++ b/tier0/build.cpp @@ -2,14 +2,14 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" CUtlVector tier0_CompiledFiles = { "lib.cpp", "mem.cpp", "platform.cpp", "network.cpp", - "commandline.cpp" + "commandline.cpp", + "rand.cpp", }; DECLARE_BUILD_STAGE(tier0) diff --git a/tier0/commandline.cpp b/tier0/commandline.cpp index 5a3d99e..8190f81 100644 --- a/tier0/commandline.cpp +++ b/tier0/commandline.cpp @@ -1,4 +1,4 @@ -#include "tier1/commandline.h" +#include "tier0/commandline.h" #include "tier1/utlvector.h" diff --git a/tier0/network.cpp b/tier0/network.cpp index eeec7d9..cc32de6 100644 --- a/tier0/network.cpp +++ b/tier0/network.cpp @@ -1,5 +1,4 @@ #include "tier0/network.h" -#include "tier1/commandline.h" void Net_Init() { diff --git a/tier0/rand.cpp b/tier0/rand.cpp new file mode 100644 index 0000000..764d1b1 --- /dev/null +++ b/tier0/rand.cpp @@ -0,0 +1,29 @@ +#include "tier0/rand.h" +#include "tier0/lib.h" + +static bool b_sIsRandInit = false; +static FILE *s_pURandom = NULL; + +PLATFORM_INTERFACE void Plat_InitRandom() +{ + if (b_sIsRandInit) + return; + s_pURandom = V_fopen("/dev/urandom","rb"); + if (!s_pURandom) + Plat_FatalErrorFunc("/dev/urandom wasn't found somehow\n"); + b_sIsRandInit = true; +} + +PLATFORM_INTERFACE void Plat_ShutdownRandom() +{ + b_sIsRandInit = false; +} + +PLATFORM_INTERFACE void Plat_URandom( size_t uBufferSize, uint8_t *szBuffer ) +{ + if (!b_sIsRandInit) + Plat_InitRandom(); + + V_fread(szBuffer, 1, uBufferSize, s_pURandom); +} + diff --git a/tier1/build.cpp b/tier1/build.cpp index 87b2afb..7287323 100644 --- a/tier1/build.cpp +++ b/tier1/build.cpp @@ -2,7 +2,6 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" CUtlVector tier1_CompiledFiles = { "interface.cpp", diff --git a/tier2/build.cpp b/tier2/build.cpp index cd52ef0..3cd95df 100644 --- a/tier2/build.cpp +++ b/tier2/build.cpp @@ -2,7 +2,6 @@ #include "c.h" #include "ld.h" #include "tier1/utlstring.h" -#include "tier1/commandline.h" CUtlVector tier2_CompiledFiles = { "fileformats/ini.cpp", diff --git a/tier2/fileformats/json.cpp b/tier2/fileformats/json.cpp index 46e0a5d..18e832b 100644 --- a/tier2/fileformats/json.cpp +++ b/tier2/fileformats/json.cpp @@ -218,7 +218,10 @@ void CJSONObject::CopyTo( IJSONObject *pObject ) void CJSONObject::Free() { - + for ( auto ¶m: m_params ) + { + JSONManager()->FreeValue(param.m_pValue); + } } abstract_class CJSONManager: public IJSONManager @@ -247,7 +250,8 @@ IJSONObject *CJSONManager::CreateObject( ) void CJSONManager::FreeObject( IJSONObject *pObject ) { - + pObject->Free(); + delete (CJSONObject*)pObject; } IJSONArray *CJSONManager::CreateArray( ) @@ -267,7 +271,8 @@ IJSONValue *CJSONManager::CreateValue( ) void CJSONManager::FreeValue( IJSONValue *pValue ) { - + pValue->Free(); + delete (CJSONValue*)pValue; } #define NEXT_TOKEN() \