New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add console-based hex editors for binary formats #5252
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
mitmproxy/tools/console/master.py
Outdated
for editor in "hexedit", "hexyl": | ||
if shutil.which(editor): | ||
return editor | ||
if os.name == "xxd": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this comparison. Can you explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out the error :).
I will push the new code.
mitmproxy/tools/console/master.py
Outdated
if os.name == "xxd": | ||
return "xxd" | ||
else: | ||
return "ghex" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if ghex is not installed?
mitmproxy/tools/console/master.py
Outdated
def spawn_editor(self, data): | ||
if strutils.is_mostly_bin(data): | ||
isBinary = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Please use
snake_case
for Python variables. - Is there a reason why you create a variable here instead of directly using
strutils.is_mostly_bin
later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got it! Thanks.
mitmproxy/tools/console/master.py
Outdated
if shutil.which(editor): | ||
return editor | ||
else: | ||
return "notepad" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is clearly untested as it contains a major logic bug. Please don't rely on me catching your errors but test your code yourself. Ideally by writing tests. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sir. I will add the required test and sorry for the inconvenience.
@mhils I have tested it and it is now working. |
|
@@ -13,7 +13,7 @@ | |||
import threading | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is need to use platform.system()
import platform | |
for editor in "ghex", "hexedit", "bless", "wxhexeditor", "nano": | ||
if shutil.which(editor): | ||
return editor | ||
if os.name == "nt": | ||
for editor in "HxD", "WinVi", "Cygnus", "Frhed", "notepad": | ||
if shutil.which(editor): | ||
return editor | ||
else: | ||
return "vi" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bless
command is completely different tool on macOS (in macOS, it is a tool to modify startup disk configuration / set volumes bootability), so it might be good to check Darwin or not.
also I think nano is not suitable for binary editor.
for editor in "ghex", "hexedit", "bless", "wxhexeditor", "nano": | |
if shutil.which(editor): | |
return editor | |
if os.name == "nt": | |
for editor in "HxD", "WinVi", "Cygnus", "Frhed", "notepad": | |
if shutil.which(editor): | |
return editor | |
else: | |
return "vi" | |
editors = ["ghex", "hexedit", "wxhexeditor"] | |
if platform.system() == "Darwin": | |
editors = ["hexf"] + editors | |
else: | |
editors += ["bless"] | |
if os.name == "nt": | |
editors += ["HxD", "WinVi", "Cygnus", "Frhed", "notepad"] | |
for editor in editors: | |
if shutil.which(editor): | |
return editor | |
return "vi" |
(note: hexf
command is shortcut to Hex Fiend.app https://github.com/HexFiend/HexFiend )
No description provided.