3030#include "getapi.h"
3131
3232// converts string to lowercase
33- uint32_t crc32c (const char * s )
34- {
33+ uint32_t crc32c (const char * s ) {
3534 int i ;
3635 uint32_t crc = 0 ;
3736
@@ -46,8 +45,7 @@ uint32_t crc32c(const char *s)
4645}
4746
4847#ifndef ASM
49- LPVOID search_exp (LPVOID base , DWORD hash )
50- {
48+ LPVOID search_exp (LPVOID base , DWORD hash ) {
5149 PIMAGE_DOS_HEADER dos ;
5250 PIMAGE_NT_HEADERS nt ;
5351 DWORD cnt , rva , dll_h ;
@@ -94,8 +92,7 @@ LPVOID search_exp(LPVOID base, DWORD hash)
9492 return api_adr ;
9593}
9694
97- LPVOID search_imp (LPVOID base , DWORD hash )
98- {
95+ LPVOID search_imp (LPVOID base , DWORD hash ) {
9996 DWORD dll_h , i , rva ;
10097 PIMAGE_IMPORT_DESCRIPTOR imp ;
10198 PIMAGE_THUNK_DATA oft , ft ;
@@ -116,26 +113,29 @@ LPVOID search_imp(LPVOID base, DWORD hash)
116113
117114 imp = (PIMAGE_IMPORT_DESCRIPTOR ) RVA2VA (ULONG_PTR , base , rva );
118115
119- for (i = 0 ; api_adr == NULL ; i ++ )
120- {
116+ for (i = 0 ; api_adr == NULL ; i ++ ) {
117+ // no more DLL to process?
121118 if (imp [i ].Name == 0 ) return NULL ;
122119
123- // get DLL string, calc crc32c hash
120+ // calculate crc32c hash of DLL string
124121 dll = RVA2VA (PCHAR , base , imp [i ].Name );
125122 dll_h = crc32c (dll );
126123
124+ // obtain address of API names
127125 rva = imp [i ].OriginalFirstThunk ;
128126 oft = (PIMAGE_THUNK_DATA )RVA2VA (ULONG_PTR , base , rva );
129127
128+ // obtain address of API addresses
130129 rva = imp [i ].FirstThunk ;
131130 ft = (PIMAGE_THUNK_DATA )RVA2VA (ULONG_PTR , base , rva );
132131
133- for (;; oft ++ , ft ++ )
134- {
132+ for (;; oft ++ , ft ++ ) {
135133 if (oft -> u1 .Ordinal == 0 ) break ;
134+
136135 // skip import by ordinal
137136 if (IMAGE_SNAP_BY_ORDINAL (oft -> u1 .Ordinal )) continue ;
138137
138+ // obtain address of API string
139139 rva = oft -> u1 .AddressOfData ;
140140 ibn = (PIMAGE_IMPORT_BY_NAME )RVA2VA (ULONG_PTR , base , rva );
141141
@@ -153,8 +153,7 @@ LPVOID search_imp(LPVOID base, DWORD hash)
153153 * Obtain address of API from PEB based on hash
154154 *
155155 ************************************************/
156- LPVOID get_api (DWORD dwHash )
157- {
156+ LPVOID get_api (DWORD dwHash ) {
158157 PPEB peb ;
159158 PPEB_LDR_DATA ldr ;
160159 PLDR_DATA_TABLE_ENTRY dte ;
0 commit comments