自学内容网 自学内容网

Vidmore Screen Recorde 2.0.20 学习 体验 不错!

有难度,历时5个小时,两个文件交叉验证,网络验证,QT5,源码都在图片里面。

补充补丁类
 

public class PatchManager : INotifyPropertyChanged
{
    public class PatchOperation
    {
        public long Offset { get; set; }
        public byte[] OriginalValue { get; set; }
        public byte[] NewValue { get; set; }
    }

    public class PatchFile
    {
        public string FileName { get; set; }
        public List<PatchOperation> Operations { get; set; } = new List<PatchOperation>();
    }

    public List<PatchFile> PatchFiles { get; set; } = new List<PatchFile>();

    private string _status;
    public string Status
    {
        get => _status;
        set { _status = value; OnPropertyChanged(); }
    }

    public bool ValidateAndApplyPatch(string filePath)
    {
        if (!File.Exists(filePath))
        {
            Status = "文件不存在";
            return false;
        }

        var patchFile = PatchFiles.Find(f => f.FileName == Path.GetFileName(filePath));
        if (patchFile == null)
        {
            Status = "未找到匹配的文件定义";
            return false;
        }

        try
        {
            using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
            {
                foreach (var operation in patchFile.Operations)
                {
                    if (!ValidateAndApplyOperation(fileStream, operation))
                    {
                        return false;
                    }
                }
            }

            Status = "补丁应用成功";
            return true;
        }
        catch (Exception ex)
        {
            Status = $"应用补丁时出错: {ex.Message}";
            return false;
        }
    }

    private bool ValidateAndApplyOperation(FileStream fileStream, PatchOperation operation)
    {
        fileStream.Seek(operation.Offset, SeekOrigin.Begin);
        byte[] buffer = new byte[operation.OriginalValue.Length];
        fileStream.Read(buffer, 0, buffer.Length);

        if (!buffer.SequenceEqual(operation.OriginalValue))
        {
            Status = $"偏移量 {operation.Offset} 处的值不匹配";
            return false;
        }

        fileStream.Seek(operation.Offset, SeekOrigin.Begin);
        fileStream.Write(operation.NewValue, 0, operation.NewValue.Length);
        return true;
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}

调用列子

  var patchFile = new PatchManager.PatchFile
        {
            FileName = "example.dll",
            Operations = new List<PatchManager.PatchOperation>
            {
                new PatchManager.PatchOperation
                {
                    Offset = 1000,
                    OriginalValue = new byte[] { 0x00, 0x01, 0x02 },
                    NewValue = new byte[] { 0x03, 0x04, 0x05 }
                },
                new PatchManager.PatchOperation
                {
                    Offset = 2000,
                    OriginalValue = new byte[] { 0x10, 0x11, 0x12 },
                    NewValue = new byte[] { 0x13, 0x14, 0x15 }
                }
                // 可以添加更多的操作...
            }
        };

        PatchManager.PatchFiles.Add(patchFile);
        // 可以添加更多的 PatchFile...

还是需要自己动一下手哈,代码cody 生成,没验证大概就是这个样子。


原文地址:https://blog.csdn.net/Sliphades/article/details/142966633

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!