... | ... |
@@ -2172,6 +2172,9 @@ static inline int scan_pe_impfuncs(cli_ctx *ctx, void *md5ctx, struct pe_image_i |
2172 | 2172 |
size_t dlllen = 0, fsize = map->len; |
2173 | 2173 |
int i, j, err, num_funcs = 0; |
2174 | 2174 |
const char *buffer; |
2175 |
+#if HAVE_JSON |
|
2176 |
+ json_object *imptbl = NULL; |
|
2177 |
+#endif |
|
2175 | 2178 |
|
2176 | 2179 |
toff = cli_rawaddr(image->u.OriginalFirstThunk, exe_sections, nsections, &err, fsize, hdr_size); |
2177 | 2180 |
if (err) |
... | ... |
@@ -2181,6 +2184,16 @@ static inline int scan_pe_impfuncs(cli_ctx *ctx, void *md5ctx, struct pe_image_i |
2181 | 2181 |
return CL_SUCCESS; |
2182 | 2182 |
} |
2183 | 2183 |
|
2184 |
+#if HAVE_JSON |
|
2185 |
+ if (ctx->wrkproperty) { |
|
2186 |
+ imptbl = cli_jsonarray(ctx->wrkproperty, "ImportTable"); |
|
2187 |
+ if (!imptbl) { |
|
2188 |
+ cli_dbgmsg("IMPTBL: cannot allocate import table json object\n"); |
|
2189 |
+ return CL_EMEM; |
|
2190 |
+ } |
|
2191 |
+ } |
|
2192 |
+#endif |
|
2193 |
+ |
|
2184 | 2194 |
if (!pe_plus) { |
2185 | 2195 |
struct pe_image_thunk32 thunk32; |
2186 | 2196 |
|
... | ... |
@@ -2215,7 +2228,6 @@ static inline int scan_pe_impfuncs(cli_ctx *ctx, void *md5ctx, struct pe_image_i |
2215 | 2215 |
char *fname; |
2216 | 2216 |
size_t funclen; |
2217 | 2217 |
|
2218 |
- /* JSON TOMFOOLERY */ |
|
2219 | 2218 |
//cli_dbgmsg("IMPTBL: FUNC: %s\n", funcname); |
2220 | 2219 |
|
2221 | 2220 |
if (dlllen == 0) { |
... | ... |
@@ -2239,18 +2251,25 @@ static inline int scan_pe_impfuncs(cli_ctx *ctx, void *md5ctx, struct pe_image_i |
2239 | 2239 |
j = 0; |
2240 | 2240 |
if (!*first) |
2241 | 2241 |
fname[j++] = ','; |
2242 |
- else |
|
2243 |
- *first = 0; |
|
2244 | 2242 |
for (i = 0; i < dlllen; i++, j++) |
2245 | 2243 |
fname[j] = tolower(dllname[i]); |
2246 | 2244 |
fname[j++] = '.'; |
2247 | 2245 |
for (i = 0; i < funclen; i++, j++) |
2248 | 2246 |
fname[j] = tolower(funcname[i]); |
2249 | 2247 |
|
2248 |
+ /* JSON TOMFOOLERY */ |
|
2249 |
+#if HAVE_JSON |
|
2250 |
+ if (imptbl) { |
|
2251 |
+ char *jname = *first ? fname : fname+1; |
|
2252 |
+ cli_jsonstr(imptbl, NULL, jname); |
|
2253 |
+ } |
|
2254 |
+#endif |
|
2255 |
+ |
|
2250 | 2256 |
cli_dbgmsg("%u %s\n", strlen(fname), fname); |
2251 | 2257 |
|
2252 | 2258 |
cl_update_hash(md5ctx, fname, strlen(fname)); |
2253 | 2259 |
|
2260 |
+ *first = 0; |
|
2254 | 2261 |
free(fname); |
2255 | 2262 |
free(funcname); |
2256 | 2263 |
} |
... | ... |
@@ -2419,6 +2438,10 @@ static int scan_pe_imptbl(cli_ctx *ctx, struct pe_image_data_dir *dirs, struct c |
2419 | 2419 |
cl_finish_hash(md5ctx, digest); |
2420 | 2420 |
dstr = cli_str2hex(digest, sizeof(digest)); |
2421 | 2421 |
cli_errmsg("IMPHASH: %s\n", (char *)dstr); |
2422 |
+#if HAVE_JSON |
|
2423 |
+ if (ctx->wrkproperty) |
|
2424 |
+ cli_jsonstr(ctx->wrkproperty, "Imphash", dstr); |
|
2425 |
+#endif |
|
2422 | 2426 |
free(dstr); |
2423 | 2427 |
return ret; |
2424 | 2428 |
} |