From cac7fd221f08a11e984d9b47b4383af548b388aa Mon Sep 17 00:00:00 2001 From: Syping Date: Wed, 15 Mar 2023 08:22:38 +0100 Subject: [PATCH] RagePhoto(A): add jpegSign() function - RagePhotoC: add ragephoto_getphotosign() ragephoto_getphotosignf() ragephotodata_getphotosign() and ragephotodata_getphotosignf() functions --- src/RagePhoto.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++ src/RagePhoto.h | 8 +++++++ src/RagePhotoA.h | 20 ++++++++++++++++ src/RagePhotoC.h | 22 +++++++++++++++++ 4 files changed, 110 insertions(+) diff --git a/src/RagePhoto.cpp b/src/RagePhoto.cpp index 577fde5..f2dbaa6 100644 --- a/src/RagePhoto.cpp +++ b/src/RagePhoto.cpp @@ -120,6 +120,20 @@ inline void uInt32ToCharLE(uint32_t x, char *y) y[2] = x >> 16; y[3] = x >> 24; } + +inline uint32_t joaatFromInitial(const char *data, size_t size, uint32_t init_val) +{ + uint32_t val = init_val; + for (size_t i = 0; i != size; i++) { + val += data[i]; + val += (val << 10); + val ^= (val >> 6); + } + val += (val << 3); + val ^= (val >> 11); + val += (val << 15); + return val; +} /* END OF STATIC LIBRARY FUNCTIONS */ /* BEGIN OF RAGEPHOTO CLASS */ @@ -526,6 +540,7 @@ bool RagePhoto::load(const char *data, size_t length, RagePhotoData *rp_data, Ra std::cout << "jsonBuffer: " << rp_data->jsonBuffer << std::endl; std::cout << "jsonOffset: " << rp_data->jsonOffset << std::endl; std::cout << "json: " << rp_data->json << std::endl; + std::cout << "sign: " << jpegSign(rp_data) << std::endl; std::cout << "titlBuffer: " << rp_data->titlBuffer << std::endl; std::cout << "titlOffset: " << rp_data->titlOffset << std::endl; std::cout << "title: " << rp_data->title << std::endl; @@ -617,6 +632,29 @@ const char* RagePhoto::jpegData() const return m_data->jpeg; } +uint64_t RagePhoto::jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) +{ + if (photoFormat == PhotoFormat::GTA5) + return (0x100000000000000ULL | joaatFromInitial(rp_data->jpeg, rp_data->jpegSize, SignInitials::SIGTA5)); + else + return 0; +} + +uint64_t RagePhoto::jpegSign(RagePhotoData *rp_data) +{ + return jpegSign(rp_data->photoFormat, rp_data); +} + +uint64_t RagePhoto::jpegSign(uint32_t photoFormat) const +{ + return jpegSign(photoFormat, m_data); +} + +uint64_t RagePhoto::jpegSign() const +{ + return jpegSign(m_data->photoFormat, m_data); +} + uint32_t RagePhoto::jpegSize() const { if (m_data->jpeg) @@ -1273,6 +1311,28 @@ const char* ragephoto_getphotoheader(ragephoto_t instance) return ragePhoto->header(); } +uint64_t ragephoto_getphotosign(ragephoto_t instance) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->jpegSign(); +} + +uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat) +{ + RagePhoto *ragePhoto = static_cast(instance); + return ragePhoto->jpegSign(photoFormat); +} + +uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data) +{ + return RagePhoto::jpegSign(rp_data); +} + +uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat) +{ + return RagePhoto::jpegSign(photoFormat, rp_data); +} + uint32_t ragephoto_getphotosize(ragephoto_t instance) { RagePhoto *ragePhoto = static_cast(instance); diff --git a/src/RagePhoto.h b/src/RagePhoto.h index 623abb6..6a5972c 100644 --- a/src/RagePhoto.h +++ b/src/RagePhoto.h @@ -92,6 +92,10 @@ public: GTA5 = 0x01000000UL, /**< GTA V Photo Format */ RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */ }; + /** Sign Initials */ + enum SignInitials : uint32_t { + SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */ + }; RagePhoto(); ~RagePhoto(); void addParser(RagePhotoFormatParser *rp_parser); /**< Add a custom defined RagePhotoFormatParser. */ @@ -119,6 +123,10 @@ public: const std::string_view jpeg_view() const; /**< Returns the Photo JPEG data. */ #endif const char* jpegData() const; /**< Returns the Photo JPEG data. */ + static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */ + static uint64_t jpegSign(RagePhotoData *rp_data); /**< Returns the Photo JPEG sign. */ + uint64_t jpegSign(uint32_t photoFormat) const; /**< Returns the Photo JPEG sign. */ + uint64_t jpegSign() const; /**< Returns the Photo JPEG sign. */ uint32_t jpegSize() const; /**< Returns the Photo JPEG data size. */ const char* description() const; /**< Returns the Photo description. */ const char* json() const; /**< Returns the Photo JSON data. */ diff --git a/src/RagePhotoA.h b/src/RagePhotoA.h index 504cf85..83085b5 100644 --- a/src/RagePhotoA.h +++ b/src/RagePhotoA.h @@ -92,6 +92,10 @@ public: GTA5 = 0x01000000UL, /**< GTA V Photo Format */ RDR2 = 0x04000000UL, /**< RDR 2 Photo Format */ }; + /** Sign Initials */ + enum SignInitials : uint32_t { + SIGTA5 = 0xE47AB81CUL, /**< GTA V Sign Initial */ + }; RagePhotoA() { instance = ragephoto_open(); } @@ -167,6 +171,22 @@ public: const char* jpegData() const { return ragephoto_getphotojpeg(instance); } + /**< Returns the Photo JPEG sign. */ + static uint64_t jpegSign(uint32_t photoFormat, RagePhotoData *rp_data) { + return ragephotodata_getphotosignf(rp_data, photoFormat); + } + /**< Returns the Photo JPEG sign. */ + static uint64_t jpegSign(RagePhotoData *rp_data) { + return ragephotodata_getphotosign(rp_data); + } + /**< Returns the Photo JPEG sign. */ + uint64_t jpegSign(uint32_t photoFormat) const { + return ragephoto_getphotosignf(instance, photoFormat); + } + /**< Returns the Photo JPEG sign. */ + uint64_t jpegSign() const { + return ragephoto_getphotosign(instance); + } /** Returns the Photo JPEG data size. */ uint32_t jpegSize() const { return ragephoto_getphotosize(instance); diff --git a/src/RagePhotoC.h b/src/RagePhotoC.h index b0038ac..e88a361 100644 --- a/src/RagePhotoC.h +++ b/src/RagePhotoC.h @@ -123,6 +123,28 @@ LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotojson(ragephoto_t instance); */ LIBRAGEPHOTO_C_BINDING const char* ragephoto_getphotoheader(ragephoto_t instance); +/** Returns the Photo JPEG sign. +* \param instance \p ragephoto_t instance +*/ +LIBRAGEPHOTO_C_BINDING uint64_t ragephoto_getphotosign(ragephoto_t instance); + +/** Returns the Photo JPEG sign. +* \param instance \p ragephoto_t instance +* \param photoFormat Photo Format (GTA V or RDR 2) +*/ +LIBRAGEPHOTO_C_BINDING uint64_t ragephoto_getphotosignf(ragephoto_t instance, uint32_t photoFormat); + +/** Returns the Photo JPEG sign. +* \param rp_data RagePhotoData object +*/ +LIBRAGEPHOTO_C_BINDING uint64_t ragephotodata_getphotosign(RagePhotoData *rp_data); + +/** Returns the Photo JPEG sign. +* \param rp_data RagePhotoData object +* \param photoFormat Photo Format (GTA V or RDR 2) +*/ +LIBRAGEPHOTO_C_BINDING uint64_t ragephotodata_getphotosignf(RagePhotoData *rp_data, uint32_t photoFormat); + /** Returns the Photo JPEG data size. * \param instance \p ragephoto_t instance */