stringedit 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elisha Hollander
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: stringedit
3
+ Version: 1.0.0
4
+ Summary: Replace strings in binary files.
5
+ Home-page: https://github.com/donno2048/stringedit
6
+ Author: Elisha Hollander
7
+ Author-email: just4now666666@gmail.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://github.com/donno2048/stringedit#readme
10
+ Project-URL: Bug Reports, https://github.com/donno2048/stringedit/issues
11
+ Project-URL: Source Code, https://github.com/donno2048/stringedit
12
+ Requires-Python: >=3.0
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: prompt_toolkit
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: project-url
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
27
+
28
+ # stringedit
29
+
30
+ Replace strings in binary files.
31
+
32
+ ## Installation
33
+
34
+ ### From PyPI
35
+
36
+ ```sh
37
+ pip3 install stringedit
38
+ ```
39
+
40
+ ### From GitHub
41
+
42
+ ```sh
43
+ pip3 install git+https://github.com/donno2048/stringedit
44
+ ```
45
+ ## Usage
46
+
47
+ To run the string editing use `stringed` or `python3 -m stringedit`
48
+
49
+ ```sh
50
+ $ stringed -h
51
+ usage: stringed [-h] [-n [number]] [-m {l,r,L}] filename
52
+
53
+ Replace strings in binary files
54
+
55
+ positional arguments:
56
+ filename input filename
57
+
58
+ optional arguments:
59
+ -h, --help show this help message and exit
60
+ -n [number], --bytes [number]
61
+ print amy string of at least [number] characters (default 4)
62
+ -m {l,r,L}, --method {l,r,L}
63
+ method used to widen replacement string if it's too long l - pad with
64
+ spaces from the left r - pad with spaces from the right L - leave
65
+ everything after the replacement as it was
66
+ ```
67
+
68
+ You can also use the `stringpr` to print all the strings, similar to the `strings` linux command.
69
+
70
+ ```sh
71
+ $ stringpr -h
72
+ usage: stringpr [-h] [-n [number]] [-t {o,d,x}] [-s <string>] filename
73
+
74
+ Print strings in binary files
75
+
76
+ positional arguments:
77
+ filename input filename
78
+
79
+ optional arguments:
80
+ -h, --help show this help message and exit
81
+ -n [number], --bytes [number]
82
+ print amy string of at least [number] characters (default 4)
83
+ -t {o,d,x}, --radix {o,d,x}
84
+ print the location of the string in base 8, 10 or 16
85
+ -s <string>, --output-separator <string>
86
+ string used to separate strings in output
87
+ ```
88
+
89
+ ## Uses
90
+
91
+ - Could be used to create a modded version for a game by changing dialogues and such
92
+ - Could theoretically be used to "steal" someones binary by just replacing any info (e.g. license) with the attacker's - removes the need to decompile, change and then recompile the binary
93
+ - And more
@@ -0,0 +1,66 @@
1
+ # stringedit
2
+
3
+ Replace strings in binary files.
4
+
5
+ ## Installation
6
+
7
+ ### From PyPI
8
+
9
+ ```sh
10
+ pip3 install stringedit
11
+ ```
12
+
13
+ ### From GitHub
14
+
15
+ ```sh
16
+ pip3 install git+https://github.com/donno2048/stringedit
17
+ ```
18
+ ## Usage
19
+
20
+ To run the string editing use `stringed` or `python3 -m stringedit`
21
+
22
+ ```sh
23
+ $ stringed -h
24
+ usage: stringed [-h] [-n [number]] [-m {l,r,L}] filename
25
+
26
+ Replace strings in binary files
27
+
28
+ positional arguments:
29
+ filename input filename
30
+
31
+ optional arguments:
32
+ -h, --help show this help message and exit
33
+ -n [number], --bytes [number]
34
+ print amy string of at least [number] characters (default 4)
35
+ -m {l,r,L}, --method {l,r,L}
36
+ method used to widen replacement string if it's too long l - pad with
37
+ spaces from the left r - pad with spaces from the right L - leave
38
+ everything after the replacement as it was
39
+ ```
40
+
41
+ You can also use the `stringpr` to print all the strings, similar to the `strings` linux command.
42
+
43
+ ```sh
44
+ $ stringpr -h
45
+ usage: stringpr [-h] [-n [number]] [-t {o,d,x}] [-s <string>] filename
46
+
47
+ Print strings in binary files
48
+
49
+ positional arguments:
50
+ filename input filename
51
+
52
+ optional arguments:
53
+ -h, --help show this help message and exit
54
+ -n [number], --bytes [number]
55
+ print amy string of at least [number] characters (default 4)
56
+ -t {o,d,x}, --radix {o,d,x}
57
+ print the location of the string in base 8, 10 or 16
58
+ -s <string>, --output-separator <string>
59
+ string used to separate strings in output
60
+ ```
61
+
62
+ ## Uses
63
+
64
+ - Could be used to create a modded version for a game by changing dialogues and such
65
+ - Could theoretically be used to "steal" someones binary by just replacing any info (e.g. license) with the attacker's - removes the need to decompile, change and then recompile the binary
66
+ - And more
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,24 @@
1
+ from setuptools import setup, find_packages
2
+ setup(
3
+ name='stringedit',
4
+ version='1.0.0',
5
+ license='MIT',
6
+ author='Elisha Hollander',
7
+ author_email='just4now666666@gmail.com',
8
+ description='Replace strings in binary files.',
9
+ long_description=open('README.md').read(),
10
+ long_description_content_type="text/markdown",
11
+ url='https://github.com/donno2048/stringedit',
12
+ project_urls={
13
+ 'Documentation': 'https://github.com/donno2048/stringedit#readme',
14
+ 'Bug Reports': 'https://github.com/donno2048/stringedit/issues',
15
+ 'Source Code': 'https://github.com/donno2048/stringedit',
16
+ },
17
+ python_requires='>=3.0',
18
+ packages=find_packages(),
19
+ install_requires=["prompt_toolkit"],
20
+ entry_points={ 'console_scripts': [
21
+ 'stringed=stringedit.__main__:edit_strings',
22
+ 'stringpr=stringedit.__main__:print_strings',
23
+ ] }
24
+ )
@@ -0,0 +1,69 @@
1
+ from re import finditer
2
+ from collections import OrderedDict
3
+ from mmap import mmap, ACCESS_READ, ACCESS_WRITE
4
+ from argparse import ArgumentTypeError
5
+ from prompt_toolkit.validation import Validator, ValidationError
6
+
7
+ def get_strings(min_length: int, binary: bytes) -> dict:
8
+ strings = {}
9
+ for match in finditer(rf"[\n -~]{{{min_length},}}".encode(), binary):
10
+ strings.setdefault(match.group(), []).append(match.start())
11
+ return strings
12
+ def get_strings_from_file(min_length: int, fileno: int) -> dict:
13
+ with mmap(fileno, 0, access=ACCESS_READ) as mm:
14
+ return get_strings(min_length, mm)
15
+ def get_sorted_strings_from_file(min_length: int, fileno: int) -> OrderedDict:
16
+ return OrderedDict(sorted(get_strings_from_file(min_length, fileno).items()))
17
+
18
+ def print_ordered_strings(min_length: int, binary: bytes, radix: str = None, sep: str = None) -> None:
19
+ radix_format = f"{{:{radix}}} " if radix else ""
20
+ print(
21
+ *(radix_format.format(match.start()) + match.group().decode()
22
+ for match in finditer(rf"[\n -~]{{{min_length},}}".encode(), binary)),
23
+ sep=sep if sep is not None else '\n'
24
+ )
25
+ def print_ordered_strings_from_file(min_length: int, fileno: int, radix: str = None, sep: str = None) -> None:
26
+ with mmap(fileno, 0, access=ACCESS_READ) as mm:
27
+ print_ordered_strings(min_length, mm, radix, sep)
28
+
29
+ def replace_all_string(binary: bytes, starts: list, replacement: bytes) -> None:
30
+ for i, c in enumerate(replacement):
31
+ for start in starts:
32
+ binary[start + i] = c
33
+ def replace_all_file(starts: dict, replacement: bytes, fileno: int) -> None:
34
+ with mmap(fileno, 0, access=ACCESS_WRITE) as mm:
35
+ replace_all_string(mm, starts, replacement)
36
+
37
+ def int_gt_one(value: str) -> int:
38
+ try:
39
+ ivalue = int(value)
40
+ except ValueError:
41
+ raise ArgumentTypeError(f"{value} is not an integer")
42
+ if ivalue <= 1:
43
+ raise ArgumentTypeError("minimal byte count must be > 1")
44
+ return ivalue
45
+
46
+ def radix_type(value: str) -> str:
47
+ if value not in "odx" and value is not None:
48
+ raise ArgumentTypeError("radix must be either o, d or x")
49
+ return value
50
+
51
+ def method_type(value: str) -> str:
52
+ if value not in "lrL":
53
+ raise ArgumentTypeError("method must be either l, r or L")
54
+ return value
55
+
56
+ class MaxLengthValidator(Validator):
57
+ def __init__(self, max_len):
58
+ super().__init__()
59
+ self.max_len = max_len
60
+ def validate(self, document):
61
+ if len(document.text) > self.max_len:
62
+ raise ValidationError(
63
+ message="Replacement cannot be longer than original string",
64
+ cursor_position=len(document.text)
65
+ )
66
+ def sanitize(replacement: str, to_size: int, method: str = "L") -> str:
67
+ if method == 'l': return replacement.rjust(to_size)
68
+ if method == 'r': return replacement.ljust(to_size)
69
+ return replacement
@@ -0,0 +1,63 @@
1
+ from argparse import ArgumentParser
2
+ from prompt_toolkit.shortcuts import choice, input_dialog
3
+
4
+ try:
5
+ from . import int_gt_one, radix_type, method_type, print_ordered_strings_from_file,\
6
+ get_sorted_strings_from_file, MaxLengthValidator, replace_all_file, sanitize
7
+ except ImportError:
8
+ from stringedit import int_gt_one, radix_type, method_type, print_ordered_strings_from_file,\
9
+ get_sorted_strings_from_file, MaxLengthValidator, replace_all_file, sanitize
10
+
11
+ def get_main_arguments() -> ArgumentParser:
12
+ parser = ArgumentParser(description="Replace strings in binary files")
13
+ parser.add_argument("filename", help="input filename")
14
+ parser.add_argument("-n", "--bytes", default=4, type=int_gt_one, metavar="[number]",
15
+ help="print amy string of at least %(metavar)s characters (default %(default)s)")
16
+ return parser
17
+
18
+ def get_print_arguments() -> ArgumentParser:
19
+ parser = get_main_arguments()
20
+ parser.description = "Print strings in binary files"
21
+ parser.add_argument("-t", "--radix", type=radix_type, metavar="{o,d,x}",
22
+ help="print the location of the string in base 8, 10 or 16")
23
+ parser.add_argument("-s", "--output-separator", metavar="<string>",
24
+ help="string used to separate strings in output")
25
+ return parser
26
+
27
+ def get_edit_arguments() -> ArgumentParser:
28
+ parser = get_main_arguments()
29
+ parser.add_argument("-m", "--method", default='r', type=method_type, metavar="{l,r,L}",
30
+ help="method used to widen replacement string if it's too long\n"
31
+ "l - pad with spaces from the left\n"
32
+ "r - pad with spaces from the right\n"
33
+ "L - leave everything after the replacement as it was\n")
34
+ return parser
35
+
36
+ def print_strings() -> None:
37
+ args = get_print_arguments().parse_args()
38
+ with open(args.filename, "rb") as file:
39
+ print_ordered_strings_from_file(args.bytes, file.fileno(), args.radix, args.output_separator)
40
+
41
+ def edit_strings() -> None:
42
+ args = get_edit_arguments().parse_args()
43
+ with open(args.filename, "rb+") as file:
44
+ strings = get_sorted_strings_from_file(args.bytes, file.fileno())
45
+ while True:
46
+ string = choice(
47
+ message="The file is loaded please choose a string to edit:",
48
+ options=[(b'', "Save and Exit"), *((string, string.decode()) for string in strings.keys())],
49
+ mouse_support=True
50
+ )
51
+ if not string: break
52
+ replacement = input_dialog(
53
+ title=string.decode(),
54
+ text="Please enter a replacement",
55
+ ok_text="REPLACE",
56
+ validator=MaxLengthValidator(len(string))
57
+ ).run()
58
+ if replacement is not None:
59
+ replace_all_file(strings[string], sanitize(replacement, len(string), args.method).encode(), file.fileno())
60
+ strings[replacement.encode() + string[len(replacement):]] = strings.pop(string)
61
+
62
+ if __name__ == '__main__':
63
+ edit_strings()
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: stringedit
3
+ Version: 1.0.0
4
+ Summary: Replace strings in binary files.
5
+ Home-page: https://github.com/donno2048/stringedit
6
+ Author: Elisha Hollander
7
+ Author-email: just4now666666@gmail.com
8
+ License: MIT
9
+ Project-URL: Documentation, https://github.com/donno2048/stringedit#readme
10
+ Project-URL: Bug Reports, https://github.com/donno2048/stringedit/issues
11
+ Project-URL: Source Code, https://github.com/donno2048/stringedit
12
+ Requires-Python: >=3.0
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: prompt_toolkit
16
+ Dynamic: author
17
+ Dynamic: author-email
18
+ Dynamic: description
19
+ Dynamic: description-content-type
20
+ Dynamic: home-page
21
+ Dynamic: license
22
+ Dynamic: license-file
23
+ Dynamic: project-url
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
27
+
28
+ # stringedit
29
+
30
+ Replace strings in binary files.
31
+
32
+ ## Installation
33
+
34
+ ### From PyPI
35
+
36
+ ```sh
37
+ pip3 install stringedit
38
+ ```
39
+
40
+ ### From GitHub
41
+
42
+ ```sh
43
+ pip3 install git+https://github.com/donno2048/stringedit
44
+ ```
45
+ ## Usage
46
+
47
+ To run the string editing use `stringed` or `python3 -m stringedit`
48
+
49
+ ```sh
50
+ $ stringed -h
51
+ usage: stringed [-h] [-n [number]] [-m {l,r,L}] filename
52
+
53
+ Replace strings in binary files
54
+
55
+ positional arguments:
56
+ filename input filename
57
+
58
+ optional arguments:
59
+ -h, --help show this help message and exit
60
+ -n [number], --bytes [number]
61
+ print amy string of at least [number] characters (default 4)
62
+ -m {l,r,L}, --method {l,r,L}
63
+ method used to widen replacement string if it's too long l - pad with
64
+ spaces from the left r - pad with spaces from the right L - leave
65
+ everything after the replacement as it was
66
+ ```
67
+
68
+ You can also use the `stringpr` to print all the strings, similar to the `strings` linux command.
69
+
70
+ ```sh
71
+ $ stringpr -h
72
+ usage: stringpr [-h] [-n [number]] [-t {o,d,x}] [-s <string>] filename
73
+
74
+ Print strings in binary files
75
+
76
+ positional arguments:
77
+ filename input filename
78
+
79
+ optional arguments:
80
+ -h, --help show this help message and exit
81
+ -n [number], --bytes [number]
82
+ print amy string of at least [number] characters (default 4)
83
+ -t {o,d,x}, --radix {o,d,x}
84
+ print the location of the string in base 8, 10 or 16
85
+ -s <string>, --output-separator <string>
86
+ string used to separate strings in output
87
+ ```
88
+
89
+ ## Uses
90
+
91
+ - Could be used to create a modded version for a game by changing dialogues and such
92
+ - Could theoretically be used to "steal" someones binary by just replacing any info (e.g. license) with the attacker's - removes the need to decompile, change and then recompile the binary
93
+ - And more
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ stringedit/__init__.py
5
+ stringedit/__main__.py
6
+ stringedit.egg-info/PKG-INFO
7
+ stringedit.egg-info/SOURCES.txt
8
+ stringedit.egg-info/dependency_links.txt
9
+ stringedit.egg-info/entry_points.txt
10
+ stringedit.egg-info/requires.txt
11
+ stringedit.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ stringed = stringedit.__main__:edit_strings
3
+ stringpr = stringedit.__main__:print_strings
@@ -0,0 +1 @@
1
+ prompt_toolkit
@@ -0,0 +1 @@
1
+ stringedit