Skip to content

Commit 0696c5c

Browse files
authored
shellcraft/*/freebsd: match linux in switching cs (#2232)
* shellcraft/*/freebsd: match linux in switching cs * shellcraft: note trashed registers in switching cs
1 parent ac855ab commit 0696c5c

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<%docstring>Returns code to switch from amd64 to i386 mode. Trashes eax, ecx, edx.
2+
3+
Note that you most surely want to set up some stack (and place this code)
4+
in low address space before (or afterwards).</%docstring>
5+
.code64
6+
call $+4
7+
.byte 0xc0 /* inc eax */
8+
mov byte ptr [rsp+4], 0x33 /* This is the segment we want to go to */
9+
retfd
10+
.code32

pwnlib/shellcraft/templates/amd64/linux/amd64_to_i386.asm

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<% from pwnlib.shellcraft import common %>
2-
<%docstring>Returns code to switch from amd64 to i386 mode.
1+
<%docstring>Returns code to switch from amd64 to i386 mode. Trashes eax, ecx, edx.
32

43
Note that you most surely want to set up some stack (and place this code)
54
in low address space before (or afterwards).</%docstring>
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
<% from pwnlib.shellcraft import common %>
2-
<%docstring>Returns code to switch from i386 to amd64 mode.</%docstring>
3-
<% helper, end = common.label("helper"), common.label("end") %>
1+
<%docstring>Returns code to switch from i386 to amd64 mode. Trashes eax.</%docstring>
42
.code32
53
push 0x43 /* This is the segment we want to go to */
4+
/* "db 0xff; sub al,0x24" is "jmp far [esp]" by chance */
65
call $+4
7-
${helper}:
8-
.byte 0xc0
9-
add dword ptr [esp], ${end} - ${helper}
10-
jmp far [esp]
11-
${end}:
6+
sub al, 0x24
127
.code64

pwnlib/shellcraft/templates/i386/linux/i386_to_amd64.asm

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<% from pwnlib.shellcraft import common %>
2-
<%docstring>Returns code to switch from i386 to amd64 mode.</%docstring>
1+
<%docstring>Returns code to switch from i386 to amd64 mode. Trashes eax.</%docstring>
32
.code32
43
push 0x33 /* This is the segment we want to go to */
54
/* "db 0xff; sub al,0x24" is "jmp far [esp]" by chance */

0 commit comments

Comments
 (0)