------------------------------------------------------------------------------------------
                      [BUG/PRB.] VFP 9.0 FIX - THE NUMBER OF TIMES TO TRY AGAIN AFTER LOCK FILE FAILED
                                 January 2024
                 ------------------------------------------------------------------------------------------
                                     CCB



1. BUG:

     In vfp9 (and vfp6, vfp7, vfp8), somtimes the RLOCK() function runs failed on Windows Vista or later.


2. CAUSE:

     There are some compatible problems when the RLOCK() function calls the LockFile Windows API
     for the Windows Defender program or the antivirus programs.
     Now if the RLOCK() function calls the LockFile Windows API failed,
     it will call the LockFile Windows API many times again.

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Fun41fd5f :: ; proc near
             sub esp , 018h                                                  ;0x0041fd5f :        83ec18
             mov eax ,  dword ptr [ Data937108 ]                             ;0x0041fd62 :        a108719300
             push ebx                                                        ;0x0041fd67 :        53
             push ebp                                                        ;0x0041fd68 :        55
             push esi                                                        ;0x0041fd69 :        56
             mov ebx , ecx                                                   ;0x0041fd6a :        8bd9
             cmp ebx , eax                                                   ;0x0041fd6c :        3bd8
             mov esi , edx                                                   ;0x0041fd6e :        8bf2
             push edi                                                        ;0x0041fd70 :        57
             mov  dword ptr [ esp + 24 ] , esi                               ;0x0041fd71 :        89742418
             mov  dword ptr [ esp + 28 ] , ebx                               ;0x0041fd75 :        895c241c
             mov  byte ptr [ esp + 22 ] , 00h                                ;0x0041fd79 :        c644241600
             jnb Label57fbdd                                                 ;0x0041fd7e :        0f8359fe1500
             mov  ecx , dword ptr [ Data93757c ]                             ;0x0041fd84 :        8b0d7c759300
             mov edi , ebx                                                   ;0x0041fd8a :        8bfb
             imul edi , edi , 038h                                           ;0x0041fd8c :        6bff38
             mov  al , byte ptr [ edi + ecx + 44 ]                           ;0x0041fd8f :        8a440f2c
             add edi , ecx                                                   ;0x0041fd93 :        03f9
             test al , 01h                                                   ;0x0041fd95 :        a801
             mov  dword ptr [ esp + 32 ] , edi                               ;0x0041fd97 :        897c2420
             je Label57fbe7                                                  ;0x0041fd9b :        0f8446fe1500
             test esi , esi                                                  ;0x0041fda1 :        85f6
             je Label52445d                                                  ;0x0041fda3 :        0f84b4461000

     Label41fda9 ::
             mov  eax , dword ptr [ edi + 44 ]                               ;0x0041fda9 :        8b472c
             mov  ecx , dword ptr [esi]                                      ;0x0041fdac :        8b0e
             mov  ebp , dword ptr [ ecx + 0164h ]                            ;0x0041fdae :        8ba964010000
             shr eax , 0Ah                                                   ;0x0041fdb4 :        c1e80a
             and eax , 03h                                                   ;0x0041fdb7 :        83e003
             cmp eax , 01h                                                   ;0x0041fdba :        83f801
             je Label57fbf1                                                  ;0x0041fdbd :        0f842efe1500

     Label41fdc3 ::
             cmp eax , 03h                                                   ;0x0041fdc3 :        83f803
             je Label57fc00                                                  ;0x0041fdc6 :        0f8434fe1500

     Label41fdcc ::
             mov  eax , dword ptr [ esp + 48 ]                               ;0x0041fdcc :        8b442430
             test eax , eax                                                  ;0x0041fdd0 :        85c0
             mov  ecx , dword ptr [ esp + 44 ]                               ;0x0041fdd2 :        8b4c242c
             je Label51f010                                                  ;0x0041fdd6 :        0f8434f20f00

     Label41fddc ::
             or ecx , 040000000h                                             ;0x0041fddc :        81c900000040
             test ebp , ebp                                                  ;0x0041fde2 :        85ed
             mov  dword ptr [ esp + 44 ] , ecx                               ;0x0041fde4 :        894c242c
             jne Label57fc50                                                 ;0x0041fde8 :        0f8562fe1500

     Label41fdee ::
             mov  eax , dword ptr [ esp + 52 ]                               ;0x0041fdee :        8b442434
             test eax , eax                                                  ;0x0041fdf2 :        85c0
             mov  eax , dword ptr [ edi + 44 ]                               ;0x0041fdf4 :        8b472c
             je Label41fe33                                                  ;0x0041fdf7 :        743a
             test  byte ptr ah , 01h                                         ;0x0041fdf9 :        f6c401
             je Label57ff05                                                  ;0x0041fdfc :        0f8403011600

     Label41fe02 ::
             mov  edx , dword ptr [ esp + 48 ]                               ;0x0041fe02 :        8b542430
             mov  edi , dword ptr [ edi + 40 ]                               ;0x0041fe06 :        8b7f28

     
     ;
     ;                 -------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE NUMBER OF TIMES TO TRY AGAIN AFTER LOCK FILE FAILED
     ;                                February 2020
     ;                 -------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The number of times to try again after lock file failed.
     ;
     ; 2020/2/9, by ccb
     ;

     ;         pushd 00h                                                       ;0x0041fe09 :        6a00
     ;         push edx                                                        ;0x0041fe0b :        52
     ;         pushd 00h                                                       ;0x0041fe0c :        6a00
     ;         push ecx                                                        ;0x0041fe0e :        51
     ;         push edi                                                        ;0x0041fe0f :        57
     ;         call  LockFile                                    ;0x0041fe10 :        ff15c0709100

             mov dword ptr vfpa_lockfile_lockfile_cnt,00h
             mov dword ptr vfpa_lockfile_lockfile_file,edi
             mov dword ptr vfpa_lockfile_lockfile_fileoffsetlow,ecx
             mov dword ptr vfpa_lockfile_lockfile_fileoffsethigh,00h
             mov dword ptr vfpa_lockfile_lockfile_numberofbytestolocklow,edx
             mov dword ptr vfpa_lockfile_lockfile_numberofbytestolockhigh,00h

     Label41fe09 ::
             push dword ptr vfpa_lockfile_lockfile_numberofbytestolockhigh
             push dword ptr vfpa_lockfile_lockfile_numberofbytestolocklow
             push dword ptr vfpa_lockfile_lockfile_fileoffsethigh
             push dword ptr vfpa_lockfile_lockfile_fileoffsetlow
             push dword ptr vfpa_lockfile_lockfile_file
             call  LockFile
             test eax , eax
             jne Label41fe16
             mov ecx,dword ptr vfpa_sys9030_data
             inc dword ptr vfpa_lockfile_lockfile_cnt
             cmp dword ptr vfpa_lockfile_lockfile_cnt,ecx
             ja Label41fe16
             push dword ptr vfpa_sys9074_data
             call  Sleep
             jmp Label41fe09

     
     Label41fe16 ::
             test eax , eax                                                  ;0x0041fe16 :        85c0
             je Label57ff23                                                  ;0x0041fe18 :        0f8405011600

     Label41fe1e ::
             xor eax , eax                                                   ;0x0041fe1e :        33c0

     Label41fe20 ::
             xor ecx , ecx                                                   ;0x0041fe20 :        33c9
             test eax , eax                                                  ;0x0041fe22 :        85c0
             sete cl                                                         ;0x0041fe24 :        0f94c1
             pop edi                                                         ;0x0041fe27 :        5f
             pop esi                                                         ;0x0041fe28 :        5e
             pop ebp                                                         ;0x0041fe29 :        5d
             pop ebx                                                         ;0x0041fe2a :        5b
             mov eax , ecx                                                   ;0x0041fe2b :        8bc1
             add esp , 018h                                                  ;0x0041fe2d :        83c418
             ret 0Ch                                                         ;0x0041fe30 :        c20c00


4. APPLIES TO:

     VFP 6.0.8167.0
     VFP 6.0.8961.0 (SP5)

     VFP 7.0.0.9262
     VFP 7.0.0.9465 (SP1)

     VFP 8.0.0.2521
     VFP 8.0.0.3117 (SP1)

     VFP 9.0.0.2412
     VFP 9.0.0.3504 (SP1)
     VFP 9.0.0.4611 (SP2)
     VFP 9.0.0.5015 (SP2)
     VFP 9.0.0.5411 (SP2)
     VFP 9.0.0.5721 (SP2)
     VFP 9.0.0.5815 (SP2)
     VFP 9.0.0.6303 (SP2)
     VFP 9.0.0.6602 (SP2)
     VFP 9.0.0.7423 (SP2)

     The bug has been fixed in VFP Advanced.


5. REFERENCE WEBSITES:

     1, baiyujia.com:
     http://www.baiyujia.com
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix109.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix65.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix66.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix67.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix68.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix69.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix70.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix71.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix72.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix73.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix74.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix84.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix85.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix107.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix108.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix143.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix144.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix145.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix146.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix147.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix148.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix149.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix150.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix203.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix261.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix262.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix269.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix270.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix278.asp
     http://www.baiyujia.com/vfpdocuments/f_vfp9fix279.asp

     2, microsoft.com:
     https://devblogs.microsoft.com/oldnewthing/20120907-00/?p=6663


6. OTHER:

     For reference only, there is no guarantees.

     Any questions or suggestions, please send me an email at ccb2000@163.com.