-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrust-spoof.py
More file actions
38 lines (27 loc) · 1.38 KB
/
Copy pathrust-spoof.py
File metadata and controls
38 lines (27 loc) · 1.38 KB
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
import pefile
def get_exported_functions(dll_path):
pe = pefile.PE(dll_path)
exported_functions = []
for entry in pe.DIRECTORY_ENTRY_EXPORT.symbols:
func_name = entry.name.decode('utf-8') if entry.name else f"Function_{entry.ordinal}"
exported_functions.append(func_name)
return exported_functions
def generate_rust_file(dll_path, output_rust_file, exported_functions):
with open(output_rust_file, "w") as rust_file:
rust_file.write("// Auto-generated Rust file for exported functions\n\n")
for func_name in exported_functions:
rust_file.write("#[no_mangle]\n")
rust_file.write(f'pub extern "C" fn {func_name}() {{\n')
rust_file.write(f" main()\n")
rust_file.write("}\n\n")
print(f"Saved Rust exports file: {output_rust_file}")
def main():
import argparse
parser = argparse.ArgumentParser(description="Generate a Rust file with pub extern functions from a DLL.")
parser.add_argument("dll_path", help="Path to the DLL to inspect and create the Rust source for.")
args = parser.parse_args()
output_rust_file = "exports.rs" # Output Rust source file
exported_functions = get_exported_functions(args.dll_path)
generate_rust_file(args.dll_path, output_rust_file, exported_functions)
if __name__ == "__main__":
main()