开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 229|回复: 4
收起左侧

[已解决] C++内存特征码有没有可用的?

 关闭 [复制链接]
结帖率:83% (90/109)
发表于 2024-7-29 18:13:23 | 显示全部楼层 |阅读模式   浙江省丽水市
9精币
C++内存特征码有没有可用的?  我在网上找了很多都不可用,搜索不出来,不知道为什么,是否有可用的方法?支持通配符的那种,


补充内容 (2024-7-29 18:53):
X64位特征搜索

最佳答案

查看完整内容

之前我也研究这个C++搜索内存,现在有三个不同的实现方法

回答提醒:如果本帖被关闭无法回复,您有更好的答案帮助楼主解决,请发表至 源码区 可获得加分喔。
友情提醒:本版被采纳的主题可在 申请荣誉值 页面申请荣誉值,获得 1点 荣誉值,荣誉值可兑换荣誉会员、终身vip用户组。
快捷通道:申请荣誉值无答案申请取消悬赏投诉有答案未采纳为最佳
结帖率:100% (2/2)

签到天数: 25 天

发表于 2024-7-29 18:13:24 | 显示全部楼层   广东省梅州市
之前我也研究这个C++搜索内存,现在有三个不同的实现方法
回复

使用道具 举报

结帖率:100% (2/2)

签到天数: 25 天

发表于 2024-7-29 20:28:32 | 显示全部楼层   广东省梅州市
#include <string>
#include <algorithm>
#include <array>
#include <immintrin.h>

static constexpr char charhexset[] = "0123456789ABCDEFabcdef";
typedef unsigned int                u32;
#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
typedef long long               s96;
typedef unsigned long long      u96;
#else
typedef int                     s96;
typedef unsigned int            u96;
#endif
static bool StringReplace(std::string& source, const std::string& delimiters, const std::string& dispose = "", const std::size_t offset = 1)
{
    if (source.empty())
    {
        return false;
    }

    if (delimiters.empty())
    {
        return true;
    }

    for (std::string::size_type pos = source.find(delimiters); pos != std::string::npos; pos = source.find(delimiters))
    {
        if (source.replace(pos, offset, dispose).size())
        {
            continue;
        }
        return false;
    }

    return true;
}

static bool Hexadec2xdigit(const std::string& data, std::string& buffer, std::size_t offset)
{
    if (data.empty())
    {
        return false;
    }

    for (std::size_t i = 0; i < data.size(); i += offset)
    {
        if (std::isxdigit(data[i]))
        {
            buffer += static_cast<char>(std::stoul(data.substr(i, offset), nullptr, 16));
        }
        else
        {
            buffer += 'X';
        }
    }

    return true;
}

static bool Hexadec2xdigitEx(const std::string& data, std::string& buffer, u32 checkxdigit = 0, u32 transform = 1)
{
    if (data.empty())
    {
        return false;
    }

    std::string masks(data);
    {
        // 去掉 0x 去掉 空格
        if (StringReplace(masks, "0x") && StringReplace(masks, " "))
        {
            // 大小写转换
            if (masks.end() == (1 == transform ? std::transform(masks.begin(), masks.end(), masks.begin(), [] (unsigned char ch) { return toupper(ch); }) : std::transform(masks.begin(), masks.end(), masks.begin(), [] (unsigned char ch) { return tolower(ch); })))
            {
                // 检查是否是完整的十六进制数
                if (checkxdigit)
                {
                    if (std::string::npos != masks.find_first_not_of(charhexset))
                    {
                        return false;
                    }
                }

                return Hexadec2xdigit(static_cast<const std::string&>(masks), buffer, 2);
            }
        }
    }

    return false;
}

static bool SearchPattern(const unsigned char* pos, const std::string& chars)
{
    for (std::string::const_iterator xdigit = chars.cbegin(); xdigit != chars.cend(); ++xdigit, ++pos)
    {
        if (*pos != static_cast<const unsigned char>(*xdigit) &&     // no match
            'X' != static_cast<const unsigned char>(*xdigit))        // filter out arbitrary characters
        {
            return false;
        }
        else
        {
            // hit character
            continue;
        }
    }

    return true;
}

static bool SearchPattern(const void* start,                    // start address
                          const void* end,                      // end address
                          const std::string& keyword,           // characteristic code
                          std::size_t index,                    // take out the serial number
                          void*& address)                       // return to address
{
    if (keyword.empty())
    {
        return false;
    }

    if (start != end && static_cast<const unsigned char*>(end) > static_cast<const unsigned char*>(start) && static_cast<std::size_t>(static_cast<const unsigned char*>(end) - static_cast<const unsigned char*>(start)) > keyword.size())
    {
        std::string chars;
        {
            if (Hexadec2xdigitEx(keyword, chars, 0))
            {
                for (auto [pos, i] = std::make_tuple(static_cast<const unsigned char*>(start), static_cast<std::size_t>(0)); pos <= end; ++pos)
                {
                    if (SearchPattern(pos, chars))
                    {
                        if (++i != index)
                        {
                            continue;
                        }
                        else
                        {
                            address = const_cast<void*>(reinterpret_cast<const void*>(pos));
                        }

                        return true;
                    }
                }
            }
        }
    }

    return false;
}

static bool SearchPattern(const u96 start, const u96 end, const std::string& keyword, std::size_t index, void*& address)
{
    return SearchPattern(reinterpret_cast<const void*>(start), reinterpret_cast<const void*>(end), keyword, index, address);
}

static bool SearchPatternEx(const void* start, const void* end, const std::string& chars, std::size_t index, std::size_t count, void*& address)
{
    for (auto [masks, i, n, pos] = std::make_tuple(std::array<std::size_t, 32>{}, static_cast<std::size_t>(0), static_cast<std::size_t>(0), static_cast<const unsigned char*>(start)); i < count; ++i)
    {
        for (std::size_t j = 0; j < 16 && n < chars.size(); ++j, ++n)
        {
            if ('X' != static_cast<const char*>(chars.c_str() + i * 16)[j])
            {
                masks[i] |= static_cast<std::size_t>(1) << j;
            }
        }

        for (auto [store, j] = std::make_tuple(_mm_loadu_si128(reinterpret_cast<const __m128i *>(chars.c_str() + i * 16)), static_cast<std::size_t>(0)); pos <= end; _mm_prefetch(reinterpret_cast<const char*>(++pos + 64), _MM_HINT_NTA))
        {
            if (static_cast<std::size_t>(static_cast<std::size_t>(_mm_movemask_epi8(_mm_cmpeq_epi8(_mm_loadu_si128(reinterpret_cast<const __m128i *>(pos + i * 16)), store))) & masks[i]) == masks[i])
            {
                if (n < chars.size())
                {
                    break;
                }

                if (++j != index)
                {
                    continue;
                }
                else
                {
                    address = const_cast<void*>(reinterpret_cast<const void*>(pos));
                }

                return true;
            }
        }
    }

    return false;
}

static bool SearchPatternEx(const void* start, const void* end, const std::string& keyword, std::size_t index, void*& address)
{
    if (keyword.empty())
    {
        return false;
    }

    if (start != end && static_cast<const unsigned char*>(end) > static_cast<const unsigned char*>(start) && static_cast<std::size_t>(static_cast<const unsigned char*>(end) - static_cast<const unsigned char*>(start)) > keyword.size())
    {
        std::string chars;
        {
            if (Hexadec2xdigitEx(keyword, chars, 0))
            {
                return SearchPatternEx(start, end, chars, index, static_cast<std::size_t>((((chars.size()) + (16 - 1)) & ~(16 - 1)) >> 4), address);
            }
        }
    }

    return false;
}

static bool SearchPatternEx(const u96 start, const u96 end, const std::string& keyword, std::size_t index, void*& address)
{
    return SearchPatternEx(reinterpret_cast<const void*>(start), reinterpret_cast<const void*>(end), keyword, index, address);
}

回复

使用道具 举报

结帖率:83% (90/109)

签到天数: 2 天

 楼主| 发表于 2024-7-30 07:12:43 | 显示全部楼层   浙江省丽水市
fireandice 发表于 2024-7-29 20:28
#include
#include
#include

你这个是吾爱上复制来的吧。他这个不知道为什么没用的
回复

使用道具 举报

结帖率:83% (90/109)

签到天数: 2 天

 楼主| 发表于 2024-7-31 12:28:05 | 显示全部楼层   浙江省丽水市
fireandice 发表于 2024-7-30 16:38
之前我也研究这个C++搜索内存,现在有三个不同的实现方法

我已经找到了个可以用的了 ,还是谢谢你的帮忙
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 793400750,邮箱:wp@125.la
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

快速回复 返回顶部 返回列表