From 87f90ee72b057fe6e9cc9ae37f22bff06f37a5b6 Mon Sep 17 00:00:00 2001 From: Joel Allred Date: Mon, 30 Jul 2018 17:06:03 +0100 Subject: [PATCH 1/2] Add replace_all string utility Utility to search and replace strings inside a string. --- src/util/string_utils.cpp | 21 +++++++++++++++++++++ src/util/string_utils.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/util/string_utils.cpp b/src/util/string_utils.cpp index dc889684205..996039e0409 100644 --- a/src/util/string_utils.cpp +++ b/src/util/string_utils.cpp @@ -148,3 +148,24 @@ std::string escape(const std::string &s) return result; } + +/// Replace all occurrences of a string inside a string +/// \param [out] str: string to search +/// \param from: string to replace +/// \param to: string to replace with +/// Copyright notice: +/// Attributed to Gauthier Boaglio +/// Source: https://stackoverflow.com/a/24315631/7501486 +/// Used under MIT license +void replace_all( + std::string &str, + const std::string &from, + const std::string &to) +{ + size_t start_pos = 0; + while((start_pos = str.find(from, start_pos)) != std::string::npos) + { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); + } +} diff --git a/src/util/string_utils.h b/src/util/string_utils.h index dbd7e634a52..17936ede3de 100644 --- a/src/util/string_utils.h +++ b/src/util/string_utils.h @@ -67,4 +67,6 @@ Stream &join_strings( /// programming language. std::string escape(const std::string &); +void replace_all(std::string &, const std::string &, const std::string &); + #endif From 1f4ef405efcccfa97bf32427049dda05398ed670 Mon Sep 17 00:00:00 2001 From: Joel Allred Date: Tue, 31 Jul 2018 11:02:43 +0100 Subject: [PATCH 2/2] Add class loader debug output --- jbmc/src/java_bytecode/java_class_loader_limit.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jbmc/src/java_bytecode/java_class_loader_limit.cpp b/jbmc/src/java_bytecode/java_class_loader_limit.cpp index c04e9caa4c2..5fc58d4326c 100644 --- a/jbmc/src/java_bytecode/java_class_loader_limit.cpp +++ b/jbmc/src/java_bytecode/java_class_loader_limit.cpp @@ -24,7 +24,11 @@ void java_class_loader_limitt::setup_class_load_limit( // '@' signals file reading with list of class files to load use_regex_match = java_cp_include_files[0] != '@'; if(use_regex_match) + { regex_matcher=std::regex(java_cp_include_files); + debug() << "Limit loading to classes matching '" << java_cp_include_files + << "'" << eom; + } else { assert(java_cp_include_files.length()>1); @@ -54,7 +58,10 @@ bool java_class_loader_limitt::load_class_file(const std::string &file_name) if(use_regex_match) { std::smatch string_matches; - return std::regex_match(file_name, string_matches, regex_matcher); + if(std::regex_match(file_name, string_matches, regex_matcher)) + return true; + debug() << file_name + " discarded since not matching loader regexp" << eom; + return false; } else // load .class file only if it is in the match set