From bafc29f02ad6397c42b19ab7f97c5bf8072b6d7a Mon Sep 17 00:00:00 2001 From: Sam Bingner Date: Fri, 21 Feb 2020 23:34:30 -1000 Subject: Update User-Agent string --- methods/http.cc | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/methods/http.cc b/methods/http.cc index 508cf5727..e52318055 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -59,9 +59,12 @@ using namespace std; #define _(str) str -CFStringRef Firmware_; -const char *Machine_; -CFStringRef UniqueID_; +CFStringRef Firmware_ = NULL; +CFStringRef Product_ = NULL; +CFStringRef Arch_ = NULL; +const char *Machine_ = NULL; +CFStringRef UniqueID_ = NULL; +CFStringRef UserAgent_ = NULL; void CfrsError(const char *name, CFReadStreamRef rs) { CFStreamError se = CFReadStreamGetError(rs); @@ -341,7 +344,7 @@ int HttpMethod::Loop() if (UniqueID_ != NULL) CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("X-Unique-ID"), UniqueID_); - CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.592")); + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), UserAgent_); #if TARGET_OS_TV if (isNito) { @@ -646,13 +649,16 @@ int main(int, const char *argv[]) if (plist != NULL) { Firmware_ = (CFStringRef) CFRetain(CFDictionaryGetValue((CFDictionaryRef) plist, CFSTR("ProductVersion"))); + Product_ = (CFStringRef) CFRetain(CFDictionaryGetValue((CFDictionaryRef) plist, CFSTR("ProductName"))); CFRelease(plist); } if (UniqueID_ == NULL) if (void *libMobileGestalt = dlopen("/usr/lib/libMobileGestalt.dylib", RTLD_GLOBAL | RTLD_LAZY)) - if (CFStringRef (*$MGCopyAnswer)(CFStringRef) = (CFStringRef (*)(CFStringRef)) dlsym(libMobileGestalt, "MGCopyAnswer")) + if (CFStringRef (*$MGCopyAnswer)(CFStringRef) = (CFStringRef (*)(CFStringRef)) dlsym(libMobileGestalt, "MGCopyAnswer")) { UniqueID_ = $MGCopyAnswer(CFSTR("UniqueDeviceID")); + Arch_ = $MGCopyAnswer(CFSTR("CPUArchitecture")); + } if (UniqueID_ == NULL) if (void *lockdown = lockdown_connect()) { @@ -660,6 +666,22 @@ int main(int, const char *argv[]) lockdown_disconnect(lockdown); } + if (Arch_ == NULL) + Arch_ = CFSTR("Unknown"); + + if (Firmware_ == NULL) + Firmware_ = CFSTR("Unknown"); + + if (Product_ == NULL) + Product_ = CFSTR("Unknown"); + + if (UniqueID_ == NULL) + UniqueID_ = CFSTR("Unknown"); + + UserAgent_ = CFStringCreateWithFormat(NULL, NULL, CFSTR("Telesphoreo APT/%s (Darwin; %@ %@; %@; Elucubratus)"), PACKAGE_VERSION, Product_, Firmware_, Arch_); + if (UserAgent_ == NULL) + UserAgent_ = CFSTR("Telesphoreo APT/" PACKAGE_VERSION " (Darwin; Unknown Unknown; Unknown; Elucubratus)"); + std::string Binary = flNotDir(argv[0]); if (Binary.find('+') == std::string::npos && Binary != "https" && Binary != "http") Binary.append("+http"); -- cgit v1.2.3