From 8f31017a9a3fbe83c6ce7ea568eae6eeb8442fef Mon Sep 17 00:00:00 2001 From: Jakub Pruzinec Date: Sat, 16 Mar 2019 12:05:58 +0100 Subject: [PATCH] json and plain presentation --- .../types/resource_table/resource_table.h | 23 +++-- src/fileformat/CMakeLists.txt | 4 +- .../types/resource_table/resource_table.cpp | 89 +++++++++++------- src/fileinfo/CMakeLists.txt | 4 +- .../file_information/file_information.cpp | 58 ++++++++++++ .../file_information/file_information.h | 6 ++ .../resource_table/resource_table.cpp | 62 +++++++++++++ .../resource_table/resource_table.h | 6 ++ ...rsion_info_language_table_plain_getter.cpp | 93 +++++++++++++++++++ ...version_info_language_table_plain_getter.h | 31 +++++++ ...version_info_string_table_plain_getter.cpp | 93 +++++++++++++++++++ .../version_info_string_table_plain_getter.h | 31 +++++++ ...visual_basic_extern_table_plain_getter.cpp | 2 +- .../file_presentation/getters/plain_getters.h | 2 + .../file_presentation/json_presentation.cpp | 40 ++++++++ .../file_presentation/json_presentation.h | 1 + .../file_presentation/plain_presentation.cpp | 2 + 17 files changed, 501 insertions(+), 46 deletions(-) create mode 100644 src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp create mode 100644 src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h create mode 100644 src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp create mode 100644 src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h diff --git a/include/retdec/fileformat/types/resource_table/resource_table.h b/include/retdec/fileformat/types/resource_table/resource_table.h index e21ba3feea..4c42c3f287 100644 --- a/include/retdec/fileformat/types/resource_table/resource_table.h +++ b/include/retdec/fileformat/types/resource_table/resource_table.h @@ -8,6 +8,7 @@ #define RETDEC_FILEFORMAT_TYPES_RESOURCE_TABLE_RESOURCE_TABLE_H #include +#include #include #include "retdec/fileformat/types/resource_table/resource.h" @@ -25,14 +26,16 @@ class ResourceTable { private: using resourcesIterator = std::vector>::const_iterator; - std::vector> table; ///< stored resources - std::vector resourceVersions; ///< icon groups - std::vector iconGroups; ///< icon groups - std::vector icons; ///< icons - std::string iconHashCrc32; ///< iconhash CRC32 - std::string iconHashMd5; ///< iconhash MD5 - std::string iconHashSha256; ///< iconhash SHA256 - std::string iconPerceptualAvgHash; ///< icon perceptual hash AvgHash + std::vector> table; ///< stored resources + std::vector resourceVersions; ///< icon groups + std::vector iconGroups; ///< icon groups + std::vector icons; ///< icons + std::vector> languages; ///< supported languages, LCID and code page + std::vector> strings; ///< version info strings + std::string iconHashCrc32; ///< iconhash CRC32 + std::string iconHashMd5; ///< iconhash MD5 + std::string iconHashSha256; ///< iconhash SHA256 + std::string iconPerceptualAvgHash; ///< icon perceptual hash AvgHash std::string computePerceptualAvgHash(const ResourceIcon &icon) const; bool parseVersionInfo(const std::vector &bytes); @@ -47,9 +50,13 @@ class ResourceTable /// @name Getters /// @{ std::size_t getNumberOfResources() const; + std::size_t getNumberOfLanguages() const; + std::size_t getNumberOfStrings() const; std::size_t getSizeInFile() const; std::size_t getLoadedSize() const; const Resource* getResource(std::size_t rIndex) const; + const std::pair* getLanguage(std::size_t rIndex) const; + const std::pair* getString(std::size_t rIndex) const; const Resource* getResourceWithName(const std::string &rName) const; const Resource* getResourceWithName(std::size_t rId) const; const Resource* getResourceWithType(const std::string &rType) const; diff --git a/src/fileformat/CMakeLists.txt b/src/fileformat/CMakeLists.txt index 58bb0a8371..55cb7abffa 100644 --- a/src/fileformat/CMakeLists.txt +++ b/src/fileformat/CMakeLists.txt @@ -32,11 +32,11 @@ set(FILEFORMAT_SOURCES types/relocation_table/relocation_table.cpp types/relocation_table/relocation.cpp types/resource_table/resource.cpp + types/resource_table/resource_icon.cpp + types/resource_table/resource_icon_group.cpp types/resource_table/resource_table.cpp types/resource_table/resource_tree.cpp types/resource_table/resource_version.cpp - types/resource_table/resource_icon.cpp - types/resource_table/resource_icon_group.cpp types/resource_table/bitmap_image.cpp types/certificate_table/certificate.cpp types/certificate_table/certificate_table.cpp diff --git a/src/fileformat/types/resource_table/resource_table.cpp b/src/fileformat/types/resource_table/resource_table.cpp index b4599db7bd..00c306aa02 100644 --- a/src/fileformat/types/resource_table/resource_table.cpp +++ b/src/fileformat/types/resource_table/resource_table.cpp @@ -35,7 +35,8 @@ struct FixedFileInfo std::uint32_t signature; ///< signature FFI_SIGNATURE std::uint16_t strucVersionMaj; ///< binary major version number std::uint16_t strucVersionMin; ///< binary minor version number - std::uint64_t fileVersion; ///< file version number + std::uint32_t fileVersionMaj; ///< file major version number + std::uint32_t fileVersionMin; ///< file minor version number std::uint64_t productVersion; ///< product version number std::uint32_t fileFlagsMask; ///< validity mask of fileFalgs member std::uint32_t fileFlags; ///< file flags @@ -47,9 +48,9 @@ struct FixedFileInfo static std::size_t structSize() { return - sizeof(signature) + sizeof(strucVersionMaj) + sizeof(strucVersionMin) + sizeof(fileVersion) + - sizeof(productVersion) + sizeof(fileFlagsMask) + sizeof(fileFlags) + sizeof(fileOS) + - sizeof(fileType) + sizeof(fileSubtype) + sizeof(timestamp); + sizeof(signature) + sizeof(strucVersionMaj) + sizeof(strucVersionMin) + sizeof(fileVersionMaj) + + sizeof(fileVersionMin) + sizeof(productVersion) + sizeof(fileFlagsMask) + sizeof(fileFlags) + + sizeof(fileOS) + sizeof(fileType) + sizeof(fileSubtype) + sizeof(timestamp); } }; @@ -140,6 +141,24 @@ std::size_t ResourceTable::getNumberOfResources() const return table.size(); } +/** + * Get number of supported languages + * @return Number of supported languages + */ +std::size_t ResourceTable::getNumberOfLanguages() const +{ + return languages.size(); +} + +/** + * Get number of strings + * @return Number of strings + */ +std::size_t ResourceTable::getNumberOfStrings() const +{ + return strings.size(); +} + /** * Get total declared size of resources * @return Total declared size of resources @@ -182,6 +201,26 @@ const Resource* ResourceTable::getResource(std::size_t rIndex) const return (rIndex < getNumberOfResources()) ? table[rIndex].get() : nullptr; } +/** + * Get selected language + * @param rIndex Index of selected language (indexed from 0) + * @return Pointer to selected language or @c nullptr if language index is invalid + */ +const std::pair* ResourceTable::getLanguage(std::size_t rIndex) const +{ + return (rIndex < getNumberOfLanguages()) ? &languages[rIndex] : nullptr; +} + +/** + * Get selected string + * @param rIndex Index of selected string (indexed from 0) + * @return Pointer to selected string or @c nullptr if string index is invalid + */ +const std::pair* ResourceTable::getString(std::size_t rIndex) const +{ + return (rIndex < getNumberOfStrings()) ? &strings[rIndex] : nullptr; +} + /** * Get resource by name * @param rName Name of the resource to get @@ -410,14 +449,7 @@ void ResourceTable::parseVersionInfoResources() { continue; } - if (parseVersionInfo(bytes)) - { - std::cerr << "SUCCESS\n\n"; - } - else - { - std::cerr << "FAILED\n\n"; - } + parseVersionInfo(bytes); } } @@ -459,10 +491,13 @@ bool ResourceTable::parseVersionInfo(const std::vector &bytes) } ffi.signature = structContent.read(offset); offset += sizeof(ffi.signature); - ffi.strucVersionMaj = structContent.read(offset); offset += sizeof(ffi.strucVersionMaj); ffi.strucVersionMin = structContent.read(offset); offset += sizeof(ffi.strucVersionMin); - ffi.fileVersion = structContent.read(offset); offset += sizeof(ffi.fileVersion); - ffi.productVersion = structContent.read(offset); offset += sizeof(ffi.productVersion); + ffi.strucVersionMaj = structContent.read(offset); offset += sizeof(ffi.strucVersionMaj); + std::uint32_t t1 = structContent.read(offset); + ffi.fileVersionMaj = t1 >> 16; offset += sizeof(ffi.fileVersionMaj); + ffi.fileVersionMin = t1 & 0xFFFF; offset += sizeof(ffi.fileVersionMin); + std::uint64_t t2 = structContent.read(offset); + ffi.productVersion = t2 >> 16; offset += sizeof(ffi.productVersion); ffi.fileFlagsMask = structContent.read(offset); offset += sizeof(ffi.fileFlagsMask); ffi.fileFlags = structContent.read(offset); offset += sizeof(ffi.fileFlags); ffi.fileOS = structContent.read(offset); offset += sizeof(ffi.fileOS); @@ -587,8 +622,7 @@ bool ResourceTable::parseVarFileInfoChild(const std::vector &bytes std::uint32_t lang = structContent.read(offset); offset += sizeof(lang); std::uint16_t lcid = lang & 0xFFFF; std::uint16_t codePage = lang >> 16; - std::cerr << ">>> code page:\t" << codePageToStr(codePage) << "\n"; - std::cerr << ">>> lcid:\t" << lcidToStr(lcid) << "\n"; + languages.emplace_back(std::make_pair(lcidToStr(lcid), codePageToStr(codePage))); } offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t)); @@ -617,22 +651,11 @@ bool ResourceTable::parseStringFileInfoChild(const std::vector &by std::size_t nRead; std::string key = retdec::utils::unicodeToAscii(&bytes.data()[offset], bytes.size() - offset, nRead); - std::cerr << "key: " << key << "\n"; - if (nRead != STRTAB_KEY_SIZE) { return false; } - std::uint32_t lang; - if (retdec::utils::strToNum(key, lang, std::hex)) - { - std::uint16_t lcid = lang >> 16; - std::uint16_t codePage = lang & 0xFFFF; - std::cerr << ">>> code page:\t" << codePageToStr(codePage) << "\n"; - std::cerr << ">>> lcid:\t" << lcidToStr(lcid) << "\n"; - } - offset += STRTAB_KEY_SIZE; offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t)); @@ -682,10 +705,9 @@ bool ResourceTable::parseVarString(const std::vector &bytes, std:: std::size_t nToRead = targetOffset - offset; std::size_t nRead; - std::string key = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead); + std::string name = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead); offset += nRead; offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t)); - std::cerr << "stringKey: " << key << "\n"; if (offset > targetOffset) { @@ -693,16 +715,15 @@ bool ResourceTable::parseVarString(const std::vector &bytes, std:: } nToRead = targetOffset - offset; + std::string value; if (nToRead > 0) { - std::string value = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead); + value = retdec::utils::unicodeToAscii(&bytes.data()[offset], nToRead, nRead); offset += nRead; - - std::cerr << "stringValue: " << value << "\n"; - offset = retdec::utils::alignUp(offset, sizeof(std::uint32_t)); } + strings.emplace_back(std::make_pair(name, value)); return true; } diff --git a/src/fileinfo/CMakeLists.txt b/src/fileinfo/CMakeLists.txt index 2970c81629..0c718ea964 100644 --- a/src/fileinfo/CMakeLists.txt +++ b/src/fileinfo/CMakeLists.txt @@ -52,12 +52,14 @@ set(FILEINFO_SOURCES file_presentation/getters/iterative_getter/iterative_distribution_getter/relocation_tables_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/resource_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/rich_header_plain_getter.cpp - file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/section_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/segment_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/strings_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/symbol_tables_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_distribution_getter/typeref_table_plain_getter.cpp + file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp + file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp + file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_getter.cpp file_presentation/getters/iterative_getter/iterative_simple_getter/certificate_table_plain_getter.cpp file_presentation/getters/iterative_getter/iterative_simple_getter/iterative_simple_getter.cpp diff --git a/src/fileinfo/file_information/file_information.cpp b/src/fileinfo/file_information/file_information.cpp index 280b45b0ed..8b2e138068 100644 --- a/src/fileinfo/file_information/file_information.cpp +++ b/src/fileinfo/file_information/file_information.cpp @@ -1365,6 +1365,24 @@ std::size_t FileInformation::getNumberOfStoredResources() const return resourceTable.getNumberOfResources(); } +/** + * Get number of supported version info languages + * @return Number of supported version info languages + */ +std::size_t FileInformation::getNumberOfVersionInfoLanguages() const +{ + return resourceTable.getNumberOfLanguages(); +} + +/** + * Get number of version info strings + * @return Number of version info strings + */ +std::size_t FileInformation::getNumberOfVersionInfoStrings() const +{ + return resourceTable.getNumberOfStrings(); +} + /** * Get CRC32 of selected resource * @param index Index of selected resource (indexed from 0) @@ -1461,6 +1479,46 @@ std::string FileInformation::getResourceLanguage(std::size_t index) const return resourceTable.getResourceLanguage(index); } +/** + * Get LCID of selected version info language + * @param index Index of selected version info language (indexed from 0) + * @return LCID of selected version info language + */ +std::string FileInformation::getVersionInfoLanguageLcid(std::size_t index) const +{ + return resourceTable.getLanguageLcid(index); +} + +/** + * Get code page of selected version info language + * @param index Index of selected version info language (indexed from 0) + * @return Code page of selected version info language + */ +std::string FileInformation::getVersionInfoLanguageCodePage(std::size_t index) const +{ + return resourceTable.getLanguageCodePage(index); +} + +/** + * Get name of selected version info string + * @param index Index of selected version info string (indexed from 0) + * @return Name of selected version info string + */ +std::string FileInformation::getVersionInfoStringName(std::size_t index) const +{ + return resourceTable.getStringName(index); +} + +/** + * Get value of selected version info string + * @param index Index of selected version info string (indexed from 0) + * @return Value of selected version info string + */ +std::string FileInformation::getVersionInfoStringValue(std::size_t index) const +{ + return resourceTable.getStringValue(index); +} + /** * Get name ID of selected resource * @param index Index of selected resource (indexed from 0) diff --git a/src/fileinfo/file_information/file_information.h b/src/fileinfo/file_information/file_information.h index 56261e630e..463fb07ca7 100644 --- a/src/fileinfo/file_information/file_information.h +++ b/src/fileinfo/file_information/file_information.h @@ -234,6 +234,8 @@ class FileInformation /// @name Getters of @a resourceTable /// @{ std::size_t getNumberOfStoredResources() const; + std::size_t getNumberOfVersionInfoLanguages() const; + std::size_t getNumberOfVersionInfoStrings() const; std::string getResourceCrc32(std::size_t index) const; std::string getResourceMd5(std::size_t index) const; std::string getResourceSha256(std::size_t index) const; @@ -244,6 +246,10 @@ class FileInformation std::string getResourceName(std::size_t index) const; std::string getResourceType(std::size_t index) const; std::string getResourceLanguage(std::size_t index) const; + std::string getVersionInfoLanguageLcid(std::size_t index) const; + std::string getVersionInfoLanguageCodePage(std::size_t index) const; + std::string getVersionInfoStringName(std::size_t index) const; + std::string getVersionInfoStringValue(std::size_t index) const; std::string getResourceNameIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; std::string getResourceTypeIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; std::string getResourceLanguageIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; diff --git a/src/fileinfo/file_information/file_information_types/resource_table/resource_table.cpp b/src/fileinfo/file_information/file_information_types/resource_table/resource_table.cpp index b51e1c23be..9ba734a5d6 100644 --- a/src/fileinfo/file_information/file_information_types/resource_table/resource_table.cpp +++ b/src/fileinfo/file_information/file_information_types/resource_table/resource_table.cpp @@ -34,6 +34,24 @@ std::size_t ResourceTable::getNumberOfResources() const return table ? table->getNumberOfResources() : 0; } +/** + * Get number of supported languages + * @return Number of supported languages + */ +std::size_t ResourceTable::getNumberOfLanguages() const +{ + return table ? table->getNumberOfLanguages() : 0; +} + +/** + * Get number of strings + * @return Number of strings + */ +std::size_t ResourceTable::getNumberOfStrings() const +{ + return table ? table->getNumberOfStrings() : 0; +} + /** * Get CRC32 of selected resource * @param index Index of selected resource (indexed from 0) @@ -146,6 +164,50 @@ std::string ResourceTable::getResourceLanguage(std::size_t index) const return record ? record->getLanguage() : ""; } +/** + * Get LCID of supported language + * @param index Index of selected supported language (indexed from 0) + * @return LCID of supported language + */ +std::string ResourceTable::getLanguageLcid(std::size_t index) const +{ + const auto *record = table ? table->getLanguage(index) : nullptr; + return record ? record->first : ""; +} + +/** + * Get code page of supported language + * @param index Index of selected code page (indexed from 0) + * @return Code page of supported language + */ +std::string ResourceTable::getLanguageCodePage(std::size_t index) const +{ + const auto *record = table ? table->getLanguage(index) : nullptr; + return record ? record->second : ""; +} + +/** + * Get name of selected string + * @param index Index of selected string (indexed from 0) + * @return Name of string + */ +std::string ResourceTable::getStringName(std::size_t index) const +{ + const auto *record = table ? table->getString(index) : nullptr; + return record ? record->first : ""; +} + +/** + * Get value of selected string + * @param index Index of selected string (indexed from 0) + * @return Value of string + */ +std::string ResourceTable::getStringValue(std::size_t index) const +{ + const auto *record = table ? table->getString(index) : nullptr; + return record ? record->second : ""; +} + /** * Get name ID of selected resource * @param index Index of selected resource (indexed from 0) diff --git a/src/fileinfo/file_information/file_information_types/resource_table/resource_table.h b/src/fileinfo/file_information/file_information_types/resource_table/resource_table.h index 1b3b9b85a1..ed84c4de30 100644 --- a/src/fileinfo/file_information/file_information_types/resource_table/resource_table.h +++ b/src/fileinfo/file_information/file_information_types/resource_table/resource_table.h @@ -31,6 +31,8 @@ class ResourceTable /// @name Getters /// @{ std::size_t getNumberOfResources() const; + std::size_t getNumberOfLanguages() const; + std::size_t getNumberOfStrings() const; std::string getResourceCrc32(std::size_t index) const; std::string getResourceMd5(std::size_t index) const; std::string getResourceSha256(std::size_t index) const; @@ -43,6 +45,10 @@ class ResourceTable std::string getResourceName(std::size_t index) const; std::string getResourceType(std::size_t index) const; std::string getResourceLanguage(std::size_t index) const; + std::string getLanguageLcid(std::size_t index) const; + std::string getLanguageCodePage(std::size_t index) const; + std::string getStringName(std::size_t index) const; + std::string getStringValue(std::size_t index) const; std::string getResourceNameIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; std::string getResourceTypeIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; std::string getResourceLanguageIdStr(std::size_t index, std::ios_base &(* format)(std::ios_base &)) const; diff --git a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp new file mode 100644 index 0000000000..be329ec4ec --- /dev/null +++ b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp @@ -0,0 +1,93 @@ +/** + * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.cpp + * @brief Definition of VersionInfoLanguageTablePlainGetter class. + * @copyright (c) 2017 Avast Software, licensed under the MIT license + */ + +#include "retdec/utils/conversion.h" +#include "retdec/utils/string.h" +#include "retdec/fileformat/utils/conversions.h" +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h" + +using namespace retdec::utils; +using namespace retdec::fileformat; + +namespace fileinfo { + +namespace +{ + +const std::size_t distributionArray[] = {6, 40, 40}; +const std::string headerArray[] = {"i", "lcid", "codePage"}; +const std::string headerDesc[] = {"index", "microsoft language identifier", "IBM code page"}; + +} // anonymous namespace + +/** + * Constructor + * @param fileInfo Information about file + */ +VersionInfoLanguageTablePlainGetter::VersionInfoLanguageTablePlainGetter(FileInformation &fileInfo) : IterativeDistributionGetter(fileInfo) +{ + numberOfStructures = 1; + numberOfStoredRecords.push_back(fileinfo.getNumberOfVersionInfoLanguages()); + numberOfExtraElements.push_back(0); + title = "Version info languages"; + distribution.insert(distribution.begin(), std::begin(distributionArray), std::end(distributionArray)); + commonHeaderElements.insert(commonHeaderElements.begin(), std::begin(headerArray), std::end(headerArray)); + commonHeaderDesc.insert(commonHeaderDesc.begin(), std::begin(headerDesc), std::end(headerDesc)); + loadRecords(); +} + +/** + * Destructor + */ +VersionInfoLanguageTablePlainGetter::~VersionInfoLanguageTablePlainGetter() +{ + +} + +std::size_t VersionInfoLanguageTablePlainGetter::getBasicInfo(std::size_t structIndex, std::vector &desc, std::vector &info) const +{ + if(structIndex >= numberOfStructures || !fileinfo.getNumberOfVersionInfoLanguages()) + { + return 0; + } + + desc.clear(); + info.clear(); + + desc.push_back("Number of languages: "); + info.push_back(numToStr(fileinfo.getNumberOfVersionInfoLanguages())); + + return info.size(); +} + +bool VersionInfoLanguageTablePlainGetter::loadRecord(std::size_t structIndex, std::size_t recIndex, std::vector &record) +{ + if(structIndex >= numberOfStructures || recIndex >= numberOfStoredRecords[structIndex]) + { + return false; + } + + record.clear(); + record.push_back(numToStr(recIndex)); + record.push_back(fileinfo.getVersionInfoLanguageLcid(recIndex)); + record.push_back(fileinfo.getVersionInfoLanguageCodePage(recIndex)); + return true; +} + +bool VersionInfoLanguageTablePlainGetter::getFlagDescriptors(std::size_t structIndex, std::vector &desc, std::vector &abbv) const +{ + if(structIndex >= numberOfStructures) + { + return false; + } + + desc.clear(); + abbv.clear(); + + return true; +} + +} // namespace fileinfo diff --git a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h new file mode 100644 index 0000000000..6e7d353bca --- /dev/null +++ b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h @@ -0,0 +1,31 @@ +/** + * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h + * @brief Definition of VersionInfoLanguageTablePlainGetter class. + * @copyright (c) 2017 Avast Software, licensed under the MIT license + */ + +#ifndef FILEINFO_FILE_PRESENTATION_GETTERS_ITERATIVE_GETTER_ITERATIVE_DISTRIBUTION_GETTER_VERSION_INFO_LANGUAGE_TABLE_PLAIN_GETTER_H +#define FILEINFO_FILE_PRESENTATION_GETTERS_ITERATIVE_GETTER_ITERATIVE_DISTRIBUTION_GETTER_VERSION_INFO_LANGUAGE_TABLE_PLAIN_GETTER_H + +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/iterative_distribution_getter.h" + +namespace fileinfo { + +/** + * Getter for visual basic objects + */ +class VersionInfoLanguageTablePlainGetter : public IterativeDistributionGetter +{ + protected: + virtual bool loadRecord(std::size_t structIndex, std::size_t recIndex, std::vector &record) override; + public: + VersionInfoLanguageTablePlainGetter(FileInformation &fileInfo); + virtual ~VersionInfoLanguageTablePlainGetter() override; + + virtual std::size_t getBasicInfo(std::size_t structIndex, std::vector &desc, std::vector &info) const override; + virtual bool getFlagDescriptors(std::size_t structIndex, std::vector &desc, std::vector &abbv) const override; +}; + +} // namespace fileinfo + +#endif diff --git a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp new file mode 100644 index 0000000000..92e3994c90 --- /dev/null +++ b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp @@ -0,0 +1,93 @@ +/** + * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.cpp + * @brief Definition of VersionInfoStringTablePlainGetter class. + * @copyright (c) 2017 Avast Software, licensed under the MIT license + */ + +#include "retdec/utils/conversion.h" +#include "retdec/utils/string.h" +#include "retdec/fileformat/utils/conversions.h" +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h" + +using namespace retdec::utils; +using namespace retdec::fileformat; + +namespace fileinfo { + +namespace +{ + +const std::size_t distributionArray[] = {6, 40, 40}; +const std::string headerArray[] = {"i", "name", "value"}; +const std::string headerDesc[] = {"index", "string name", "string value"}; + +} // anonymous namespace + +/** + * Constructor + * @param fileInfo Information about file + */ +VersionInfoStringTablePlainGetter::VersionInfoStringTablePlainGetter(FileInformation &fileInfo) : IterativeDistributionGetter(fileInfo) +{ + numberOfStructures = 1; + numberOfStoredRecords.push_back(fileinfo.getNumberOfVersionInfoStrings()); + numberOfExtraElements.push_back(0); + title = "Version info strings"; + distribution.insert(distribution.begin(), std::begin(distributionArray), std::end(distributionArray)); + commonHeaderElements.insert(commonHeaderElements.begin(), std::begin(headerArray), std::end(headerArray)); + commonHeaderDesc.insert(commonHeaderDesc.begin(), std::begin(headerDesc), std::end(headerDesc)); + loadRecords(); +} + +/** + * Destructor + */ +VersionInfoStringTablePlainGetter::~VersionInfoStringTablePlainGetter() +{ + +} + +std::size_t VersionInfoStringTablePlainGetter::getBasicInfo(std::size_t structIndex, std::vector &desc, std::vector &info) const +{ + if(structIndex >= numberOfStructures || !fileinfo.getNumberOfVersionInfoStrings()) + { + return 0; + } + + desc.clear(); + info.clear(); + + desc.push_back("Number of strings: "); + info.push_back(numToStr(fileinfo.getNumberOfVersionInfoStrings())); + + return info.size(); +} + +bool VersionInfoStringTablePlainGetter::loadRecord(std::size_t structIndex, std::size_t recIndex, std::vector &record) +{ + if(structIndex >= numberOfStructures || recIndex >= numberOfStoredRecords[structIndex]) + { + return false; + } + + record.clear(); + record.push_back(numToStr(recIndex)); + record.push_back(replaceNonprintableChars(fileinfo.getVersionInfoStringName(recIndex))); + record.push_back(replaceNonprintableChars(fileinfo.getVersionInfoStringValue(recIndex))); + return true; +} + +bool VersionInfoStringTablePlainGetter::getFlagDescriptors(std::size_t structIndex, std::vector &desc, std::vector &abbv) const +{ + if(structIndex >= numberOfStructures) + { + return false; + } + + desc.clear(); + abbv.clear(); + + return true; +} + +} // namespace fileinfo diff --git a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h new file mode 100644 index 0000000000..2e31952239 --- /dev/null +++ b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h @@ -0,0 +1,31 @@ +/** + * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h + * @brief Definition of VersionInfoStringTablePlainGetter class. + * @copyright (c) 2017 Avast Software, licensed under the MIT license + */ + +#ifndef FILEINFO_FILE_PRESENTATION_GETTERS_ITERATIVE_GETTER_ITERATIVE_DISTRIBUTION_GETTER_VERSION_INFO_STRING_TABLE_PLAIN_GETTER_H +#define FILEINFO_FILE_PRESENTATION_GETTERS_ITERATIVE_GETTER_ITERATIVE_DISTRIBUTION_GETTER_VERSION_INFO_STRING_TABLE_PLAIN_GETTER_H + +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/iterative_distribution_getter.h" + +namespace fileinfo { + +/** + * Getter for visual basic objects + */ +class VersionInfoStringTablePlainGetter : public IterativeDistributionGetter +{ + protected: + virtual bool loadRecord(std::size_t structIndex, std::size_t recIndex, std::vector &record) override; + public: + VersionInfoStringTablePlainGetter(FileInformation &fileInfo); + virtual ~VersionInfoStringTablePlainGetter() override; + + virtual std::size_t getBasicInfo(std::size_t structIndex, std::vector &desc, std::vector &info) const override; + virtual bool getFlagDescriptors(std::size_t structIndex, std::vector &desc, std::vector &abbv) const override; +}; + +} // namespace fileinfo + +#endif diff --git a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp index 4596a33267..9a68357d9c 100644 --- a/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp +++ b/src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp @@ -1,5 +1,5 @@ /** - * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.h + * @file src/fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.cpp * @brief Definition of VisualBasicExternTablePlainGetter class. * @copyright (c) 2017 Avast Software, licensed under the MIT license */ diff --git a/src/fileinfo/file_presentation/getters/plain_getters.h b/src/fileinfo/file_presentation/getters/plain_getters.h index 8a01af36d7..59756df5e7 100644 --- a/src/fileinfo/file_presentation/getters/plain_getters.h +++ b/src/fileinfo/file_presentation/getters/plain_getters.h @@ -25,6 +25,8 @@ #include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/symbol_tables_plain_getter.h" #include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/typeref_table_plain_getter.h" #include "fileinfo/file_presentation/getters/iterative_getter/iterative_simple_getter/certificate_table_plain_getter.h" +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_language_table_plain_getter.h" +#include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/version_info_string_table_plain_getter.h" #include "fileinfo/file_presentation/getters/iterative_getter/iterative_distribution_getter/visual_basic_extern_table_plain_getter.h" #include "fileinfo/file_presentation/getters/simple_getter/basic_plain_getter.h" #include "fileinfo/file_presentation/getters/simple_getter/dotnet_plain_getter.h" diff --git a/src/fileinfo/file_presentation/json_presentation.cpp b/src/fileinfo/file_presentation/json_presentation.cpp index 95c2041651..97122277c4 100644 --- a/src/fileinfo/file_presentation/json_presentation.cpp +++ b/src/fileinfo/file_presentation/json_presentation.cpp @@ -552,6 +552,45 @@ void JsonPresentation::presentVisualBasicInfo(Json::Value &root) const root["visualBasicInfo"] = jVBasic; } +/** + * Present version information + * @param root Parent node in output document + */ +void JsonPresentation::presentVersionInfo(Json::Value &root) const +{ + Value jVerInfo; + + auto nStrings = fileinfo.getNumberOfVersionInfoStrings(); + if (nStrings) + { + Value jStrings; + for (std::size_t i = 0; i < nStrings; i++) + { + Value jStr; + jStr["name"] = fileinfo.getVersionInfoStringName(i); + jStr["value"] = fileinfo.getVersionInfoStringValue(i); + jStrings.append(jStr); + } + jVerInfo["strings"] = jStrings; + } + + auto nLangs = fileinfo.getNumberOfVersionInfoLanguages(); + if (nLangs) + { + Value jLanguages; + for (std::size_t i = 0; i < nLangs; i++) + { + Value jLang; + jLang["lcid"] = fileinfo.getVersionInfoLanguageLcid(i); + jLang["codePage"] = fileinfo.getVersionInfoLanguageCodePage(i); + jLanguages.append(jLang); + } + jVerInfo["languages"] = jLanguages; + } + + root["versionInfo"] = jVerInfo; +} + /** * Present ELF notes * @param root Parent node in output document @@ -813,6 +852,7 @@ bool JsonPresentation::present() presentCertificateAttributes(root); presentDotnetInfo(root); presentVisualBasicInfo(root); + presentVersionInfo(root); } else { diff --git a/src/fileinfo/file_presentation/json_presentation.h b/src/fileinfo/file_presentation/json_presentation.h index e530230191..b807995011 100644 --- a/src/fileinfo/file_presentation/json_presentation.h +++ b/src/fileinfo/file_presentation/json_presentation.h @@ -33,6 +33,7 @@ class JsonPresentation : public FilePresentation void presentLoaderInfo(Json::Value &root) const; void presentCertificateAttributes(Json::Value &root) const; void presentDotnetInfo(Json::Value &root) const; + void presentVersionInfo(Json::Value &root) const; void presentVisualBasicInfo(Json::Value &root) const; void presentElfNotes(Json::Value &root) const; void presentFlags(Json::Value &root, const std::string &title, const std::string &flags, const std::vector &desc) const; diff --git a/src/fileinfo/file_presentation/plain_presentation.cpp b/src/fileinfo/file_presentation/plain_presentation.cpp index 466f2c0117..a1f8e0c516 100644 --- a/src/fileinfo/file_presentation/plain_presentation.cpp +++ b/src/fileinfo/file_presentation/plain_presentation.cpp @@ -748,6 +748,8 @@ bool PlainPresentation::present() presentIterativeDistribution(RelocationTablesPlainGetter(fileinfo), explanatory); presentIterativeDistribution(DynamicSectionsPlainGetter(fileinfo), explanatory); presentIterativeDistribution(ResourcePlainGetter(fileinfo), explanatory); + presentIterativeDistribution(VersionInfoStringTablePlainGetter(fileinfo), explanatory); + presentIterativeDistribution(VersionInfoLanguageTablePlainGetter(fileinfo), explanatory); presentNotes();