
标题: [文件操作] [已解决]批处理如何把文本内容替换到文件里? [打印本页]
作者: a574045075 时间: 2023-2-20 15:40 标题: [已解决]批处理如何把文本内容替换到文件里?
本帖最后由 a574045075 于 2023-2-21 11:42 编辑
这里有个01.txt文本,内容如下图

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

最终想要的结果如下图

作者: 23618342 时间: 2023-2-20 17:59
这个论坛图片上传不了
作者: a574045075 时间: 2023-2-20 18:28
回复 2# 23618342
看到图片吗?
作者: yyz219 时间: 2023-2-20 18:55
回复 23618342
看到图片吗?
a574045075 发表于 2023-2-20 18:28 
有图片
作者: czjt1234 时间: 2023-2-20 20:03
本帖最后由 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"
复制代码
作者: terse 时间: 2023-2-20 20:51
你们看到图片?
作者: 77七 时间: 2023-2-20 21:04
回复 6# terse
可以看到顶楼图片,刷新等待一下,试试
作者: WHY 时间: 2023-2-20 21:37
本帖最后由 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();
复制代码
作者: a574045075 时间: 2023-2-21 06:50
回复 8# WHY
中午回来试试.
作者: 23618342 时间: 2023-2-21 09:17
看到了,我上次就没有成功,奇怪了
作者: terse 时间: 2023-2-21 12:23
奇怪 看不了图
作者: qixiaobin0715 时间: 2023-2-21 12:31
回复 11# terse
可能是浏览器的事,Edge可以看到。
作者: czjt1234 时间: 2023-2-21 13:32
回复 9# a574045075
测试的结果能发一下吗
如果不成功的,也希望看到错在哪里的
作者: terse 时间: 2023-2-21 13:59
回复 12# qixiaobin0715
Edge chrome Firefox都试了 唉! 算了
作者: cnnetstar 时间: 2023-2-21 14:15
回复 1# a574045075
请问你的图片是怎么上传的? 我试了好像上传不了图片呢.
作者: a574045075 时间: 2023-2-21 15:08
回复 15# cnnetstar
论坛好像上传不了图片,一上传就失败,我用网络图片.
作者: Batcher 时间: 2023-2-21 15:33
回复 11# terse
有可能是楼主使用的那个图床的网络问题
作者: Batcher 时间: 2023-2-21 15:34
回复 15# cnnetstar
如果需要上传文件,可以用阿里云盘或百度网盘。
如果需要上传截图,可以找个图床,例如:
http://bbs.bathome.net/thread-60985-1-1.html
作者: idwma 时间: 2023-2-21 16:14
回复 14# terse
把广告过滤插件关了试试
作者: WHY 时间: 2023-2-21 16:43
HexTool.exe下载- @echo off
- setlocal enabledelayedexpansion
-
- set "file1=01.txt"
- set "file2=basetik.tik"
-
- for /f "tokens=1-2 delims=:" %%i in ('type "%file1%"') do (
- if /i "%%i" == "Using title id" (
- set "HexNum1=%%j"
- ) else if /i "%%i" == "generated encrypted" (
- set "HexNum2=%%j"
- )
- )
-
- set "tmp1=%HexNum1: =%"
- set "tmp2=%HexNum2: =%"
- for %%i in (256, 128, 64, 32, 16, 8, 4, 2, 1) do (
- if "!tmp1:~%%i!" NEQ "" (set "tmp1=!tmp1:~%%i!" & set /a Len1 += %%i)
- if "!tmp2:~%%i!" NEQ "" (set "tmp2=!tmp2:~%%i!" & set /a Len2 += %%i)
- )
-
- set /a "offSet1=0x01DC, offSet2=0x01BF, Len1=(Len1+1)/2, Len2=(Len2+1)/2"
-
- HexTool "%file2%" %offSet1% %Len1% %HexNum1%
- HexTool "%file2%" %offSet2% %Len2% %HexNum2%
- pause
复制代码
作者: terse 时间: 2023-2-22 11:32
- <# : PS
- @echo off
- powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
- pause & exit
- #>
- $filename = ls '.\01.txt'
- $file = ls 'basetik.tik';
- $offset = @(0x01DC,0x01BF);
- $text = [IO.File]::ReadAllText($filename);
- [regex]$reg = '(?i)(?<=Using title id: *|generated encrypted: *)([0-9a-f]{2})+';
- $group = $reg.Matches($text);
- $fs=new-object io.filestream $file,open;
- (0..($group.Count-1)).ForEach({
- [void]$fs.seek($offset[$_],0);
- $Group[$_].Groups[1].Captures.Value.ForEach({$fs.writebyte( "0x$_" )});
- })
- $fs.flush();
- $fs.close();
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |