-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathxorblocks.py
executable file
·61 lines (49 loc) · 1.75 KB
/
xorblocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# Copyright 2023 Tobias Mueller <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
from hexdump import hexdump
from pathlib import Path
from extractblock import make_int
from decryptblocks import xor_blocks
def main():
argparser = argparse.ArgumentParser(description="XOR a single chunk in a file at a given offset")
argparser.add_argument("--hexdump", action="store_true")
argparser.add_argument("--output", type=Path)
argparser.add_argument("file", type=Path)
argparser.add_argument("nullblock", type=Path)
argparser.add_argument("offset", type=make_int)
args = argparser.parse_args()
args.hexdump
f = args.file
null = args.nullblock
offset = args.offset
output = args.output
null_block = null.open("rb").read()
print ("Null:")
hexdump(null_block)
with f.open("rb") as fd:
fd.seek(offset)
b = fd.read(len(null_block))
r = xor_blocks(b, null_block)
print ("Original:")
hexdump(b)
print ("Result:")
hexdump(r)
if output:
output.open("bx").write(r)
return r
if __name__ == "__main__":
main()