Skip to content

Commit

Permalink
shellcraft.amd64.mov: fix logic once again
Browse files Browse the repository at this point in the history
  • Loading branch information
Arusekk committed Jan 21, 2024
1 parent ea22cc8 commit b819878
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pwnlib/shellcraft/templates/aarch64/mov.asm
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,28 @@ if isinstance(src, six.integer_types):
dst = 'x15'
lobits = 15

src = unpack(b''.join(words))
xor = unpack(b''.join(xor))
if xor:
src = unpack(b''.join(words))

tmp = 'x14'
if dst == tmp:
tmp = 'x15'

%>
%if not isinstance(src, six.integer_types):
mov ${dst}, ${src}
%else:
%if src & 0xffff == 0:
%if src == 0:
mov ${dst}, xzr
%endif
%if src & 0xffff == src != 0:
%elif src & 0xffff == src:
mov ${dst}, #${src}
%else:
/* Set ${dst} = ${src} = ${pretty(src, False)} */
%if src & 0x000000000000ffff:
mov ${dst}, #${(src >> 0x00) & 0xffff}
%else:
mov ${dst}, xzr
%endif
%if src & 0x00000000ffff0000:
movk ${dst}, #${(src >> 0x10) & 0xffff}, lsl #16
Expand All @@ -106,8 +112,8 @@ if isinstance(src, six.integer_types):
%endif
%endif
%if xor:
${SC.mov('x14', xor)}
eor ${dst}, ${dst}, x14
${SC.mov(tmp, xor)}
eor ${dst}, ${dst}, ${tmp}
%endif
%if mov_x15:
${SC.mov(mov_x15,'x15')}
Expand Down

0 comments on commit b819878

Please sign in to comment.