#include "..\include_eapi_header.h"#include<map>#include<fstream>#include <iomanip>#include <sstream>#include <algorithm>inline std::string byte2hex(const std::vector<unsigned char>& data) {std::stringstream result;result << std::hex << std::setfill('0');for (unsigned char b : data) {result << std::setw(2) << static_cast<int>(b);}std::string str = result.str();std::transform(str.begin(), str.end(), str.begin(), ::toupper);return str;}// 调用格式: SDT_TEXT 取图片格式, 命令说明: "获取指定图片格式,失败返回空"// 参数<1>: 图片路径或数据 _SDT_ALL, 参数说明: "可以选择图片路径,或者内存图片字节集。"EAPI_EXTERN_C void eapi_GetPictureFormat_92_eapi(PMDATA_INF pRetData, INT nArgCount, PMDATA_INF pArgInf){static std::map<std::string, const char*> pictureFormats = {{"FFD8FF", "JPEG"},{"89504E470D0A1A0A0000000D49484452", "PNG"},{"47494638", "GIF"},{"474946383761", "GIF"},{"474946383961", "GIF"},{"49492A00", "TIFF"},{"4D4D002A", "TIFF"},{"424D", "BMP"},{"0A", "PCX"},{"3C", "SVG"},{"38425053000100000000000000", "PSD"},{"465753", "SWF"},{"D7CDC69A0000", "WMF"},{"01000000", "EMF"},{"C5D0D3C6", "EPS"},{"0000020000", "TGA"},{"0000100000", "TGA"},{"00000100", "ICO"},{"00000200", "CUR"},{"52494646", "ANI"},{"464F524D", "IFF"}};if (pArgInf[0].m_dtDataType == SDT_TEXT && pArgInf->m_pText){auto GetPictureFormat = [](const std::string_view& path)->char*{std::ifstream file(path.data(), std::ios::binary);if (!file) {return nullptr;}std::vector<unsigned char> buffer(16);file.read(reinterpret_cast<char*>(buffer.data()), 16);file.close();std::string hex = byte2hex(buffer);for (const auto& [formatHex, formatName] : pictureFormats) {if (hex.substr(0, formatHex.size()) == formatHex) {return CloneTextData(formatName);}}return nullptr;};pRetData->m_pText = GetPictureFormat(pArgInf[0].m_pText);}else if (pArgInf[0].m_dtDataType == SDT_BIN){auto GetPictureFormat = [](unsigned char* pBuffer, size_t lenth)->char* {if (!pBuffer || lenth < 16) {return nullptr;}std::vector<unsigned char> buffer = std::vector<unsigned char>(pBuffer, pBuffer + 16);std::string hex = byte2hex(buffer);for (const auto& [formatHex, formatName] : pictureFormats) {if (hex.substr(0, formatHex.size()) == formatHex) {return CloneTextData(formatName);}}return nullptr;};pRetData->m_pText = GetPictureFormat(get_ebin_data(pArgInf[0].m_pBin), get_ebin_lenth(pArgInf[0].m_pBin));}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。