返回列表 发帖

[文件操作] [已解决]批处理如何把文本内容替换到文件里?

本帖最后由 a574045075 于 2023-2-21 11:42 编辑

这里有个01.txt文本,内容如下图

如何用批处理命令把Using title id的0005000000012400和generated encrypted的e734ae04fb23bf6de77a6e21646c95a6替换到如下图的位置,另外Using title id的值和generated encrypted的值是随机的,不一定是0005000000012400和e734ae04fb23bf6de77a6e21646c95a6

最终想要的结果如下图
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

这个论坛图片上传不了

TOP

回复 2# 23618342


    看到图片吗?

TOP

回复  23618342


    看到图片吗?
a574045075 发表于 2023-2-20 18:28



    有图片
我是小白,希望老师多多帮助

TOP

本帖最后由 czjt1234 于 2023-2-21 10:15 编辑

vbs
file1 = "01.txt"
file2 = "basetik.tik"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oTextStream = oFSO.OpenTextFile(file1)
s = oTextStream.ReadAll()
oTextStream.Close()
Set oRegExp = CreateObject("VBScript.RegExp")
oRegExp.IgnoreCase = True
oRegExp.Pattern = "Using title id\: (.+)?\r\n"
For Each i In oRegExp.Execute(s)
    t = i.SubMatches.Item(0)
Next
With CreateObject("Msxml2.DOMDocument").CreateElement("hex")
    .DataType = "bin.hex"
    .Text = t
    arrByte = .NodeTypedValue
End With
With CreateObject("ADODB.Stream")
    .Type = 1    'adTypeBinary
    .Mode = 3    'adModeReadWrite
    .Open()
    .LoadFromFile file2
    .Position = &H01DC
    .Write arrByte
    .SaveToFile file2, 2
    .Close()
End With
oRegExp.Pattern = "generated encrypted\: (.+)?\r\n"
For Each i In oRegExp.Execute(s & vbCrLf)
    t = i.SubMatches.Item(0)
Next
With CreateObject("Msxml2.DOMDocument").CreateElement("hex")
    .DataType = "bin.hex"
    .Text = t
    arrByte = .NodeTypedValue
End With
With CreateObject("ADODB.Stream")
    .Type = 1    'adTypeBinary
    .Mode = 3    'adModeReadWrite
    .Open()
    .LoadFromFile file2
    .Position = &H01BF
    .Write arrByte
    .SaveToFile file2, 2
    .Close()
End With
MsgBox "ok"COPY
1

评分人数


QQ 20147578

TOP

你们看到图片?

TOP

回复 6# terse

可以看到顶楼图片,刷新等待一下,试试
bat小白,请多指教!谢谢!

TOP

本帖最后由 WHY 于 2023-2-22 20:04 编辑

PowerShell 脚本
2023/02/22 简化脚本。我测试没有发现问题
$file1 = '01.txt';
$file2 = 'basetik.tik';          #修改前的文件名
$file3 = 'basetik_001.tik';      #修改后的文件名
$text  = [IO.File]::ReadAllText($file1, [Text.Encoding]::Default);
$bytes = [IO.File]::ReadAllBytes($file2);
Function Set-ByteValue($key, [int]$offSet){
    $reg = '(?i)(?<=' + $key + ' *)[a-f0-9]+';
    $s = ([regex]::Match($text, $reg)).Value;
    for ($i = 0; $i -lt $s.Length; $i+=2) {
        $x = $i / 2 + $offSet;
        $bytes[$x] = [byte][int]('0x' + $s.SubString($i, 2));
    }
}
Set-ByteValue -key 'Using title id:' -offSet 0x01DC;
Set-ByteValue -key 'generated encrypted:' -offSet 0x01BF;
[IO.File]::WriteAllBytes($file3, $bytes);
echo 'Done';
[Console]::ReadLine();COPY
1

评分人数

TOP

回复 8# WHY


    中午回来试试.

TOP

看到了,我上次就没有成功,奇怪了

TOP

奇怪 看不了图

TOP

回复 11# terse
可能是浏览器的事,Edge可以看到。

TOP

回复 9# a574045075


   测试的结果能发一下吗
如果不成功的,也希望看到错在哪里的

QQ 20147578

TOP

回复 12# qixiaobin0715

Edge  chrome  Firefox都试了 唉! 算了

TOP

回复 1# a574045075


    请问你的图片是怎么上传的? 我试了好像上传不了图片呢.

TOP

返回列表