Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

C# How to create hex editor?

views
     
TSFlierMateI
post Sep 10 2022, 02:25 PM, updated 4y ago

New Member
*
Validating
12 posts

Joined: Sep 2022
I have my own hexdump file utility (Windows & Linux version both got). The problem is, I don't know yet how to create a hex editor.

The file reading and writing part is OK to me. The hex conversion is OK to me as well.

Just that I don't understand what is the form control to edit each of the hex values, and also that one to edit the ASCII string.

CODE
00000000    7F  45  4C  46  02  01  01  03  00  00  00  00  00  00  00  00      .ELF............
00000010    02  00  3E  00  01  00  00  00  B0  00  40  00  00  00  00  00      ..>.......@.....
00000020    40  00  00  00  00  00  00  00  00  00  00  00  00  00  00  00      @...............
00000030    00  00  00  00  40  00  38  00  02  00  40  00  00  00  00  00      ....@.8...@.....


I can't put text box there, because when user delete a character, its adjacent character isn't shifted.
And I am not sure whether to put multiple "form control" for each hex bytes or not.

Does anyone plan to write a hex editor in the future? Do you know how to do it? Not necessarily in C#.


flashang
post Sep 11 2022, 11:14 AM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


if existing tool is good enough to complete all the tasks,
no plan to create similar tools which is almost never used again.

p/s : just download some working hex editor if needed.

smile.gif



This post has been edited by flashang: Sep 11 2022, 11:15 AM
TSFlierMateI
post Sep 11 2022, 03:19 PM

New Member
*
Validating
12 posts

Joined: Sep 2022
QUOTE(flashang @ Sep 11 2022, 11:14 AM)
if existing tool is good enough to complete all the tasks,
no plan to create similar tools which is almost never used again.

p/s : just download some working hex editor if needed.

smile.gif
*
I am thinking of MaskedTextBox (an enhanced text box control) but it is still not perfect.

And I am not commercializing my hex editor, it is just fun learning how to do it.

I use Visual Studio built-in hex editor, by the way.

Thanks for your reply.
flashang
post Sep 11 2022, 05:01 PM

Casual
***
Junior Member
355 posts

Joined: Aug 2021


QUOTE(FlierMateI @ Sep 11 2022, 03:19 PM)
I am thinking of MaskedTextBox (an enhanced text box control) but it is still not perfect.

And I am not commercializing my hex editor, it is just fun learning how to do it.

I use Visual Studio built-in hex editor, by the way.

Thanks for your reply.
*
I try to analyse how hex editor work, and required "module" :

1. open file, and display 2 areas : hex / ascii (for non-display character, you may need to use some symbol).

2. allow user to edit (insert / overwrite) on ascii area, and update changes on hex area.
* this should be similar to normal text editor.
* this could be improved to accept special non-display character.

3. allow user to edit (insert / overwrite) on hex area, and update changes on ascii area.
* the challenge should be how to handle hex input.

4. save.

smile.gif


junyian
post Sep 11 2022, 06:06 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


What would be nice is a hex editor that can output something like this, that matches bytes against structures.

https://n0.lol/sk_buff.png (created by netspooky).

I've yet to find a hex editor that can display data like this. The image is just some internal notes when netspooky is analyzing some Linux kernel structures.

A big bonus would be something that can properly support ASN.1 PER.

This post has been edited by junyian: Sep 11 2022, 06:08 PM
TSFlierMateI
post Sep 11 2022, 08:37 PM

New Member
*
Validating
12 posts

Joined: Sep 2022
QUOTE(junyian @ Sep 11 2022, 06:06 PM)
What would be nice is a hex editor that can output something like this, that matches bytes against structures.

n0.lol/sk_buff.png (created by netspooky).

I've yet to find a hex editor that can display data like this. The image is just some internal notes when netspooky is analyzing some Linux kernel structures.

A big bonus would be something that can properly support ASN.1 PER.
*
Nice diagram.

For that kind of hex editor to work, maybe can first open a file in binary mode, and then let user to import a C header file, such as winnt.h (or in the diagram, skbuff.h), so that the hex editor can do the mapping. rclxm9.gif

I am totally new to "Abstract Syntax Notation One", according to Wikipedia, it is broadly used in telecommunication (your job industry laugh.gif ) and computer networking, such as cryptography (your hobby brows.gif ).


junyian
post Sep 11 2022, 10:02 PM

Casual
***
Junior Member
401 posts

Joined: Jan 2003


QUOTE(FlierMateI @ Sep 11 2022, 08:37 PM)
Nice diagram.

For that kind of hex editor to work, maybe can first open a file in binary mode, and then let user to import a C header file, such as winnt.h (or in the diagram, skbuff.h), so that the hex editor can do the mapping.  rclxm9.gif

I am totally new to "Abstract Syntax Notation One", according to Wikipedia, it is broadly used in telecommunication (your job industry  laugh.gif ) and computer networking, such as cryptography (your hobby  brows.gif ).
*
Or a self-created header file. It's useful when dealing with common file formats, like PE, ELF, PNG, etc., or custom ones.

Yup, ASN.1 is used in many industries smile.gif There are a few types of encodings. If I remember correctly, cryto typically uses BER. Telecommunications typically uses PER, which is a little bit painful.
ASN.1 is simply an encoding format though. There is the ASN.1 notation that defines how data is stored, a bit like C header files.
Here's a taste of how it looks like.

CODE

-- ASN1START
-- TAG-MIB-START
MIB ::=                             SEQUENCE {
   systemFrameNumber                   BIT STRING (SIZE (6)),
   subCarrierSpacingCommon             ENUMERATED {scs15or60, scs30or120},
   ssb-SubcarrierOffset                INTEGER (0..15),
   dmrs-TypeA-Position                 ENUMERATED {pos2, pos3},
   pdcch-ConfigSIB1                    PDCCH-ConfigSIB1,
   cellBarred                          ENUMERATED {barred, notBarred},
   intraFreqReselection                ENUMERATED {allowed, notAllowed},
   spare                               BIT STRING (SIZE (1))
}
-- TAG-MIB-STOP
-- ASN1STOP


 

Change to:
| Lo-Fi Version
0.0276sec    1.20    5 queries    GZIP Disabled
Time is now: 24th December 2025 - 05:03 PM