Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ASLR option for 32-bit and 64-bit (high entropy) #14

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
34 changes: 17 additions & 17 deletions packages/x86/include/cpu/x64.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1898,11 +1898,17 @@ iterate reg, ax,cx,dx,bx,sp,bp,si,di,r8w,r9w,r10w,r11w,r12w,r13w,r14w,r15w, \
define x86.compact.reg? {reg}
end iterate

iterate <instr,handler,size>, push,push_instruction,0, pushw,push_instruction,2, pushd,push_instruction,4, pushq,push_instruction,8, \
pop,pop_instruction,0, popw,pop_instruction,2, popd,pop_instruction,4, popq,pop_instruction,8
iterate <instr, size, handler>,\
push, 0, push_instruction,\
pushw, 2, push_instruction,\
pushd, 4, push_instruction,\
pushq, 8, push_instruction,\
pop, 0, pop_instruction,\
popw, 2, pop_instruction,\
popd, 4, pop_instruction,\
popq, 8, pop_instruction

calminstruction instr? operand

local head, tail

match head tail, operand
Expand All @@ -1911,27 +1917,21 @@ iterate <instr,handler,size>, push,push_instruction,0, pushw,push_instruction,2,
jno plain
match {head}, head
jno plain
loop:
xcall x86.handler, (size),head
match head tail, tail
jno final
loop:
xcall x86.handler, (size), head
match head tail?, tail
jno done
transform head, x86.compact
jno error
match {head}, head
jyes loop
error:
error:
err 'only register operands allowed in compact syntax'
exit
final:
transform tail, x86.compact
jno error
match {operand}, tail
jno error
plain:
xcall x86.handler, (size),operand

plain:
xcall x86.handler, (size), operand
done:
end calminstruction

end iterate

iterate <instr,opcode>, ret,0C2h, retn,0C2h, retf,0CAh
Expand Down
32 changes: 19 additions & 13 deletions packages/x86/include/format/format.inc
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@

macro local_include? instr
local pos,chr,path
pos = lengthof __FILE__
while pos
chr = (__FILE__ shr (8*(pos-1))) and 0FFh
if chr = '/' | chr = '\'
break
end if
pos = pos - 1
end while
path = string __FILE__ and not ( (-1) shl (8*pos) )
macro instr file
include string path + file shl (8*lengthof path)
end macro
local pos,chr,path
pos = lengthof __FILE__
while pos
chr = (__FILE__ shr (8*(pos-1))) and 0FFh
if chr = '/' | chr = '\'
break
end if
pos = pos - 1
end while
path = string __FILE__ and not ( (-1) shl (8*pos) )
macro instr file
include string path + file shl (8*lengthof path)
end macro
end macro

local_include format?.include
Expand Down Expand Up @@ -44,6 +44,9 @@ macro format?.PE? settings
else match =NX? more, seq
PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_NX_COMPAT
redefine seq more
else match =ASLR? more, seq
PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
redefine seq more
else match =at? base =on? stub :, seq
PE.Settings.ImageBase = base
PE.Settings.Stub = stub
Expand Down Expand Up @@ -123,6 +126,9 @@ macro format?.PE64? settings
else match =NX? more, seq
PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_NX_COMPAT
redefine seq more
else match =ASLR? more, seq
PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE or IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
redefine seq more
else match =at? base =on? stub :, seq
PE.Settings.ImageBase = base
PE.Settings.Stub = stub
Expand Down