(args)
| 227 | return available_symbols |
| 228 | |
| 229 | def main(args): |
| 230 | if len(sys.argv) < 3: |
| 231 | parser.print_usage() |
| 232 | sys.exit() |
| 233 | |
| 234 | if args.libc_command == 'lookup': |
| 235 | pairs = args.symbol_offset_pairs |
| 236 | if len(pairs) % 2 != 0: |
| 237 | log.failure('Uneven number of arguments. Please provide "symbol offset" pairs') |
| 238 | return |
| 239 | |
| 240 | symbols = {pairs[i]:pairs[i+1] for i in range(0, len(pairs), 2)} |
| 241 | matched_libcs = libcdb.search_by_symbol_offsets(symbols, offline_only=args.offline_only, return_raw=True) |
| 242 | |
| 243 | for libc in matched_libcs: |
| 244 | print_libc_info(libc) |
| 245 | if args.download_libc: |
| 246 | path = libcdb.search_by_build_id(libc['buildid'], args.unstrip) |
| 247 | if path: |
| 248 | shutil.copy(path, './{}.so'.format(libc['id'])) |
| 249 | |
| 250 | elif args.libc_command == 'hash': |
| 251 | inverted_map = {v: k for k, v in libcdb.MAP_TYPES.items()} |
| 252 | hash_type = inverted_map.get(args.hash_type, args.hash_type) |
| 253 | |
| 254 | for hash_value in args.hash_value: |
| 255 | path = libcdb.search_by_hash(hash_value, hash_type, unstrip=args.unstrip, offline_only=args.offline_only) |
| 256 | exe = ELF(path, checksec=False) |
| 257 | print_libc_elf(exe) |
| 258 | |
| 259 | if args.download_libc: |
| 260 | # if we cannot get actual libc version then copy with cache name |
| 261 | shutil.copy(path, './libc-{}.so'.format(get_libc_version(exe) or Path(path).stem)) |
| 262 | |
| 263 | elif args.libc_command == 'file': |
| 264 | for file in args.files: |
| 265 | if not os.path.exists(file) or not os.path.isfile(file): |
| 266 | log.failure('File does not exist %s', args.file) |
| 267 | continue |
| 268 | |
| 269 | if args.unstrip: |
| 270 | libcdb.unstrip_libc(file) |
| 271 | |
| 272 | print_libc_elf(ELF(file, checksec=False)) |
| 273 | |
| 274 | elif args.libc_command == 'fetch': |
| 275 | |
| 276 | if args.update: |
| 277 | subprocess.check_call(['./get'] + args.update, cwd=args.path) |
| 278 | |
| 279 | else: |
| 280 | if not Path(args.path).exists(): |
| 281 | if yesno("Would you like to initialize the libc-database repository? " |
| 282 | "If the path already exists, this prompt will not display, and automatically upgrade repository."): |
| 283 | log.waitfor("init libc-database repository") |
| 284 | subprocess.check_call(['git', 'clone', 'https://github.com/niklasb/libc-database/', args.path]) |
| 285 | else: |
| 286 | log.waitfor("upgrade libc-database repository") |
nothing calls this directly
no test coverage detected