-
Notifications
You must be signed in to change notification settings - Fork 655
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
467 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
# IDE/Filesystem | ||
.idea | ||
.vscode | ||
.DS_Store | ||
|
||
*.swp | ||
*.swo | ||
*.gcno | ||
*.gcda | ||
*.kdev4 | ||
/.kdev4 | ||
|
||
# Python | ||
__pycache__ | ||
*.egg-info | ||
.venv | ||
build/ | ||
|
||
# Build outputs | ||
bytes/*.cpp | ||
*.so | ||
*.o | ||
*.a | ||
|
||
# Test artifacts | ||
tests/*.tok.* | ||
tests/*.src.* | ||
tests/*.err | ||
tests/tests | ||
|
||
# CMake/Ninja artifacts | ||
*.cmake | ||
cmake-build-debug/ | ||
CMakeFiles/ | ||
Testing/ | ||
CMakeCache.txt | ||
build.ninja | ||
.ninja_deps | ||
.ninja_log | ||
|
||
# Executables | ||
pycdc | ||
pycdas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Find the interpreter as well for byte files generation | ||
find_package(Python COMPONENTS Interpreter Development REQUIRED) | ||
|
||
# Find pybind11 | ||
execute_process( | ||
COMMAND ${Python_EXECUTABLE} -c "import pybind11; print(pybind11.get_cmake_dir(), end='')" | ||
OUTPUT_VARIABLE pybind11_DIR | ||
) | ||
find_package(pybind11 CONFIG REQUIRED) | ||
|
||
# Create C library | ||
pybind11_add_module(bindings | ||
bindings.cpp | ||
../pycdc.cpp | ||
../ASTree.cpp | ||
../ASTNode.cpp | ||
) | ||
|
||
target_include_directories(bindings PRIVATE pybind11::headers ${Python_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}) | ||
target_link_libraries(bindings PRIVATE pycxx) | ||
|
||
if (NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/lib") | ||
endif () | ||
|
||
target_compile_definitions( | ||
bindings | ||
PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sys | ||
|
||
from .bindings import decompyle as _decompyle | ||
|
||
__version__ = '0.0.1' | ||
|
||
|
||
def decompyle(code, version=(sys.version_info.major, sys.version_info.minor)): | ||
""" | ||
Decompyle the given code object. | ||
Parameters | ||
---------- | ||
code : bytes | ||
The code object to decompile. | ||
version : tuple, optional | ||
The Python version to decompile for. Defaults to the current Python version. | ||
Use None or (0, 0) to infer the Python version from the code object. This will | ||
not work for marshalled code objects. | ||
""" | ||
if version is None: | ||
return _decompyle(code, 0, 0) | ||
else: | ||
return _decompyle(code, version[0], version[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma clang diagnostic push | ||
#pragma ide diagnostic ignored "cppcoreguidelines-narrowing-conversions" | ||
|
||
#include <Python.h> | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/pytypes.h> | ||
#include <vector> | ||
#include <cstring> | ||
#include <ostream> | ||
#include <sstream> | ||
#include <optional> | ||
#include "ASTree.h" | ||
|
||
namespace py = pybind11; | ||
|
||
|
||
#ifdef WIN32 | ||
# define PATHSEP '\\' | ||
#else | ||
# define PATHSEP '/' | ||
#endif | ||
|
||
py::str decompyle_binding(py::bytes &data, int major_version, int minor_version) { | ||
PycModule mod; | ||
auto str = data.cast<std::string>(); | ||
PycBuffer buffer( | ||
reinterpret_cast<const unsigned char*>(str.c_str()), | ||
str.size() | ||
); | ||
|
||
if (major_version == 0 && minor_version == 0) { | ||
mod.loadFromStream(buffer); | ||
} | ||
else { | ||
mod.loadFromMarshalledStream( | ||
buffer, | ||
major_version, | ||
minor_version | ||
); | ||
} | ||
std::ostringstream pyc_output; | ||
decompyle(mod.code(), &mod, pyc_output); | ||
return pyc_output.str(); | ||
} | ||
|
||
PYBIND11_MODULE(bindings, m) { | ||
m.doc() = "pycdcpy bindings"; | ||
m.def("decompyle", &decompyle_binding, "Decompile a marshalled python file"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.