Skip to content

Commit

Permalink
Optimize the size of compiled WindowsEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Jan 19, 2024
1 parent 8c4b83d commit ce5cb96
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Source/WindowsEndpoints.asm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OPTION DOTNAME

.DATA
textSectionLength QWORD 0
textSectionReferenceCount QWORD 0
textSectionReferenceCount QWORD -1
textSectionLock DWORD 0

.CODE .text$a
Expand Down Expand Up @@ -38,8 +38,7 @@ makeTextSectionExecutable:
jz return
call lockTextSection
inc textSectionReferenceCount
cmp textSectionReferenceCount, 1
jne unlockTextSection
jnz unlockTextSection
mov r9, 20h ; PAGE_EXECUTE_READ
jmp changeTextSectionProtection

Expand All @@ -48,11 +47,13 @@ makeTextSectionNotExecutable:
jz return
call lockTextSection
dec textSectionReferenceCount
cmp textSectionReferenceCount, 0
jne unlockTextSection
jns unlockTextSection
mov r9, 4h ; PAGE_READWRITE
jmp changeTextSectionProtection

return:
ret

changeTextSectionProtection:
; expects protection constant (e.g. PAGE_EXECUTE_READ) in r9 register
mov r10, -1 ; first syscall parameter (handle to the current process)
Expand All @@ -71,8 +72,6 @@ changeTextSectionProtection:

unlockTextSection:
mov textSectionLock, 0

return:
ret

DllMain PROC
Expand Down

0 comments on commit ce5cb96

Please sign in to comment.