以下代码经过测试通过。
想隐藏本地磁盘和读写转移,可以查看上两篇博客。
/**
* bios int 13
*
* @author sun (9/22/2015)
*
* @param ix86 all register for int 13
*
* @return __asmcall void
*/
static __asmcall void int13_bios ( struct i386_all_regs *ix86 __unused) {
/**
* for now do nothing.
*/
//dbg_printf_p(1, "ax:%02x bx:%02x cx:%02x dx:%02x si:%02x\n"
// "cs:%02x ds:%02x es:%02x\n",
// ix86->regs.ax, ix86->regs.bx, ix86->regs.cx, ix86->regs.dx, ix86->regs.si,
// ix86->segs.cs, ix86->segs.ds, ix86->segs.es);
}
/**
* call bios int13
*
* @author sun (9/24/2015)
*
* @param ix86 all register for int 13
*
* @return int status
*/
static int int13_call_bios_int13 ( struct i386_all_regs *ix86 ) {
int status;
struct segoff es_bx, ds_si, es_di;
if ( ix86 == NULL ) {
DBG ( "Call bios INT13 arg err.\n" );
return -INT13_STATUS_INVALID;
}
es_bx.segment = ix86->segs.es;
es_bx.offset = ix86->regs.bx;
ds_si.segment = ix86->segs.ds;
ds_si.offset = ix86->regs.si;
es_di.segment = ix86->segs.es;
es_di.offset = ix86->regs.di;
__asm__ __volatile__ (
REAL_CODE (
"pushw %%bp\n\t"
"movw %%sp, %%bp\n\t"
"pushw %%ax\n\t"
"pushw %%dx\n\t"
/* call int13_bios */
"orb $0, %%al\n\t"
"stc\n\t"
"pushl %1\n\t"
"pushw %%cs\n\t"
"call prot_call\n\t"
/* set es:bx */
"pushl %%ebx\n\t"
"popw %%bx\n\t"
"popw %%es\n\t"
/* set ds:si */
"pushl %%esi\n\t"
"popw %%si\n\t"
"popw %%ds\n\t"
/* set es:di */
"pushl %%edi\n\t"
"popw %%di\n\t"
"popw %%es\n\t"
/* call bios int13 */
"pushfw\n\t"
"lcall *%%cs:int13_vector\n\t"
/* set flag register */
"pushfw\n\t"
"popw 6(%%bp)\n\t"
"movw %%bp, %%sp\n\t"
"popw %%bp\n\t"
)
: "=a" (status)
: "i" ( int13_bios ),
"a" (ix86->regs.ax), "b" (es_bx),
"c" (ix86->regs.cx), "d" (ix86->regs.dx),
"S" (ds_si), "D" (es_di));
if ( status < 0 ) {
DBG ( "Call bios INT13,%02x (%02x) failed with status "
"%02x\n", ix86->regs.ah, ix86->regs.dl, ix86->regs.ah );
dbg_printf_p (1, "Call bios INT13,%02x (%02x) failed with status "
"%02x\n", ix86->regs.ah, ix86->regs.dl, ix86->regs.ah );
return -INT13_STATUS_INVALID;
}
return INT13_STATUS_SUCCESS;
}
/**
* bios int13 8 function
*
* @author sun (9/24/2015)
*
* @param drive such as 0x81
* @param chs CHS
*
* @return int status
*/
static int int13_bios_get_parameters (unsigned int drive, struct partition_chs *chs)
{
/**
* this function has someting wrong with the return of the
* register, so need more test in future.
*/
struc