From 1e993c903ed1fb25999f89c2e8fc1d47fb82a812 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 22 Mar 2023 21:13:01 +0800 Subject: [PATCH] Fix Generator buffer realloc function error and Optimize Performance - Use std::move to insert item for bb_t::links. - Fix a generator buffer realloc size calc issue. --- Decorator.cpp | 18 ++++++++++-------- Generator.cpp | 2 +- VirtoolsScriptDeobfuscation.vcxproj | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Decorator.cpp b/Decorator.cpp index f61aac6..0a78070 100644 --- a/Decorator.cpp +++ b/Decorator.cpp @@ -152,6 +152,7 @@ class Decorator //std::set> pset; std::map> pin_chain; std::map> pout_chain; + for (auto&i : pins) { std::vector &vp = pin_chain[i] = std::vector(); @@ -166,7 +167,7 @@ class Decorator lnk_exp.start = link_endpoint_t{ vp.back().id,vp.back().idx,7 }; lnk_exp.end = last; last = lnk_exp.start; - mappedb(cb->GetID()).links.push_back(lnk_exp); + mappedb(cb->GetID()).links.push_back(std::move(lnk_exp)); ++mappedb(cb->GetID()).n_links; } } @@ -184,7 +185,7 @@ class Decorator lnk_exp.end = link_endpoint_t{ vp.back().id,vp.back().idx,8 }; lnk_exp.start = last; last = lnk_exp.end; - mappedb(cb->GetID()).links.push_back(lnk_exp); + mappedb(cb->GetID()).links.push_back(std::move(lnk_exp)); ++mappedb(cb->GetID()).n_links; } } @@ -209,7 +210,7 @@ class Decorator link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0; lnk.start = link_endpoint_t{ bb.id,bb.idx,dsrc->GetClassID() == CKCID_PARAMETERLOCAL ? 9 : 8 }; lnk.end=link_endpoint_t{aa.id,aa.idx,aa.idx==-2?10:7}; - mappedb(aa.lnk_within).links.push_back(lnk); + mappedb(aa.lnk_within).links.push_back(std::move(lnk)); ++mappedb(aa.lnk_within).n_links; conn = true; break; } @@ -221,7 +222,7 @@ class Decorator pio_pos_t sshp = GetShortcutParamPos(pinp.lnk_within, dsrc->GetID()); lnk.start = link_endpoint_t{ pinp.lnk_within,sshp.idx,5 }; lnk.end = link_endpoint_t{ pinp.id,pinp.idx,pinp.idx == -2 ? 10 : 7 }; - mappedb(pinp.lnk_within).links.push_back(lnk); + mappedb(pinp.lnk_within).links.push_back(std::move(lnk)); ++mappedb(pinp.lnk_within).n_links; } } @@ -240,7 +241,7 @@ class Decorator link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0; lnk.start = link_endpoint_t{ bb.id,bb.idx,7 }; lnk.end = link_endpoint_t{ aa.id,aa.idx,aa.idx == -2 ? 10 : 7 }; - mappedb(aa.lnk_within).links.push_back(lnk); + mappedb(aa.lnk_within).links.push_back(std::move(lnk)); ++mappedb(aa.lnk_within).n_links; conn = true; break; } @@ -268,7 +269,7 @@ class Decorator link_t lnk; lnk.id = 0; lnk.type = 2; lnk.point_count = 0; lnk.start = link_endpoint_t{ aa.id,aa.idx,8 }; lnk.end = dendp; - mappedb(aa.lnk_within).links.push_back(lnk); + mappedb(aa.lnk_within).links.push_back(std::move(lnk)); ++mappedb(aa.lnk_within).n_links; conn = true; break; } @@ -280,7 +281,7 @@ class Decorator pio_pos_t sshp = GetShortcutParamPos(ssp.lnk_within, dest->GetID()); lnk.start = link_endpoint_t{ ssp.id,ssp.idx,8 }; lnk.end = link_endpoint_t{ sshp.id,sshp.idx,5 }; - mappedb(ssp.lnk_within).links.push_back(lnk); + mappedb(ssp.lnk_within).links.push_back(std::move(lnk)); ++mappedb(ssp.lnk_within).n_links; } else ctx->OutputToConsoleEx("pout: can't connect %d <-> %d, dest type is %d", po->GetID(), dest->GetID(), dest->GetClassID()); @@ -631,7 +632,7 @@ class Decorator lnk.end.index = blink->GetOutBehaviorIO()->GetOwner()->GetOutputPosition(blink->GetOutBehaviorIO()); lnk.end.type = 13; } - bb.links.push_back(lnk); + bb.links.push_back(std::move(lnk)); } for (int i = 0, c = beh->GetParameterOperationCount(); i> bq; bq.push(std::make_pair(beh, 0)); while (!bq.empty()) diff --git a/Generator.cpp b/Generator.cpp index 41203e8..a700208 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -14,7 +14,7 @@ class Generator size_t needed = this->genbuffer_currsor + size_in_char; if (needed > this->genbuffer_length) { // if ordered buffer too low, allocated 512 DWORD directly - needed = std::max(needed, 1024u * sizeof(DWORD)); + needed = this->genbuffer_currsor + std::max(size_in_char, 1024u * sizeof(DWORD)); // create new buffer char* newbuf = new char[needed]; diff --git a/VirtoolsScriptDeobfuscation.vcxproj b/VirtoolsScriptDeobfuscation.vcxproj index 40a7a18..e64662b 100644 --- a/VirtoolsScriptDeobfuscation.vcxproj +++ b/VirtoolsScriptDeobfuscation.vcxproj @@ -55,7 +55,6 @@ - Disabled $(VIRTOOLS_INCLUDE_PATH);%(AdditionalIncludeDirectories) WIN32;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_DEPRECATE;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) EnableFastChecks @@ -71,6 +70,7 @@ precomp.h $(IntDir)$(ProjectName).pch stdcpp17 + Disabled ck2.lib;vxmath.lib;%(AdditionalDependencies)