@@ -24,26 +24,38 @@ function import_name(oh::COFFHandle, idata::COFFSectionRef, iid)
24
24
return strip (readuntil (oh, ' \0 ' ), ' \0 ' )
25
25
end
26
26
27
+ function find_section_for_rva (oh:: H , rva) where {H <: COFFHandle }
28
+ for s in Sections (oh)
29
+ if section_address (s) < rva && section_address (s) + section_size (s) > rva
30
+ return s
31
+ end
32
+ end
33
+ error (" Unable to find section for RVA $(rva) " )
34
+ end
35
+
27
36
function COFFDynamicLinks (oh:: H ) where {H <: COFFHandle }
28
- # Find the import table section
29
- idata = findfirst (Sections (oh), " .idata" )
37
+ # Start by finding the virtual address of the import table
38
+ import_table_rva = oh. opt_header. directories. ImportTable. VirtualAddress
39
+
40
+ # Next figure out which section that belongs to:
41
+ s = find_section_for_rva (oh, import_table_rva)
30
42
31
43
# We'll load in all the ImageImportDescriptors we can
32
44
iids = COFFImageImportDescriptor[]
33
45
34
46
# Read in ImageImportDescriptors until it's all NULL
35
- seek (oh, section_offset (idata ))
47
+ seek (oh, (import_table_rva - section_address (s)) + section_offset (s ))
36
48
while true
37
49
iid = unpack (oh, COFFImageImportDescriptor)
38
- if iid. Name == 0 && iid. FirstThunk == 0
50
+ if iid. Name == 0 && iid. FirstThunk == 0 && iid . Characteristics == 0 && iid . ForwarderChain == 0 && iid . TimeDateStamp == 0
39
51
break
40
52
else
41
53
push! (iids, iid)
42
54
end
43
55
end
44
56
45
57
# Now, jump around and get all the strings
46
- links = [COFFDynamicLink {H} (import_name (oh, idata , iid)) for iid in iids]
58
+ links = [COFFDynamicLink {H} (import_name (oh, s , iid)) for iid in iids]
47
59
return COFFDynamicLinks (oh, links)
48
60
end
49
61
DynamicLinks (oh:: COFFHandle ) = COFFDynamicLinks (oh)
0 commit comments