Reverse Engineering for Beginners

(avery) #1

CHAPTER 38. NETWORK ADDRESS CALCULATION EXAMPLE CHAPTER 38. NETWORK ADDRESS CALCULATION EXAMPLE


xor ecx, ecx
xor bl, bl
test esi, esi
jle SHORT $LN9@form_netma
xor edx, edx
$LL3@form_netma:
mov eax, 31
sub eax, edx
push eax
push ecx
call _set_bit
inc bl
movzx edx, bl
add esp, 8
mov ecx, eax
cmp edx, esi
jl SHORT $LL3@form_netma
$LN9@form_netma:
pop esi
mov eax, ecx
pop ebx
ret 0
_form_netmask ENDP


set_bit()is primitive: it just shift left 1 to number of bits we need and then ORs it with the “input” value.form_netmask()
has a loop: it will set as many bits (starting from theMSB) as passed in thenetmask_bitsargument


38.5 Summary.


That’s it! We run it and getting:


netmask=255.255.255.0
network address=10.1.2.0
netmask=255.0.0.0
network address=10.0.0.0
netmask=255.255.255.128
network address=10.1.2.0
netmask=255.255.255.192
network address=10.1.2.64

Free download pdf