@@ -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_only = 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_only :
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
@@ -607,7 +614,7 @@ def search_by_symbol_offsets(symbols, select_index=None, unstrip=True, return_as
607
614
selected_libc = _handle_multiple_matching_libcs (matching_libcs )
608
615
return search_by_build_id (selected_libc ['buildid' ], unstrip = unstrip )
609
616
610
- def search_by_build_id (hex_encoded_id , unstrip = True ):
617
+ def search_by_build_id (hex_encoded_id , unstrip = True , offline_only = False ):
611
618
"""
612
619
Given a hex-encoded Build ID, attempt to download a matching libc from libcdb.
613
620
@@ -616,6 +623,10 @@ def search_by_build_id(hex_encoded_id, unstrip=True):
616
623
Hex-encoded Build ID (e.g. 'ABCDEF...') of the library
617
624
unstrip(bool):
618
625
Try to fetch debug info for the libc and apply it to the downloaded file.
626
+ offline_only(bool):
627
+ Both offline and online providers are used by default. When pass
628
+ `offline_only=True`, libcdb enable an exclusive offline search mode,
629
+ which will disable online providers.
619
630
620
631
Returns:
621
632
Path to the downloaded library on disk, or :const:`None`.
@@ -631,9 +642,9 @@ def search_by_build_id(hex_encoded_id, unstrip=True):
631
642
>>> hex(ELF(filename).symbols.read)
632
643
'0xeef40'
633
644
"""
634
- return search_by_hash (hex_encoded_id , 'build_id' , unstrip )
645
+ return search_by_hash (hex_encoded_id , 'build_id' , unstrip , offline_only )
635
646
636
- def search_by_md5 (hex_encoded_id , unstrip = True ):
647
+ def search_by_md5 (hex_encoded_id , unstrip = True , offline_only = False ):
637
648
"""
638
649
Given a hex-encoded md5sum, attempt to download a matching libc from libcdb.
639
650
@@ -642,6 +653,10 @@ def search_by_md5(hex_encoded_id, unstrip=True):
642
653
Hex-encoded md5sum (e.g. 'ABCDEF...') of the library
643
654
unstrip(bool):
644
655
Try to fetch debug info for the libc and apply it to the downloaded file.
656
+ offline_only(bool):
657
+ Both offline and online providers are used by default. When pass
658
+ `offline_only=True`, libcdb enable an exclusive offline search mode,
659
+ which will disable online providers.
645
660
646
661
Returns:
647
662
Path to the downloaded library on disk, or :const:`None`.
@@ -657,9 +672,9 @@ def search_by_md5(hex_encoded_id, unstrip=True):
657
672
>>> hex(ELF(filename).symbols.read)
658
673
'0xeef40'
659
674
"""
660
- return search_by_hash (hex_encoded_id , 'md5' , unstrip )
675
+ return search_by_hash (hex_encoded_id , 'md5' , unstrip , offline_only )
661
676
662
- def search_by_sha1 (hex_encoded_id , unstrip = True ):
677
+ def search_by_sha1 (hex_encoded_id , unstrip = True , offline_only = False ):
663
678
"""
664
679
Given a hex-encoded sha1, attempt to download a matching libc from libcdb.
665
680
@@ -668,6 +683,10 @@ def search_by_sha1(hex_encoded_id, unstrip=True):
668
683
Hex-encoded sha1sum (e.g. 'ABCDEF...') of the library
669
684
unstrip(bool):
670
685
Try to fetch debug info for the libc and apply it to the downloaded file.
686
+ offline_only(bool):
687
+ Both offline and online providers are used by default. When pass
688
+ `offline_only=True`, libcdb enable an exclusive offline search mode,
689
+ which will disable online providers.
671
690
672
691
Returns:
673
692
Path to the downloaded library on disk, or :const:`None`.
@@ -683,10 +702,9 @@ def search_by_sha1(hex_encoded_id, unstrip=True):
683
702
>>> hex(ELF(filename).symbols.read)
684
703
'0xeef40'
685
704
"""
686
- return search_by_hash (hex_encoded_id , 'sha1' , unstrip )
687
-
705
+ return search_by_hash (hex_encoded_id , 'sha1' , unstrip , offline_only )
688
706
689
- def search_by_sha256 (hex_encoded_id , unstrip = True ):
707
+ def search_by_sha256 (hex_encoded_id , unstrip = True , offline_only = False ):
690
708
"""
691
709
Given a hex-encoded sha256, attempt to download a matching libc from libcdb.
692
710
@@ -695,6 +713,10 @@ def search_by_sha256(hex_encoded_id, unstrip=True):
695
713
Hex-encoded sha256sum (e.g. 'ABCDEF...') of the library
696
714
unstrip(bool):
697
715
Try to fetch debug info for the libc and apply it to the downloaded file.
716
+ offline_only(bool):
717
+ Both offline and online providers are used by default. When pass
718
+ `offline_only=True`, libcdb enable an exclusive offline search mode,
719
+ which will disable online providers.
698
720
699
721
Returns:
700
722
Path to the downloaded library on disk, or :const:`None`.
@@ -710,7 +732,7 @@ def search_by_sha256(hex_encoded_id, unstrip=True):
710
732
>>> hex(ELF(filename).symbols.read)
711
733
'0xeef40'
712
734
"""
713
- return search_by_hash (hex_encoded_id , 'sha256' , unstrip )
735
+ return search_by_hash (hex_encoded_id , 'sha256' , unstrip , offline_only )
714
736
715
737
716
738
0 commit comments