1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
//! Shellcode for calling remote functions with parameters
//!
//! This module generates architecture-specific shellcode to call arbitrary
//! functions in remote processes, supporting both parameterized and
//! parameterless function calls.
/// Generate x64 shellcode to call a function with raw byte parameter
///
/// This function creates machine code that will execute in a remote x64 process
/// to call a target function with optional parameter data. The parameter is passed
/// according to the Windows x64 calling convention (first integer/pointer in RCX).
///
/// # Arguments
/// * `function_address` - Virtual address of the function to call in target process
/// * `param_addr` - Address of parameter data in target process memory (0 if no param)
/// * `param_size` - Size of parameter data in bytes (0 if no param)
///
/// # Returns
/// Vector of bytes containing executable x64 shellcode
///
/// # Parameter Handling
/// - **4 bytes** (i32/f32): Value loaded into ECX, zero-extended to RCX
/// - **8 bytes** (i64/pointer): Value loaded directly into RCX
/// - **Other sizes**: Pointer to data passed in RCX
/// - **No parameter**: RCX zeroed out
///
/// # Generated Assembly (Conceptual for 4-byte param)
/// ```asm
/// push rax, rbx ; Save registers
/// sub rsp, 0x28 ; Align stack
/// mov rax, param_addr ; Load parameter address
/// mov ecx, [rax] ; Load 4-byte value
/// movsxd rcx, ecx ; Zero-extend to RCX
/// mov rax, function_address ; Load target function
/// call rax ; Call function
/// add rsp, 0x28 ; Restore stack
/// pop rbx, rax ; Restore registers
/// ret ; Return (result in RAX)
/// ```
///
/// # Safety
/// The generated shellcode must be:
/// 1. Written to executable memory in the target process
/// 2. Executed via CreateRemoteThread or similar mechanism
/// 3. All addresses must be valid in the target process context
/// 4. Function signature should match parameter passing convention
/// Generate x86 shellcode to call a function with raw byte parameter
///
/// This function creates machine code that will execute in a remote x86 process
/// to call a target function with optional parameter data. Parameters are pushed
/// onto the stack according to the __stdcall calling convention.
///
/// # Arguments
/// * `function_address` - Virtual address of the function to call in target process
/// * `param_addr` - Address of parameter data in target process memory (0 if no param)
/// * `param_size` - Size of parameter data in bytes (0 if no param)
///
/// # Returns
/// Vector of bytes containing executable x86 shellcode
///
/// # Parameter Handling
/// - **≤4 bytes**: Value loaded into EAX, then pushed onto stack
/// - **>4 bytes**: Pointer to data pushed onto stack
/// - **No parameter**: Nothing pushed
///
/// # Generated Assembly (Conceptual for ≤4-byte param)
/// ```asm
/// mov eax, param_addr ; Load parameter address
/// mov eax, [eax] ; Load value
/// push eax ; Push parameter
/// mov eax, function_address ; Load target function
/// call eax ; Call function (__stdcall, callee cleans stack)
/// ret ; Return (result in EAX)
/// ```
///
/// # Safety
/// The generated shellcode must be:
/// 1. Written to executable memory in the target process
/// 2. Executed via CreateRemoteThread or similar mechanism
/// 3. All addresses must be valid in the target process context
/// 4. Function should use __stdcall calling convention
/// Generate x64 shellcode to call a function with NO parameters
///
/// This is an optimized version for calling parameterless functions in remote
/// x64 processes. It generates smaller and faster shellcode than the generic
/// version by skipping parameter handling logic.
///
/// # Arguments
/// * `function_address` - Virtual address of the function to call in target process
///
/// # Returns
/// Vector of bytes containing executable x64 shellcode (typically ~40 bytes)
///
/// # Generated Assembly (Conceptual)
/// ```asm
/// push rax, rbx ; Save registers
/// sub rsp, 0x28 ; Align stack (required by Windows x64 ABI)
/// mov rax, function_address ; Load target function
/// call rax ; Call function
/// add rsp, 0x28 ; Restore stack
/// pop rbx, rax ; Restore registers
/// ret ; Return (result in RAX)
/// ```
///
/// # Performance Advantage
/// - Smaller shellcode: ~40 bytes vs ~80 bytes (with params)
/// - Faster execution: No parameter allocation/cleanup overhead
/// - Cleaner intent: Explicitly shows no parameters expected
///
/// # Safety
/// The generated shellcode must be:
/// 1. Written to executable memory in the target process
/// 2. Executed via CreateRemoteThread or similar mechanism
/// 3. Target function signature should be compatible (no parameters)
/// Generate x86 shellcode to call a function with NO parameters
///
/// This is an optimized version for calling parameterless functions in remote
/// x86 processes. It generates minimal shellcode by directly calling the target
/// function without any parameter setup.
///
/// # Arguments
/// * `function_address` - Virtual address of the function to call in target process
///
/// # Returns
/// Vector of bytes containing executable x86 shellcode (typically ~7 bytes)
///
/// # Generated Assembly (Conceptual)
/// ```asm
/// mov eax, function_address ; Load target function
/// call eax ; Call function
/// ret ; Return (result in EAX)
/// ```
///
/// # Performance Advantage
/// - Minimal shellcode: Only ~7 bytes
/// - Fastest execution: Direct call with no overhead
/// - Simplest logic: No stack manipulation needed
///
/// # Safety
/// The generated shellcode must be:
/// 1. Written to executable memory in the target process
/// 2. Executed via CreateRemoteThread or similar mechanism
/// 3. Target function signature should be compatible (no parameters)