HyperDbg Debugger
Loading...
Searching...
No Matches
test-semantic-scripts.cpp File Reference

Perform test on semantic scripts. More...

#include "pch.h"

Functions

VOID ReadDirectoryAndTestSemanticTestCases (const CHAR *ScriptSemanticPath)
 Read directory of semantic test cases and run each of them.
BOOLEAN TestSemanticScripts ()
 Test semantic scripts.

Detailed Description

Perform test on semantic scripts.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.11
Date
2024-08-16

Function Documentation

◆ ReadDirectoryAndTestSemanticTestCases()

VOID ReadDirectoryAndTestSemanticTestCases ( const CHAR * ScriptSemanticPath)

Read directory of semantic test cases and run each of them.

Parameters
ScriptSemanticPathPath to the semantic test cases
Returns
VOID
25{
26 //
27 // Iterate through the directory
28 //
29 try
30 {
31 for (const auto & entry : fs::directory_iterator(ScriptSemanticPath))
32 {
33 //
34 // Check if the entry is a file
35 //
36 if (entry.is_regular_file())
37 {
38 //
39 // Get the file path
40 //
41 std::string FilePath = entry.path().string();
42
43 //
44 // Output the file name
45 //
46 // std::cout << "Test case file: " << entry.path().filename().string() << std::endl;
47
48 //
49 // Open the file and read its contents
50 //
51 std::ifstream File(FilePath);
52 if (File.is_open())
53 {
54 std::string Content((std::istreambuf_iterator<char>(File)),
55 std::istreambuf_iterator<char>());
56
57 //
58 // Display the content of the file
59 //
60 std::cout << "Executing file " << entry.path().filename().string() << std::endl;
61
62 // std::cout << content << std::endl;
63
64 //
65 // Run the test case command
66 //
67 hyperdbg_u_run_command((CHAR *)Content.c_str());
68
69 std::cout << "--------------------------------------------" << std::endl;
70
71 //
72 // Close the file
73 //
74 File.close();
75 }
76 else
77 {
78 std::cerr << "Could not open file: " << FilePath << std::endl;
79 }
80 }
81 }
82 }
83 catch (const fs::filesystem_error & e)
84 {
85 std::cerr << "Filesystem error: " << e.what() << std::endl;
86 }
87}
char CHAR
Definition BasicTypes.h:33
IMPORT_EXPORT_LIBHYPERDBG INT hyperdbg_u_run_command(CHAR *command)
Run a command.
Definition export.cpp:205

◆ TestSemanticScripts()

BOOLEAN TestSemanticScripts ( )

Test semantic scripts.

Returns
BOOLEAN
96{
97 INT32 TestNum = 0;
98 CHAR dirPath[MAX_PATH] = {0};
99
100 //
101 // Parse the semantic script test cases from the file
102 // Setup the path for the filenames
103 //
105 {
106 //
107 // Error could not find the test case files
108 //
109 cout << "[-] Could not find the test case files" << endl;
110 return FALSE;
111 }
112
113 //
114 // Connect to the debugger
115 //
117 {
118 cout << "[-] Could not connect to the debugger" << endl;
119 return FALSE;
120 }
121
122 //
123 // Run test cases
124 //
126
127 //
128 // Close the connection
129 //
131
132 return TRUE;
133}
#define TEST_DEFAULT_NAMED_PIPE
Default named pipe name for communication between debugger and debuggee process.
Definition Definition.h:55
#define SCRIPT_SEMANTIC_TEST_CASE_DIRECTORY
Test cases directory name for script semantic tests.
Definition Definition.h:105
signed int INT32
Definition BasicTypes.h:50
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hyperdbg_u_debug_close_remote_debugger()
Close the remote debugger.
Definition export.cpp:631
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hyperdbg_u_connect_remote_debugger_using_named_pipe(const CHAR *named_pipe, BOOLEAN pause_after_connection)
Connect to the remote debugger using named pipe.
Definition export.cpp:620
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hyperdbg_u_setup_path_for_filename(const CHAR *filename, CHAR *file_location, UINT32 buffer_len, BOOLEAN check_file_existence)
Setip the path for the filename.
Definition export.cpp:725
VOID ReadDirectoryAndTestSemanticTestCases(const CHAR *ScriptSemanticPath)
Read directory of semantic test cases and run each of them.
Definition test-semantic-scripts.cpp:24