Merge uncommitted changes from old SVN copy
This commit is contained in:
62
ASTree.cpp
62
ASTree.cpp
@@ -152,11 +152,11 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
case (PY_2000 | Py2k::BINARY_SUBSCR):
|
||||
case (PY_3000 | Py3k::BINARY_SUBSCR):
|
||||
{
|
||||
PycRef<ASTNode> right = stack.top();
|
||||
PycRef<ASTNode> subscr = stack.top();
|
||||
stack.pop();
|
||||
PycRef<ASTNode> left = stack.top();
|
||||
PycRef<ASTNode> src = stack.top();
|
||||
stack.pop();
|
||||
stack.push(new ASTBinary(left, right, ASTBinary::BIN_SUBSCR));
|
||||
stack.push(new ASTSubscr(src, subscr));
|
||||
}
|
||||
break;
|
||||
case (PY_1000 | Py1k::BINARY_SUBTRACT):
|
||||
@@ -524,6 +524,13 @@ PycRef<ASTNode> BuildFromCode(PycRef<PycCode> code, PycModule* mod)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (PY_1000 | Py1k::UNARY_CALL):
|
||||
{
|
||||
PycRef<ASTNode> func = stack.top();
|
||||
stack.pop();
|
||||
stack.push(new ASTCall(func, ASTCall::pparam_t(), ASTCall::kwparam_t()));
|
||||
}
|
||||
break;
|
||||
case (PY_1000 | Py1k::UNARY_INVERT):
|
||||
case (PY_2000 | Py2k::UNARY_INVERT):
|
||||
case (PY_3000 | Py3k::UNARY_INVERT):
|
||||
@@ -830,17 +837,25 @@ void print_src(PycRef<ASTNode> node, PycModule* mod, int indent)
|
||||
} else if (src->type() == ASTNode::NODE_IMPORT) {
|
||||
PycRef<ASTImport> import = src.cast<ASTImport>();
|
||||
if (import->fromlist() != Node_NULL) {
|
||||
PycRef<PycTuple> fromlist = import->fromlist().cast<ASTObject>()->object().cast<PycTuple>();
|
||||
if (fromlist != Pyc_None && fromlist->size() != 0) {
|
||||
PycRef<PycObject> fromlist = import->fromlist().cast<ASTObject>()->object();
|
||||
if (fromlist != Pyc_None) {
|
||||
printf("from ");
|
||||
print_src(import->name(), mod, indent);
|
||||
if (import->name()->type() == ASTObject::NODE_IMPORT)
|
||||
print_src(import->name().cast<ASTImport>()->name(), mod, indent);
|
||||
else
|
||||
print_src(import->name(), mod, indent);
|
||||
printf(" import ");
|
||||
bool first = true;
|
||||
PycTuple::value_t::const_iterator ii = fromlist->values().begin();
|
||||
for (; ii != fromlist->values().end(); ++ii) {
|
||||
if (!first) printf(", ");
|
||||
printf("%s", ii->cast<PycString>()->value());
|
||||
first = false;
|
||||
if (fromlist->type() == ASTObject::NODE_TUPLE) {
|
||||
bool first = true;
|
||||
PycTuple::value_t::const_iterator ii = fromlist.cast<PycTuple>()->values().begin();
|
||||
for (; ii != fromlist.cast<PycTuple>()->values().end(); ++ii) {
|
||||
if (!first)
|
||||
printf(", ");
|
||||
printf("%s", ii->cast<PycString>()->value());
|
||||
first = false;
|
||||
}
|
||||
} else {
|
||||
printf("%s", fromlist.cast<PycString>()->value());
|
||||
}
|
||||
} else {
|
||||
printf("import ");
|
||||
@@ -851,9 +866,26 @@ void print_src(PycRef<ASTNode> node, PycModule* mod, int indent)
|
||||
print_src(import->name(), mod, indent);
|
||||
}
|
||||
} else {
|
||||
print_src(dest, mod, indent);
|
||||
printf(" = ");
|
||||
print_src(src, mod, indent);
|
||||
if (dest->type() == ASTNode::NODE_NAME &&
|
||||
dest.cast<ASTName>()->name()->isEqual("__doc__")) {
|
||||
if (src->type() == ASTNode::NODE_OBJECT) {
|
||||
PycRef<PycObject> obj = src.cast<ASTObject>()->object();
|
||||
if (obj->type() == PycObject::TYPE_STRING ||
|
||||
obj->type() == PycObject::TYPE_INTERNED ||
|
||||
obj->type() == PycObject::TYPE_STRINGREF)
|
||||
OutputString(obj.cast<PycString>(), (mod->majorVer() == 3) ? 'b' : 0, true);
|
||||
else if (obj->type() == PycObject::TYPE_UNICODE)
|
||||
OutputString(obj.cast<PycString>(), (mod->majorVer() == 3) ? 0 : 'u', true);
|
||||
} else {
|
||||
print_src(dest, mod, indent);
|
||||
printf(" = ");
|
||||
print_src(src, mod, indent);
|
||||
}
|
||||
} else {
|
||||
print_src(dest, mod, indent);
|
||||
printf(" = ");
|
||||
print_src(src, mod, indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
51
pycdas.cpp
51
pycdas.cpp
@@ -5,6 +5,48 @@
|
||||
#include "bytecode.h"
|
||||
#include "numeric.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# define PATHSEP '\\'
|
||||
#else
|
||||
# define PATHSEP '/'
|
||||
#endif
|
||||
|
||||
static const char* flag_names[] = {
|
||||
"CO_OPTIMIZED", "CO_NEWLOCALS", "CO_VARARGS", "CO_VARKEYWORDS",
|
||||
"CO_NESTED", "CO_GENERATOR", "CO_NOFREE", "<0x80>", "<0x100>", "<0x200>",
|
||||
"<0x400>", "<0x800>", "CO_GENERATOR_ALLOWED", "CO_FUTURE_DIVISION",
|
||||
"CO_FUTURE_ABSOLUTE_IMPORT", "CO_FUTURE_WITH_STATEMENT",
|
||||
"CO_FUTURE_PRINT_FUNCTION", "CO_FUTURE_UNICODE_LITERALS",
|
||||
"CO_FUTURE_BARRY_AS_BDFL", "<0x80000>", "<0x100000>", "<0x200000>",
|
||||
"<0x400000>", "<0x800000>", "<0x1000000>", "<0x2000000>", "<0x4000000>",
|
||||
"<0x8000000>", "<0x10000000>", "<0x20000000>", "<0x40000000>",
|
||||
"<0x80000000>"
|
||||
};
|
||||
|
||||
static void print_coflags(unsigned long flags)
|
||||
{
|
||||
if (flags == 0) {
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printf(" (");
|
||||
unsigned long f = 1;
|
||||
int k = 0;
|
||||
while (k < 32) {
|
||||
if ((flags & f) != 0) {
|
||||
flags &= ~f;
|
||||
if (flags == 0)
|
||||
printf("%s", flag_names[k]);
|
||||
else
|
||||
printf("%s | ", flag_names[k]);
|
||||
}
|
||||
++k;
|
||||
f <<= 1;
|
||||
}
|
||||
printf(")\n");
|
||||
}
|
||||
|
||||
static void ivprintf(int indent, const char* fmt, va_list varargs)
|
||||
{
|
||||
for (int i=0; i<indent; i++)
|
||||
@@ -33,7 +75,8 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent)
|
||||
iprintf(indent + 1, "Arg Count: %d\n", codeObj->argCount());
|
||||
iprintf(indent + 1, "Locals: %d\n", codeObj->numLocals());
|
||||
iprintf(indent + 1, "Stack Size: %d\n", codeObj->stackSize());
|
||||
iprintf(indent + 1, "Flags: 0x%08X\n", codeObj->flags());
|
||||
iprintf(indent + 1, "Flags: 0x%08X", codeObj->flags());
|
||||
print_coflags(codeObj->flags());
|
||||
|
||||
if (codeObj->names() != Pyc_NULL) {
|
||||
iprintf(indent + 1, "[Names]\n");
|
||||
@@ -154,12 +197,6 @@ void output_object(PycRef<PycObject> obj, PycModule* mod, int indent)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
# define PATHSEP '\\'
|
||||
#else
|
||||
# define PATHSEP '/'
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
|
11
pycdc.cpp
11
pycdc.cpp
@@ -1,5 +1,12 @@
|
||||
#include <cstring>
|
||||
#include "ASTree.h"
|
||||
|
||||
#ifdef WIN32
|
||||
# define PATHSEP '\\'
|
||||
#else
|
||||
# define PATHSEP '/'
|
||||
#endif
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
@@ -13,8 +20,10 @@ int main(int argc, char* argv[])
|
||||
fprintf(stderr, "Could not load file %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
const char* dispname = strrchr(argv[1], PATHSEP);
|
||||
dispname = (dispname == NULL) ? argv[1] : dispname + 1;
|
||||
printf("# Source Generated with Decompyle++\n");
|
||||
printf("# File: %s (Python %d.%d%s)\n", argv[1], mod.majorVer(), mod.minorVer(),
|
||||
printf("# File: %s (Python %d.%d%s)\n", dispname, mod.majorVer(), mod.minorVer(),
|
||||
(mod.majorVer() < 3 && mod.isUnicode()) ? " Unicode" : "");
|
||||
decompyle(mod.code(), &mod);
|
||||
|
||||
|
10
string.cpp
10
string.cpp
@@ -76,7 +76,10 @@ void OutputString(PycRef<PycString> str, char prefix, bool triple, FILE* F)
|
||||
len = str->length();
|
||||
|
||||
// Output the string
|
||||
fputc(useQuotes ? '"' : '\'', F);
|
||||
if (triple)
|
||||
fprintf(F, useQuotes ? "\"\"\"" : "'''");
|
||||
else
|
||||
fputc(useQuotes ? '"' : '\'', F);
|
||||
while (len--) {
|
||||
if (*ch < 0x20 || *ch == 0x7F) {
|
||||
if (*ch == '\r') {
|
||||
@@ -108,5 +111,8 @@ void OutputString(PycRef<PycString> str, char prefix, bool triple, FILE* F)
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
fputc(useQuotes ? '"' : '\'', F);
|
||||
if (triple)
|
||||
fprintf(F, useQuotes ? "\"\"\"" : "'''");
|
||||
else
|
||||
fputc(useQuotes ? '"' : '\'', F);
|
||||
}
|
||||
|
Reference in New Issue
Block a user