PDA

View Full Version : بوت سکتور و اسمبلی برای ویندوز



Developer Programmer
جمعه 05 دی 1382, 12:11 عصر
سلام
دو سوال داشتم

کسی از عزیزان تا حال با TASM برنامه بوت سکتور نوشته اند ؟ اگه اره بیزحمت سورس اون و نحوه کامپایل اون رو بطور کامل توضیح بدن

Hidarneh
جمعه 05 دی 1382, 18:26 عصر
اولا منظورت از برنامه بوت سکتور چیه؟ یعنی چی کار می خوای بکنی ؟
دوما تا اونجایی که سوات من قد می ده ( و تا اونجایی که من با tasm ) کار کرده تحت داس هستش یعنی اون نسخه هایی که من کار می کردم وقفه های ویندوزی رو نمی شناخت .

Developer Programmer
جمعه 05 دی 1382, 18:31 عصر
مفهوم بوت سکتور کاملا واضحه یه برنامه که بخواد با اون کار کنه حالا هر کاری ( من یکی نوشتم اما کامپایل نمی شه چون به آدرس صفر حافظه اشاره می کنه )
tasm ربطی به داس یا ویندوز نداره برنامه اسمبلی رو کامپایل می کنه

Hidarneh
جمعه 05 دی 1382, 19:22 عصر
اولا چه ربطی به حافظه صفر داره ؟ تحت داس با int 13h می تونی به راحتی بوت سکتور و یا هر جای دیگه رو بخونی و فرقشون هم همینجا معلوم می شه در تحت ویندوز اگه سعی در اجرای int 13h بکنی برنامه ات با یه پیغام خطای خوشگل مبنی بر انجام کار غیر مجاز بسته می شه .

Best Programmer
جمعه 05 دی 1382, 23:16 عصر
;================================================= ======================
; HDBOOT version 1.0
; (c) Computer Magazine þ BlackMedia 41 þ
;-----------------------------------------------------------------------
; This program alters the boot record on a floppy disk so that it loads
; the primary boot record from your first physical hard disk (usually
; C:). If you then boot your PC with the altered floppy in drive A:,
; it will boot from the HD, bypassing that "Non-System disk" message.
; Reformat or SYSing the floppy restores its original boot record.
;
; Syntax: HDBOOT a:
;
; where a: must be a floppy drive
;-----------------------------------------------------------------------
; This program is designed to be assemled with TASM, OPTASM, or
; MASM 5.x. Create using the following commands:
;
; MASM HDBOOT;
; LINK HDBOOT;
; EXE2BIN HDBOOT.EXE HDBOOT.COM
; DEL HDBOOT.OBJ
; DEL HDBOOT.EXE
;-----------------------------------------------------------------------
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
ORG 100H ;COM file format

ENTPT: JMP MAIN

;================================================= ======================
; Program data.
;-----------------------------------------------------------------------
COPYRIGHT$ DB "HDBOOT 1.0 (c)First Published in"
DB " BlackMedia 41 þ Computer Magazine"
CRLF$ DB 13,10,"$"

USAGE$ DB "Usage: HDBOOT a:$"
INVDRIVE$ DB "Drive is invalid$"
DRIVEERR$ DB "Can't access drive$"
NOTFLOPPY$ DB "Drive is not a floppy$"
RDERR$ DB "Read error$"
WRERR$ DB "Write error$"
MEMERR$ DB "Not Enough Memory$"
SUCCESS$ DB "Success!$"

TARGET DB 0 ;Destination floppy

;-----------------------------------------------------------------------
; This is the new bootstrap code to boot from the hard disk.
;-----------------------------------------------------------------------
JMP_TARGET LABEL NEAR
BOOTSTRAP LABEL BYTE

CLI ;Disable interrupts
MOV BX,7C00H ;Load code here
SUB AX,AX ;AX=0

MOV SS,AX ;Set stack to
MOV SP,BX ; 0:7C00h

MOV ES,AX ;Dest is ES:BX

MOV AX,13CDH ;Int 13 instruction
PUSH AX ;Below our code

MOV AX,201H ;Read one sector
MOV CX,0001H ;Cyl 0, SECT 1
MOV DX,0080H ;head 0, drive 80h

DB 0EAH ;JMP to INT 13
DW 7BFEH,0 ; instruction

BOOT_LEN EQU $-BOOTSTRAP

;================================================= ======================
; MAIN procedure
;-----------------------------------------------------------------------
MAIN PROC NEAR
ASSUME CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG

;-----------------------------------------------------------------------
; Initialize and display the programm title.
;-----------------------------------------------------------------------
CLD ;String moves forward

MOV CX,AX ;Save drive status

MOV AH,9 ;Display string fn
MOV DX,OFFSET COPYRIGHT$ ; located here
INT 21H ; Thru DOS
;-----------------------------------------------------------------------
; If the first command line argument contained an invalid drive spec,
; AL = FFh. If so, report an error to the user.
;-----------------------------------------------------------------------
CMP CL,0FFH ;Check for invalid drv
JNE M_2

MOV AH,9 ;Display string
MOV DX,OFFSET INVDRIVE$ ; in DX
INT 21H ; Thru DOS
;-----------------------------------------------------------------------
; Terminate the program.
;-----------------------------------------------------------------------
MOV DX,OFFSET CRLF$ ; located here
M_EXIT:
MOV AH,9 ;Display string
INT 21H ; Thru DOS

RET ;Exit
;-----------------------------------------------------------------------
; The first FCB will contain the parsed drive spec. (0=none, 1=A, etc).
; If none specified, display usage message.
;-----------------------------------------------------------------------
M_2:
MOV DX,OFFSET USAGE$ ;Usage message
MOV BL,DS:[5CH] ;Get specified drive
OR BL,BL ;0=none specified
JZ M_EXIT

MOV [TARGET],BL ;Target drive 1-BASED
;-----------------------------------------------------------------------
; The target disk must be a floppy and must be in the drive.
;-----------------------------------------------------------------------
MOV AX,4408H ;Ckeck removable media
; Drive in BL
INT 21H ; Thru DOS
M_3:
MOV DX,OFFSET DRIVEERR$ ;Assume drve error
JC M_EXIT

MOV DX,OFFSET NOTFLOPPY$ ;Assume not a floppy
OR AX,AX ;0=REMOVABLE
JNZ M_EXIT
;-----------------------------------------------------------------------
; Read the boot sector from the floppy.
;-----------------------------------------------------------------------
MOV AL,[TARGET] ;1-based
DEC AL ;0-based
MOV BX,OFFSET BOOTBUF ;Destination DS:BX
MOV CX,1 ;Read 1 sector
SUB DX,DX ;At sector 0
INT 25H ;Absolute disk read
POP DX ;Discard old flags

JNC M_4

MOV DX,OFFSET RDERR$
JMP M_EXIT
M_4:
CMP WORD PTR [BX+1FEH],0AA55H ;Verify signature
JNE M_EXIT
;-----------------------------------------------------------------------
; Determine the location of the current bootstrap code by examining the
; type and relative offset of the jump at the start of the code.
;-----------------------------------------------------------------------
MOV BX,OFFSET BOOTBUF

MOV CL,[BX] ;Get jump type
MOV AX,[BX+1] ;Get relative offset

ADD AX,3 ;Assume 3-byte jump

CMP CL,0E9H ;16-bit disp?
JE M_5

DEC AX ;2-byte jump
SUB AH,AH ;Clear top byte
M_5:
ADD AX,BX ;Add buffer start adr
MOV DI,AX ;Destination for move

MOV SI,OFFSET BOOTSTRAP ;Source
MOV CX,BOOT_LEN ;Length
REP MOVSB ;Move them
;-----------------------------------------------------------------------
; Write the code to perform the HD boot to the floppy.
;-----------------------------------------------------------------------
MOV AL,[TARGET] ;1-based
DEC AL ;0-based
MOV BX,OFFSET BOOTBUF ;Source is DX:BX
MOV CX,1 ;Write 1 sector
SUB DX,DX ;At sector 0
INT 26H ;Absolute disk write
POP DX ;Discard old flags

JNC M_6

MOV DX,OFFSET WRERR$
JMP M_EXIT
M_6:
MOV DX,OFFSET SUCCESS$
JMP M_EXIT

MAIN ENDP

;================================================= ======================
BOOTBUF EQU $

CSEG ENDS
END ENTPT

Developer Programmer
شنبه 06 دی 1382, 18:30 عصر
اولا چه ربطی به حافظه صفر داره ؟ تحت داس با int 13h می تونی به راحتی بوت سکتور و یا هر جای دیگه رو بخونی و فرقشون هم همینجا معلوم می شه در تحت ویندوز اگه سعی در اجرای int 13h بکنی برنامه ات با یه پیغام خطای خوشگل مبنی بر انجام کار غیر مجاز بسته می شه .

عزیز بابا ... منم می دونم
چطور بهت بگم علت پیغام ویندوز به خاطر استفاده از اینتراپت نیست به خاطر اونه که آدرس اینتراپت رو به برنامه خودت کشیدی
بدش هم من هرچی برنامه بوت سکتور می نویسم و دستور Tasm /x/t رو تایپ می کنم
می گه این فایل دارای دستور Org 0h می باشد و همانطوری که می دونی فایل کام از آدرس 100h شروع می شه
واسه همین ازش یه فایل exe می سازم بعد با exe2bin می خوام فایل کام کنم بازهم همون پیام ظاهر می شه در صورتیکه تمام برنامه نویسان در توضیحات مربوط به کامپایل از این دستورات استفاده می کنند
حالا نمی دونم چی کار کنم که درست کامپایل بشه

Developer Programmer
شنبه 06 دی 1382, 18:31 عصر
Best Programmer جان مرسی دستت درد نکنه نحوه کامپایلش رو هم می دونید؟

Best Programmer
یک شنبه 07 دی 1382, 00:40 صبح
دوست عزیز تو خوده سورسش هست.



; This program is designed to be assemled with TASM, OPTASM, or
; MASM 5.x. Create using the following commands:
;
; MASM HDBOOT;
; LINK HDBOOT;
; EXE2BIN HDBOOT.EXE HDBOOT.COM
; DEL HDBOOT.OBJ
; DEL HDBOOT.EXE