From b3776d0a8c8a9e29f9e4bf1e91ad4fc7af3f09a9 Mon Sep 17 00:00:00 2001 From: gogo Date: Sat, 14 Sep 2024 02:46:04 +0200 Subject: [PATCH] set template --- .../workflows/Publish-Python3-Bindings.yml | 89 +++++++++++++++++++ .github/workflows/Testing.yml | 46 ---------- Readme.md | 7 +- pwnlib/tubes/Makefile | 8 +- pwnlib/tubes/process.c | 42 --------- pwnlib/tubes/process.cpp | 53 +++++++++++ pwnlib/tubes/process.h | 10 --- pwnlib/tubes/process.hpp | 16 ++++ pwnlib/tubes/process.i | 4 +- 9 files changed, 168 insertions(+), 107 deletions(-) delete mode 100644 .github/workflows/Testing.yml delete mode 100644 pwnlib/tubes/process.c create mode 100644 pwnlib/tubes/process.cpp delete mode 100644 pwnlib/tubes/process.h create mode 100644 pwnlib/tubes/process.hpp diff --git a/.github/workflows/Publish-Python3-Bindings.yml b/.github/workflows/Publish-Python3-Bindings.yml index e69de29..f0007d8 100644 --- a/.github/workflows/Publish-Python3-Bindings.yml +++ b/.github/workflows/Publish-Python3-Bindings.yml @@ -0,0 +1,89 @@ +name: Publish + +on: + push: + branches: + - '*' + tags-ignore: + - '*' + pull_request: + +jobs: + windows-testing: + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + choco install nuget.commandline --yes + nuget install Bison -Version 3.7.4 -OutputDirectory C:\Tools\bison + nuget install PCRE2 -Version 10.39 -OutputDirectory C:\Tools\pcre2 + + git clone https://github.com/swig/swig/ + cd swig + mkdir C:\install\swig + + $env:PATH="C:\Tools\CMake\CMake-win64.3.15.5\bin;C:\Tools\bison\Bison.3.7.4\bin;" + $env:PATH + $PCRE_ROOT="C:\Tools\pcre2\PCRE2.10.39.0" + $PCRE_PLATFORM="x64" + $WORKING_DIR=(Get-Location).ToString() -replace "\\","/" + cmake -G "Visual Studio 17 2022" -A "x64" ` + -DCMAKE_INSTALL_PREFIX="C:\install\swig" ` + -DCMAKE_C_FLAGS="/DPCRE2_STATIC" ` + -DCMAKE_CXX_FLAGS="/DPCRE2_STATIC" ` + -DPCRE2_INCLUDE_DIR="$PCRE_ROOT/include" ` + -DPCRE2_LIBRARY="$PCRE_ROOT/lib/pcre2-8-static.lib" ` + -S . -B build + cmake --build build --config Release + cmake --install build --config Release + + $env:Path += "C:\install\swig" + + cd .. + choco install --yes doxygen.install + choco install --yes doxygen.portable + choco install --yes visualstudio2022community --package-parameters "--add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended --includeOptional" #choco install --yes visualstudio2022community --package-parameters "--allWorkloads --includeRecommended --includeOptional" + choco install --yes windows-sdk-10.0 windowsdriverkit10 + - name: Install catch2 + run: | + git clone https://github.com/catchorg/Catch2 + cd Catch2 ; mkdir build ; cd build + cmake -G "Visual Studio 17 2022" .. + cmake --build . --target install + cd .. + - name: Build + run: | + make all PYENV=C:\hostedtoolcache\windows\Python\3.12.1\x64 + - name: Generate doxygen documentation + run: | + doxygen .\Doxyfile -w html + - name: run C catch2 doctests + run: | + cd testing + mkdir build && cd build + cmake .. + cmake --build . + .\Debug\custom-main-tests.exe + - name: Run Binding Tests + run: | + make all PYENV=C:\hostedtoolcache\windows\Python\3.12.1\x64 + python -c "from pwnlib.tubes.process import Process; p = Process('C:\hostedtoolcache\windows\Python\3.12.1\x64\python.exe'); p.recv(123)" + - name: Clean + run: make clean + + ubuntu-testing: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build + run: echo "hello world" \ No newline at end of file diff --git a/.github/workflows/Testing.yml b/.github/workflows/Testing.yml deleted file mode 100644 index cbce684..0000000 --- a/.github/workflows/Testing.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Testing - -on: - push: - branches: - - '*' - tags-ignore: - - '*' - pull_request: - -jobs: - windows-testing: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-python@v4 - with: - python-version: '3.8' - - - name: Install dependencies - run: | - choco install --yes swig - - name: Build - run: | - make all PYENV=C:\hostedtoolcache\windows\Python\3.8.10\x64 - - name: Run Tests - run: | - make all PYENV=C:\hostedtoolcache\windows\Python\3.8.10\x64 - python -c "from pwnlib.tubes import process; process.send()" - - name: Clean - run: make clean - - ubuntu-testing: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Install swig - run: | - sudo apt install --yes swig - - name: Build - run: echo "hello world" \ No newline at end of file diff --git a/Readme.md b/Readme.md index 94ea038..f9d3fe8 100644 --- a/Readme.md +++ b/Readme.md @@ -13,16 +13,17 @@ As the dev have some experience with the old pwntools, the new tool aims to fix # I.1 Install building dependencies ``` -choco install --yes python --version 3.8.0 +choco install --yes python --version 3.13.0-rc2 choco install --yes swig +choco install --yes llvm ``` # I.2 Build/Clean project -In order to build pwnto-driver including swig bindings, you must specify your python path. For example, if you installed python 3 with the command `choco install --yes python --version 3.8.0`, the you could build with: +In order to build pwnto-driver including swig bindings, you must specify your python path. For example, if you installed python 3 with the command `choco install --yes python --version 3.13.0-rc2`, the you could build with: ```shell -make all PYENV=C:\Python38 +make all PYENV=C:\Python313 ``` clean with diff --git a/pwnlib/tubes/Makefile b/pwnlib/tubes/Makefile index 8663053..78e4a85 100644 --- a/pwnlib/tubes/Makefile +++ b/pwnlib/tubes/Makefile @@ -5,10 +5,10 @@ INC=-I include/ all: swig-all swig-all: - swig -python process.i - gcc -O2 -fPIC -c process.c - gcc -O2 -fPIC -c process_wrap.c -I"$(PYENV)\include" - gcc -shared process.o process_wrap.o -o _process.pyd -L "$(PYENV)\libs" -l python3 + swig -c++ -python process.i + clang++ -O2 -shared -c process.cpp + clang++ -O2 -shared -c process_wrap.cxx -I"$(PYENV)\include" + clang++ -shared process.o process_wrap.o -o _process.pyd -L "$(PYENV)\libs" -l python3 clean: @rm process.o diff --git a/pwnlib/tubes/process.c b/pwnlib/tubes/process.c deleted file mode 100644 index c4738d5..0000000 --- a/pwnlib/tubes/process.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include "process.h" - -Process proc; - -void process (char *command) { - /** - * @brief open a file. - * - * @param file , the file to execute. - * @return Nothing. - * - * @test - * File * fdesc = process("python"); - * //CHECK(p.recv(5) == "Hello"); - */ - - - printf("hello\n"); -} - -void recv(int size) { - char *buff; - fgets(buff, sizeof(size), proc.process_PID); -} - -void send () { - printf("hey!"); -} - -void libs() { - -} - -void libc() { - -} - -void bin() { - -} \ No newline at end of file diff --git a/pwnlib/tubes/process.cpp b/pwnlib/tubes/process.cpp new file mode 100644 index 0000000..2a3b4ab --- /dev/null +++ b/pwnlib/tubes/process.cpp @@ -0,0 +1,53 @@ +#include +#include +#include + +#include "process.hpp" + + +Process::Process() { + /** + * @brief open a file. + * + * @param file , the file to execute. + * @return Nothing. + * + * @test + * File * fdesc = process("python"); + * //CHECK(p.recv(5) == "Hello"); + */ + + printf("executing...\n"); +} + +Process::~Process() { + std::cout << " destroying process." << std::endl; +} + +void Process::recv(int size) { + +} + +void Process::send() { + +} + +void Process::libs() { + +} + +void Process::libc() { + +} + +void Process::bin() { + +} + +/* +void recv(int size) { + char *buff; + fgets(buff, sizeof(size), proc.process_PID); +} + +*/ \ No newline at end of file diff --git a/pwnlib/tubes/process.h b/pwnlib/tubes/process.h deleted file mode 100644 index cc61080..0000000 --- a/pwnlib/tubes/process.h +++ /dev/null @@ -1,10 +0,0 @@ -typedef struct { - FILE *process_PID; -} Process; - -void process (char *command); -void recv(int size); -void send(); -void libs(); -void libc(); -void bin(); \ No newline at end of file diff --git a/pwnlib/tubes/process.hpp b/pwnlib/tubes/process.hpp new file mode 100644 index 0000000..b960321 --- /dev/null +++ b/pwnlib/tubes/process.hpp @@ -0,0 +1,16 @@ +#include +#include +#include + +class Process { + public: + Process(); + ~Process(); + void recv(int size); + void send(); + void libs(); + void libc(); + void bin(); + private: + int processPid; +}; \ No newline at end of file diff --git a/pwnlib/tubes/process.i b/pwnlib/tubes/process.i index 5cebee8..3ed2f7f 100644 --- a/pwnlib/tubes/process.i +++ b/pwnlib/tubes/process.i @@ -1,6 +1,6 @@ %module process %{ -#include "process.h" +#include "process.hpp" %} -%include "process.h" \ No newline at end of file +%include "process.hpp" \ No newline at end of file