Skip to content
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

Binary Executable breaks on Write Back #18

Closed
AlexZoe opened this issue Mar 3, 2024 · 3 comments
Closed

Binary Executable breaks on Write Back #18

AlexZoe opened this issue Mar 3, 2024 · 3 comments

Comments

@AlexZoe
Copy link
Contributor

AlexZoe commented Mar 3, 2024

Overview

Opening a binary file and trying to save it after using :HexToggle breaks the executable.

The problem stems from the binary being opened as a regular file, since the plugin cannot determine that the file is a binary due to missing file extension and not being opened with the -b flag.

From the VIM docs, this will likely break the file due to wrong handling.

This is likely a user error since the flag should be provided when opening the file but (some) users likely don't know about this behavior.

Proposed Fix

Set the buffer as "binary" when calling dump_to_hex.

  vim.bo.bin = true

I can prepare a PR for this if you'd like.

Steps to Reproduce

Prepare Binary

Compile the following content with gcc -o run main.c.

#include <stdio.h>

int main() {
  printf("hello\n");
  return 0;
}

Executing the binary prints "hello", as expected.

Save Binary

  1. Open the binary with nvim run
  2. Call :HexToggle (hexdump content still correct)
  3. Save with :w

The binary is broken after step 3.
Trying to execute the binary now gives the output

Segmentation fault (core dumped)
@RaafatTurki
Copy link
Owner

Thanks for your thoroughness!
As you said this is user error but it still falls on the plugin to prevent such error paths.

Your suggestion is decent however I'm in the process of a complete rewrite of this plugin in order to iron out some rough edges like this one.

In the meantime feel free to PR the fix!

@AlexZoe
Copy link
Contributor Author

AlexZoe commented Mar 3, 2024

I see.

Do you have a timeline for the rewrite?

Will this be part of this repo or a separate one?

@AlexZoe AlexZoe mentioned this issue Mar 3, 2024
@RaafatTurki
Copy link
Owner

The rewrite is basically a separate plugin that utilizes hex.nvim as a "view mode" for buffers that are hex viewable.

And it's already written as are the edits for hex.nvim (locally).

The new hex.nvim will be a branch in here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants