Skip to content

Commit 18f79a2

Browse files
Add files via upload
# Conflicts: # CMakeLists.txt # README.md # example/hwrng_example.py # example/process_inspect_example.py # src/hRng.c # tool/compilerHelper.ps1
1 parent 76ad11e commit 18f79a2

File tree

8 files changed

+340
-1206
lines changed

8 files changed

+340
-1206
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
cmake_minimum_required(VERSION 4.0)
2-
project(pyCTools C)
2+
project(example/pyCTools C)
33

44
set(CMAKE_C_STANDARD 11)
55

66
add_library(PyCTools SHARED
77
src/hRng.c
88
src/processInspect.c)
9-
# Unused really, but kept for reference

README.md

Lines changed: 43 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
1-
<div align="center">
2-
<h1>PyCTools</h1>
3-
<img src="https://img.shields.io/badge/license-MIT-blue" alt="License" />
4-
<img src="https://img.shields.io/badge/platform-Windows-lightgray" alt="Platform" />
5-
<img src="https://img.shields.io/github/languages/top/DefinetlyNotAI/PyCTools" alt="Languages" />
6-
<img src="https://img.shields.io/github/v/tag/DefinetlyNotAI/PyCTools" alt="Version" />
7-
</div>
8-
9-
> [!NOTE]
10-
> There are multiple ways to install the pyCTools library!
11-
>
12-
> * **Manual installation:**
13-
>
14-
> 1. Clone the repository and build the DLLs yourself.
15-
> 2. Run `python ./tools/setup.py bdist_wheel` to create the wheel file.
16-
> 3. The setup script will show you how to install the package locally with pip and how to create a virtual environment for testing.
17-
> * **Automatic installation:**
18-
> Go to the [releases page](https://github.com/DefinetlyNotAI/PyCTools/releases) and select the version you wish to install, and click on it, then copy the top `pip` command that will allow you to install it
19-
> [Auto installation support from v0.2.0-beta and above]
20-
1+
# Project Overview
212

223
This project provides a cross-language toolkit for Windows process inspection and hardware random number generation, with both Python and C components. It includes:
234

@@ -26,101 +7,56 @@ This project provides a cross-language toolkit for Windows process inspection an
267
- **Example Python scripts**: Demonstrate usage of the library.
278
- **PowerShell build helper**: Automates DLL compilation for x86/x64.
289

29-
> [!IMPORTANT]
30-
> To get the `dist` binary folder, choose **one** of the following options:
31-
>
32-
> | Method | Description | Requirements |
33-
> |--------------------------|--------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|
34-
> | Manual Build | Compile the binaries yourself using `cl.exe` or similar toolchains | Microsoft Visual Studio with MSVC installed |
35-
> | Auto Build Script | Run the [`tool/compilerHelper.ps1`](tool/compilerHelper.ps1) PowerShell script | Visual Studio Build Tools + PowerShell |
36-
> | Prebuilt Release Archive | Download precompiled binaries from the [releases page](https://github.com/DefinetlyNotAI/PyCTools/releases/) | None, make sure to use the latest available version |
37-
>
38-
> No matter what you decide, do still read the important notice about the `dist` from the [release](https://github.com/DefinetlyNotAI/PyCTools/releases/) OR check the [Wiki](https://github.com/DefinetlyNotAI/PyCTools/wiki#dll-discovery-and-dist-directory) page about the DLL discovery explanation.
39-
4010
## Directory Structure
4111

42-
<details>
43-
<summary>📁 Project Structure (click to expand)</summary>
44-
45-
root/
46-
├── bin/ # Auto-generated folder containing compiled DLL binaries
47-
│ ├── x86/ # 32-bit DLL builds
48-
│ └── x64/ # 64-bit DLL builds
49-
50-
├── dist/ # Release artifacts for distribution
51-
│ ├── bin.zip # Zipped prebuilt binaries
52-
│ └── bin.zip.sha256 # SHA256 checksum for `bin.zip`
53-
54-
├── examples/ # Example Python scripts demonstrating usage
55-
│ ├── hwrng_example.py # Example: Hardware RNG usage
56-
│ ├── process_inspect_example.py # Example: Process inspection usage
57-
│ └── rng_tests/ # RNG test scripts and outputs
58-
│ ├── rng_output.bin # 10M bytes of RNG data (complexity 1, threaded)
59-
│ ├── rng_entropy_output.png # PNG entropy visualization of RNG output
60-
│ ├── Results.txt # Test results from `rng_test.py`
61-
│ ├── rng_test.py # Script to test hardware RNG
62-
│ └── generate_bin.py # Generates binary file from RNG
63-
64-
├── pyCTools/ # Python package (library code)
65-
│ ├── __init__.py # Package initializer
66-
│ ├── hwrng.py # Hardware RNG DLL wrapper
67-
│ ├── processInspect.py # Process inspection DLL wrapper
68-
│ └── _loadDLL.py # DLL loading logic used by wrappers
69-
70-
├── tool/ # Build and distribution tools
71-
│ ├── compilerHelper.ps1 # Compiles C code into DLLs
72-
│ └── distributionHelper.ps1 # Creates `bin.zip` and SHA256 checksum
73-
74-
├── src/ # C source code for DLLs
75-
│ ├── hRng.c # Hardware RNG implementation
76-
│ └── processInspect.c # Process inspection implementation
77-
78-
└── CMakeLists.txt # CMake build configuration (currently unused)
79-
80-
</details>
12+
```
13+
example/
14+
pyCTools/
15+
hwrng.py # Python wrapper for hardware RNG DLL
16+
processInspect.py # Python wrapper for process inspection DLL
17+
hwrng_example.py # Example: hardware RNG usage
18+
process_inspect_example.py # Example: process metrics usage
19+
src/
20+
hRng.c # C source for hardware RNG DLL
21+
processInspect.c # C source for process inspection DLL
22+
tool/
23+
compilerHelper.ps1 # PowerShell script to build DLLs for x86/x64
24+
dist/
25+
x64/ # Compiled DLLs for 64-bit
26+
x86/ # Compiled DLLs for 32-bit
27+
```
8128

8229
## Building the DLLs
8330

84-
1. Open **PowerShell** and run:
85-
```powershell
86-
cd ./tool/
87-
compilerHelper.ps1
88-
```
89-
90-
2. Choose the `.c` source files you want to compile.
91-
92-
3. The script will compile for **both x86 and x64** architectures, placing the output in:
93-
- `bin/x86` (32-bit builds)
94-
- `bin/x64` (64-bit builds)
95-
96-
> [!IMPORTANT]
97-
> The build process uses `cl.exe` from the **MSVC toolchain** in Visual Studio, so make sure it’s installed and available in your PATH.
98-
99-
> [!NOTE]
100-
> - Each compiled source produces **four files per architecture**: `.dll`, `.exp`, `.lib`, and `.obj`.
101-
>
102-
> - Only the `.dll` is needed by the Python library.
103-
>
104-
> - DLL filenames include an architecture suffix:
105-
>
106-
> - Example: `hRng_x86.dll`, `hRng_x64.dll`.
31+
1. Open PowerShell and run `tool/compilerHelper.ps1`.
32+
2. Select which `.c` files to compile.
33+
3. The script will build both x86 and x64 DLLs and place them in `dist/x86` and `dist/x64`.
10734

10835
## Using the Python Library
10936

110-
- Place the `dist/` folder inside the `pyCTools` package directory, or at max two levels up the library.
111-
- Import and use `hwrng` or `processInspect` from `pyCTools`.
112-
- The library will automatically load the correct DLL based on your Python interpreter architecture (x86 or x64).
37+
- Place the `dist/` folder as a sibling to your Python scripts or as described in the wrappers.
38+
- Import and use `pyCTools.hwrng` or `pyCTools.processInspect` as shown in the examples.
39+
40+
## Example Usage
11341

114-
> [!TIP]
115-
> Example usages for both modules in detail:
116-
>
117-
> #### Hardware RNG
118-
> Either check out the [example script](example/hwrng_example.py) or the [Wiki page](https://github.com/DefinetlyNotAI/PyCTools/wiki/Py-Documentation-‐-hwrng#methods)
119-
>
120-
> #### Process Inspection
121-
> Either check out the [example script](example/process_inspect_example.py) or the [Wiki page](https://github.com/DefinetlyNotAI/PyCTools/wiki/Py-Documentation-‐-processInspect#methods)
42+
**Hardware RNG:**
43+
```python
44+
from pyCTools.hwrng import get_hardware_random_bytes
45+
rb = get_hardware_random_bytes(16)
46+
print(rb.hex())
47+
```
12248

123-
### DLL Discovery
49+
**Process Inspection:**
50+
```python
51+
from pyCTools.processInspect import ProcessMetrics
52+
metrics = ProcessMetrics()
53+
pid = 1234 # Target PID
54+
flags = ProcessMetrics.METRIC_WORKING_SET | ProcessMetrics.METRIC_CPU_USAGE
55+
snapshot = metrics.get_snapshot(pid, flags)
56+
print(snapshot)
57+
```
58+
59+
## DLL Discovery
12460

12561
The Python wrappers automatically search for the correct DLL in:
12662
- `./dist/{arch}/<dll>`
@@ -129,14 +65,7 @@ The Python wrappers automatically search for the correct DLL in:
12965

13066
where `{arch}` is `x64` or `x86` depending on your Python interpreter.
13167

132-
> More details on how the DLL discovery works can be found in the [Wiki page](https://github.com/DefinetlyNotAI/PyCTools/wiki#dll-discovery-and-dist-directory)
133-
134-
## Extra resources
68+
## License
13569

136-
> [!TIP]
137-
> Want to dive deeper into how everything works? Head over to the [PyCTools Wiki](https://github.com/DefinetlyNotAI/PyCTools/wiki) for detailed breakdowns of the key parts:
138-
>
139-
> **DLL explanations**: learn how the DLLs are structured, discovered, and loaded
140-
> **Python examples, wrappers, and usage**: practical code snippets and usage patterns in Python
141-
> **C code explanation**: understand the underlying native implementation
70+
MIT or specify your license here.
14271

0 commit comments

Comments
 (0)