How to create hex editor inside of winforms app












-4















I'm still confused whats better to use, datagridview or Be.HexEditor,
I am pretty sure I'll be able to do it with datagridview, but I like be.hex more, especially speed, UI etc...



But I tried to understand the code of be.hex, and I can't figure out how does it work, and also is it possible to show values from bytes arrays to the HexBox(not only from opening .bin files). it also uses dynamicFileByteProvider, and there is no info on the net about this class.



dynamicFileByteProvider = new DynamicFileByteProvider(fileName);
dynamicFileByteProvider.Changed += new EventHandler(byteProvider_Changed);
dynamicFileByteProvider.LengthChanged += new EventHandler(byteProvider_LengthChanged);


my app will open 1024 bytes files max, and also it will read bytes from comm port










share|improve this question

























  • Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

    – Peter B
    Nov 21 '18 at 10:55
















-4















I'm still confused whats better to use, datagridview or Be.HexEditor,
I am pretty sure I'll be able to do it with datagridview, but I like be.hex more, especially speed, UI etc...



But I tried to understand the code of be.hex, and I can't figure out how does it work, and also is it possible to show values from bytes arrays to the HexBox(not only from opening .bin files). it also uses dynamicFileByteProvider, and there is no info on the net about this class.



dynamicFileByteProvider = new DynamicFileByteProvider(fileName);
dynamicFileByteProvider.Changed += new EventHandler(byteProvider_Changed);
dynamicFileByteProvider.LengthChanged += new EventHandler(byteProvider_LengthChanged);


my app will open 1024 bytes files max, and also it will read bytes from comm port










share|improve this question

























  • Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

    – Peter B
    Nov 21 '18 at 10:55














-4












-4








-4








I'm still confused whats better to use, datagridview or Be.HexEditor,
I am pretty sure I'll be able to do it with datagridview, but I like be.hex more, especially speed, UI etc...



But I tried to understand the code of be.hex, and I can't figure out how does it work, and also is it possible to show values from bytes arrays to the HexBox(not only from opening .bin files). it also uses dynamicFileByteProvider, and there is no info on the net about this class.



dynamicFileByteProvider = new DynamicFileByteProvider(fileName);
dynamicFileByteProvider.Changed += new EventHandler(byteProvider_Changed);
dynamicFileByteProvider.LengthChanged += new EventHandler(byteProvider_LengthChanged);


my app will open 1024 bytes files max, and also it will read bytes from comm port










share|improve this question
















I'm still confused whats better to use, datagridview or Be.HexEditor,
I am pretty sure I'll be able to do it with datagridview, but I like be.hex more, especially speed, UI etc...



But I tried to understand the code of be.hex, and I can't figure out how does it work, and also is it possible to show values from bytes arrays to the HexBox(not only from opening .bin files). it also uses dynamicFileByteProvider, and there is no info on the net about this class.



dynamicFileByteProvider = new DynamicFileByteProvider(fileName);
dynamicFileByteProvider.Changed += new EventHandler(byteProvider_Changed);
dynamicFileByteProvider.LengthChanged += new EventHandler(byteProvider_LengthChanged);


my app will open 1024 bytes files max, and also it will read bytes from comm port







c# winforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:48









Foo

1




1










asked Nov 21 '18 at 10:45









James_BKJames_BK

116




116













  • Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

    – Peter B
    Nov 21 '18 at 10:55



















  • Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

    – Peter B
    Nov 21 '18 at 10:55

















Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

– Peter B
Nov 21 '18 at 10:55





Please edit the question in such a way that there is a clear question with a limited scope. "How to create hex editor" to me is an enormous scope. I also can't see how it relates in any way to the very few lines of code that you posted.

– Peter B
Nov 21 '18 at 10:55












2 Answers
2






active

oldest

votes


















0














I've tinkered a bit with this. What I did was



1) put an invisible picture box as control placeholder on the form, here named ph1



2) configure the HexBox control in Form_Load()



private HexBox hexBox;

private void Form1_Load(object sender, EventArgs e)
{
hexBox = new HexBox()
{
Top = ph1.Top,
Width = ph1.Width,
Height = ph1.Height,
Left = ph1.Left,
Visible = true,
UseFixedBytesPerLine = true,
BytesPerLine = 16,
ColumnInfoVisible = true,
LineInfoVisible = true,
StringViewVisible = true,
VScrollBarVisible = true
};
this.Controls.Add(hexBox);
this.Controls.Remove(ph1);
}


3) Load the actual file in DragDrop event



var filePath = ((string)(e.Data.GetData(DataFormats.FileDrop)))[0];
var source = new FileByteProvider(filePath);
hexBox.ByteProvider = source;
hexBox.Refresh();


Example after drag/drop of a docx file onto the form:



enter image description here



Edit: if you wish to provide some self-generated array of bytes, it is as simple as this:



byte byteArr = {0xaa, 0x3f, 0x4b};
hexBox.ByteProvider = new DynamicByteProvider(byteArr);


Edit 2: To save the contents of the hex box:
I am sure there is some better way to do this. What I found for now is to simply add a handler in the hex box definition block:



hexBox.CopiedHex += HexBox_CopiedHex;


Have some kind of "save" button with such a code:



private void button1_Click(object sender, EventArgs e)
{
hexBox.SelectAll();
hexBox.CopyHex();
hexBox.SelectionLength = 0;
}


And such an event handler:



private void HexBox_CopiedHex(object sender, EventArgs e)
{
var hex = Clipboard.GetText();
var hexHex = hex.Split(' ');
var hexArr = new byte[hexHex.Length];
for (var i = 0; i < hexHex.Length; i++)
{
hexArr[i] = byte.Parse(hexHex[i], NumberStyles.AllowHexSpecifier);
}
File.WriteAllBytes(@"C:0_Worktest.bin", hexArr);
}





share|improve this answer


























  • Thx for your anser, but what it actually does?

    – James_BK
    Nov 22 '18 at 4:30











  • i need to be able to put bytes array in the hexbox, not only from openning a bin file

    – James_BK
    Nov 22 '18 at 4:31











  • Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

    – LocEngineer
    Nov 22 '18 at 9:42













  • I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

    – LocEngineer
    Nov 22 '18 at 15:53











  • Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

    – James_BK
    Nov 23 '18 at 6:27





















0














To show byte in hexbox use new DynamicByteProvider(byte



To get modified byte from hexbox
use DynamicByteProvider.Bytes.ToArray()






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410380%2fhow-to-create-hex-editor-inside-of-winforms-app%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've tinkered a bit with this. What I did was



    1) put an invisible picture box as control placeholder on the form, here named ph1



    2) configure the HexBox control in Form_Load()



    private HexBox hexBox;

    private void Form1_Load(object sender, EventArgs e)
    {
    hexBox = new HexBox()
    {
    Top = ph1.Top,
    Width = ph1.Width,
    Height = ph1.Height,
    Left = ph1.Left,
    Visible = true,
    UseFixedBytesPerLine = true,
    BytesPerLine = 16,
    ColumnInfoVisible = true,
    LineInfoVisible = true,
    StringViewVisible = true,
    VScrollBarVisible = true
    };
    this.Controls.Add(hexBox);
    this.Controls.Remove(ph1);
    }


    3) Load the actual file in DragDrop event



    var filePath = ((string)(e.Data.GetData(DataFormats.FileDrop)))[0];
    var source = new FileByteProvider(filePath);
    hexBox.ByteProvider = source;
    hexBox.Refresh();


    Example after drag/drop of a docx file onto the form:



    enter image description here



    Edit: if you wish to provide some self-generated array of bytes, it is as simple as this:



    byte byteArr = {0xaa, 0x3f, 0x4b};
    hexBox.ByteProvider = new DynamicByteProvider(byteArr);


    Edit 2: To save the contents of the hex box:
    I am sure there is some better way to do this. What I found for now is to simply add a handler in the hex box definition block:



    hexBox.CopiedHex += HexBox_CopiedHex;


    Have some kind of "save" button with such a code:



    private void button1_Click(object sender, EventArgs e)
    {
    hexBox.SelectAll();
    hexBox.CopyHex();
    hexBox.SelectionLength = 0;
    }


    And such an event handler:



    private void HexBox_CopiedHex(object sender, EventArgs e)
    {
    var hex = Clipboard.GetText();
    var hexHex = hex.Split(' ');
    var hexArr = new byte[hexHex.Length];
    for (var i = 0; i < hexHex.Length; i++)
    {
    hexArr[i] = byte.Parse(hexHex[i], NumberStyles.AllowHexSpecifier);
    }
    File.WriteAllBytes(@"C:0_Worktest.bin", hexArr);
    }





    share|improve this answer


























    • Thx for your anser, but what it actually does?

      – James_BK
      Nov 22 '18 at 4:30











    • i need to be able to put bytes array in the hexbox, not only from openning a bin file

      – James_BK
      Nov 22 '18 at 4:31











    • Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

      – LocEngineer
      Nov 22 '18 at 9:42













    • I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

      – LocEngineer
      Nov 22 '18 at 15:53











    • Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

      – James_BK
      Nov 23 '18 at 6:27


















    0














    I've tinkered a bit with this. What I did was



    1) put an invisible picture box as control placeholder on the form, here named ph1



    2) configure the HexBox control in Form_Load()



    private HexBox hexBox;

    private void Form1_Load(object sender, EventArgs e)
    {
    hexBox = new HexBox()
    {
    Top = ph1.Top,
    Width = ph1.Width,
    Height = ph1.Height,
    Left = ph1.Left,
    Visible = true,
    UseFixedBytesPerLine = true,
    BytesPerLine = 16,
    ColumnInfoVisible = true,
    LineInfoVisible = true,
    StringViewVisible = true,
    VScrollBarVisible = true
    };
    this.Controls.Add(hexBox);
    this.Controls.Remove(ph1);
    }


    3) Load the actual file in DragDrop event



    var filePath = ((string)(e.Data.GetData(DataFormats.FileDrop)))[0];
    var source = new FileByteProvider(filePath);
    hexBox.ByteProvider = source;
    hexBox.Refresh();


    Example after drag/drop of a docx file onto the form:



    enter image description here



    Edit: if you wish to provide some self-generated array of bytes, it is as simple as this:



    byte byteArr = {0xaa, 0x3f, 0x4b};
    hexBox.ByteProvider = new DynamicByteProvider(byteArr);


    Edit 2: To save the contents of the hex box:
    I am sure there is some better way to do this. What I found for now is to simply add a handler in the hex box definition block:



    hexBox.CopiedHex += HexBox_CopiedHex;


    Have some kind of "save" button with such a code:



    private void button1_Click(object sender, EventArgs e)
    {
    hexBox.SelectAll();
    hexBox.CopyHex();
    hexBox.SelectionLength = 0;
    }


    And such an event handler:



    private void HexBox_CopiedHex(object sender, EventArgs e)
    {
    var hex = Clipboard.GetText();
    var hexHex = hex.Split(' ');
    var hexArr = new byte[hexHex.Length];
    for (var i = 0; i < hexHex.Length; i++)
    {
    hexArr[i] = byte.Parse(hexHex[i], NumberStyles.AllowHexSpecifier);
    }
    File.WriteAllBytes(@"C:0_Worktest.bin", hexArr);
    }





    share|improve this answer


























    • Thx for your anser, but what it actually does?

      – James_BK
      Nov 22 '18 at 4:30











    • i need to be able to put bytes array in the hexbox, not only from openning a bin file

      – James_BK
      Nov 22 '18 at 4:31











    • Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

      – LocEngineer
      Nov 22 '18 at 9:42













    • I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

      – LocEngineer
      Nov 22 '18 at 15:53











    • Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

      – James_BK
      Nov 23 '18 at 6:27
















    0












    0








    0







    I've tinkered a bit with this. What I did was



    1) put an invisible picture box as control placeholder on the form, here named ph1



    2) configure the HexBox control in Form_Load()



    private HexBox hexBox;

    private void Form1_Load(object sender, EventArgs e)
    {
    hexBox = new HexBox()
    {
    Top = ph1.Top,
    Width = ph1.Width,
    Height = ph1.Height,
    Left = ph1.Left,
    Visible = true,
    UseFixedBytesPerLine = true,
    BytesPerLine = 16,
    ColumnInfoVisible = true,
    LineInfoVisible = true,
    StringViewVisible = true,
    VScrollBarVisible = true
    };
    this.Controls.Add(hexBox);
    this.Controls.Remove(ph1);
    }


    3) Load the actual file in DragDrop event



    var filePath = ((string)(e.Data.GetData(DataFormats.FileDrop)))[0];
    var source = new FileByteProvider(filePath);
    hexBox.ByteProvider = source;
    hexBox.Refresh();


    Example after drag/drop of a docx file onto the form:



    enter image description here



    Edit: if you wish to provide some self-generated array of bytes, it is as simple as this:



    byte byteArr = {0xaa, 0x3f, 0x4b};
    hexBox.ByteProvider = new DynamicByteProvider(byteArr);


    Edit 2: To save the contents of the hex box:
    I am sure there is some better way to do this. What I found for now is to simply add a handler in the hex box definition block:



    hexBox.CopiedHex += HexBox_CopiedHex;


    Have some kind of "save" button with such a code:



    private void button1_Click(object sender, EventArgs e)
    {
    hexBox.SelectAll();
    hexBox.CopyHex();
    hexBox.SelectionLength = 0;
    }


    And such an event handler:



    private void HexBox_CopiedHex(object sender, EventArgs e)
    {
    var hex = Clipboard.GetText();
    var hexHex = hex.Split(' ');
    var hexArr = new byte[hexHex.Length];
    for (var i = 0; i < hexHex.Length; i++)
    {
    hexArr[i] = byte.Parse(hexHex[i], NumberStyles.AllowHexSpecifier);
    }
    File.WriteAllBytes(@"C:0_Worktest.bin", hexArr);
    }





    share|improve this answer















    I've tinkered a bit with this. What I did was



    1) put an invisible picture box as control placeholder on the form, here named ph1



    2) configure the HexBox control in Form_Load()



    private HexBox hexBox;

    private void Form1_Load(object sender, EventArgs e)
    {
    hexBox = new HexBox()
    {
    Top = ph1.Top,
    Width = ph1.Width,
    Height = ph1.Height,
    Left = ph1.Left,
    Visible = true,
    UseFixedBytesPerLine = true,
    BytesPerLine = 16,
    ColumnInfoVisible = true,
    LineInfoVisible = true,
    StringViewVisible = true,
    VScrollBarVisible = true
    };
    this.Controls.Add(hexBox);
    this.Controls.Remove(ph1);
    }


    3) Load the actual file in DragDrop event



    var filePath = ((string)(e.Data.GetData(DataFormats.FileDrop)))[0];
    var source = new FileByteProvider(filePath);
    hexBox.ByteProvider = source;
    hexBox.Refresh();


    Example after drag/drop of a docx file onto the form:



    enter image description here



    Edit: if you wish to provide some self-generated array of bytes, it is as simple as this:



    byte byteArr = {0xaa, 0x3f, 0x4b};
    hexBox.ByteProvider = new DynamicByteProvider(byteArr);


    Edit 2: To save the contents of the hex box:
    I am sure there is some better way to do this. What I found for now is to simply add a handler in the hex box definition block:



    hexBox.CopiedHex += HexBox_CopiedHex;


    Have some kind of "save" button with such a code:



    private void button1_Click(object sender, EventArgs e)
    {
    hexBox.SelectAll();
    hexBox.CopyHex();
    hexBox.SelectionLength = 0;
    }


    And such an event handler:



    private void HexBox_CopiedHex(object sender, EventArgs e)
    {
    var hex = Clipboard.GetText();
    var hexHex = hex.Split(' ');
    var hexArr = new byte[hexHex.Length];
    for (var i = 0; i < hexHex.Length; i++)
    {
    hexArr[i] = byte.Parse(hexHex[i], NumberStyles.AllowHexSpecifier);
    }
    File.WriteAllBytes(@"C:0_Worktest.bin", hexArr);
    }






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 26 '18 at 11:01

























    answered Nov 21 '18 at 15:07









    LocEngineerLocEngineer

    2,2271922




    2,2271922













    • Thx for your anser, but what it actually does?

      – James_BK
      Nov 22 '18 at 4:30











    • i need to be able to put bytes array in the hexbox, not only from openning a bin file

      – James_BK
      Nov 22 '18 at 4:31











    • Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

      – LocEngineer
      Nov 22 '18 at 9:42













    • I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

      – LocEngineer
      Nov 22 '18 at 15:53











    • Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

      – James_BK
      Nov 23 '18 at 6:27





















    • Thx for your anser, but what it actually does?

      – James_BK
      Nov 22 '18 at 4:30











    • i need to be able to put bytes array in the hexbox, not only from openning a bin file

      – James_BK
      Nov 22 '18 at 4:31











    • Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

      – LocEngineer
      Nov 22 '18 at 9:42













    • I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

      – LocEngineer
      Nov 22 '18 at 15:53











    • Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

      – James_BK
      Nov 23 '18 at 6:27



















    Thx for your anser, but what it actually does?

    – James_BK
    Nov 22 '18 at 4:30





    Thx for your anser, but what it actually does?

    – James_BK
    Nov 22 '18 at 4:30













    i need to be able to put bytes array in the hexbox, not only from openning a bin file

    – James_BK
    Nov 22 '18 at 4:31





    i need to be able to put bytes array in the hexbox, not only from openning a bin file

    – James_BK
    Nov 22 '18 at 4:31













    Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

    – LocEngineer
    Nov 22 '18 at 9:42







    Did you try it? That's exactly what this does! I'll put a screenshot in my answer. You need to show a little more effort.

    – LocEngineer
    Nov 22 '18 at 9:42















    I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

    – LocEngineer
    Nov 22 '18 at 15:53





    I think now I know what you mean. I have adjusted my answer accordingly, see the edit.

    – LocEngineer
    Nov 22 '18 at 15:53













    Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

    – James_BK
    Nov 23 '18 at 6:27







    Also, how can i save file after i provided some self-generated array of bytes? Seems like it can save file only which was opened before. But how to create .bin file and write values on it from hexbox

    – James_BK
    Nov 23 '18 at 6:27















    0














    To show byte in hexbox use new DynamicByteProvider(byte



    To get modified byte from hexbox
    use DynamicByteProvider.Bytes.ToArray()






    share|improve this answer






























      0














      To show byte in hexbox use new DynamicByteProvider(byte



      To get modified byte from hexbox
      use DynamicByteProvider.Bytes.ToArray()






      share|improve this answer




























        0












        0








        0







        To show byte in hexbox use new DynamicByteProvider(byte



        To get modified byte from hexbox
        use DynamicByteProvider.Bytes.ToArray()






        share|improve this answer















        To show byte in hexbox use new DynamicByteProvider(byte



        To get modified byte from hexbox
        use DynamicByteProvider.Bytes.ToArray()







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 31 at 15:40









        dns_nx

        1,40811729




        1,40811729










        answered Jan 31 at 14:21









        bernhardebernharde

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410380%2fhow-to-create-hex-editor-inside-of-winforms-app%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith