-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHexEditor.py
138 lines (133 loc) · 5.75 KB
/
HexEditor.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/python3
############################################################################
#
# HexEditor [ Main Program ]
# © 2020 ABDULKADİR GÜNGÖR All Rights Reserved
# Contact email address: [email protected]
#
# Developper: Abdulkadir GÜNGÖR ([email protected])
# Date: 08/2020
# All Rights Reserved (Tüm Hakları Saklıdır)
#
############################################################################
from lib.hexlib.ReadBinaryFileWithABuffer import ReadBinaryFileWithABuffer as rfile
from lib.hexlib.ShowHex import showIndexHexFile
import os
settings = dict( # <<Start Settings>>
file='', # Başlangıçta tanımlı dosya adı (YOK)
index=1,
columnsize=10, # Hex Editorde 10 karakter Uzunluk
lineshalt=-1, # Satır Sonu Yok
buffer=1024 # 1024 bayt, 1024 bayt okuyacak
) # <</Start Settings>>
# Ekranı Temizlemek için
def screenClear():
print("\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n") # Konsol dışı kullanımda ekranı temizlemek için
# clear screen
# ********************
# Windows
if os.name=='nt':
os.system('cls')
# Linux or MAC
elif os.name=='posix':
os.system('clear')
# ********************
print("")
# Giriş Menüsü
def menu0(settings:dict)->dict:
screenClear()
print()
print('\t#####################################################')
print('\t#/*************************************************\#')
print('\t#**||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||**#')
print('\t#**|| ||**#')
print('\t#**|| Hex Editor V2.1 ||**#')
print('\t#**|| 08/2020 ||**#')
print('\t#**|| ||**#')
print('\t#**|| Developer: Abdulkadir GÜNGÖR ||**#')
print('\t#**|| ([email protected]) ||**#')
print('\t#**|| ||**#')
print('\t#**||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||**#')
print('\t#\*************************************************/#')
print('\t#####################################################')
print()
print()
tmp=input('\tFile : ')
file = tmp.strip()
if file.isprintable():
settings['file']=file
return settings
# Ayar Menüsü
def menu1(settings:dict)->dict:
while True:
screenClear()
print()
print("\tAyarlar (Settings)")
print("\t"+'-'*30)
print("\t1) File : '{}'".format(settings['file']))
print("\t2) Hex Editor Start Index : {}".format(settings['index']))
print("\t3) Hex Editor Column Size : {}".format(settings['columnsize']))
print("\t4) Hex Editor Line Halt : {}".format(settings['lineshalt']))
print("\t5) Hex Editor Buffer Size : {}".format(settings['buffer']))
print()
print()
if settings['lineshalt'] != -1:
suggestion_val = settings['columnsize'] * settings['lineshalt']
if settings['buffer'] < suggestion_val:
print("\tHex Editor için minimum buffer size '{}'\n"
"\tdeğerinden büyük olması önerilmektedir.".format(suggestion_val))
print()
print()
selection=input('\n\tSelection (Continue <<Enter>> , Exit <<e>>) : ')
if selection.isdigit():
if selection == "1":
selection=input("\tFile :")
if selection.strip().isprintable():
settings['file'] = selection.strip()
elif selection == "2":
selection=input("\tStart Index : ")
if selection.strip().isdigit():
settings['index'] = int(selection.strip())
elif selection == "3":
selection=input("\tColumn Size : ")
if selection.strip().isdigit():
settings['columnsize'] = int(selection.strip())
elif selection == "4":
selection = input("\tLine Halt : ")
if selection.strip().isdigit():
if int(selection.strip()) > 0:
settings['lineshalt'] = int(selection.strip())
elif selection.strip() == "-1":
settings['lineshalt'] = -1
elif selection == "5":
selection = input("\tBuffer Size : ")
if selection.strip().isdigit():
if int(selection.strip()) > 0:
settings['buffer'] = int(selection.strip())
elif selection.lower() == 'e':
exit(0)
elif len(selection) == 0:
break
return settings
# <<Programın Akışı>>
settings=menu0(settings=settings)
while True:
settings=menu1(settings=settings)
try:
screenClear()
print()
rfile_tmp = rfile(filename=settings['file'], buffer=settings['buffer'])
showIndexHexFile (readFile=rfile_tmp, columnSize=settings['columnsize'],linesHalt=settings['lineshalt'],index=settings['index'] )
selection=input('\n\t[Program] Ayarlar (Settings) <<Enter>> , Çıkış (Exit) <<e>> : ')
if selection.strip().lower() == 'e':
break
except IOError:
screenClear()
print()
print("\t'{}' adlı bir dosya okunurken hata oluştu.".format(settings['file']))
print()
print()
selection = input('\n\t[Program] Ayarlar (Settings) <<Enter>> , Çıkış (Exit) <<e>> : ')
if selection.strip().lower() == 'e':
break
# <</Program Akışı>>