MCPcopy Index your code
hub / github.com/b1tg/rust-windows-shellcode / get_module_by_name

Function get_module_by_name

shellcode/src/main.rs:68–92  ·  view source on GitHub ↗
(module_name: *const u16)

Source from the content-addressed store, hash-verified

66}
67
68fn get_module_by_name(module_name: *const u16) -> PVOID {
69 let peb: *mut PEB;
70 unsafe {
71 asm!(
72 "mov {}, gs:[0x60]",
73 out(reg) peb,
74 );
75 let ldr = (*peb).Ldr;
76 let list_entry = &((*ldr).InLoadOrderModuleList);
77 let mut cur_module: *const LDR_DATA_TABLE_ENTRY = &list_entry as *const _ as *const _;
78 loop {
79 if cur_module.is_null() || (*cur_module).BaseAddress.is_null() {
80 // TODO: when to break
81 }
82 let cur_name = (*cur_module).BaseDllName.Buffer;
83 if !cur_name.is_null() {
84 if compare_raw_str(module_name, cur_name) {
85 return (*cur_module).BaseAddress;
86 }
87 }
88 let flink = (*cur_module).InLoadOrderModuleList.Flink;
89 cur_module = flink as *const LDR_DATA_TABLE_ENTRY;
90 }
91 }
92}
93
94fn get_func_by_name(module: PVOID, func_name: *const u8) -> PVOID {
95 let idh: *const IMAGE_DOS_HEADER = module as *const _;

Callers 1

mainFunction · 0.85

Calls 1

compare_raw_strFunction · 0.85

Tested by

no test coverage detected