I hope this is the right place for reporting the bugs I've found in the 32-bit Version of the Compiler.
1. not()
does'nt work properly if used in some conditions, try this:
Code: Select all
dim as ulongint a, nota
dim as ulong b, notb
dim as ushort c, notc
a=1
nota=not(a)
print hex(a), hex(nota)
b=1
notb=not(b)
nota=not(b)
print hex(b), hex(notb), hex(nota)
'nota should be 64bit, but is only 32bit and thus false
c=1
notc=not(c)
notb=not(c)
nota=not(c)
print hex(c), hex(notc), hex(notb), hex(nota)
& works not properly if zerobytes are involved:
Code: Select all
dim as string a,b
dim as ulong c,d
dim as string*4 e
dim as string f,g,h
a="&h00123456"
print a
b="&h12345600"
print b
c=valuint(a)
d=valuint(b)
print c
print d
e=mki<32>(c)
f=mki<32>(d)
print len(e)
print len(f)
g="xxxx" & e 'the zerobyte goes missing
h="xxxx" & f
print len(g)
print len(h)
hex () is not overloaded for all datatypes, you'll get the error "Ambigious call to overloaded function". This fix is to actually overload hex for the missing types, including one for binary strings:
Code: Select all
Declare Function hex Overload (a as long,b as integer) as string
Declare Function hex Overload (a as ulong,b as integer) as string
Declare Function hex Overload (a as longint,b as integer) as string
Declare Function hex Overload (byref a as string) as string
Function hex Overload (a as long,b as integer) as string
dim as integer c = cint(a)
return hex(c,b)
End Function
Function hex Overload (a as ulong,b as integer) as string
dim as integer c = cint(a)
return hex(c,b)
End Function
Function hex Overload (byval a as longint,b as integer) as string
dim as integer lo = cint(a)
dim as integer hi = cint(a shr 32)
dim as string result
if b > 16 then
result = string(b-16,"0") & hex(hi) & hex(lo)
else
result = right(hex(hi,8) & hex(lo,8),b)
end if
return result
End Function
Function hex Overload (byref aa as string) as string
'Achtung auf Endian-switch!
dim a as string = aa
dim ablocks as ulong
dim pad as ubyte
pad=4-(len(a) mod 4)
if pad <> 4 then a &= string(pad,chr(0))
ablocks=len(a)\4 - 1
dim pa as ulong ptr = cast(ulong ptr,strptr(a))
dim result as string = space(len(a)*2)
dim presult as ulongint ptr = cast(ulongint ptr,strptr(result))
dim i as integer
for i = 0 to ablocks
*(presult+ablocks-i)=cvlongint(hex(*(pa+i),8))
next i
return result
End Function
Function hex Overload (byref aa as string,b as integer) as string
'Achtung auf Endian-switch!
dim a as string = aa
dim ablocks as ulong
dim pad as ubyte
pad=4-(len(a) mod 4)
if pad <> 4 then a &= string(pad,chr(0))
ablocks=len(a)\4 - 1
dim pa as ulong ptr = cast(ulong ptr,strptr(a))
dim result as string = space(len(a)*2)
dim presult as ulongint ptr = cast(ulongint ptr,strptr(result))
dim i as integer
for i = 0 to ablocks
*(presult+ablocks-i)=cvlongint(hex(*(pa+i),8))
next i
'----
dim lena as integer = len(result)
dim result2 as string
if b < lena then
result2 = right(result,b)
elseif b = lena then
result2 = result
elseif b > lena then
if a[lena-1] = 70 or a[lena-1] = 102 then
result2 = string(b-lena,"f") & result
else
result2 = string(b-lena,"0") & result
end if
end if
return result2
End Function
(bit rotate right and left) are not supported, but used often in crypto. For 32bit rotate left, it looks like:
Code: Select all
Function rotateleft(ByVal x As ulong, byval y as ubyte) as ulong
Asm
mov eax,[x]
mov cl,[y]
rol eax,cl
mov [Function],eax
End Asm
End Function