From 669d3b1f0bf2b590f2faca19898a5d541c1be7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E5=B9=BF?= Date: Sun, 29 May 2022 12:43:22 +0800 Subject: [PATCH 1/4] feat[junk-code]support remove jump-abs junk --- ASTree.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ASTree.cpp b/ASTree.cpp index 62bb4eb49..2a86a0fb3 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1331,7 +1331,15 @@ PycRef BuildFromCode(PycRef code, PycModule* mod) } break; } - + // should check if stack_history has any item,if empty ,that count be a `junkcode-absjump` + if (!stack_hist.size()) { + // reset to next byte of JUMP_ABS + for (int i = 0; i < 4; i++) { + pos++; + source.getByte(); + } + break; + } stack = stack_hist.top(); stack_hist.pop(); @@ -2843,10 +2851,16 @@ void print_src(PycRef node, PycModule* mod) auto map = new ASTMap; for (const auto& key : keys) { // Values are pushed onto the stack in reverse order. - PycRef value = values.back(); - values.pop_back(); + if (values.size() > 0) { + PycRef value = values.back(); + values.pop_back(); + map->add(new ASTObject(key), value); + } + else { + map->add(new ASTObject(key), PycRef()); + } - map->add(new ASTObject(key), value); + } print_src(map, mod); @@ -3401,7 +3415,7 @@ void decompyle(PycRef code, PycModule* mod) clean->removeFirst(); } } - if (clean->nodes().back().type() == ASTNode::NODE_RETURN) { + if (clean->nodes().size() && clean->nodes().back().type() == ASTNode::NODE_RETURN) { PycRef ret = clean->nodes().back().cast(); if (ret->value() == NULL || ret->value().type() == ASTNode::NODE_LOCALS) { From 39169a5f4d1e88da9fe45af60fb30c89e7d176fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E5=B9=BF?= Date: Thu, 26 Jan 2023 18:16:15 +0800 Subject: [PATCH 2/4] feat[header]add-banner --- pycdc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycdc.cpp b/pycdc.cpp index a114a3f45..580828b59 100644 --- a/pycdc.cpp +++ b/pycdc.cpp @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) } const char* dispname = strrchr(infile, PATHSEP); dispname = (dispname == NULL) ? infile : dispname + 1; - fputs("# Source Generated with Decompyle++\n", pyc_output); + fputs("# Source Generated with Decompyle++ , apply in pydumpck\n", pyc_output); fprintf(pyc_output, "# File: %s (Python %d.%d%s)\n\n", dispname, mod.majorVer(), mod.minorVer(), (mod.majorVer() < 3 && mod.isUnicode()) ? " Unicode" : ""); try { From 91460b60551cad841927ed79acd43da6dda3a2c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E5=B9=BF?= Date: Thu, 26 Jan 2023 18:17:02 +0800 Subject: [PATCH 3/4] fix[pyc-string]unicode judge condition --- pyc_string.cpp | 233 ++++++++++++++++++++++++++----------------------- 1 file changed, 122 insertions(+), 111 deletions(-) diff --git a/pyc_string.cpp b/pyc_string.cpp index 3c8befd61..460e23a7d 100644 --- a/pyc_string.cpp +++ b/pyc_string.cpp @@ -2,138 +2,149 @@ #include "pyc_module.h" #include "data.h" #include +#include static bool check_ascii(const std::string& data) { - auto cp = reinterpret_cast(data.c_str()); - while (*cp) { - if (*cp & 0x80) - return false; - ++cp; - } - return true; + auto cp = reinterpret_cast(data.c_str()); + while (*cp) { + if (*cp & 0x80) + return false; + ++cp; + } + return true; } /* PycString */ void PycString::load(PycData* stream, PycModule* mod) { - if (type() == TYPE_STRINGREF) { - PycRef str = mod->getIntern(stream->get32()); - m_type = str->m_type; - m_value = str->m_value; - } else { - int length; - if (type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) - length = stream->getByte(); - else - length = stream->get32(); + if (type() == TYPE_STRINGREF) { + PycRef str = mod->getIntern(stream->get32()); + m_type = str->m_type; + m_value = str->m_value; + } + else { + int length; + if (type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) + length = stream->getByte(); + else + length = stream->get32(); - if (length < 0) - throw std::bad_alloc(); + if (length < 0) + throw std::bad_alloc(); - m_value.resize(length); - if (length) { - stream->getBuffer(length, &m_value.front()); - if (type() == TYPE_ASCII || type() == TYPE_ASCII_INTERNED || - type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) { - if (!check_ascii(m_value)) - throw std::runtime_error("Invalid bytes in ASCII string"); - } - } + m_value.resize(length); + if (length) { + stream->getBuffer(length, &m_value.front()); + if (type() == TYPE_ASCII || type() == TYPE_ASCII_INTERNED || + type() == TYPE_SHORT_ASCII || type() == TYPE_SHORT_ASCII_INTERNED) { + if (!check_ascii(m_value)) + throw std::runtime_error("Invalid bytes in ASCII string"); + } + } - if (type() == TYPE_INTERNED || type() == TYPE_ASCII_INTERNED || - type() == TYPE_SHORT_ASCII_INTERNED) - mod->intern(this); - } + if (type() == TYPE_INTERNED || type() == TYPE_ASCII_INTERNED || + type() == TYPE_SHORT_ASCII_INTERNED) + mod->intern(this); + } } bool PycString::isEqual(PycRef obj) const { - if (type() != obj.type()) - return false; + if (type() != obj.type()) + return false; - PycRef strObj = obj.cast(); - return isEqual(strObj->m_value); + PycRef strObj = obj.cast(); + return isEqual(strObj->m_value); } void OutputString(PycRef str, char prefix, bool triple, FILE* F, const char* parent_f_string_quote) { - if (prefix != 0) - fputc(prefix, F); + if (prefix != 0) + fputc(prefix, F); - const char* ch = str->value(); - int len = str->length(); - if (ch == 0) { - fputs("''", F); - return; - } + const char* ch = str->value(); + int len = str->length(); + if (ch == 0) { + fputs("''", F); + return; + } - // Determine preferred quote style (Emulate Python's method) - bool useQuotes = false; - if (!parent_f_string_quote) { - while (len--) { - if (*ch == '\'') { - useQuotes = true; - } else if (*ch == '"') { - useQuotes = false; - break; - } - ch++; - } - } else { - useQuotes = parent_f_string_quote[0] == '"'; - } - ch = str->value(); - len = str->length(); + // Determine preferred quote style (Emulate Python's method) + bool useQuotes = false; + if (!parent_f_string_quote) { + while (len--) { + if (*ch == '\'') { + useQuotes = true; + } + else if (*ch == '"') { + useQuotes = false; + break; + } + ch++; + } + } + else { + useQuotes = parent_f_string_quote[0] == '"'; + } + ch = str->value(); + len = str->length(); - // Output the string - if (!parent_f_string_quote) { - if (triple) - fputs(useQuotes ? "\"\"\"" : "'''", F); - else - fputc(useQuotes ? '"' : '\'', F); - } - while (len--) { - if (*ch < 0x20 || *ch == 0x7F) { - if (*ch == '\r') { - fputs("\\r", F); - } else if (*ch == '\n') { - if (triple) - fputc('\n', F); - else - fputs("\\n", F); - } else if (*ch == '\t') { - fputs("\\t", F); - } else { - fprintf(F, "\\x%02x", (*ch & 0xFF)); - } - } else if ((unsigned char)(*ch) >= 0x80) { - if (str->type() == PycObject::TYPE_UNICODE) { - // Unicode stored as UTF-8... Let the stream interpret it - fputc(*ch, F); - } else { - fprintf(F, "\\x%x", (*ch & 0xFF)); - } - } else { - if (!useQuotes && *ch == '\'') - fputs("\\'", F); - else if (useQuotes && *ch == '"') - fputs("\\\"", F); - else if (*ch == '\\') - fputs("\\\\", F); - else if (parent_f_string_quote && *ch == '{') - fputs("{{", F); - else if (parent_f_string_quote && *ch == '}') - fputs("}}", F); - else - fputc(*ch, F); - } - ch++; - } - if (!parent_f_string_quote) { - if (triple) - fputs(useQuotes ? "\"\"\"" : "'''", F); - else - fputc(useQuotes ? '"' : '\'', F); - } + // Output the string + if (!parent_f_string_quote) { + if (triple) + fputs(useQuotes ? "\"\"\"" : "'''", F); + else + fputc(useQuotes ? '"' : '\'', F); + } + + while (len--) { + if ((*ch > 0 && *ch < 0x20) || *ch == 0x7F) { + if (*ch == '\r') { + fputs("\\r", F); + } + else if (*ch == '\n') { + if (triple) + fputc('\n', F); + else + fputs("\\n", F); + } + else if (*ch == '\t') { + fputs("\\t", F); + } + else { + fprintf(F, "\\x%02x", (*ch & 0xFF)); + } + } + else if ((unsigned char)(*ch) >= 0x80) { + if (str->type() == PycObject::TYPE_UNICODE) { + // Unicode stored as UTF-8... Let the stream interpret it + fputc(*ch, F); + } + else { + fprintf(F, "\\x%x", (*ch & 0xFF)); + } + } + else { + if (!useQuotes && *ch == '\'') + fputs("\\'", F); + else if (useQuotes && *ch == '"') + fputs("\\\"", F); + else if (*ch == '\\') + fputs("\\\\", F); + else if (parent_f_string_quote && *ch == '{') + fputs("{{", F); + else if (parent_f_string_quote && *ch == '}') + fputs("}}", F); + else + fputc(*ch, F); + } + ch++; + } + if (!parent_f_string_quote) { + if (triple) + fputs(useQuotes ? "\"\"\"" : "'''", F); + else + fputc(useQuotes ? '"' : '\'', F); + } } From 4fb8af5cb95cac98139c800a5482cbe847072ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=89=E5=B9=BF?= Date: Fri, 13 Oct 2023 21:46:20 +0800 Subject: [PATCH 4/4] feat[git]remove project-template-files --- .gitignore | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index 6237ddae6..c3b3fdc1a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,20 @@ *.kdev4 /.kdev4 __pycache__ +/bytes +/CMake* +/Debug +/.vs +ALL_BUILD* +*.vcxproj +*.filter +*.filters +*.recipe +*.log +*.tlog +*.obj +*.exe +*.pdb +*.txt +*.ilk +*.sln