NASM - The Netwide Assembler
NASM Forum => Example Code => Topic started by: greco558 on July 12, 2016, 12:14:20 AM
-
Hi All,
I recently changed a HEX dump program to give you the ability to edit the file at the byte level by inputting either HEX or ASCII byte.
You can also enter an ASCII string. It includes 1 main nasm file with several supporting files to Assembly into an executable.
It is written for Linux 32bit os. There is a included README and makefile.
Hope you find it helpful.
Any comments or suggestions are welcome.
If anyone knows how I can make it so you don't have to press ENTER after selecting an action it would be much appreciated.
Best Regards
John
-
Hi John,
Beautiful work! Thank you!
I've only started to look at it, but one thing caught my eye - in your openfile routine, "0777" is decimal. Unlike the C language, Nasm does not take a leading '0' to mean octal. This probably isn't a problem, but it may not be what you really want to do.
I do have code that will allow you to input a single character without having to hit "enter". I'm not terribly happy with it, but it "seems to work". I'll just paste it in here "as is". It'll need some work, but may give you something to start with. I don't know when/if I'll get to improving it any....
; misc. equates
%define NL 10
%define STDIN 0
%define STDOUT 1
; sys_calls
%define SYS_EXIT 1
%define SYS_READ 3
%define SYS_WRITE 4
%define SYS_IOCTL 54
;-----------------------------
; ioctl subfunctions
%define TCGETS 0x5401 ; tty-"magic"
%define TCSETS 0x5402
; flags for 'em
%define ICANON 2 ;.Do erase and kill processing.
%define ECHO 8 ;.Enable echo.
struc termios
alignb 4
.c_iflag: resd 1 ; input mode flags
.c_oflag: resd 1 ; output mode flags
.c_cflag: resd 1 ; control mode flags
.c_lflag: resd 1 ; local mode flags
.c_line: resb 1 ; line discipline
.c_cc: resb 19 ; control characters
endstruc
;---------------------------------
getc:
push ebp
mov ebp, esp
sub esp, termios_size ; make a place for current kbd mode
push edx
push ecx
push ebx
mov eax, SYS_IOCTL ; get current mode
mov ebx, STDIN
mov ecx, TCGETS
lea edx, [ebp - termios_size]
int 80h
; monkey with it
and dword [ebp - termios_size + termios.c_lflag], ~(ICANON | ECHO)
mov eax, SYS_IOCTL
mov ebx, STDIN
mov ecx, TCSETS
lea edx, [ebp - termios_size]
int 80h
xor eax, eax
push eax ; this is the buffer to read into
mov eax, SYS_READ
mov ebx, STDIN
mov ecx, esp ; character goes on the stack
mov edx, 1 ; just one
int 80h ; do it
; restore normal kbd mode
or dword [ebp - termios_size + termios.c_lflag], ICANON | ECHO
mov eax, SYS_IOCTL
mov ebx, STDIN
mov ecx, TCSETS
lea edx, [ebp - termios_size]
int 80h
pop eax ; get character into al
pop ebx ; restore caller's regs
pop ecx
pop edx
mov esp, ebp ; leave
pop ebp
ret
;-------------------------
Later,
Frank
-
Frank,
Thank you for your input, this is the first all Assembly code project I have tried In NASM.
I usually just code small procedures in NASM that I call from my C programs.
I checked on that openfile routine with the 0777 and yes I wanted it to be Octal so I went
ahead and changed it to 0777o, thank you for that catch.
What I don't understand is that it worked either way as a decimal or octal when opening
read only files, they both allowed me to edit the file and write changes.
Also thank you for the code for single key hit I will have to try and incorporate it into my
byte editor.
Best Regards
John
-
Found some bugs when editing the end of a sector you could end up with a buffer overflow.
Also after editing in either ASCII/HEX, or ASCII String the phantom cursor would disappear.
Both have been fixed.
Still need to add Frank's keyboard code in.
BR
John
-
Hi All,
I have incorporated Frank Kotler's keyboard procedure getc into my editbin program,
which has eliminated the need to press RETURN key for movement.
Now when you press keys(h,j,k,l,n,p,r,R,w) you get an immediate response.
Here is updated version including new README and MAKE file.
Thanks again Frank!
The program is getting to where I would like it to be, but I still have some changes that I would like to make, so I will post any updates I make here.
Best Regards
John
-
Hi All,
Updated editbin.asm to show Binary of HEX/ASCII Byte highlighted.
Best Regards
John
-
Hi All,
Cleaned up some code and removed Procedure that showed decimal values down the
left side of screen to a Procedure to show Hex values to match the Hex values across
top of screen.
Procedures added and removed
Removed: PrintInt
Added: DwordToHex
-
Updated to include u-key for undo changes.
Also changed movement keys hjkl to arrow keys from feedback of users.
You can now undo changes you made in current sector by navigating to the Byte you changed
which is highlited in Red and pressing u key. When you write changes to file by pressing w key
the Red Bytes will turn White. You can still undo the changes as long as you don't change
sectors by pressing the n or p keys. Just navigate to the Bytes highlited in White and press u key
to undo previous written changes, make sure to press w key to write the undo changes to file if you previously wrote changes to file and you want them undone.
Best Regards,
John
-
Small change to undo just in the way bytes are Highlighted to show they have not been saved.
see below.
(u)key will undo Byte changes highlited in RED or WHITE as long as you stay
in that sector if you move to previous or next sector undo is lost.
The changes in RED have NOT been written to file yet and can be undone
by navigating to RED Byte and pressing (u key).
The Bytes in WHITE have been written to file but you can still
undo them by navigating to byte in WHITE and pressing(u key)
which will turn byte to Red again indicating undo changes have not been
saved to file. Press (w key) to save Red undo changes to file.
Best Regards
John
-
Updated Menu display, EOF message and Prompt for Byte or Ascii string entry.
Best Regards
John
-
Hi All,
I recently changed a HEX dump program to give you the ability to edit the file at the byte level by inputting either HEX or ASCII byte.
You can also enter an ASCII string. It includes 1 main nasm file with several supporting files to Assembly into an executable.
It is written for Linux 32bit os. There is a included README and makefile.
Hope you find it helpful.
Any comments or suggestions are welcome.
If anyone knows how I can make it so you don't have to press ENTER after selecting an action it would be much appreciated.
Best Regards
John
How do I use the makefile ?
-
Hi fixit,
Just extract files to your directory of choice go to terminal change to that directory and at the prompt type make then press enter it will build executable. The make command will use the makefile to build binary.
Best Regards
John
-
I have been working on the windows version and I noticed some redundant code in DumpBytes procedure moved it to new Procedure HighLiteBytes.
Also fixed bug with mark bytes which left prompt on screen and in wrong location.
Best Regards
John
-
Thanks a lot.
-
Hi all,
Just updated README file to explain program a little more and added some more comments
thought out code.
Also I just finished a Windows version editbyte.exe which is posted on Masm32 Forum under greco558, it is written in Masm32 Assembler.
Best Regards
John
-
Made Changes to DwordToHex procedure to allow a little more flexibility when calling.
It now receives where to store conversion in edi and what to covert in eax.
I also change the location tracker which shows byte you are currently on in the top left of display to Green, it will now turn red when you navigate Phantom cursor to last byte in file or beyond.
I am working on undo of changed sectors even after you write changes to file and close program.
Best Regards
John
-
Hi All,
Here is last update for a while, added g=goto key, so if you have a big file and you want
to goto sector 2,000, you do not have to press n=next sector key 2,000 times.
You press g key and enter sector you want to jump to.
Program was getting long broke it up into smaller files of related procedures.
Also updated masm32 assembly Windows version on Masm32 forum.
Fixed bug in sector jump routine StrToDword procedure.
Changed StrToDword Procedure to find end of string passed to it so all you do
is pass it string in ESI
Best Regards
John
-
Updated program added Search Mode to search file for Hex Word or Dword entered by user.
See README file for use.
Best Regards
John
-
Just a quick update to search mode you can search for Byte, Word or Dword.
Changed prompt to read Enter BYTE/WORD/DWORD >
Regards
John
-
Updated byte Editor. Changed mark byte to remain from sector to sector highlighting the Hex
byte you entered until you hit c key to clear mark or m key and enter new hex byte to highlight.
Another quick update for anyone interested, added decimal value of byte in lower right of screen
above the binary value.
All source code files & makefile included.
BR
John
-
Updated to check for Terminal screen size on startup to make sure Terminal is set to a minimum
of 80x25 so Byte editor displays properly.
Used TIOCGWINSZ.
BR
John
-
Wow John!
Thats really a great piece of software, what you have created here! Unfortunately, currently I can not help in any way to improve it but I will take a close look at it to see how things work. Even how the binaries it self look, hehe :)
Really incredible work!
Thanks a lot =)
-
0xDEADBEEF,
Thanks for the kind words, I started as a project to improve my assembly language programming.
It started out very basic as a simple hex dump program and I slowly add features.
Best Regards,
John
-
Hi All,
Fixed Bug in MarkByte that would not show Phantom Cursor when on a Marked byte.
Also added Unicode box shapes for a cleaner display.
See update.log in download for bug fix and changes.
05/08/2-2017 changed DwordToHex procedure to be more flexible and only convert and
not print conversion.
Also fixed small Bug when phantom cursor is on byte beyond EOF top left hex byte numbers
should turn red but the Unicode box characters also turned red fixed so only hex numbers turn red.
Best Regards
John