2012-08-28 4 views
0

예를 들어 00010101과 같은 명령어가 있고 프로그램에 액세스 할 수있는 RAM이 있으면 운영 체제를 사용하지 않고 어셈블리어로 해당 명령어를 excecute 할 수 있습니까? 기능? 나는 인텔을 위해 Fasm을 사용하고있다. 감사.어셈블리 언어로 기계 명령어를 excecute하는 방법 (인텔)

편집 : 나는 이것이 정말로 진절머리 나는 코드라는 것을 안다. 나는 아직 조립하지 않았고, 많은 부분이 잘못되었다는 것을 알고있다.하지만 이것은 학습 목적을위한 것이다. 이것은 바이너리 명령어로 파일을로드하고이를 램에 저장하는 코드의 일부입니다. 다시 한번 나는 이것이 매우 진절머리 나는 것을 안다.

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. 

답변

2

실행 환경에 따라 프로그램의 OS 실행 - 비활성화 보안을 (대부분의 경우) 비활성화해야 할 수 있습니다. 이것은 취약한 프로그램이 코드를 삽입하기가 훨씬 더 어려워 지도록 배치됩니다. 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 
+0

의 복제본입니다. 매우 도움이됩니다. 이것은 가장 빠른 방법일까요? –

+0

@kjmcgrinder 물론, 모든 코드를 한꺼번에 복사하여 한꺼번에 실행할 수는 있지만 원하는 작업에 따라 다릅니다. 또한 이와 같은 코드를 로딩하면 캐시 등이 무효화되어 성능이 저하되므로 메모리에 코드를 한 번 작성하고 필요하지 않은 경우 다시 쓰지 마십시오 – Earlz

1

명령이 저장된 주소로 간단하게 건너 뜁니다.

+0

심지어 램 주소 :

어쨌든, 당신이해야 할 모든이 무엇입니까? –

+0

어쩌면 코드를 제공 할 수 있습니다 ;-) 그리고 네, 심지어 주소. 당신은 그것을 계산해야하는데, 이것은 당신이 어디서 뛰어 내리는가에 달려 있습니다. 물론 주소는 .data 섹션이 아니라 .code 섹션에 있어야합니다. – akluth

+0

은 운영 시스템에서 작동하지 않습니다. 일단 모든 보호 기능을 무효화 한 다음에는 간단합니다. 지시 사항을 어딘가에 작성하고 간단하게 해당 항목으로 분기하십시오. 이것은 자체 수정 코드 질문 –

관련 문제