Making Minimalist Hex Editor in C on Linux

  Рет қаралды 10,264

Nir Lichtman

Nir Lichtman

6 ай бұрын

Making a minimalist hex editor in the C Programming Language.
The code is just for fun and not suitable for production :)
Link to the code:
github.com/nir9/welcome/tree/...

Пікірлер: 64
@nirlichtman
@nirlichtman 6 ай бұрын
Interesting points about the behavior of the program: - Reminding that the code is just for fun and not suitable for production and skips many error checking and other checks - If you open a file that is larger than 1024 bytes and save it will discard all the bytes after 1024 since it truncates the file when saving and saves the 1024 byte long buffer - You can use the p and e commands to go beyond the buffer limits and access memory outside of the buffer
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 ай бұрын
For production it would be better to ``` fseek(f, 0,SEEK_END); long lenght = ftell(f); char* buffer = calloc(lenght, sizeof(char)); fseek(f,0,SEEK_SET); ```
@d9h34nu0df
@d9h34nu0df 6 ай бұрын
Never stop posting videos, your videos are great inspirations and help me come up with ideas for cool projects to do, as well as already helping with a foundation of how logic works
@benhetland576
@benhetland576 6 ай бұрын
To be pedantic, the scanf on line 31 contains a memory overwrite bug. It should be given a (unsigned int*) but you give it an (unsigned char*).
@metamirasi
@metamirasi 6 ай бұрын
Very clear and concise purpose und workflow! I look forward to the next videos👋🙌
@N7TWL
@N7TWL 6 ай бұрын
Nicely done!
@jannatgaoshiqqalb3598
@jannatgaoshiqqalb3598 6 ай бұрын
What kind if books do you recommend us to have a solid understanding of C if we are beginner for C?
@nirlichtman
@nirlichtman 6 ай бұрын
I enjoyed reading the first edition of "Writing Solid Code" by Steve Maguire, it does require some prior knowledge in C and is a little old but generally has great tips. But the best way to learn in my opinion is to just practically write C for projects and work with the manuals as much as you can. (I recommend trying both Linux and Windows programming and learning to work with the man pages and Microsoft win32 api docs)
@AnalogDude_
@AnalogDude_ 6 ай бұрын
@@nirlichtman win32/64 is death, but doesn't know it yet.
@baranjan6969
@baranjan6969 7 күн бұрын
For absolute beginners K&R is also good one.
@silme9417
@silme9417 6 ай бұрын
suggestion : make a terminal text editor like nano or vim
@N7TWL
@N7TWL 6 ай бұрын
Have a look at Nir Lichtman's "Minimalist Text Editor" put up about 2 weeks ago.
@benhetland576
@benhetland576 6 ай бұрын
He's doing the terminal editor the true old style, the line editor! Like MS-DOS's edlin or Unix's ed. It will probably work with Curious Marc's teletype as its "user interface" too 😊
@juliovata9194
@juliovata9194 6 ай бұрын
What terminal do you use?
@greybrunix
@greybrunix 6 ай бұрын
looks like the windows terminal xD Unironically I think this is Windows with a DWM port for the layout
@thatonemailbox
@thatonemailbox 6 ай бұрын
​@@greybrunix What is a DWN port?
@nirlichtman
@nirlichtman 6 ай бұрын
@@thatonemailbox DWM is a minimalist tiling window manager for X Window System and is one of the projects of the Suckless group, I use a port of this for Windows called dwm-win32
@juliovata9194
@juliovata9194 6 ай бұрын
@@nirlichtmanOk I thought it looked like Windows Terminal lol
@naturebc
@naturebc 28 күн бұрын
Even if you’re writing code just for fun and not for production you should do it right.
@mattiasevstedt9340
@mattiasevstedt9340 6 ай бұрын
Since no one else has mentioned it, the reason for the reversed order on the numbers is because of intel based computers being "little endian".
@sanjaybalnad4180
@sanjaybalnad4180 6 ай бұрын
I am a high level programmer, usually i work with javascript and python. When i see mid and low level code my head gets burst. But i am really interested in c language 😂
@AnalogDude_
@AnalogDude_ 6 ай бұрын
pretty much every things is based on C/C++, java, perl, etc.
@rafaeldasilvasena9332
@rafaeldasilvasena9332 6 ай бұрын
In (buffer, 1, 1024, f), the "1" would be the size of what exactly?
@nirlichtman
@nirlichtman 6 ай бұрын
The size of each item to write/read, for example if you were writing an array of 4 byte integers you could specify the size to be 4 and the count to be the length of the array. In this video I am working with an array of 1 byte characters and so I decided to use 1 in the count - this also causes the function to return the number of bytes written/read.
@arta6183
@arta6183 6 ай бұрын
@@nirlichtman I know sizeof(char) is a bit redundant but maybe it could make it more readable, also what if a char's size is different on another platform?
@blacklistnr1
@blacklistnr1 6 ай бұрын
​@@arta6183Then you add a disclaimer that this editor does not support quantum computers :)) All computing devices have the notion of a byte(char). It only gets complicated when you want unicode support and run into wchar and multi byte sequences. or if you go above 1 byte(short, int, long) and run into endiannes(byte order) and platform-dependent sizes.
@rafaeldasilvasena9332
@rafaeldasilvasena9332 6 ай бұрын
​@@nirlichtmanoh, I get it now, thank you
@benhetland576
@benhetland576 6 ай бұрын
@@arta6183 sizeof(char) is always 1 -- by definition -- regardless of how many bits it contains. The sizeof operator reports the size in number of chars, not in octets or "bytes" that is commonly assumed.
@NullCyan
@NullCyan 6 ай бұрын
I have always wondered why argv is a pointer of a pointer, why, just why does that "magically" turn into an array of strings?
@ahmedsat4780
@ahmedsat4780 6 ай бұрын
actually array is just a pointer , so when you create a pointer off characters it's a string ( string is an array of characters ) pointer off string is array of strings
@Zeutomehr
@Zeutomehr 6 ай бұрын
arrays decay into pointers when passed as function arguments. within a function they were not declared in, they are identical. could you explain what exactly bugs you, maybe I can help you?
@NullCyan
@NullCyan 6 ай бұрын
@@Zeutomehr so an array is a pointer to a location of the memory with sequential data?
@StefanoTrevisani
@StefanoTrevisani 6 ай бұрын
well because, in the C point of view, an array is simply a contiguos block of memory, and a string is just an array with additional semantics for humans. A CPU does not atomically manipulate entire blocks of memory, but only small "words" (usually 8, 16, 32 or 64 bits): then, to represent a full block of memory, you can use two words, e.g. one representing the starting location of your block of memory (aka a pointer) and one representing its length. You can also use the single word (pointer) that represents its initial location, if you know that the block is ended by a special delimiter value which is not allowed to appear anywhere else inside the block. And in C, sequences (arrays) of characters (strings) are supposed to always terminate with the non-printable NUL character (i.e. the byte 0). Similarly, the NULL pointer (i.e. the word 0) is assumed to be an invalid memory address, hence it can be used to delimit an arrray of pointers. And this is what argv is: just a machine word telling you "hey, I am a pointer to a block of memory, and each word in the block of memory I point to is also a pointer, and the last of them is the NULL pointer. By the way, they are all pointers to blocks of memory where each byte in those blocks is a character, and the last character in them is the NUL character"
@StefanoTrevisani
@StefanoTrevisani 6 ай бұрын
If you wonder why argc exists, I think it is beacuse it is allowed for arguments other than the last one to be actually NULL pointers...
@gabriellevesque2185
@gabriellevesque2185 6 ай бұрын
How can you can call a file VIEWER an Editor?
@nirlichtman
@nirlichtman 6 ай бұрын
Since it is also an editor, it has an edit command ('e') that can modify the bytes
@NullCyan
@NullCyan 6 ай бұрын
also what if the file has more than 1024 characters?
@ahmedsat4780
@ahmedsat4780 6 ай бұрын
it will only deal with the first 1024 of the file and ignore the rest
@NullCyan
@NullCyan 6 ай бұрын
@@ahmedsat4780 oh ok thanks
@xblxckxpxny1005
@xblxckxpxny1005 6 ай бұрын
@@ahmedsat4780 That is not totally correct. Yes you can only modify the first 1024 chars, but what is more important os that when you save, the characters that come after the initial 1024 will be discarded. In simple terms: You lose all characters after 1024. Your file: 1024 * 'A' (1024 'A' in a row) and then 10 * 'b' for example So you have 1024 AAAA... and then 10 bbbbbbbbbb When you execute his program and save your hex-edits. you keep your edits in 1024 'A' region. BUT you lose all the 10 bbbbbbbbbb at the end! If I am wrong here please correct me :) But this should be the result, I also tested.
@nirlichtman
@nirlichtman 6 ай бұрын
@@xblxckxpxny1005That is correct, part of why the code is just for fun and not for production :)
@ahmedsat4780
@ahmedsat4780 6 ай бұрын
@@xblxckxpxny1005 i know 😊😊 but I might not be able to express it correctly because English is not my first language thanks for correcting me.
@richardgrosman5798
@richardgrosman5798 6 ай бұрын
Better than a bot 😋
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 ай бұрын
still waiting for minimalist https server 😅
@ZsomborBerki
@ZsomborBerki 6 ай бұрын
he already did that
@ItsCOMMANDer_
@ItsCOMMANDer_ 6 ай бұрын
no he didnt, he did an https CLIENT and an HTTP server.@@ZsomborBerki
@cozyfog
@cozyfog 6 ай бұрын
bro uses windows terminal on linux
@myrix_dev
@myrix_dev 6 ай бұрын
he uses wsl, windows sumsystem for linux and yes, there are tiling wms for windows
@pavlovidankmemeovi
@pavlovidankmemeovi 6 ай бұрын
He's using a windows port of dwm
@cozyfog
@cozyfog 6 ай бұрын
@@myrix_dev sound cool ig, I knew of the dwm port but lately its been everywhere idk
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 6 ай бұрын
I duplicated the video in Rust. Is anyone interested in?
@nirlichtman
@nirlichtman 6 ай бұрын
That could be interesting, I haven't programmed in Rust, but I can't find the video on your channel, did you upload it?
@silakanveli
@silakanveli 6 ай бұрын
Please just keep going with C. This content is fantastic a When it is minimalistic.
@kamertonaudiophileplayer847
@kamertonaudiophileplayer847 6 ай бұрын
@@nirlichtman I didn't do a video yet, just created a similar program.
Making Minimalist HTTPS Server in C on Linux
16:11
Nir Lichtman
Рет қаралды 16 М.
What's inside a .EXE File?
8:27
Inkbox
Рет қаралды 412 М.
1❤️#thankyou #shorts
00:21
あみか部
Рет қаралды 88 МЛН
🍕Пиццерия FNAF в реальной жизни #shorts
00:41
BCPL Program with loop and if statement.
1:35
redbear8174
Рет қаралды 2,7 М.
The Importance of Error Handling in C
8:18
Nir Lichtman
Рет қаралды 29 М.
Writing My Own Text Editor | Prime Reacts
16:10
ThePrimeTime
Рет қаралды 91 М.
Making Minimalist Snake Game in C on Linux
8:01
Nir Lichtman
Рет қаралды 28 М.
Best Programming Languages Tier List
33:02
Serif Sundown
Рет қаралды 10 М.
Creating a game in C and Raylib in 1 year - Making of Sidestep Legends
23:35
you need to stop using print debugging (do THIS instead)
7:07
Low Level Learning
Рет қаралды 409 М.
why do header files even exist?
10:53
Low Level Learning
Рет қаралды 367 М.
ThePrimeagen On Running Linux
9:40
Tech Over Tea
Рет қаралды 195 М.
Making Minimalist Web Server in C on Windows
10:52
Nir Lichtman
Рет қаралды 8 М.
i like you subscriber ♥️♥️ #trending #iphone #apple #iphonefold
0:14
WWDC 2024 Recap: Is Apple Intelligence Legit?
18:23
Marques Brownlee
Рет қаралды 6 МЛН
Will the battery emit smoke if it rotates rapidly?
0:11
Meaningful Cartoons 183
Рет қаралды 25 МЛН
#miniphone
0:16
Miniphone
Рет қаралды 3,4 МЛН
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 7 МЛН