13 ut8 buf[
sizeof(
PE_(image_import_directory))];
21 return sizeof(
PE_(image_import_directory));
29 ut8 buf[
sizeof(
PE_(image_delay_import_directory))];
40 return sizeof(
PE_(image_delay_import_directory));
61 PE_Word import_hint, import_ordinal = 0;
65 char *sdb_module =
NULL;
68 char *symdllname =
NULL;
70 if (!dll_name || !*dll_name || *dll_name ==
'0') {
88 }
else if (import_table) {
90 import_ordinal = import_table &
ILT_MASK2;
94 strncpy(
name, dll_name,
sizeof(
name) - 1);
99 size_t len = strlen(symdllname);
104 if (!sdb_module || strcmp(symdllname, sdb_module)) {
111 sdb_module =
strdup(symdllname);
156 if (
len >=
sizeof(import_name)) {
157 RZ_LOG_WARN(
"Import name '%s' has been truncated.\n", import_name);
165 *importp = new_importp;
172 (*importp)[*nimp].hint = import_hint;
173 (*importp)[*nimp].ordinal = import_ordinal;
174 (*importp)[*nimp].last = 0;
178 }
while (import_table);
206 PE_(image_import_directory)
208 PE_(image_delay_import_directory)
209 curr_delay_import_dir;
214 if (
bin->import_directory_offset >=
bin->size) {
217 if (
bin->import_directory_offset + 20 >
bin->size) {
221 off =
bin->import_directory_offset;
222 if (off < bin->
size &&
off > 0) {
225 if (
off +
sizeof(
PE_(image_import_directory)) >
bin->size) {
233 if (
bin->import_directory_size < 1) {
236 if (
off +
bin->import_directory_size >
bin->size) {
239 bin->import_directory_size =
bin->size -
bin->import_directory_offset;
241 last =
bin->import_directory_offset +
bin->import_directory_size;
242 while (
r ==
sizeof(curr_import_dir) &&
bin->import_directory_offset + (idi + 1) *
sizeof(curr_import_dir) <=
last && (curr_import_dir.FirstThunk != 0 || curr_import_dir.Name != 0 || curr_import_dir.TimeDateStamp != 0 || curr_import_dir.Characteristics != 0 || curr_import_dir.ForwarderChain != 0)) {
244 dll_name_offset = curr_import_dir.Name;
263 curr_import_dir.Characteristics,
264 curr_import_dir.FirstThunk)) {
275 off =
bin->delay_import_directory_offset;
276 if (off < bin->
size &&
off > 0) {
277 if (
off +
sizeof(
PE_(image_delay_import_directory)) >
bin->size) {
281 for (didi = 0;; didi++) {
283 &curr_delay_import_dir);
284 if (
r !=
sizeof(curr_delay_import_dir)) {
287 if ((curr_delay_import_dir.Name == 0) || (curr_delay_import_dir.DelayImportAddressTable == 0)) {
290 if (!curr_delay_import_dir.Attributes) {
295 import_func_name_offset = curr_delay_import_dir.DelayImportNameTable;
306 curr_delay_import_dir.DelayImportAddressTable)) {
333 PE_(image_import_directory) *import_dir =
NULL;
334 PE_(image_import_directory) *new_import_dir =
NULL;
335 PE_(image_import_directory) *curr_import_dir =
NULL;
337 PE_(image_delay_import_directory) *delay_import_dir =
NULL;
338 PE_(image_delay_import_directory) *new_delay_import_dir =
NULL;
339 PE_(image_delay_import_directory) *curr_delay_import_dir =
NULL;
341 int dir_size =
sizeof(
PE_(image_import_directory));
342 int delay_import_size =
sizeof(
PE_(image_delay_import_directory));
345 int import_dir_size = data_dir_import->Size;
346 int delay_import_dir_size = data_dir_delay_import->Size;
348 if (!import_dir_size) {
350 import_dir_size = data_dir_import->Size = 0xffff;
352 if (!delay_import_dir_size) {
353 data_dir_delay_import->Size = 0xffff;
356 maxidsz -= import_dir_offset;
363 if (import_dir_paddr != 0) {
364 if (import_dir_size < 1 || import_dir_size > maxidsz) {
365 RZ_LOG_INFO(
"Invalid import directory size: 0x%x is now 0x%x\n", import_dir_size, maxidsz);
366 import_dir_size = maxidsz;
368 bin->import_directory_offset = import_dir_offset;
371 new_import_dir = (
PE_(image_import_directory) *)
realloc(import_dir, ((1 +
indx) * dir_size));
372 if (!new_import_dir) {
378 import_dir = new_import_dir;
379 new_import_dir =
NULL;
380 curr_import_dir = import_dir +
indx;
386 if (((2 +
indx) * dir_size) > import_dir_size) {
391 }
while (curr_import_dir->FirstThunk != 0 || curr_import_dir->Name != 0 ||
392 curr_import_dir->TimeDateStamp != 0 || curr_import_dir->Characteristics != 0 ||
393 curr_import_dir->ForwarderChain != 0);
395 bin->import_directory = import_dir;
396 bin->import_directory_size = import_dir_size;
401 if ((delay_import_dir_offset != 0) && (delay_import_dir_offset < (
ut32)
rz_buf_size(
bin->b))) {
403 bin->delay_import_directory_offset = delay_import_dir_offset;
406 off =
indx * delay_import_size;
408 RZ_LOG_INFO(
"Cannot find end of import symbols\n");
411 new_delay_import_dir = (
PE_(image_delay_import_directory) *)
realloc(
412 delay_import_dir, (
indx * delay_import_size) + 1);
413 if (!new_delay_import_dir) {
415 free(delay_import_dir);
418 delay_import_dir = new_delay_import_dir;
419 curr_delay_import_dir = delay_import_dir + (
indx - 1);
421 curr_delay_import_dir);
422 if (rr != dir_size) {
426 }
while (curr_delay_import_dir->Name != 0);
427 bin->delay_import_directory = delay_import_dir;
434 bin->import_directory = import_dir;
435 free(delay_import_dir);
RzList * imports(RzBinFile *bf)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
RZ_API char * sdb_fmt(const char *fmt,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
PE_DWord PE_() bin_pe_rva_to_paddr(RzBinPEObj *bin, PE_DWord rva)
PE_DWord PE_() bin_pe_rva_to_va(RzBinPEObj *bin, PE_DWord rva)
ut64 PE_() rz_bin_pe_get_image_base(RzBinPEObj *bin)
#define PE_READ_STRUCT_FIELD(var, struct_type, field, size)
int PE_() read_image_delay_import_directory(RzBuffer *b, ut64 addr, PE_(image_delay_import_directory) *directory)
static int bin_pe_parse_imports(RzBinPEObj *bin, struct rz_bin_pe_import_t **importp, int *nimp, const char *dll_name, PE_DWord OriginalFirstThunk, PE_DWord FirstThunk)
int PE_() read_image_import_directory(RzBuffer *b, ut64 addr, PE_(image_import_directory) *import_dir)
struct rz_bin_pe_import_t *PE_() rz_bin_pe_get_imports(RzBinPEObj *bin)
int PE_() bin_pe_init_imports(RzBinPEObj *bin)
static char * resolveModuleOrdinal(Sdb *sdb, const char *module, int ordinal)
#define PE_IMAGE_DIRECTORY_ENTRY_IMPORT
#define PE_IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT
#define RZ_BUF_READ_PE_DWORD_AT
#define rz_buf_read_le16_at(b, addr, result)
RZ_API st64 rz_buf_seek(RZ_NONNULL RzBuffer *b, st64 addr, int whence)
Modify the current cursor position in the buffer.
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
RZ_API st64 rz_buf_read(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
RZ_API bool rz_file_exists(const char *str)
#define RZ_LOG_INFO(fmtstr,...)
#define RZ_LOG_WARN(fmtstr,...)
RZ_API RZ_OWN char * rz_path_system(RZ_NULLABLE const char *path)
Return the full system path of the given subpath path.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API void rz_str_case(char *str, bool up)
#define RZ_JOIN_3_PATHS(p1, p2, p3)
RZ_API Sdb * sdb_new(const char *path, const char *name, int lock)
RZ_API char * sdb_get(Sdb *s, const char *key, ut32 *cas)
RZ_API bool sdb_free(Sdb *s)
ut8 libname[PE_NAME_LENGTH+1]
void error(const char *msg)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int indx(const char **ptr, const char **list, int error, const char **expr)