@@ -886,9 +886,14 @@ def fmtstr_payload(offset, writes, numbwritten=0, write_size='byte', write_size_
886
886
all_atoms = make_atoms (writes , sz , szmax , numbwritten , overflows , strategy , badbytes )
887
887
888
888
fmt = b""
889
+ # Predict the size of bytes to substract.
890
+ # We consider that the pattern ``START%XXX$pEND`` is always used.
891
+ # This is because ``prefix`` got placed after ``payload``.
892
+ search_pattern = "START%{}$pEND" .format (offset )
893
+ reverse_offset = len (search_pattern ) + (len (search_pattern ) % context .bytes )
889
894
for _ in range (1000000 ):
890
895
data_offset = (offset_bytes + len (fmt )) // context .bytes
891
- fmt , data = make_payload_dollar (offset + data_offset , all_atoms , numbwritten = numbwritten , no_dollars = no_dollars )
896
+ fmt , data = make_payload_dollar (offset + data_offset - ( reverse_offset // context . bytes ) , all_atoms , numbwritten = numbwritten , no_dollars = no_dollars )
892
897
fmt = fmt + cyclic ((- len (fmt )- offset_bytes ) % context .bytes )
893
898
894
899
if len (fmt ) + offset_bytes == data_offset * context .bytes :
@@ -935,7 +940,7 @@ def __init__(self, execute_fmt, offset=None, padlen=0, numbwritten=0, badbytes=f
935
940
936
941
def leak_stack (self , offset , prefix = b"" ):
937
942
payload = b"START%%%d$pEND" % offset
938
- leak = self .execute_fmt (prefix + payload )
943
+ leak = self .execute_fmt (payload + prefix )
939
944
try :
940
945
leak = re .findall (br"START(.*?)END" , leak , re .MULTILINE | re .DOTALL )[0 ]
941
946
leak = int (leak , 16 )
0 commit comments