import
pefile
dll_name_map
=
{
0x176684
:
'ntdll.dll'
,
0x246132
:
'kernel32.dll'
,
0x52325
:
'ws2_32.dll'
,
0x234324
:
'user32.dll'
,
0x523422
:
'advapi32.dll'
,
0x43493856
:
'gdi32.dll'
,
0x4258672
:
'ole32.dll'
,
0x7468951
:
'oleaut32.dll'
}
fix_api_addr
=
[
[
0x40245e
,
0x246132
,
0x66fff672
],
[
0x4027bc
,
0x246132
,
0xed79e920
],
[
0x402803
,
0x246132
,
0x3ea79291
],
[
0x402898
,
0x246132
,
0x3ea79291
],
[
0x4028e3
,
0x246132
,
0x3ea79291
],
[
0x402aed
,
0x523422
,
0xf0271154
],
[
0x402b21
,
0x523422
,
0x4c9945c7
],
[
0x402b7a
,
0x523422
,
0x59504677
],
[
0x402ba2
,
0x246132
,
0x3ea79291
],
[
0x402bc0
,
0x246132
,
0xed79e920
],
[
0x402c99
,
0x246132
,
0x3ea79291
],
[
0x402cf6
,
0x246132
,
0x4f2e84b7
],
[
0x402d39
,
0x246132
,
0x3ea79291
],
[
0x402dc1
,
0x246132
,
0x1c5d2c5e
],
[
0x402ec5
,
0x246132
,
0x4f2e84b7
],
[
0x402efc
,
0x246132
,
0x3ea79291
],
[
0x4030a1
,
0x7468951
,
0x15cf2779
],
[
0x4030c2
,
0x7468951
,
0x15cf2779
],
[
0x4030e3
,
0x7468951
,
0x15cf2779
],
[
0x40310a
,
0x7468951
,
0x7492cdd5
],
[
0x4032d1
,
0x523422
,
0xe2b0c97a
],
[
0x403377
,
0x7468951
,
0x72154b28
],
[
0x403395
,
0x7468951
,
0x3b224daa
],
[
0x4033b3
,
0x7468951
,
0x3b224daa
],
[
0x4033d1
,
0x7468951
,
0x3b224daa
],
[
0x403450
,
0x7468951
,
0x15cf2779
],
[
0x403470
,
0x4258672
,
0x9913c77c
],
[
0x403512
,
0x4258672
,
0x3a4d550b
],
[
0x40360d
,
0x246132
,
0x3ea79291
],
[
0x403753
,
0x246132
,
0x3ea79291
],
[
0x403ac0
,
0x52325
,
0x97e90ebc
],
[
0x403b1b
,
0x52325
,
0xd5af7bf3
],
[
0x403b5b
,
0x52325
,
0x3ad795fd
],
[
0x403c30
,
0x52325
,
0xd5af7bf3
],
[
0x403cdd
,
0x246132
,
0x1c5d2c5e
],
[
0x403dc2
,
0x52325
,
0xf0b9c6a8
],
[
0x403e04
,
0x52325
,
0xf0b9c6a8
],
[
0x403e41
,
0x52325
,
0xf0b9c6a8
],
[
0x403ea7
,
0x52325
,
0xf0b9c6a8
],
[
0x403ed2
,
0x52325
,
0xf0b9c6a8
],
[
0x404002
,
0x246132
,
0x30fb5637
],
[
0x404062
,
0x234324
,
0x7c1b5535
],
[
0x40408b
,
0x43493856
,
0xc496854f
],
[
0x40419b
,
0x43493856
,
0xaac30c
],
[
0x4042ac
,
0x43493856
,
0x52e698ca
],
[
0x4042d0
,
0x43493856
,
0xdc5bd1aa
],
[
0x404440
,
0x52325
,
0x8f04bc74
],
[
0x404477
,
0x52325
,
0x8f04bc74
],
[
0x4044a4
,
0x52325
,
0x8f04bc74
],
[
0x40461c
,
0x246132
,
0x5bb9ce5d
],
[
0x404646
,
0x246132
,
0x53805498
],
[
0x404781
,
0x246132
,
0x53805498
],
[
0x40650b
,
0x246132
,
0x1c5d2c5e
],
[
0x40671d
,
0x52325
,
0x88efa52b
],
[
0x40674c
,
0x52325
,
0x88efa52b
],
[
0x40692a
,
0x523422
,
0x4fbdc973
],
[
0x402773
,
0x246132
,
0x5d22746
],
[
0x40284a
,
0x246132
,
0xb243fe0c
],
[
0x402a52
,
0x246132
,
0x307d41cd
],
[
0x402a9f
,
0x246132
,
0xb3d0027c
],
[
0x402ac1
,
0x246132
,
0xb243fe0c
],
[
0x402c26
,
0x246132
,
0x307d41cd
],
[
0x402cd3
,
0x246132
,
0xb87be91c
],
[
0x402d11
,
0x246132
,
0xb87be91c
],
[
0x402de6
,
0x246132
,
0xb3d0027c
],
[
0x402e21
,
0x246132
,
0x5d22746
],
[
0x402e57
,
0x246132
,
0x5d22746
],
[
0x4031ab
,
0x523422
,
0xcac815fa
],
[
0x4031db
,
0x523422
,
0xcac815fa
],
[
0x40320e
,
0x523422
,
0xcac815fa
],
[
0x403246
,
0x523422
,
0x555cd98
],
[
0x4032ad
,
0x523422
,
0x15547697
],
[
0x4034b2
,
0x4258672
,
0x36e2fadd
],
[
0x40371d
,
0x246132
,
0xb3d0027c
],
[
0x403baf
,
0x52325
,
0xeb68c9d0
],
[
0x403c06
,
0x52325
,
0xa572514d
],
[
0x403c74
,
0x52325
,
0xa572514d
],
[
0x403fa7
,
0x52325
,
0xa4e84503
],
[
0x404039
,
0x246132
,
0xf8395491
],
[
0x40411b
,
0x43493856
,
0x6cdb8a4
],
[
0x4041e6
,
0x43493856
,
0x58f1cfd
],
[
0x4043b2
,
0x52325
,
0x774bbdd0
],
[
0x4043d2
,
0x52325
,
0xa0b3da21
],
[
0x404ffd
,
0x52325
,
0xa0b3da21
],
[
0x406530
,
0x246132
,
0xb3d0027c
],
[
0x406567
,
0x246132
,
0x5d22746
],
[
0x40659d
,
0x246132
,
0x5d22746
],
[
0x406638
,
0x246132
,
0x5d22746
],
[
0x406671
,
0x246132
,
0x5d22746
],
[
0x406767
,
0x52325
,
0xc3e4c63f
],
[
0x40682d
,
0x523422
,
0xcac815fa
],
[
0x40685d
,
0x523422
,
0xcac815fa
],
[
0x406890
,
0x523422
,
0xcac815fa
],
[
0x4068c5
,
0x523422
,
0x94f7a04c
],
[
0x4068f3
,
0x523422
,
0x151b52df
],
[
0x40279e
,
0x246132
,
0x277d84bb
],
[
0x402874
,
0x246132
,
0x3f2eef6c
],
[
0x402c53
,
0x246132
,
0xcfe0d62f
],
[
0x402d83
,
0x246132
,
0x277d84bb
],
[
0x4032f7
,
0x523422
,
0x539dda96
],
[
0x403af2
,
0x52325
,
0xddc03158
],
[
0x40416a
,
0x43493856
,
0x90ee9f3b
],
[
0x4042f7
,
0x234324
,
0x2cae18a6
],
[
0x404557
,
0x246132
,
0x277d84bb
],
[
0x4046c7
,
0x246132
,
0x277d84bb
],
[
0x4046fe
,
0x246132
,
0x277d84bb
],
[
0x406950
,
0x523422
,
0x539dda96
],
[
0x4024ae
,
0x246132
,
0xa31beaa4
],
[
0x4024e4
,
0x246132
,
0xa31beaa4
],
[
0x40255d
,
0x246132
,
0xa31beaa4
],
[
0x4025aa
,
0x246132
,
0xa31beaa4
],
[
0x402a80
,
0x523422
,
0x613a1fc5
],
[
0x403275
,
0x523422
,
0xf2ae646
],
[
0x403ca0
,
0x246132
,
0xd6c07d79
],
[
0x4066a7
,
0x246132
,
0xf5d407d0
],
]
pe_info_cache_hit
=
{}
def
pe_cache_hit(dll_name,api_hash):
if
dll_name
in
pe_info_cache_hit:
if
api_hash
in
pe_info_cache_hit[dll_name]:
return
pe_info_cache_hit[dll_name][api_hash]
return
None
def
add_pe_cache(dll_name,api_hash,api_name):
if
dll_name
in
pe_info_cache_hit:
if
api_hash
in
pe_info_cache_hit[dll_name]:
return
else
:
pe_info_cache_hit[dll_name][api_hash]
=
api_name
else
:
pe_info_cache_hit[dll_name]
=
{api_hash:api_name}
def
hash_api_name(s):
s
=
bytearray(s)
v
=
0x40
for
i
in
range
(
len
(s)):
v
=
(s[i]
-
0x45523F21
*
v)&
0xffffffff
return
v
def
get_api_symbols(dll_hash,api_hash):
system_dir
=
"C:\\Windows\\SysWOW64\\"
dll_name
=
dll_name_map[dll_hash]
path
=
system_dir
+
dll_name
api_name
=
pe_cache_hit(dll_name,api_hash)
if
api_name:
return
api_name
pe
=
pefile.PE(path)
for
exp
in
pe.DIRECTORY_ENTRY_EXPORT.symbols:
api_name
=
exp.name
func_hash
=
hash_api_name(api_name)
add_pe_cache(dll_name,func_hash,api_name.decode(
'utf-8'
))
if
func_hash
=
=
api_hash:
return
api_name.decode(
'utf-8'
)
if
__name__
=
=
'__main__'
:
for
i
in
fix_api_addr:
api_name
=
get_api_symbols(i[
1
],i[
2
])
print
(
'[0x%x,"%s","%s"],'
%
(i[
0
],dll_name_map[i[
1
]],api_name))