开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

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


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

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

查看: 179|回复: 1
收起左侧

[C#源码] VX图片定位

[复制链接]
发表于 前天 19:26 | 显示全部楼层 |阅读模式   浙江省温州市
      VXdat文件解码到图片的代码很多了,但是没有看到从数据信息cha询图片位置的代码。
      众所周知,VX图片(或者其他文件)的都是先上传到TX的CDN服务器,然后服务器返回给你一个fileId从服务器下载,我们收到的图片信息往往是这样的:
[XML] 纯文本查看 复制代码
{
        "from_wxid": "***",
        "msgid": "6473877768939539653",
        "raw_msg": "
            <?xml version=\"1.0\"?>
            <msg>
               <img aeskey=\"1076d11a1875a8a78fd2e6eb7c194688\" encryver=\"1\" cdnthumbaeskey=\"1076d11a1875a8a78fd2e6eb7c194688\" cdnthumburl=\"3057020100044b30490201000204c1473b4002032df7fa02040eecd476020468906599042464353132353132662d623636662d346139652d613232642d6439393632623635613535360204052418020201000405004c4dfe00\" cdnthumblength=\"7785\" cdnthumbheight=\"240\" cdnthumbwidth=\"135\" cdnmidheight=\"0\" cdnmidwidth=\"0\" cdnhdheight=\"0\" cdnhdwidth=\"0\" cdnmidimgurl=\"3057020100044b30490201000204c1473b4002032df7fa02040eecd476020468906599042464353132353132662d623636662d346139652d613232642d6439393632623635613535360204052418020201000405004c4dfe00\" length=\"750297\" md5=\"d898add08467de961353a319a3210ffa\">
                   <secHashInfoBase64 />
                   <live>
                       <duration>0</duration>
                       <size>0</size>
                       <md5 />
                       <fileid />
                       <hdsize>0</hdsize>
                       <hdmd5 />
                       <hdfileid />
                       <stillimagetimems>0</stillimagetimems>
                   </live>
               </img>
               <platform_signature />
               <imgdatahash />
               <ImgSourceInfo>
                   <ImgSourceUrl />
                   <BizType>0</BizType>
               </ImgSourceInfo>
            </msg>",
        "room_wxid": "***",
        "timestamp": 1754293889,
        "to_wxid": "***",
        "wx_type": 3
}


一大堆数据无从下手,其实cdnthumbaeskey和cdnthumburl就是用来从CDN服务器请求图片信息的。这里讨论的是用消息ID从数据库cha询路径的地址:
大致步骤:
先用$"select * from MSG where MsgSvrID= {MsgId}"查到bytesExtra文本,再Base64解码文本。(3.x版本用的是MSG表,4.0好像已经改成Message表了。)
[C#] 纯文本查看 复制代码
string jsonString = await API.ExecSql(dbHandle0, $"select * from MSG where MsgSvrID= {MsgId}");
JObject jsonObject = JObject.Parse(jsonString);
byte[] bytesExtra = Array.Empty<byte>();
try
{
    if (jsonObject["data"] != null && jsonObject["data"].HasValues && jsonObject["data"][0] != null)
    {
        ocrContext.Finished = true;
        string bytesExtraBase64 = jsonObject["data"][0]["BytesExtra"]?.ToString();
        if (!string.IsNullOrEmpty(bytesExtraBase64))
        {
            bytesExtra = Convert.FromBase64String(bytesExtraBase64);
        }
    }
}
catch (Exception e)
{
    Debug.Print(e.Message);
}


解码后都得的Proto数组里面就包含图片路径:
[C#] 纯文本查看 复制代码
#region 消息结构
[ProtoContract]
public class GetDatPath
{
    [ProtoMember(1, IsRequired = true)]
    public byte[] field1;
    [ProtoMember(2, IsRequired = false)]
    public int field2;
    [ProtoMember(3, IsRequired = true)]
    public DatPathInfo dataPath;
}

[ProtoContract]
public class DatPathInfo
{
    [ProtoMember(1, IsRequired = true)]
    public int item1;

    [ProtoMember(2, IsRequired = true)]
    public List<string> list;  
}


#endregion

public static string GetDatFilePath(byte[] bytesIn)//bytesExtra解码后的数组
{
    try
    {
        using (MemoryStream ms = new MemoryStream(bytesIn))
        {
            var result = Serializer.Deserialize<GetDatPath>(ms);
            if (!string.IsNullOrEmpty(result.dataPath.list[result.dataPath.list.Count - 1]))
            {
                return result.dataPath.list[result.dataPath.list.Count - 2];
            }
        }
    }
    catch (Exception ex)
    {
        Debug.Print($"解析错误: {ex.Message}"); 
    }
  
    return null;    
}



评分

参与人数 2好评 +2 精币 +4 收起 理由
祭祀雨人 + 1 + 2 因为很少有用易去获取数据库句柄取消息ID来进行解密的,Github上倒是挺多.
mosheng + 1 + 2 YYDS~!

查看全部评分

签到天数: 2 天

发表于 昨天 00:39 | 显示全部楼层   重庆市重庆市
厉害,易语言学对了
回复 支持 反对

使用道具 举报

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

本版积分规则 致发广告者

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

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

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