From 9863091620301c9fac2bd32db43dd312e12d22f0 Mon Sep 17 00:00:00 2001 From: Rickey Bowers Jr Date: Thu, 23 Mar 2023 17:31:23 -0600 Subject: [PATCH 1/5] add ASLR option for 32-bit and 64-bit (high entropy) --- packages/x86/include/format/format.inc | 32 +++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/x86/include/format/format.inc b/packages/x86/include/format/format.inc index ca76dbe..940a1c1 100644 --- a/packages/x86/include/format/format.inc +++ b/packages/x86/include/format/format.inc @@ -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 @@ -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 @@ -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 From 5b3dece4bdada78051d51448394417e581a50d08 Mon Sep 17 00:00:00 2001 From: Rickey Bowers Jr Date: Mon, 24 Apr 2023 05:16:47 -0600 Subject: [PATCH 2/5] Leaky `count` variable should be `local` #5. --- packages/x86/include/encoding/utf8.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/x86/include/encoding/utf8.inc b/packages/x86/include/encoding/utf8.inc index 5de01c2..1710db8 100644 --- a/packages/x86/include/encoding/utf8.inc +++ b/packages/x86/include/encoding/utf8.inc @@ -2,7 +2,7 @@ ; UTF-8 macro WCHAR arg - local current,__input,char,wide + local current,__input,char,wide,count if arg eqtype '' virtual at 0 __input:: From 5b11b4a0fc9685b750993f63b8516c7311e60c45 Mon Sep 17 00:00:00 2001 From: Rickey Bowers Jr Date: Tue, 9 May 2023 09:49:41 -0600 Subject: [PATCH 3/5] minor refactor to use new CALM feature --- packages/x86/include/cpu/x64.inc | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/x86/include/cpu/x64.inc b/packages/x86/include/cpu/x64.inc index fb35193..89c79f7 100644 --- a/packages/x86/include/cpu/x64.inc +++ b/packages/x86/include/cpu/x64.inc @@ -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 , 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 ,\ + 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 @@ -1911,27 +1917,21 @@ iterate , 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 , ret,0C2h, retn,0C2h, retf,0CAh From b93486fba1be41478b44b29f27bd7780d56e1c8b Mon Sep 17 00:00:00 2001 From: Rickey Bowers Jr Date: Sun, 30 Jul 2023 15:30:54 -0600 Subject: [PATCH 4/5] revert to upstream master (spaces) --- packages/x86/include/format/format.inc | 32 +++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/packages/x86/include/format/format.inc b/packages/x86/include/format/format.inc index 940a1c1..ca76dbe 100644 --- a/packages/x86/include/format/format.inc +++ b/packages/x86/include/format/format.inc @@ -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 @@ -44,9 +44,6 @@ 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 @@ -126,9 +123,6 @@ 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 From 611051612850de2cfea3550ddc513393284c2a23 Mon Sep 17 00:00:00 2001 From: Rickey Bowers Jr Date: Sun, 30 Jul 2023 21:18:02 -0600 Subject: [PATCH 5/5] re-add ASLR change inadvertly removed with prior commit --- packages/x86/include/format/format.inc | 32 +++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/x86/include/format/format.inc b/packages/x86/include/format/format.inc index ca76dbe..940a1c1 100644 --- a/packages/x86/include/format/format.inc +++ b/packages/x86/include/format/format.inc @@ -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 @@ -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 @@ -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