include \masm32\include\masm32rt.inc
comment * -----------------------------------------------------
                GPCore.dll->49 53 4F 2D 38 38 35 39 2D 31 
                            47 42 4B 00 00 00 00 00 00 00
                ISO-8859-1->GBK
        ----------------------------------------------------- *
        .data
        fname    db "GPCore.dll",0
        fbakname db "GPCore.dll.bak",0
        findStr  db "ISO-8859-1",0
        fixData  db 47H,42H,4BH,00,00,00,00,00,00,00 ;10
        .code
start:
        call main
        exit
main proc
        LOCAL hFile     :DWORD
        LOCAL hBakFile  :DWORD
        LOCAL dSize     :DWORD
        LOCAL hMem      :DWORD
        LOCAL hMemBase  :DWORD
        .if rv(exist,offset fname) != 0
                mov hFile, fopen(offset fname)
        .else
                print "not find "
                print offset fname
                ret
        .endif
        mov dSize, fseek(hFile,0,FILE_END)
        mov hMem, alloc(dSize)

        mov eax , fseek(hFile,0,FILE_BEGIN)
        mov eax , fread(hFile,hMem,dSize)
  
        mov ebx,0
        mov eax , hMem
        mov hMemBase , eax
        .while ebx < dSize
            invoke lstrcmp, offset findStr , hMem
            .if eax == 0
                ;backup file to GPCore.dll.bak
                mov hBakFile, fcreate( offset fbakname )
                mov eax , fwrite( hBakFile, hMemBase, dSize)
                fclose hBakFile
                ;fix to GBK
                mov eax , fseek(hFile,ebx,FILE_BEGIN)
                mov eax , fwrite( hFile, offset fixData, 10)
                print "Guitar Pro 6 现在可以正常使用简体",13,10
                jmp pos1
            .endif
            add hMem,1
            inc ebx
        .endw
        pos1:
        fclose hFile
        free hMem
        ret
main endp

end start
