------------------------------------------------------------------------------
                      VFP 9.0 FIX - THE FILETOSTR() FUNCTION USES THE WINDOWS SYSTEM CACHE
                                February 2019
                 ------------------------------------------------------------------------------
                                     CCB



1. BUG:

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


2. CAUSE:

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

     There are some BUGs in the following code.


3. RESOLUTION:

     We can write some code to fix the BUG.

     Label488d4b ::
             push ebp                                                        ;0x00488d4b :        55
             lea ebp ,  dword ptr [ esp + 0FFFFFDBCh ]                       ;0x00488d4c :        8dac24bcfdffff
             sub esp , 02C4h                                                 ;0x00488d53 :        81ecc4020000
             mov eax ,  dword ptr [ Data937090 ]                             ;0x00488d59 :        a190709300
             push ebx                                                        ;0x00488d5e :        53
             push esi                                                        ;0x00488d5f :        56
             push edi                                                        ;0x00488d60 :        57
             mov  dword ptr [ ebp + 0240h ] , eax                            ;0x00488d61 :        898540020000
             call Fun420d8c                                                  ;0x00488d67 :        e82080f9ff
             mov esi , eax                                                   ;0x00488d6c :        8bf0
             mov  dword ptr [ ebp + 40 ] , esi                               ;0x00488d6e :        897528
             call Fun42371d                                                  ;0x00488d71 :        e8a7a9f9ff
             cmp  dword ptr [ Data936f1c ] , 01h                             ;0x00488d76 :        833d1c6f930001
             jne Label488e91                                                 ;0x00488d7d :        0f850e010000
             cmp  byte ptr [esi] , 048h                                      ;0x00488d83 :        803e48
             jne Label488e91                                                 ;0x00488d86 :        0f8505010000
             mov edx , esi                                                   ;0x00488d8c :        8bd6
             lea ebx ,  dword ptr [ ebp + 52 ]                               ;0x00488d8e :        8d5d34
             call Fun52b398                                                  ;0x00488d91 :        e802260a00
             xor ebx , ebx                                                   ;0x00488d96 :        33db
             push ebx                                                        ;0x00488d98 :        53
             pushd offset Data93a8c0                                                  ;0x00488d99 :        68c0a89300
             pushd offset Data91aed0                                                  ;0x00488d9e :        68d0ae9100
             pushd 0104h                                                     ;0x00488da3 :        6804010000
             lea eax ,  dword ptr [ ebp + 52 ]                               ;0x00488da8 :        8d4534
             push eax                                                        ;0x00488dab :        50
             call Fun437e2a                                                  ;0x00488dac :        e879f0faff
             push eax                                                        ;0x00488db1 :        50
             lea edx ,  dword ptr [ ebp + 52 ]                               ;0x00488db2 :        8d5534
             lea ecx ,  dword ptr [ ebp + 0138h ]                            ;0x00488db5 :        8d8d38010000
             call Fun42cc34                                                  ;0x00488dbb :        e8743efaff
             lea edx ,  dword ptr [ ebp + 32 ]                               ;0x00488dc0 :        8d5520
             lea eax ,  dword ptr [ ebp - 128 ]                              ;0x00488dc3 :        8d4580
             call Fun42c27f                                                  ;0x00488dc6 :        e8b434faff
             push ebx                                                        ;0x00488dcb :        53
             push eax                                                        ;0x00488dcc :        50
             call Fun42c2be                                                  ;0x00488dcd :        e8ec34faff
             mov esi , eax                                                   ;0x00488dd2 :        8bf0
             cmp esi , ebx                                                   ;0x00488dd4 :        3bf3
             pop ecx                                                         ;0x00488dd6 :        59
             pop ecx                                                         ;0x00488dd7 :        59
             jne Label488deb                                                 ;0x00488dd8 :        7511


     ;
     ;                 ------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE FILETOSTR() FUNCTION USES THE WINDOWS SYSTEM CACHE
     ;                                February 2019
     ;                 ------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The FILETOSTR() function uses the windows system cache.
     ;
     ; 2019/2/28, by ccb
     ;

     ;         mov dword ptr vfpa_filetostr_isfiletostr,01h


             pushd 021h                                                      ;0x00488dda :        6a21
             pop edx                                                         ;0x00488ddc :        5a
             lea ecx ,  dword ptr [ ebp + 0138h ]                            ;0x00488ddd :        8d8d38010000
             call Fun42ce21                                                  ;0x00488de3 :        e83940faff


     ;
     ;                 ------------------------------------------------------------------------------
     ;                      VFP 9.0 FIX - THE FILETOSTR() FUNCTION USES THE WINDOWS SYSTEM CACHE
     ;                                February 2019
     ;                 ------------------------------------------------------------------------------
     ;                                     CCB
     ;
     ; The FILETOSTR() function uses the windows system cache.
     ;
     ; 2019/2/28, by ccb
     ;

     Label488de7 ::
     ;         mov dword ptr vfpa_filetostr_isfiletostr,00h


     Label488de8 ::
             mov  dword ptr [ ebp + 48 ] , eax                               ;0x00488de8 :        894530

     Label488deb ::
             lea eax ,  dword ptr [ ebp + 32 ]                               ;0x00488deb :        8d4520
             push eax                                                        ;0x00488dee :        50
             lea eax ,  dword ptr [ ebp - 128 ]                              ;0x00488def :        8d4580
             call Fun42d200                                                  ;0x00488df2 :        e80944faff
             mov  edi , dword ptr [ ebp + 48 ]                               ;0x00488df7 :        8b7d30
             cmp edi , 0FFFFFFFFh                                            ;0x00488dfa :        83ffff
             je Label60c6f7                                                  ;0x00488dfd :        0f84f4381800
             cmp esi , ebx                                                   ;0x00488e03 :        3bf3
             jne Label488e96                                                 ;0x00488e05 :        0f858b000000
             call Fun433ef7                                                  ;0x00488e0b :        e8e7b0faff
             mov  esi , dword ptr [ ebp + 40 ]                               ;0x00488e10 :        8b7528
             mov  dword ptr [ ebp + 44 ] , eax                               ;0x00488e13 :        89452c
             call Fun420d46                                                  ;0x00488e16 :        e82b7ff9ff
             test eax , eax                                                  ;0x00488e1b :        85c0
             je Label60c70c                                                  ;0x00488e1d :        0f84e9381800
             lea edx ,  dword ptr [ ebp + 36 ]                               ;0x00488e23 :        8d5524
             lea eax ,  dword ptr [ ebp - 48 ]                               ;0x00488e26 :        8d45d0
             call Fun42c27f                                                  ;0x00488e29 :        e85134faff
             push ebx                                                        ;0x00488e2e :        53
             push eax                                                        ;0x00488e2f :        50
             call Fun42c2be                                                  ;0x00488e30 :        e88934faff
             mov  edi , dword ptr [ ebp + 40 ]                               ;0x00488e35 :        8b7d28
             mov ebx , eax                                                   ;0x00488e38 :        8bd8
             test ebx , ebx                                                  ;0x00488e3a :        85db
             pop ecx                                                         ;0x00488e3c :        59
             pop ecx                                                         ;0x00488e3d :        59
             jne Label488e52                                                 ;0x00488e3e :        7512
             push  dword ptr [ ebp + 44 ]                                    ;0x00488e40 :        ff752c
             mov  eax , dword ptr [ edi + 32 ]                               ;0x00488e43 :        8b4720
             push  dword ptr [eax]                                           ;0x00488e46 :        ff30
             mov  eax , dword ptr [ ebp + 48 ]                               ;0x00488e48 :        8b4530
             xor esi , esi                                                   ;0x00488e4b :        33f6
             call Fun4348d8                                                  ;0x00488e4d :        e886bafaff

     Label488e52 ::
             lea eax ,  dword ptr [ ebp + 36 ]                               ;0x00488e52 :        8d4524
             push eax                                                        ;0x00488e55 :        50
             lea eax ,  dword ptr [ ebp - 48 ]                               ;0x00488e56 :        8d45d0
             call Fun42d200                                                  ;0x00488e59 :        e8a243faff
             mov  ecx , dword ptr [ ebp + 48 ]                               ;0x00488e5e :        8b4d30
             call Fun42ddf2                                                  ;0x00488e61 :        e88c4ffaff
             test ebx , ebx                                                  ;0x00488e66 :        85db
             jne Label60c71d                                                 ;0x00488e68 :        0f85af381800
             mov  eax , dword ptr [ ebp + 44 ]                               ;0x00488e6e :        8b452c
             mov  dword ptr [ edi + 8 ] , eax                                ;0x00488e71 :        894708
             mov  byte ptr [edi] , 048h                                      ;0x00488e74 :        c60748
             and  dword ptr [ edi + 4 ] , 00h                                ;0x00488e77 :        83670400

     Label488e7b ::
             mov  ecx , dword ptr [ ebp + 0240h ]                            ;0x00488e7b :        8b8d40020000
             call Fun42bf1d                                                  ;0x00488e81 :        e89730faff
             pop edi                                                         ;0x00488e86 :        5f
             pop esi                                                         ;0x00488e87 :        5e
             pop ebx                                                         ;0x00488e88 :        5b
             add ebp , 0244h                                                 ;0x00488e89 :        81c544020000
             leave                                                           ;0x00488e8f :        c9
             ret                                                             ;0x00488e90 :        c3


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_vfp9fix65.asp

     2, microsoft.com:
     https://blogs.msdn.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.