int
main
(
)
{
_asm
{
nop
nop
nop
nop
nop
CLD ; clear flag DF
;store hash
push
0
x
1
e
380
a
6
a ;hash
of
MessageBoxA
push
0
x
4
fd
18963
;hash
of
ExitProcess
push
0
x
0
c
917432
;hash
of
LoadLibraryA
mov esi
,
esp ; esi
=
addr
of
first
function hash
lea edi
,
[esi
-0
xc] ; edi
=
addr
to
start writing function
;
make
some
stack space
xor ebx
,
ebx
mov bh
,
0
x
04
sub esp
,
ebx
; push a pointer
to
"user32"
onto
stack
mov bx
,
0
x
3233
;
rest
of
ebx
is
null
push ebx
push
0
x
72657375
push esp
xor edx
,
edx
; find base addr
of
kernel
32.
dll
mov ebx
,
fs
:
[
0
x
30
]
/
/
得到peb结构体的地址
mov ebx
,
[ebx
+
0
xc]
/
/
得到Ldr结构体的地址
mov ebx
,
[ebx
+
0
xc]
/
/
得到ldr.InLoadOrderModuleList.Flink 第一个模块,当前进程
mov ebx
,
[ebx]
/
/
得到第二个模块地址 ntdll.dll
mov ebx
,
[ebx]
/
/
得到第三个模块地址 kernel
32.
dll
mov ebx
,
[ebx
+
0
x
18
]
/
/
得到第三个模块地址(kernel
32
模块的dllbase
)
mov ebp
,
ebx
find_lib_functions
:
lodsd ; load next hash
into
al
and
increment esi
cmp eax
,
0
x
1
e
380
a
6
a ; hash
of
MessageBoxA
-
trigger
; LoadLibrary
(
"user32"
)
jne find_functions
xchg eax
,
ebp ;
save
current hash
call [edi
-
0
x
8
] ; LoadLibraryA
xchg eax
,
ebp ; restore current hash
,
and
update
ebp
;
with
base
address
of
user
32.
dll
find_functions
:
pushad ; preserve registers
mov eax
,
[ebp
+
0
x
3
c] ; eax
=
start
of
PE header
mov ecx
,
[ebp
+
eax
+
0
x
78
] ; ecx
=
relative
offset
of
export table
add
ecx
,
ebp ; ecx
=
absolute addr
of
export table
mov ebx
,
[ecx
+
0
x
20
] ; ebx
=
relative
offset
of
names table
add
ebx
,
ebp ; ebx
=
absolute addr
of
names table
xor edi
,
edi ; edi will
count
through
the
functions
next_function_loop
:
inc edi ; increment function counter
mov esi
,
[ebx
+
edi
*
4
] ; esi
=
relative
offset
of
current function
name
add
esi
,
ebp ; esi
=
absolute addr
of
current function
name
cdq ; dl will hold hash
(
we know eax
is
small
)
hash_loop
:
movsx eax
,
byte ptr[esi]
cmp al
,
ah
jz compare_hash
ror edx
,
7
add
edx
,
eax
inc esi
jmp hash_loop
compare_hash
:
cmp edx
,
[esp
+
0
x
1
c] ; compare
to
the
requested hash
(
saved
on
stack
from
pushad
)
jnz next_function_loop
mov ebx
,
[ecx
+
0
x
24
] ; ebx
=
relative
offset
of
ordinals table
add
ebx
,
ebp ; ebx
=
absolute addr
of
ordinals table
mov di
,
[ebx
+
2
*
edi] ; di
=
ordinal
number
of
matched function
mov ebx
,
[ecx
+
0
x
1
c] ; ebx
=
relative
offset
of
address
table
add
ebx
,
ebp ; ebx
=
absolute addr
of
address
table
add
ebp
,
[ebx
+
4
*
edi] ;
add
to
ebp
(
base addr
of
module
)
the
; relative
offset
of
matched function
xchg eax
,
ebp ;
move
func addr
into
eax
pop edi ; edi
is
last
onto
stack
in
pushad
stosd ;
write
function addr
to
[edi]
and
increment edi
push edi
popad ; restore registers
; loop until we reach
end
of
last
hash
cmp eax
,
0
x
1
e
380
a
6
a
jne find_lib_functions
function_call
:
xor ebx
,
ebx
push ebx
/
/
cut
string
push
0
x
20756
F
68
/
/
push
" uoh"
push
0
x
43796
F
4
A
/
/
push
"CyoJ"
mov eax
,
esp
/
/
load
address
of
JoyChou
push ebx
push eax
push eax
push ebx
call [edi
-
0
x
04
] ;
/
/
call MessageboxA
push ebx
call [edi
-
0
x
08
] ;
/
/
call ExitProcess
nop
nop
nop
nop
}
return
0
;
}