Skip to content

Commit

Permalink
?cxx/*.*x: undo C++14 code, support -std=c++11
Browse files Browse the repository at this point in the history
?`cxx/ClassSys.hxx`: support `-std=c++11`.
	?`classSysUSeconds`: `error: 'auto' return without trailing return type; deduced return types are a C++14 extension` fix.
	?`classSysColoredParamStr`: `error: 'auto' return without trailing return type; deduced return types are a C++14 extension` fix.
	?`classSysColoredParamStr`: `error: no member named 'remove_const_t' in namespace 'std'; did you mean 'remove_copy_if'?` fix.
	?`templateCatchAll`: `error: 'auto' return without trailing return type; deduced return types are a C++14 extension` fix.

?`cxx/ClassResultList.hxx`: support `-std=c++11`.
	?`listMaxSize`: `:%s/const auto &/const typename List::const_iterator::value_type &/`: `error: 'auto' not allowed in lambda parameter before C++14` fix.
	?`listFindValue`: `error: 'auto' return without trailing return type; deduced return types are a C++14 extension` fix.
	-`listDefaultIterator`: `warning: variable templates are a C++14 extension [-Wc++14-extensions]` fix.
	?`listFindValue`, ?`listHasValue`: `:%s/listDefaultIterator/List::value_type::const_iterator()/`.
	+`#include <string>`: `warning: no header providing

?`cxx/VirusAnalysis.*xx`: support `-std=c++11`.
	?`virusAnalyses`: `:%s/typeof(virusAnalysisFun)/virusAnalysisFun/`: `error: unexpected type name 'VirusAnalysisFun': expected expression` fix, `error: template argument for template type parameter must be a type` fix.

?`cxx/AssistantCns.cxx`: support `-std=c++11`.
	?`questionsResponsesFromXhtml`: `:%s/typeof question/decltype(question)/`: `error: unknown type name 'typeof'; did you mean 'typedef'?` fix.

`clang-tidy`:
	?`cxx/ClassResultList.hxx`:
		+`#include <string>`: `warning: no header providing "std::string" is directly included [misc-include-cleaner]` fix.
	?`cxx/ClassResultList.cxx`:
		[misc-use-anonymous-namespace].
		-`#include "ClassSys.hxx": `warning: included header ClassSys.hxx is not used directly [misc-include-cleaner]`: fix.
		`warning: function 'classResultListDumpToTest' declared 'static', move to anonymous namespace instead [misc-use-anonymous-namespace]`: suppressed (function is called.)
		+`#include <string>`: `warning: no header providing "std::string" is directly included [misc-include-cleaner]` fix.
		?`classResultListTests`: `warning: 0x32 is a magic number; consider replacing it with a named constant [cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers]` fix.

?`posts/VirusAnalysis.md`: Include all this.

?`README.md`: ?`# How to`: Minimum requirement is now C++11 to use.

As this allows `./build.sh` to include `-std=c++11`, this has to do with issue #18 (support more tools.)
The last commit about issue #18 was 2a6e624 (?`build.sh`: incremental builds (reuse objects)), which doesn't touch `cxx/*` nor `posts/*`.
  • Loading branch information
SwuduSusuwu committed Nov 17, 2024
1 parent 2a6e624 commit d7370e8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Dual licenses: choose [_Creative Commons_](https://creativecommons.org/share-you
[`./cxx/`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/cxx/) _C++_ implementations of posts (for now is just neural system pure virtual template ([`./cxx/ClassCns.hxx`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/cxx/ClassCns.hxx)) + antivirus([`./cxx/VirusAnalysis.cxx`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/cxx/VirusAnalysis.cxx)) + assistant([`./cxx/AssistantCns.cxx`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/cxx/AssistantCns.cxx)), with lots of [issues](https://github.com/SwuduSusuwu/SubStack/issues) which you can contribute to, or can request that more resources go to).

# How to use this
Targets: Windows/Linux/Android/OSX/iOS; minimum [_C++11_](https://gcc.gnu.org/projects/cxx-status.html#cxx11) (all `CXX` with `201102 <= __cplusplus`,) due to use of `auto`, `decltype`, `for(value: list) {}`, `nullptr`, `__func__`). [TODO: It is possible that [..."warning: use default member initializer for 'inputNeurons' [cppcoreguidelines-use-defau lt-member-init,modernize-use-default-member-init]" fix@579a908](https://github.com/SwuduSusuwu/SubStack/commit/579a9089248a018005f36522968026ee464fc061) bumped the minimum up to [_C++14_](https://gcc.gnu.org/projects/cxx-status.html#cxx14) (if so will undo, as was told that not all microcontrollers have compilers which support _C++14_).]
Targets: Windows/Linux/Android/OSX/iOS; minimum [_C++11_](https://gcc.gnu.org/projects/cxx-status.html#cxx11) (all `CXX` with `201102 <= __cplusplus`,) due to use of `auto`, `decltype`, `for(value: list) {}`, `nullptr`, `__func__`).

Usage: [`./build.sh [OPTIONS]`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/build.sh) produces objects (`./obj/*.o`, for distribution into other tools,) plus [_Executable and Linkable Format_](https://wikipedia.org/wiki/Executable_and_Linkable_Format) (`./bin/a.out`, to do examples/[unit tests](https://wikipedia.org/wiki/Unit_test#Agile) which prove how effective functions execute,) both of which you can redirect with `export OBJDIR=___` (or `export BINDIR=___`.)
- [`./cxx/main.hxx`](https://github.com/SwuduSusuwu/SubStack/blob/trunk/cxx/main.hxx) has constants to use to interpret `a.out`'s return values.
Expand Down
4 changes: 2 additions & 2 deletions cxx/AssistantCns.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void questionsResponsesFromXhtml(ResultList &questionsOrNull, ResultList &respon
if(!question.empty()) {
auto questionSha2 = sha2(question);
if(listHasValue(questionsOrNull.hashes, questionSha2)) { /* TODO */ } else {
typeof question response = "";
decltype(question) response = "";
auto responses = assistantParseResponses(localXhtml);
if(!responses.empty()) {
questionsOrNull.hashes.insert(questionSha2);
Expand All @@ -98,7 +98,7 @@ void questionsResponsesFromXhtml(ResultList &questionsOrNull, ResultList &respon
auto responseSha2 = sha2(response);
if(listHasValue(responsesOrNull.hashes, responseSha2)) { /* TODO */ } else {
responsesOrNull.hashes.insert(responseSha2);
responsesOrNull.bytecodes.push_back(response);
responsesOrNull.bytecodes.push_back(response);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cxx/ClassResultList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#ifndef INCLUDES_cxx_ClassResultList_cxx
#define INCLUDES_cxx_ClassResultList_cxx
#include "ClassResultList.hxx" /* resultList resultListDumpTo ResultListHash */
#include "ClassSys.hxx" /* templateCatchAll */
#include "Macros.hxx" /* SUSUWU_ERRSTR SUSUWU_SH_GREEN SUSUWU_NOEXCEPT SUSUWU_SH_RED SUSUWU_SH_WHITE */
#include <sstream> /* std::stringstream */
#include <string> /* std::string */
#include <stdexcept> /* std::runtime_error */
namespace Susuwu {
static void classResultListDumpToTest(const ResultList &resultList, bool index, bool whitespace, bool pascalValues, const std::string &expectedValue) {
static void classResultListDumpToTest(const ResultList &resultList, bool index, bool whitespace, bool pascalValues, const std::string &expectedValue) { /* NOLINT(misc-use-anonymous-namespace): have to call */
std::stringstream os;
resultListDumpTo(resultList, os, index, whitespace, pascalValues);
if(expectedValue != os.str()) {
Expand All @@ -16,7 +16,7 @@ static void classResultListDumpToTest(const ResultList &resultList, bool index,
}
const bool classResultListTests() {
ResultList resultList;
resultList.hashes.insert(ResultListHash({0x32})); /* `.hashes` is `std::unordered_set`, thus test just 1 value. */
resultList.hashes.insert(ResultListHash({'\x32'})); /* `.hashes` is `std::unordered_set`, thus test just 1 value. */
resultList.signatures = {"1", "2"};
resultList.bytecodes = {"01", "02"};
classResultListDumpToTest(resultList, false, false, false, "list.hashes={0x32};list.signatures={0x31,0x32};list.bytecodes={0x3031,0x3032};");
Expand Down
14 changes: 7 additions & 7 deletions cxx/ClassResultList.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#if SUSUWU_PREFER_CSTR
# include <cstring> /* strlen memmem */
#endif /* SUSUWU_PREFER_CSTR */
#include <string> /* std::string */
#include <tuple> /* std::tuple std::get */
#include <unordered_set> /* std::unordered_set */
#include <vector> /* std::vector */
Expand Down Expand Up @@ -42,7 +43,7 @@ const size_t listMaxSize(const List &list) {
for(auto it = &list[0]; list.cend() != it; ++it) { const size_t temp = strlen(*it); if(temp > max) {max = temp;}}
return max; /* WARNING! `strlen()` just does UTF8-strings/hex-strings; if binary, must use `it->size()` */
#else /* else !SUSUWU_PREFER_CSTR */
auto it = std::max_element(list.cbegin(), list.cend(), [](const auto &s, const auto &x) { return s.size() < x.size(); });
auto it = std::max_element(list.cbegin(), list.cend(), [](const typename List::const_iterator::value_type &s, const typename List::const_iterator::value_type &x) { return s.size() < x.size(); });
return it->size();
#endif /* SUSUWU_PREFER_CSTR else */
}
Expand Down Expand Up @@ -113,33 +114,32 @@ const bool listsIntersect(const List &list, const List &list2) {

template<class List>
/* return `list`'s `const_iterator` to first instance of `value`, or `list.cend()` (if not found) */
auto listFindValue(const List &list, const typename List::value_type &value) {
auto listFindValue(const List &list, const typename List::value_type &value) -> decltype(std::find(list.cbegin(), list.cend(), value)) {
//const class List::const_iterator listFindValue(const List &list, const typename List::value_type &value) {
return std::find(list.cbegin(), list.cend(), value);
}
template<class List>
const bool listHasValue(const List &list, const typename List::value_type &value) {
return list.cend() != listFindValue(list, value);
}

template<class List>
const typename List::value_type::const_iterator listDefaultIterator = typename List::value_type::const_iterator(); /* Equates to "Not found" */
template<class List>
/* return `list`'s `const_iterator` to first instance of `std::string(itBegin, itEndSubstr)`, or default iterator (if not found)
* @pre @code itBegin < itEnd @endcode */
decltype(listDefaultIterator<List>) listFindSubstr(const List &list, typename List::value_type::const_iterator itBegin, typename List::value_type::const_iterator itEnd) {
const typename List::value_type::const_iterator listFindSubstr(const List &list, typename List::value_type::const_iterator itBegin, typename List::value_type::const_iterator itEnd) {
#pragma unroll
for(const auto &value : list) {
auto result = std::search(value.cbegin(), value.cend(), itBegin, itEnd, [](char chValue, char chIt) { return chValue == chIt; });
if(value.cend() != result) {
return result;
}
}
return listDefaultIterator<List>;
return typename List::value_type::const_iterator(); /* Equates to "Not found" */
}
template<class List>
/* @pre @code itBegin < itEnd @endcode */
const bool listHasSubstr(const List &list, typename List::value_type::const_iterator itBegin, typename List::value_type::const_iterator itEnd) {
return listDefaultIterator<List> != listFindSubstr(list, itBegin, itEnd);
return typename List::value_type::const_iterator() != listFindSubstr(list, itBegin, itEnd);
}
template<class List>
/* Returns shortest substr from `value`, which is not found in `list`
Expand Down
12 changes: 6 additions & 6 deletions cxx/ClassSys.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#else
typedef int pid_t;
#endif
#include <type_traits> /* std::remove_const_t */
#include <type_traits> /* std::remove_const */
#include <vector> /* std::vector */
/* Abstractions to do with: `sh` scripts (such as: exec*, sudo), sockets (TODO), filesystems (TODO) */
namespace Susuwu {
Expand All @@ -28,10 +28,10 @@ extern const char **classSysArgs;
* @post @code (0 < classSysArgc && nullptr != classSysArgs && nullptr != classSysArgs[0] */
const bool classSysInit(int argc, const char **args);

inline const auto classSysUSecondClock() {
typedef decltype(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count()) ClassSysUSeconds;
inline const ClassSysUSeconds classSysUSecondClock() {
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}
typedef decltype(classSysUSecondClock()) ClassSysUSeconds;

/* `std::array<char *>argv = argvS; argv += NULL; envp = envpS + NULL: pid_t pid = fork(); if(-1 != pid) {pid || (envpS.empty() ? execv(argv[0], &argv[0]) : execve(argv[0], &argv[0], &envp[0]));} return pid;`
* @pre @code (-1 != access(argvS[0], X_OK) @endcode */
Expand Down Expand Up @@ -90,8 +90,8 @@ inline Os &classSysColoredParamOs(Os &os, const List &argvS, const bool parenthe
return os;
}
template<class List>
inline const auto classSysColoredParamStr(const List &argvS, const bool parenthesis/* {...} */ = true) {
std::remove_const_t<typename List::value_type> str = (parenthesis ? "{" : "");
inline const typename List::value_type classSysColoredParamStr(const List &argvS, const bool parenthesis/* {...} */ = true) {
typename List::value_type str = (parenthesis ? "{" : "");
for(const auto &it: argvS) {
if(&it != &*argvS.cbegin()) {
str += ", ";
Expand All @@ -107,7 +107,7 @@ inline const auto classSysColoredParamStr(const List &argvS, const bool parenthe
}

template<typename Func, typename... Args>
auto templateCatchAll(Func func, const std::string &funcName, Args... args) {
auto templateCatchAll(Func func, const std::string &funcName, Args... args) -> const decltype(func(args...)) {
try {
return func(args...);
} catch (const std::exception &ex) {
Expand Down
2 changes: 1 addition & 1 deletion cxx/VirusAnalysis.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void virusAnalysisResetCaches() SUSUWU_NOEXCEPT {
cnsAnalysisCaches.clear();
sandboxAnalysisCaches.clear();
}
std::vector<typeof(VirusAnalysisFun)> virusAnalyses = {hashAnalysis, signatureAnalysis, staticAnalysis, cnsAnalysis, sandboxAnalysis /* sandbox is slow, so put last*/};
std::vector<VirusAnalysisFun> virusAnalyses = {hashAnalysis, signatureAnalysis, staticAnalysis, cnsAnalysis, sandboxAnalysis /* sandbox is slow, so put last*/};

const bool virusAnalysisTests() {
ResultList abortOrNull; {
Expand Down
2 changes: 1 addition & 1 deletion cxx/VirusAnalysis.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern std::map<ResultListHash, VirusAnalysisResult> hashAnalysisCaches, signatu
void virusAnalysisResetCaches() SUSUWU_NOEXCEPT;

typedef const VirusAnalysisResult (*VirusAnalysisFun)(const PortableExecutable &file, const ResultListHash &fileHash);
extern std::vector<typeof(VirusAnalysisFun)> virusAnalyses;
extern std::vector<VirusAnalysisFun> virusAnalyses;
const VirusAnalysisResult virusAnalysis(const PortableExecutable &file); /* auto hash = sha2(file.bytecode); for(VirusAnalysisFun analysis : virusAnalyses) {analysis(file, hash);} */
const VirusAnalysisResult virusAnalysisRemoteAnalysis(const PortableExecutable &file, const ResultListHash &fileHash); /* TODO: compatible hosts to upload to */
const VirusAnalysisResult virusAnalysisManualReviewCacheless(const PortableExecutable &file, const ResultListHash &fileHash); /* Ask user to "Block", "Submit to remote hosts for analysis", or "Allow". */
Expand Down
Loading

0 comments on commit d7370e8

Please sign in to comment.