@@ -143,9 +143,12 @@ def provider_local_database(hex_encoded_id, hash_type):
143
143
144
144
return None
145
145
146
- PROVIDERS = [provider_local_system , provider_local_database , provider_libcdb , provider_libc_rip ]
146
+ PROVIDERS = {
147
+ "offline" : [provider_local_system , provider_local_database ],
148
+ "online" : [provider_libcdb , provider_libc_rip ]
149
+ }
147
150
148
- def search_by_hash (hex_encoded_id , hash_type = 'build_id' , unstrip = True ):
151
+ def search_by_hash (hex_encoded_id , hash_type = 'build_id' , unstrip = True , offline = False ):
149
152
assert hash_type in HASHES , hash_type
150
153
151
154
# Ensure that the libcdb cache directory exists
@@ -157,8 +160,12 @@ def search_by_hash(hex_encoded_id, hash_type='build_id', unstrip=True):
157
160
if cache is None :
158
161
return None
159
162
163
+ providers = PROVIDERS ["offline" ]
164
+ if not offline :
165
+ providers += PROVIDERS ["online" ]
166
+
160
167
# Run through all available libc database providers to see if we have a match.
161
- for provider in PROVIDERS :
168
+ for provider in providers :
162
169
data = provider (hex_encoded_id , hash_type )
163
170
if data and data .startswith (b'\x7F ELF' ):
164
171
break
@@ -603,7 +610,7 @@ def search_by_symbol_offsets(symbols, select_index=None, unstrip=True, return_as
603
610
selected_libc = _handle_multiple_matching_libcs (matching_libcs )
604
611
return search_by_build_id (selected_libc ['buildid' ], unstrip = unstrip )
605
612
606
- def search_by_build_id (hex_encoded_id , unstrip = True ):
613
+ def search_by_build_id (hex_encoded_id , unstrip = True , offline = False ):
607
614
"""
608
615
Given a hex-encoded Build ID, attempt to download a matching libc from libcdb.
609
616
@@ -612,6 +619,8 @@ def search_by_build_id(hex_encoded_id, unstrip=True):
612
619
Hex-encoded Build ID (e.g. 'ABCDEF...') of the library
613
620
unstrip(bool):
614
621
Try to fetch debug info for the libc and apply it to the downloaded file.
622
+ offline(bool):
623
+ Enable offline search mode, which will disable online providers.
615
624
616
625
Returns:
617
626
Path to the downloaded library on disk, or :const:`None`.
@@ -627,9 +636,9 @@ def search_by_build_id(hex_encoded_id, unstrip=True):
627
636
>>> hex(ELF(filename).symbols.read)
628
637
'0xeef40'
629
638
"""
630
- return search_by_hash (hex_encoded_id , 'build_id' , unstrip )
639
+ return search_by_hash (hex_encoded_id , 'build_id' , unstrip , offline )
631
640
632
- def search_by_md5 (hex_encoded_id , unstrip = True ):
641
+ def search_by_md5 (hex_encoded_id , unstrip = True , offline = False ):
633
642
"""
634
643
Given a hex-encoded md5sum, attempt to download a matching libc from libcdb.
635
644
@@ -638,6 +647,8 @@ def search_by_md5(hex_encoded_id, unstrip=True):
638
647
Hex-encoded md5sum (e.g. 'ABCDEF...') of the library
639
648
unstrip(bool):
640
649
Try to fetch debug info for the libc and apply it to the downloaded file.
650
+ offline(bool):
651
+ Enable offline search mode, which will disable online providers.
641
652
642
653
Returns:
643
654
Path to the downloaded library on disk, or :const:`None`.
@@ -653,9 +664,9 @@ def search_by_md5(hex_encoded_id, unstrip=True):
653
664
>>> hex(ELF(filename).symbols.read)
654
665
'0xeef40'
655
666
"""
656
- return search_by_hash (hex_encoded_id , 'md5' , unstrip )
667
+ return search_by_hash (hex_encoded_id , 'md5' , unstrip , offline )
657
668
658
- def search_by_sha1 (hex_encoded_id , unstrip = True ):
669
+ def search_by_sha1 (hex_encoded_id , unstrip = True , offline = False ):
659
670
"""
660
671
Given a hex-encoded sha1, attempt to download a matching libc from libcdb.
661
672
@@ -664,6 +675,8 @@ def search_by_sha1(hex_encoded_id, unstrip=True):
664
675
Hex-encoded sha1sum (e.g. 'ABCDEF...') of the library
665
676
unstrip(bool):
666
677
Try to fetch debug info for the libc and apply it to the downloaded file.
678
+ offline(bool):
679
+ Enable offline search mode, which will disable online providers.
667
680
668
681
Returns:
669
682
Path to the downloaded library on disk, or :const:`None`.
@@ -679,10 +692,10 @@ def search_by_sha1(hex_encoded_id, unstrip=True):
679
692
>>> hex(ELF(filename).symbols.read)
680
693
'0xeef40'
681
694
"""
682
- return search_by_hash (hex_encoded_id , 'sha1' , unstrip )
695
+ return search_by_hash (hex_encoded_id , 'sha1' , unstrip , offline )
683
696
684
697
685
- def search_by_sha256 (hex_encoded_id , unstrip = True ):
698
+ def search_by_sha256 (hex_encoded_id , unstrip = True , offline = False ):
686
699
"""
687
700
Given a hex-encoded sha256, attempt to download a matching libc from libcdb.
688
701
@@ -691,6 +704,8 @@ def search_by_sha256(hex_encoded_id, unstrip=True):
691
704
Hex-encoded sha256sum (e.g. 'ABCDEF...') of the library
692
705
unstrip(bool):
693
706
Try to fetch debug info for the libc and apply it to the downloaded file.
707
+ offline(bool):
708
+ Enable offline search mode, which will disable online providers.
694
709
695
710
Returns:
696
711
Path to the downloaded library on disk, or :const:`None`.
@@ -706,7 +721,7 @@ def search_by_sha256(hex_encoded_id, unstrip=True):
706
721
>>> hex(ELF(filename).symbols.read)
707
722
'0xeef40'
708
723
"""
709
- return search_by_hash (hex_encoded_id , 'sha256' , unstrip )
724
+ return search_by_hash (hex_encoded_id , 'sha256' , unstrip , offline )
710
725
711
726
712
727
0 commit comments