Author Topic: Byte Editor Project  (Read 5704 times)

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Byte Editor Project
« 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




Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2361
  • Country: us
Re: Byte Editor Project
« Reply #1 on: July 12, 2016, 07:25:33 PM »
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....

Code: [Select]

; 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


Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #2 on: July 13, 2016, 11:28:34 AM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #3 on: July 13, 2016, 08:00:22 PM »
 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 

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #4 on: July 14, 2016, 12:00:11 PM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project update
« Reply #5 on: July 18, 2016, 03:31:50 PM »
Hi All,

 Updated editbin.asm to show Binary of HEX/ASCII Byte highlighted.

Best Regards
John
« Last Edit: July 18, 2016, 07:53:18 PM by greco558 »

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #6 on: July 27, 2016, 06:59:26 PM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #7 on: August 02, 2016, 07:48:05 PM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #8 on: August 03, 2016, 06:51:30 PM »
    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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #9 on: August 04, 2016, 02:53:49 PM »
Updated Menu display, EOF message and Prompt for Byte or Ascii string entry.

Best Regards
John

Offline fixit

  • Jr. Member
  • *
  • Posts: 23
Re: Byte Editor Project
« Reply #10 on: August 05, 2016, 01:30:18 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

How do I use the makefile ?


Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #11 on: August 05, 2016, 11:06:17 AM »
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

Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #12 on: August 12, 2016, 01:06:12 AM »
 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

Offline fixit

  • Jr. Member
  • *
  • Posts: 23
Re: Byte Editor Project
« Reply #13 on: August 12, 2016, 01:33:32 AM »
Thanks a lot.


Offline greco558

  • Jr. Member
  • *
  • Posts: 32
Re: Byte Editor Project
« Reply #14 on: August 15, 2016, 02:19:05 PM »
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