diff --git a/sys/jit/kern_jit.pas b/sys/jit/kern_jit.pas index 3a99c434..fb3e1d84 100644 --- a/sys/jit/kern_jit.pas +++ b/sys/jit/kern_jit.pas @@ -193,6 +193,11 @@ begin end; end; +procedure trim_flow(var ctx:t_jit_context2); +begin + ctx.trim:=True; +end; + procedure op_push_rip(var ctx:t_jit_context2); var stack:TRegValue; @@ -364,7 +369,7 @@ begin // op_jmp_dispatcher(ctx); // - ctx.trim:=True; + trim_flow(ctx); end; procedure op_jmp(var ctx:t_jit_context2); @@ -433,7 +438,7 @@ begin op_jmp_dispatcher(ctx); end; // - ctx.trim:=True; + trim_flow(ctx); end; procedure op_jcc(var ctx:t_jit_context2); @@ -799,13 +804,13 @@ begin begin // ctx.builder.call_far(@jit_system_error); //TODO error dispatcher - ctx.trim:=True; + trim_flow(ctx); end; else begin ctx.builder.call_far(@jit_unknow_int); - ctx.trim:=True; + trim_flow(ctx); end; end; end; @@ -814,14 +819,14 @@ procedure op_ud2(var ctx:t_jit_context2); begin //exit proc? ctx.builder.call_far(@jit_exit_proc); //TODO exit dispatcher - ctx.trim:=True; + trim_flow(ctx); end; procedure op_iretq(var ctx:t_jit_context2); begin //exit proc? ctx.builder.call_far(@jit_exit_proc); //TODO exit dispatcher - ctx.trim:=True; + trim_flow(ctx); end; procedure op_hlt(var ctx:t_jit_context2); @@ -1080,6 +1085,12 @@ begin while True do begin + if not ctx.is_text_addr(QWORD(ptr)) then + begin + writeln('not excec:0x',HexStr(ptr)); + goto _invalid; + end; + if ((pmap_get_raw(QWORD(ptr)) and PAGE_PROT_EXECUTE)=0) then begin writeln('not excec:0x',HexStr(ptr)); diff --git a/sys/jit/kern_jit_asm.pas b/sys/jit/kern_jit_asm.pas index 07a84d7d..f7fd620b 100644 --- a/sys/jit/kern_jit_asm.pas +++ b/sys/jit/kern_jit_asm.pas @@ -79,31 +79,31 @@ function IS_JIT_FUNC(rip:qword):Boolean; const copyout_mov_size:array[TOperandSize] of Pointer=( - @copyout_mov_1 , - @copyout_mov_1 , - @copyout_mov_2 , - @copyout_mov_4 , - @copyout_mov_8 , - @copyout_mov_6 , - @copyout_mov_10, - @copyout_mov_16, - @copyout_mov_32, - @copyout_mov_64, - @copyout_mov_512 + @copyout_mov_1 , //os0 + @copyout_mov_1 , //os8 + @copyout_mov_2 , //os16 + @copyout_mov_4 , //os32 + @copyout_mov_8 , //os64 + @copyout_mov_6 , //os48 + @copyout_mov_10, //os80 + @copyout_mov_16, //os128 + @copyout_mov_32, //os256 + @copyout_mov_64, //os512 + @copyout_mov_512 //os4096 ); copyin_mov_size:array[TOperandSize] of Pointer=( - @copyin_mov_1 , - @copyin_mov_1 , - @copyin_mov_2 , - @copyin_mov_4 , - @copyin_mov_8 , - @copyin_mov_6 , - @copyin_mov_10, - @copyin_mov_16, - @copyin_mov_32, - @copyin_mov_64, - @copyin_mov_512 + @copyin_mov_1 , //os0 + @copyin_mov_1 , //os8 + @copyin_mov_2 , //os16 + @copyin_mov_4 , //os32 + @copyin_mov_8 , //os64 + @copyin_mov_6 , //os48 + @copyin_mov_10, //os80 + @copyin_mov_16, //os128 + @copyin_mov_32, //os256 + @copyin_mov_64, //os512 + @copyin_mov_512 //os4096 ); implementation @@ -275,7 +275,7 @@ label var addr:Pointer; size:QWORD; - data:array[0..31] of Byte; + data:array[0..511] of Byte; asm pushfq // @@ -392,7 +392,7 @@ label _simple, _exit; var - data:array[0..31] of Byte; + data:array[0..511] of Byte; asm pushfq //