CryptoRndIV

General FreeBASIC programming questions.
Post Reply
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CryptoRndIV

Post by dodicat »

You have to disable wordwrap to use goto line in notepad.
Using -RR switch

Code: Select all

#cmdline "-RR"
declare function rand cdecl alias "rand" () as long
declare sub srand cdecl alias "srand" (byval as ulong)

Function rndX(s1 As String) As String
    #macro GetNumber
    #define range(f,l)  (rand mod ((l-f)+1)) + f
      s[0]=range(48,s1[0])
    For n As Long = 1 To L-1
        s[n]=range(48,57)
    Next
    #endmacro
    #macro compare(n1,n2,ans)
        Var lenn1=Cast(Integer Ptr,@n1)[1],lenn2=Cast(Integer Ptr,@n2)[1]
        If lenn1 > lenn2 Then ans=-1:Goto lbl
        If lenn1 < lenn2 Then ans=0:Goto lbl
        If n1 > n2 Then ans = -1  Else ans= 0
        lbl:
    #endmacro
    Dim As Long L=Cast(Integer Ptr,@s1)[1],ans=1
    Dim As String s=String(L,0)
    While ans
        GetNumber
        compare(s,s1,ans)
    Wend
    Return iif(s<>"0",Ltrim(s,"0"),"0")
End Function

srand(timer)
print "Biggish random number:"
print rndx("9"+string(2000,"9"))
var file= rtrim(command(0),".exe")+".asm"
shell "notepad "+file
kill file
sleep
 
Anybody:
Is there a bug in 32 bits Win 10? The #cmdline "-RR" seems to do nothing.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

@dodicat

It's working for me.

Previous text removed – I need to do further tests.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

It seems that -RR is useful for checking out asm blocks that may be causing problems.

I was interested in 'TempVar = *Cast(Uinteger Ptr, ptrBuffer)'. -RR is no good for that.

In the .c file, from -R, we have TEMPVAR$1 = *(uint32*)PTRBUFFER$;

Now, if we want to see an asm dump of that, then OllyDbg is the way to go.
SARG
Posts: 1766
Joined: May 27, 2005 7:15
Location: FRANCE

Re: CryptoRndIV

Post by SARG »

@deltarho
I don't see a problem with -RR.
Compiling this snippet with gcc -RR :

Code: Select all

type tudt
		aaa as INTEGER
		bbb as INTEGER
End Type
dim as tudt udt
dim as any ptr ptrbuffer
dim as uinteger tempvar
asm nop '''added for an easy search
TempVar = *Cast(Uinteger Ptr, ptrBuffer)
asm nop
I get this (only the interesting part) :

Code: Select all

# 32 "D:\fbdebugger\fbdebugger-New\test2.c" 1
	nop
 # 0 "" 2
/NO_APP
	mov	rax, QWORD PTR -88[rbp]
	mov	rax, QWORD PTR [rax]
	mov	QWORD PTR -96[rbp], rax
/APP
 # 34 "D:\fbdebugger\fbdebugger-New\test2.c" 1
	nop

By the way there is x64dbg (32/64bit) that is the little brother of ollydbg. https://x64dbg.com
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

Thanks SARG.

I can see where my problem is.

I have just ran your code in 32-bit mode.

Your second code block is nowhere to be seen in the asm file.

I did quite a few different searches and, nope, it isn't there. :)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CryptoRndIV

Post by dodicat »

Here, 64 bit fbc creates the .asm file and shows it via notepad.
32 bit fbc doesn't create the asm file, so notepad cannot show it, but throws up a cannot find the file error.
If I use -RR as an ide setting or bare command line flag then no problems.
I cannot use RdRand because my computer is 2011, so my example is a different random function (bottom up instead of top down).
But of course any bit of source which compiles would do.
So my query is why doesn't #cmdline "-RR" not work in 32 bits, or does it work with others here?
Win 10, official builds and SARG's _latest.exe builds.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

I have just compiled in 64-bit, and I'm still not getting what SARG showed.
SARG
Posts: 1766
Joined: May 27, 2005 7:15
Location: FRANCE

Re: CryptoRndIV

Post by SARG »

I did a test with 32bit and I got this :

Code: Select all

 # 32 "test6.c" 1
	nop
 # 0 "" 2
/NO_APP
	mov	eax, DWORD PTR [ebp-40]
	mov	eax, DWORD PTR [eax]
	mov	DWORD PTR [ebp-44], eax
/APP
 # 34 "test6.c" 1
	nop
 # 0 "" 2
L3:
So weird if you get no asm file. ????
Try with -RR and -R

Edit : #cmdline -RR with gas doesn't work and with gcc it works
coderJeff
Site Admin
Posts: 4326
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: CryptoRndIV

Post by coderJeff »

dodicat wrote: Mar 11, 2023 19:52 Anybody:
Is there a bug in 32 bits Win 10? The #cmdline "-RR" seems to do nothing.
Looks like a bug. In the case of gas backends: because neither '-R' nor '-RR' is on the real command line, the '.ASM' file is added by default to the list of temporary files to clean up even before parsing starts. '#cmdline "-RR"' doesn't restart the parser and so gives the effect of doing nothing.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CryptoRndIV

Post by dodicat »

SARG I get the .asm with 64 bits only, not 32 bits even with -gen gcc.
With "-R" I get the c file ok.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CryptoRndIV

Post by dodicat »

Deltarho
Does this work for you in 64 bits?
SARG's code plus onerror macros which makes the .asm bigger but the asm nop lets you find the culprit.

Code: Select all

#cmdline "-exx -gen gcc -RR"
#macro errload
Print "Error handler active."
Dim errnum as long
On Error Goto ehandler
#endmacro

#macro errhandle
Goto skipover
	ehandler:
    Errnum = Err()
    Print "ERROR ";Errnum;"  ";
    Select Case as const Errnum
    case 0: Print " ... "
    Case 1 :Print  "Illegal function call" 
    Case 2 :Print  "File not found signal" 
    Case 3 :Print  "File I/O error" 
    Case 4 :Print  "Out of memory" 
    Case 5 :Print  "Illegal resume" 
    Case 6 :Print "Out of bounds array access" 
    Case 7 :Print  "Null Pointer Access" 
    Case 8 :Print  "No privileges" 
    Case 9 :Print  "interrupted signal" 
    Case 10 :Print  "illegal instruction signal" 
    Case 11 :Print  "floating point error signal" 
    Case 12 :Print  "segmentation violation signal" 
    Case 13 :Print  "Termination request signal" 
    Case 14 :Print  "abnormal termination signal" 
    Case 15 :Print  "quit request signal" 
    Case 16 :Print  "return without gosub" 
    Case 17 :Print  "end of file" 
    End Select
    Print "Function: " &__function__
    #ifdef __FB_LANG__
    #if __FB_LANG__ = "qb"
    Print "Module: " & *__Ermn
    #else
     Print "Module: " & *Ermn
    #endif
    #endif
    Print "Line: " & Erl
    Print "Press a key to exit"
    'Sleep
    'End 
skipover: 
#endmacro

errload

type tudt
		aaa as INTEGER
		bbb as INTEGER
End Type
dim as tudt udt
dim as any ptr ptrbuffer
dim as uinteger tempvar
asm nop '''added for an easy search
TempVar = *Cast(Uinteger Ptr, ptrBuffer)
asm nop
errhandle

var file= rtrim(command(0),".exe")+".asm"

shell "notepad "+file
kill file

sleep 
The .asm exists while notepad shows it, as you can see it gets deleted afterwards to declutter your folder.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

OK I am now getting this in 32-bit.

Code: Select all

/NO_APP
	mov	eax, DWORD PTR [ebp-40]
	mov	eax, DWORD PTR [eax]
	mov	DWORD PTR [ebp-44], eax
/APP
and in 64-bit

Code: Select all

/NO_APP
	mov	rax, QWORD PTR -104[rbp]
	mov	rax, QWORD PTR [rax]
	mov	QWORD PTR -112[rbp], rax
/APP
I had a lengthy command line but reduced it to only: -RR -gen gcc

Optimization from -O 1 and above and the above is not displayed.

I am now going to have some fun because there are many BASIC statements that I should like to see deciphered. I don't use #cmdline - I edit the command line using my SerCompilerSwitches.exe in WinFBE.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: CryptoRndIV

Post by deltarho[1859] »

dodicat wrote:Does this work for you in 64 bits?
No I get this.

Code: Select all

I:\WinFBE_Suite\TMPAF54.bas(63) error 24: Invalid data types
I:\WinFBE_Suite\TMPAF54.bas(65) error 20: Type mismatch
I:\WinFBE_Suite\TMPAF54.bas(66) error 58: Type mismatch, at parameter 1 of KILL()
SARG
Posts: 1766
Joined: May 27, 2005 7:15
Location: FRANCE

Re: CryptoRndIV

Post by SARG »

dodicat wrote: Mar 12, 2023 12:54 SARG I get the .asm with 64 bits only, not 32 bits even with -gen gcc.
With "-R" I get the c file ok.
-gen gcc was with the command line not with #cmdline....
Nothing is simple :D
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: CryptoRndIV

Post by dodicat »

Thanks all.
No problem with command line flags.
Deltarho
I usually test this kind of stuff with direct console compile, I cannot use fbide anyway because of uppercase -RR if I were to use switches.
All derived filetypes from the source, (.exe,.asm,.c,.a,.dll, . . . ) appear alongside the original .bas file, direct console compile will at least guarantee this behaviour.
(Just a thought)
Post Reply