0

たとえば、00010101 のような命令があり、プログラムがアクセスするために RAM にある場合、OS 関数を使用せずにアセンブリ言語でその命令を実行するにはどうすればよいでしょうか? 私はIntelにFasmを使用しています。ありがとう。

編集:これは本当にくだらないコードであることはわかっています。まだ組み立てていません。多くのことが間違っていることはわかっていますが、これは学習目的であることを覚えておいてください。これは、バイナリ命令を含むファイルをロードして RAM に格納するコードの一部です。すごくヤバイことだと改めて思い知らされました。

loadkernel:
    mov dx, 1F7h
    in dx, bl
    bt bl, 6    ;this reads the sixth bit of bl and stores it in the carry flag(cf)

    cmp cf, 1   ;if bit 6 is one, then the hard drive is signaling that it is ready for the next operation
    jz loadkernel
    clc ;clear carry flag


beginload:
    mov eax, 300h
    mov ecx, eax    ;copy the starting point of the kernel in memory to ecx
    mov ebx, 0  ;clear
    mov edx, 0  ;clear

    mov bl, 1F4h
    out ebx, bl ;give the hard drive the low address of the location of the kernel
    mov bl, 1F5h
    out 0h, bl      ;give the hard drive the high address of the location of the kernel

    mov bl, 1F0h

    in edx, bl   ;read the hard drive
    mov [eax], edx   ;add kernel data to memory
    add eax, 1

    inc ebx     ;move the hard drive reading head thing forward

    mov ip, [eax]   ;mov the instruction pointer to memory, so that the computer excecutes the kernel

    cmp edx, 0AA55h
    jz beginload    ;if 0AA55h is not at the end, then read the next data of the kernel.
4

2 に答える 2

2

実行環境によっては、プログラムの (ほとんどの) OS の Execute-Disable セキュリティを無効にする必要がある場合があります。これは、脆弱なプログラムにコードを挿入するのがはるかに困難になるように配置されています。DOS や独自のカーネルなどの独立した環境で実行している場合、これは心配する必要はありません。

とにかく、あなたがしなければならないのはこれだけです:

mov ax,0x9090 //0x90 is opcode for NOP
mov [code],ax
code:
jmp  foo //this is a 2-byte opcode (so long as it does the "correct" behavior and generate a relative jmp

bar:
hlt //this will get executed "magically"

foo:
//won't get here
于 2012-08-28T16:11:53.747 に答える
1

命令が格納されているアドレスにジャンプするだけです。

于 2012-08-28T15:47:23.503 に答える