Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: demo_pml.py
- # Version: 1.0.2
- # Author: Jeoi Reqi
- """
- This script generates a demo Process Monitor Log (PML) file (.pml) containing sample process monitoring data.
- The generated .pml file simulates process events such as process name, operation, path, result, and detail.
- It serves as a convenient tool for generating sample input data for testing the pml2csv.py script.
- Requirements:
- - Python 3.x
- Usage:
- 1. Ensure Python 3.x is installed on your system.
- 2. Save the demo_pml.py script to a directory of your choice.
- 3. Open a terminal or command prompt.
- 4. Navigate to the directory where the demo_pml.py script is saved.
- 5. Run the script using the following command: 'python demo_pml.py'
- 6. After successful execution, a demo .pml file named "demo.pml" will be created in the same directory.
- Additional Notes:
- - The generated .pml file contains sample process monitoring data in tab-separated format.
- - This script is intended for demonstration purposes and generates static demo data.
- - Users can customize the script to adjust the generated data according to their testing needs.
- Demo Output:
- Time Process Name PID Operation Path Result Detail
- 2024-04-14 10:05:39 svchost.exe 2278 Open C:\Users\user\Documents\document.docx ERROR File opened
- 2024-04-14 10:20:33 cmd.exe 1790 Close C:\Users\user\Downloads\data.csv ERROR File deleted
- 2024-04-14 10:27:54 svchost.exe 8502 Delete C:\Users\user\Downloads\data.csv SUCCESS File opened
- 2024-04-14 10:49:44 explorer.exe 9543 Close C:\Users\user\Downloads\data.csv ERROR File created
- 2024-04-14 10:50:43 svchost.exe 2515 Read C:\Users\user\Downloads\data.csv ERROR Data written
- 2024-04-14 10:29:51 chrome.exe 4401 Delete C:\Users\user\Desktop\file.txt SUCCESS File deleted
- 2024-04-14 10:02:40 notepad.exe 9053 Open C:\Users\user\Downloads\data.csv ERROR File opened
- 2024-04-14 10:44:16 cmd.exe 9617 Delete C:\Users\user\Desktop\file.txt SUCCESS File deleted
- 2024-04-14 10:32:35 explorer.exe 8641 Write C:\Users\user\Desktop\file.txt ERROR File deleted
- 2024-04-14 10:23:53 explorer.exe 3626 Close C:\Users\user\Desktop\file.txt ERROR Data written
- 2024-04-14 10:22:16 explorer.exe 8256 Open C:\Users\user\Documents\document.docx SUCCESS Access denied
- 2024-04-14 10:37:15 cmd.exe 9703 Open C:\Users\user\Downloads\data.csv SUCCESS File created
- 2024-04-14 10:34:29 cmd.exe 4558 Read C:\Users\user\Desktop\file.txt SUCCESS File opened
- 2024-04-14 10:39:57 svchost.exe 5124 Read C:\Users\user\Desktop\file.txt ERROR File opened
- 2024-04-14 10:35:53 chrome.exe 6575 Write C:\Users\user\Documents\document.docx ERROR Access denied
- 2024-04-14 10:19:27 svchost.exe 8720 Read C:\Users\user\Downloads\data.csv ERROR File created
- 2024-04-14 10:53:14 notepad.exe 2171 Create C:\Users\user\Downloads\data.csv ERROR File created
- 2024-04-14 10:41:20 chrome.exe 4867 Write C:\Users\user\Downloads\data.csv ERROR Data written
- 2024-04-14 10:15:16 svchost.exe 6153 Create C:\Users\user\Documents\document.docx ERROR File opened
- 2024-04-14 10:46:36 chrome.exe 2582 Create C:\Users\user\Downloads\data.csv ERROR Access denied
- """
- import random
- def generate_demo_pml(filename):
- with open(filename, 'w') as f:
- # Write header
- f.write("Time\tProcess Name\tPID\tOperation\tPath\tResult\tDetail\n")
- # Generate sample process events
- processes = ["explorer.exe", "notepad.exe", "chrome.exe", "svchost.exe", "cmd.exe"]
- operations = ["Create", "Read", "Write", "Delete", "Open", "Close"]
- paths = ["C:\\Users\\user\\Desktop\\file.txt", "C:\\Users\\user\\Documents\\document.docx", "C:\\Users\\user\\Downloads\\data.csv"]
- results = ["SUCCESS", "ERROR"]
- details = ["File created", "File opened", "File deleted", "Data written", "Access denied"]
- for i in range(20): # Generate 20 sample events
- time = f"2024-04-14 10:{random.randint(0, 59):02d}:{random.randint(0, 59):02d}"
- process = random.choice(processes)
- pid = random.randint(1000, 9999)
- operation = random.choice(operations)
- path = random.choice(paths)
- result = random.choice(results)
- detail = random.choice(details)
- f.write(f"{time}\t{process}\t{pid}\t{operation}\t{path}\t{result}\t{detail}\n")
- if __name__ == "__main__":
- generate_demo_pml("demo.pml")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement