中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-08 13:23
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS开发编程 & 发展交流 (开发室) » Binary File Handling Tool STR (Updated on 2020.11.16)
Printable Version  41,114 / 72
Floor1 19951001 Posted 2008-04-26 21:45
高级用户 Posts 272 Credits 570 From 北京
STR
File: A File to be Processed data. //File: A file to process data
Start: Offset to Process data. //Start: Offset to process data (the beginning of the file is 0)
Bytes: Bytes to Process. //Bytes: Bytes to process (if 0 is entered, it means from Start to the end of the file)
/C: Copy Bytes from File to dstFile. ///C: Copy bytes from the file to the destination file
/I: Insert Bytes to dstFile from File. ///I: Insert bytes from the file into the destination file, and the destination file will increase by Bytes bytes after insertion
dstFile: A File to Write Result data. //dstFile: A file to write result data
Address: Offset to Write Result data. //Address: Offset to write result data (if the destination file does not exist, this value is ignored)

STR
/D: Delete Bytes from File & Write Result to dstFile. ///D: Delete bytes from the file and write the result to the destination file

STR
/V: View File In Hex Style. ///V: View the file in hexadecimal style
/A: Show ASCII Value. ///A: Show ASCII value
/P: Pause Echo Screen. ///P: Pause the echo screen

STR :
Bytes: Must be 0. //Bytes: Must be 0
/F: Find String in File. ///F: Find string in the file
/Hex: Hex Style. ///Hex: Hexadecimal style
/Asc: ASCII Style. ///Asc: ASCII style
Value: Hex_Digital/ASCII String (40 Characters Maximum). //Value: Hexadecimal number/ASCII string (maximum 40 characters) (if it is a hexadecimal string, the length should be even)
/I: Ignore Case. ///I: Ignore case
/A: Process All Value in File. ///A: Process all values in the file (default to find once)

STR :
Bytes: Must be 0. //Bytes: Must be 0
/E: Edit File. ///E: Edit the file

STR
Bytes: Must be 0. //Bytes: Must be 0
/R: Relace SrcString with DstString. ///R: Replace SrcString with DstString
SrcString: :. //SrcString: :
DstString: :. //DstString: :
/A: Process All SrcString in File. ///A: Process all SrcString in the file (default to replace once)

Instructions:
1 When using the /C and /I commands, if the destination file does not exist, the value of Address will be ignored, and directly execute to write the Bytes bytes from Start in the source file to the newly created destination file
2 When using the /C and /I commands, if the destination file exists and Address is not entered, Address defaults to 0, which is the starting position of the file.
3 The size of a single file currently processed does not exceed 2G

Examples:

str 1.exe 0x100 0x10 /d 2.bin Execute to delete 16 bytes from position 256 in file 1.exe and write the result to 2.bin. The length of file 2.bin will be 16 bytes smaller than that of 1.exe
str 1.exe 0x100 0x10 /c 2.bin 20 Execute to write 16 bytes from position 256 in file 1.exe to position 20 of 2.bin, that is, 16 bytes starting from position 20 in file 2.bin will be overwritten
str 1.exe 0x100 0x10 /i 2.bin 20 Execute to insert 16 bytes from position 256 in file 1.exe into position 20 of 2.bin, and the length of the result file 2.bin will increase by 16 bytes

str 1.exe 0x100 0 /v /p /a Display the file content on the screen starting from file offset position 256. If Bytes is entered as 0, it means from Start to the end of the file.

str 1.exe 0x100 0 /e /hex:11223344 Modify 4 bytes starting from file offset position 256 to 0x11, 0x22, 0x33, 0x44.
str 1.exe 0x100 0 /e /asc:1234 Modify 4 bytes starting from file offset position 256 to 1234, that is, 0x31, 0x32, 0x33, 0x34

The search and replace algorithm uses the KMP algorithm, and does not count repeatedly. For example, the content of file 1.txt is 10 characters 0:
0000000000

If the command is executed: str 1.txt 0 0 /f /asc:0000 /a
Then the execution result is:
Find string At:
0 0x0
4 0x4

It will not be:
Find string At:
0 0x0
1 0x1
2 0x2
3 0x3
4 0x4
5 0x5
6 0x6


The compressed package contains DOS version and Win32 version

Corrected the problem in the replace string function on 2008.12.14

Corrected the problem on floor 19 on 2008.12.19

Test version on 2009.2.15 on floor 50

[ Last edited by 19951001 on 2020-11-16 at 17:01 ]

Attachments
str.rar (18.38 KiB)
strWin32.rar (20.34 KiB)
Floor2 cchessbd Posted 2008-04-28 17:29
高级用户 Posts 222 Credits 525
Maybe I won't need this thing, but I need a tool to find and replace a certain string in a file under DOS...

I wonder if brother 19950101 can help write one?

For example: XXX /rN file "12345,d" "54321,g"

Only replace when found, or exit after replacing once. Replace all /r N times /rN

This file may be 3~10 M

[ Last edited by cchessbd on 2008-4-28 at 05:39 PM ]
Floor3 19951001 Posted 2008-05-07 22:52
高级用户 Posts 272 Credits 570 From 北京
Originally posted by cchessbd at 2008-4-28 17:29:
Maybe I don't need this thing, but I need a tool to find and replace a certain string in a file under DOS...

I wonder if brother 19950101 can help write one?

For example: XXX /rN file "123 ...


Just for text files?
Floor4 19951001 Posted 2008-11-14 21:20
高级用户 Posts 272 Credits 570 From 北京
Floor5 本是 Posted 2008-11-15 00:01
银牌会员 Posts 790 Credits 2,227
Good tool, but an error occurred when extracting the .rar file: The "WIN" header of the file is corrupted! Please re-upload!
Floor6 雨露 Posted 2008-11-15 08:07
管理员 Posts 2,601 Credits 6,215
After the error, the win32 folder is empty!
Floor7 本是 Posted 2008-11-15 11:13
银牌会员 Posts 790 Credits 2,227
The file WIN is in the root directory.
Floor8 19951001 Posted 2008-11-15 11:42
高级用户 Posts 272 Credits 570 From 北京
The damaged compressed package has been repaired
Floor9 chishingchan Posted 2008-11-24 21:25
银牌会员 Posts 538 Credits 1,284
Because I need to modify binary files, I have looked for such small software before and only found FH under pure DOS. Now this one should be good.
Floor10 goli2008 Posted 2008-12-13 11:07
中级用户 Posts 97 Credits 252
Firmly support,!!
Searched for a long time, please the landlord change the title, okay, convenient for others to search, thank you!
Floor11 chenall Posted 2008-12-13 18:10
银牌会员 Posts 469 Credits 1,276 From 福建泉州
Nice stuff, received it, thanks!
Floor12 chenall Posted 2008-12-13 19:10
银牌会员 Posts 469 Credits 1,276 From 福建泉州
Can we add a "character escape" function? For example, \0 is ASCII code 00. For example, strw test.bin 0x10 0 /e /asc:test\13\0 will write test and 0X0D and 0X00.
Floor13 19951001 Posted 2008-12-13 22:28
高级用户 Posts 272 Credits 570 From 北京
Originally posted by chenall at 2008-12-13 19:10:
Can you add another function "character escaping"?
For example, \0 is ASCII code 00
For example
strw test.bin 0x10 0 /e /asc:test\13\0
will write test and 0X0D and 0X00


Theoretically, it can be implemented, but I've been quite busy these days and don't have time to modify it for the moment.


Actually, it can be implemented like this:
strw test.bin 0x10 0 /e /asc:test
strw test.bin 0x14 0 /e /hex:1300
The above two commands can achieve the function you want.

[ Last edited by 19951001 on 2008-12-13 at 23:18 ]
Floor14 chenall Posted 2008-12-14 09:43
银牌会员 Posts 469 Credits 1,276 From 福建泉州
Well, the above can be achieved, but it will be more troublesome to calculate the character length if it is placed in a batch file.

Another question, I wonder if the program returns an errorlevel value?
For example, for a search, what is returned on success? What is returned on failure?
Floor15 chenall Posted 2008-12-14 10:14
银牌会员 Posts 469 Credits 1,276 From 福建泉州
There seems to be some issues with the find - replace function..
The content of file A.TXT

Executing strw a.txt 0 0 /r /asc:$1 /asc:j: /a results in garbled code and loss of characters

The correct result
1 2 3 45  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023