@@ -319,28 +319,35 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) {
319
319
320
320
// Update relocations
321
321
auto && it_relocation = std::find_if (
322
- std::begin (this ->pltgot_relocations_ ),
323
- std::end (this ->pltgot_relocations_ ),
322
+ std::begin (this ->relocations_ ),
323
+ std::end (this ->relocations_ ),
324
324
[&symbol] (const Relocation* relocation) {
325
- return relocation != nullptr and relocation->has_symbol () and relocation->symbol () == *symbol;
325
+ return relocation != nullptr and
326
+ relocation->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT and
327
+ relocation->has_symbol () and
328
+ relocation->symbol () == *symbol;
326
329
});
327
330
328
- if (it_relocation != std::end (this ->pltgot_relocations_ )) {
331
+ if (it_relocation != std::end (this ->relocations_ )) {
329
332
delete *it_relocation;
330
- this ->pltgot_relocations_ .erase (it_relocation);
333
+ this ->relocations_ .erase (it_relocation);
331
334
} else {
332
335
}
333
336
334
337
335
338
it_relocation = std::find_if (
336
- std::begin (this ->dynamic_relocations_ ),
337
- std::end (this ->dynamic_relocations_ ),
339
+ std::begin (this ->relocations_ ),
340
+ std::end (this ->relocations_ ),
338
341
[&symbol] (const Relocation* relocation) {
339
- return relocation != nullptr and relocation->has_symbol () and relocation->symbol () == *symbol;
342
+ return relocation != nullptr and
343
+ relocation->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC and
344
+ relocation->has_symbol () and
345
+ relocation->symbol () == *symbol;
340
346
});
341
- if (it_relocation != std::end (this ->dynamic_relocations_ )) {
347
+
348
+ if (it_relocation != std::end (this ->relocations_ )) {
342
349
delete *it_relocation;
343
- this ->dynamic_relocations_ .erase (it_relocation);
350
+ this ->relocations_ .erase (it_relocation);
344
351
}
345
352
346
353
// Update symbol versions
@@ -368,22 +375,40 @@ void Binary::remove_dynamic_symbol(Symbol* symbol) {
368
375
// Dynamics
369
376
// --------
370
377
371
- it_relocations Binary::get_dynamic_relocations (void ) {
372
- return it_relocations{std::ref (this ->dynamic_relocations_ )};
378
+ it_dynamic_relocations Binary::get_dynamic_relocations (void ) {
379
+ return filter_iterator<relocations_t >{std::ref (this ->relocations_ ),
380
+ [] (const Relocation* reloc) {
381
+ return reloc->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC;
382
+ }
383
+ };
384
+
373
385
}
374
386
375
- it_const_relocations Binary::get_dynamic_relocations (void ) const {
376
- return it_const_relocations{std::cref (this ->dynamic_relocations_ )};
387
+ it_const_dynamic_relocations Binary::get_dynamic_relocations (void ) const {
388
+ return const_filter_iterator<const relocations_t >{std::cref (this ->relocations_ ),
389
+ [] (const Relocation* reloc) {
390
+ return reloc->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_DYNAMIC;
391
+ }
392
+ };
393
+
377
394
}
378
395
379
396
// plt/got
380
397
// -------
381
- it_relocations Binary::get_pltgot_relocations (void ) {
382
- return it_relocations{std::ref (this ->pltgot_relocations_ )};
398
+ it_pltgot_relocations Binary::get_pltgot_relocations (void ) {
399
+ return filter_iterator<relocations_t >{std::ref (this ->relocations_ ),
400
+ [] (const Relocation* reloc) {
401
+ return reloc->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT;
402
+ }
403
+ };
383
404
}
384
405
385
- it_const_relocations Binary::get_pltgot_relocations (void ) const {
386
- return it_const_relocations{std::cref (this ->pltgot_relocations_ )};
406
+ it_const_pltgot_relocations Binary::get_pltgot_relocations (void ) const {
407
+ return const_filter_iterator<const relocations_t >{std::cref (this ->relocations_ ),
408
+ [] (const Relocation* reloc) {
409
+ return reloc->purpose () == RELOCATION_PURPOSES::RELOC_PURPOSE_PLTGOT;
410
+ }
411
+ };
387
412
}
388
413
389
414
LIEF::symbols_t Binary::get_abstract_symbols (void ) {
@@ -788,18 +813,19 @@ void Binary::patch_address(uint64_t address, uint64_t patch_value, size_t size)
788
813
789
814
790
815
void Binary::patch_pltgot (const Symbol& symbol, uint64_t address) {
816
+ it_pltgot_relocations pltgot_relocations = this ->get_pltgot_relocations ();
791
817
auto && it_relocation = std::find_if (
792
- std::begin (this -> pltgot_relocations_ ),
793
- std::end (this -> pltgot_relocations_ ),
794
- [&symbol] (const Relocation* relocation) {
795
- return relocation-> has_symbol () and relocation-> symbol () == symbol;
818
+ std::begin (pltgot_relocations ),
819
+ std::end (pltgot_relocations ),
820
+ [&symbol] (const Relocation& relocation) {
821
+ return relocation. has_symbol () and relocation. symbol () == symbol;
796
822
});
797
823
798
- if (it_relocation == std::end (this -> pltgot_relocations_ )) {
824
+ if (it_relocation == std::end (pltgot_relocations )) {
799
825
throw not_found (" Unable to find the relocation associated with symbol '" + symbol.name () + " '" );
800
826
}
801
827
802
- uint64_t got_address = (*it_relocation)-> address ();
828
+ uint64_t got_address = (*it_relocation). address ();
803
829
this ->patch_address (got_address, address, sizeof (uint64_t ));
804
830
// (*it_relocation)->address(0);
805
831
// delete *it_relocation;
@@ -1641,12 +1667,7 @@ std::ostream& Binary::print(std::ostream& os) const {
1641
1667
1642
1668
Binary::~Binary (void ) {
1643
1669
1644
- for (Relocation* relocation : this ->pltgot_relocations_ ) {
1645
- delete relocation;
1646
- }
1647
-
1648
-
1649
- for (Relocation* relocation : this ->dynamic_relocations_ ) {
1670
+ for (Relocation* relocation : this ->relocations_ ) {
1650
1671
delete relocation;
1651
1672
}
1652
1673
0 commit comments