China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-24 08:24
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Binary File Handling Tool STR (Updated on 2020.11.16) View 40,052 Replies 72
Original Poster Posted 2008-04-26 21:45 ·  中国 北京 电信
高级用户
★★
流落街头
Credits 570
Posts 272
Joined 2005-10-17 10:51
20-year member
UID 43609
Gender Male
From 北京
Status Offline
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, Credits to download 1 pts, Downloads: 170)
strWin32.rar (20.34 KiB, Downloads: 10)
Floor 2 Posted 2008-04-28 17:29 ·  中国 广东 深圳 电信
高级用户
★★
Credits 525
Posts 222
Joined 2006-08-28 21:07
19-year member
UID 61476
Status Offline
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 ]
Floor 3 Posted 2008-05-07 22:52 ·  中国 北京 电信
高级用户
★★
流落街头
Credits 570
Posts 272
Joined 2005-10-17 10:51
20-year member
UID 43609
Gender Male
From 北京
Status Offline
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?
Floor 4 Posted 2008-11-14 21:20 ·  中国 北京 电信
高级用户
★★
流落街头
Credits 570
Posts 272
Joined 2005-10-17 10:51
20-year member
UID 43609
Gender Male
From 北京
Status Offline
Floor 5 Posted 2008-11-15 00:01 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
Good tool, but an error occurred when extracting the .rar file: The "WIN" header of the file is corrupted! Please re-upload!
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 6 Posted 2008-11-15 08:07 ·  中国 浙江 台州 温岭市 电信
管理员
★★★★
DOS非常爱好者
Credits 6,215
Posts 2,601
Joined 2006-01-20 13:00
20-year member
UID 49256
Status Offline
After the error, the win32 folder is empty!
Floor 7 Posted 2008-11-15 11:13 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
The file WIN is in the root directory.
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 8 Posted 2008-11-15 11:42 ·  中国 北京 电信
高级用户
★★
流落街头
Credits 570
Posts 272
Joined 2005-10-17 10:51
20-year member
UID 43609
Gender Male
From 北京
Status Offline
The damaged compressed package has been repaired
Floor 9 Posted 2008-11-24 21:25 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,282
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline
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.
Floor 10 Posted 2008-12-13 11:07 ·  中国 广西 河池 电信
中级用户
★★
Credits 252
Posts 97
Joined 2006-09-17 12:00
19-year member
UID 62869
Gender Male
Status Offline
Firmly support,!!
Searched for a long time, please the landlord change the title, okay, convenient for others to search, thank you!
Floor 11 Posted 2008-12-13 18:10 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
Nice stuff, received it, thanks!
QQ:366840202
http://chenall.net
Floor 12 Posted 2008-12-13 19:10 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
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.
QQ:366840202
http://chenall.net
Floor 13 Posted 2008-12-13 22:28 ·  中国 北京 电信
高级用户
★★
流落街头
Credits 570
Posts 272
Joined 2005-10-17 10:51
20-year member
UID 43609
Gender Male
From 北京
Status Offline
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 ]
Floor 14 Posted 2008-12-14 09:43 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
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?
QQ:366840202
http://chenall.net
Floor 15 Posted 2008-12-14 10:14 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
There seems to be some issues with the find - replace function..
The content of file A.TXT

Exe =$1\TEST
Exe =$1\TEST2

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

The correct result

Exe =J:\TEST
Exe =J:\TEST2
QQ:366840202
http://chenall.net
1 2 3 5 Next ›
Forum Jump: