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 diff --git a/ASTree.cpp b/ASTree.cpp index 63a894e87..205c5aac2 100644 --- a/ASTree.cpp +++ b/ASTree.cpp @@ -1218,7 +1218,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(); @@ -2808,10 +2816,16 @@ void print_src(PycRef node, PycModule* mod, std::ostream& pyc_output) 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, pyc_output); @@ -3341,7 +3355,7 @@ void decompyle(PycRef code, PycModule* mod, std::ostream& pyc_output) 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) { diff --git a/pyc_string.cpp b/pyc_string.cpp index e43e1905c..e9b62ca86 100644 --- a/pyc_string.cpp +++ b/pyc_string.cpp @@ -2,58 +2,60 @@ #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 PycString::print(std::ostream &pyc_output, PycModule* mod, bool triple, diff --git a/pycdc.cpp b/pycdc.cpp index 7bb6bd267..23953a5c3 100644 --- a/pycdc.cpp +++ b/pycdc.cpp @@ -89,7 +89,7 @@ int main(int argc, char* argv[]) } const char* dispname = strrchr(infile, PATHSEP); dispname = (dispname == NULL) ? infile : dispname + 1; - *pyc_output << "# Source Generated with Decompyle++\n"; + *pyc_output << "# Source Generated with Decompyle++ , apply in pydumpck\n"; formatted_print(*pyc_output, "# File: %s (Python %d.%d%s)\n\n", dispname, mod.majorVer(), mod.minorVer(), (mod.majorVer() < 3 && mod.isUnicode()) ? " Unicode" : "");