[Done] Bug local labels in user library

TailBite specific forum

Moderators: gnozal, ABBKlaus, lexvictory

User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

[Done] Bug local labels in user library

Post by User_Russian »

Create a user library of the code using TailBite.

Code: Select all

ProcedureDLL MyLib_Init()
  
  x=?m1
  
  ProcedureReturn
  
  DataSection
    m1:
    Data.a 0, 0, 0, 0
  EndDataSection
EndProcedure

ProcedureDLL MyLibProc()
  ProcedureReturn 2
EndProcedure
Call MyLibProc() function from user library.

An error message.
POLINK: error: Unresolved external symbol 'MyLib_l_mylib_init_m1'.
POLINK: fatal error: 1 unresolved external(s).
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Bug local labels in user library

Post by ts-soft »

A label inside DataSection is not local!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Bug local labels in user library

Post by gnozal »

However, this used to work with PB5.00.

The labels are defined differently in PB5.10

PB5.10

Code: Select all

macro    pb_align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value }
macro pb_bssalign value { rb (value-1) - ($-_PB_BSSSection  + value-1) mod value }

define l_mylib_init_m1 l_m1
public PureBasicStart
; 
section '.code' code readable executable align 4096
; 
; 
PureBasicStart:
; 
  PUSH   dword I_BSSEnd-I_BSSStart
  PUSH   dword 0
  PUSH   dword I_BSSStart
  CALL  _memset
  ADD    esp,12
  PUSH   dword 0
  CALL  _GetModuleHandleA@4
  MOV    [_PB_Instance],eax
  PUSH   dword 0
  PUSH   dword 4096
  PUSH   dword 0
  CALL  _HeapCreate@12
  MOV    [PB_MemoryBase],eax
  MOV    eax,PB_DataSectionStart
  MOV    dword [PB_DataPointer],eax
; 
; Global x
; 
; ProcedureDLL MyLib_Init()
macro MP0{
_Procedure0:
  PUSH   ebp
  PS0=8                                                                                                                                                                                                                                           
; x=?m1
  MOV    ebp,l_mylib_init_m1
  MOV    dword [v_x],ebp
PB5.00

Code: Select all

macro    pb_align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value }
macro pb_bssalign value { rb (value-1) - ($-_PB_BSSSection  + value-1) mod value }
public PureBasicStart
; 
section '.code' code readable executable align 4096
; 
; 
PureBasicStart:
; 
  PUSH   dword I_BSSEnd-I_BSSStart
  PUSH   dword 0
  PUSH   dword I_BSSStart
  CALL  _memset
  ADD    esp,12
  PUSH   dword 0
  CALL  _GetModuleHandleA@4
  MOV    [_PB_Instance],eax
  PUSH   dword 0
  PUSH   dword 4096
  PUSH   dword 0
  CALL  _HeapCreate@12
  MOV    [PB_MemoryBase],eax
  MOV    eax,PB_DataSectionStart
  MOV    dword [PB_DataPointer],eax
; 
; Global x
; 
; ProcedureDLL MyLib_Init()
macro MP0{
_Procedure0:
  PUSH   ebp
  PS0=8                                                                                                                                                                                                                                           
; x=?m1
  MOV    ebp,l_m1
  MOV    dword [v_x],ebp
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: Bug local labels in user library

Post by mpz »

Hi,

i have the same problem. With PB 5.10 you have in the Shared file

MP3D_LibraryShared.asm

the label
Public MP3D_Library_l_cubedata
...
MP3D_Library_l_cubedata:
MP3D_Library_PB_DataSectionStart:

But in the
MP_CreateCube.asm

you find a wrong label
Extrn MP3D_Library_l_mp_createcube_cubedata

For now i can edit it manually but i hope it can be solved...

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: Bug local labels in user library

Post by ABBKlaus »

Here is a quick fix available : http://www.tailbite.com/downloads/TailBiteV1.4.9.zip

Would be nice if someone could test it :D

BR Klaus
mpz
Enthusiast
Enthusiast
Posts: 494
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: Bug local labels in user library

Post by mpz »

Hi Klaus,

i have tested my mp3d lib with some include labels (code monster over 40000 lines of code) and it work fine with 5.11 beta 1 now. I will check more functions tomorrow, but it look great.

Much Thanks for your help... :D

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Bug local labels in user library

Post by User_Russian »

ABBKlaus wrote:Would be nice if someone could test it :D s
Collect a library of code, the first post, with the mode enabled "MultiLib Option".

And try to build the library of this code (this is part of the library PBOSL), enabled mode "MultiLib Option".

Code: Select all

; Autor: DoubleDutch
; some extensions by ts-soft

Global vDBin_Size,vDBin_Compressed,vDBin_CRC

CompilerIf #PB_Compiler_Version>=510
  UseBriefLZPacker()
CompilerEndIf

Procedure iDBin_RC4Mem(Mem.l, memLen.l, key.s)
  ; based on source from Pille (German-Forum)
  Protected I.l, t.l, x.l, j.l , y.l, l.l, *Sp.LONG, *KeyP.BYTE, *Memm.BYTE
  If key
    Dim S.l(255)
    Dim K.l(255)
    I=0: j=0: t=0: x=0
    y=0
    j = 1
    l.l      = Len(key)
    *Sp      = @S()
    *KeyP    = @key
    For I = 0 To 255
      *Sp\l = I
      *Sp + 4
      If *KeyP\b = 0
        *KeyP = @key
      EndIf
      K(I) = *KeyP\b
      *KeyP+1
    Next I
    j = 0
    For I = 0 To 255
      j = (j + S(I) + K(I)) & 255
      Swap S(I),S(j)
    Next I
    I = 0
    j = 0
    *Memm = Mem
    For x = 0 To memLen-1
      I = (I+1) & 255
      j = (j + S(I)) & 255
      Swap S(I),S(j)
      t = (S(I) + (S(j) & 255)) & 255
      y = S(t)
      *Memm\b ! y
      *Memm + 1
    Next
  EndIf
  ProcedureReturn Mem
EndProcedure

Procedure iDBin_Header(file,string$,Size,compressed,crc)
  Protected len = Len(string$)
  If len
    WriteString(file,string$)
  EndIf
  WriteByte(file,len)   ; filename len
  WriteLong(file,Size)   ; no size
  WriteLong(file,compressed)   ; no pack
  WriteLong(file,crc)   ; crc of data
  WriteLong(file,$DBDBDBDB) ; id string
EndProcedure

Procedure iDBin_CheckHeader(file,pos)
  Protected result=0
  Protected len.l, Size.l, compressed.l, stringpos.l
  If pos>17
    FileSeek(file,pos-4)
    If ReadLong(file)=$DBDBDBDB
      FileSeek(file,pos-17)
      len=ReadByte(file)&$FF
      Size=ReadLong(file)
      compressed=ReadLong(file)
      stringpos=pos-17-len
      If compressed
        result=stringpos-compressed
      Else
        result=stringpos-Size
      EndIf
      FileSeek(file,pos-17)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin_Create(string$,append); Creates an empty DBin
   Protected size.l, file.l
   If append
      size=FileSize(string$)
      If size>0
         file=OpenFile(#PB_Any,string$)
         If file
            FileSeek(file,size)
         EndIf
      EndIf
   Else
      file=CreateFile(#PB_Any,string$)
   EndIf
   If file
      iDBin_Header(file,"",0,0,0)
      CloseFile(file)
   EndIf
   ProcedureReturn file
 EndProcedure
 
ProcedureDLL DBin_Create_UNICODE(string$,append); Creates an empty DBin
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  string$ = string2$
  ProcedureReturn DBin_Create(string$,append)
EndProcedure

ProcedureDLL DBin_AddFile(dest$,string$,key$,comp); Add file to DBin
  Protected result=#False
  Protected endoffile = FileSize(dest$)
  Protected Size.l, source.l, dest.l, file.l, compressed.l, file2.l

  If endoffile>0
    string$=LCase(ReplaceString(string$,"/","\"))
    Size=FileSize(string$)
    If Size>0
      source=AllocateMemory(Size)
      If source
        dest=AllocateMemory(Size+8)
        If dest
          file=ReadFile(#PB_Any,string$)
          If file
            If ReadData(file,source,Size)=Size
              If key$
                iDBin_RC4Mem(source, MemorySize(source), key$)
              EndIf
              
              CompilerIf #PB_Compiler_Version<510
                If comp>=0
                  compressed=PackMemory(source,dest,Size,comp)
                Else
                  compressed=PackMemory(source,dest,Size)
                EndIf
              CompilerElse
                compressed=CompressMemory(source, Size, dest, Size, #PB_Packer_BriefLZ)
              CompilerEndIf
                
              file2=OpenFile(#PB_Any,dest$)
              If file2
                FileSeek(file2,endoffile)
                If compressed
                  WriteData(file2,dest,compressed)
                Else
                  WriteData(file2,source,Size)
                EndIf
                iDBin_Header(file2,string$,Size,compressed,CRC32Fingerprint(source,Size))
                CloseFile(file2)
                result=#True
              EndIf
            EndIf
            CloseFile(file)
          EndIf
          FreeMemory(dest)
        EndIf
        FreeMemory(source)
      EndIf
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure
ProcedureDLL DBin_AddFile_UNICODE(dest$,string$,key$,comp); Add file to DBin
  Protected dest2$ = PeekS(@dest$,#PB_Any,#PB_Unicode)
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected key2$ = PeekS(@key$,#PB_Any,#PB_Unicode)
  dest$ = dest2$
  string$ = string2$
  key$ = key2$
  ProcedureReturn DBin_AddFile(dest$,string$,key$,comp)
EndProcedure

ProcedureDLL DBin_TotalFiles(string$); Returns total number of files in DBin
  Protected result=0
  Protected endoffile=FileSize(string$)
  Protected file.l
  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile=iDBin_CheckHeader(file,endoffile)
        If endoffile
          result+1
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure
ProcedureDLL DBin_TotalFiles_UNICODE(string$); Returns total number of files in DBin
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  string$ = string2$
  ProcedureReturn DBin_TotalFiles(string$)
EndProcedure

ProcedureDLL.s DBin_Dir(string$,pos); Returns name of file at specified index
  Protected atfile=0
  Protected result$=""
  Protected endoffile=FileSize(string$)
  Protected file.l, len.l, endoffile2.l
  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile2=endoffile
        endoffile=iDBin_CheckHeader(file,endoffile)
        If endoffile
          atfile+1
          If atfile>=pos
            len=ReadByte(file)&$FF
            If len
              result$=Space(len)
              FileSeek(file,endoffile2-17-len)
              ReadData(file,@result$,len)
              ReadByte(file) ; skip string len
              vDBin_Size=ReadLong(file)
              vDBin_Compressed=ReadLong(file)
              vDBin_CRC=ReadLong(file)
            EndIf
            Break
          EndIf
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result$
EndProcedure
ProcedureDLL.s DBin_Dir_UNICODE(string$,pos); Returns name of file at specified index
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected Result.s, Result2.s
  string$ = string2$
  Result =  DBin_Dir(string$,pos)
  Result2 = Space(Len(Result) * 2)
  PokeS(@Result2, Result, #PB_Any, #PB_Unicode)
  ProcedureReturn Result2
EndProcedure

ProcedureDLL DBin_FindFile(string$,file$)
  Protected result.l=#False
  Protected endoffile=FileSize(string$)
  Protected file.l, len.l, compare$, endoffile2.l
  file$=LCase(ReplaceString(file$,"/","\"))

  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile2=endoffile
        endoffile=iDBin_CheckHeader(file,endoffile)
        If endoffile
          len=ReadCharacter(file)
          If len
            compare$ = Space(len)
            FileSeek(file,endoffile2-17-len)
            ReadData(file, @compare$, len)
            If file$=compare$
              ReadByte(file) ; skip string len
              vDBin_Size=ReadLong(file)
              vDBin_Compressed=ReadLong(file)
              vDBin_CRC=ReadLong(file)
              result=endoffile
              Break
            EndIf
          EndIf
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure
ProcedureDLL DBin_FindFile_UNICODE(string$,file$)
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  ProcedureReturn DBin_FindFile(string$,file$)
EndProcedure

ProcedureDLL DBin_OriginalSize(string$,file$); Returns Original size of file in DBin
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_Size
  Else
    ProcedureReturn 0
  EndIf
EndProcedure
ProcedureDLL DBin_OriginalSize_UNICODE(string$,file$); Returns Original size of file in DBin
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  ProcedureReturn DBin_OriginalSize(string$,file$)
EndProcedure

ProcedureDLL DBin_CompressedSize(string$,file$); Returns Compressed size of file in DBin
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_Compressed
  Else
    ProcedureReturn 0
  EndIf
EndProcedure
ProcedureDLL DBin_CompressedSize_UNICODE(string$,file$); Returns Compressed size of file in DBin
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  ProcedureReturn DBin_CompressedSize(string$,file$)
EndProcedure

ProcedureDLL DBin_CRC32(string$,file$)
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_CRC
  Else
    ProcedureReturn 0
  EndIf
EndProcedure
ProcedureDLL DBin_CRC32_UNICODE(string$,file$)
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  ProcedureReturn DBin_CRC32(string$,file$)
EndProcedure

ProcedureDLL DBin_SaveFile(string$,file$,save$,key$); Unpack and decrypted file in DBin to Disk
  Protected result=#False
  Protected pos=DBin_FindFile(string$,file$)
  Protected dest.l, file.l, source.l
  If pos
    dest=AllocateMemory(vDBin_Size)
    If dest
      file=ReadFile(#PB_Any,string$)
      If file
        FileSeek(file,pos)
        If vDBin_Compressed
          source=AllocateMemory(vDBin_Compressed)
          If source
            If ReadData(file,source,vDBin_Compressed)=vDBin_Compressed
              CompilerIf #PB_Compiler_Version<510
                UnpackMemory(source,dest)
              CompilerElse
                UncompressMemory(source, vDBin_Compressed, dest, vDBin_Size, #PB_Packer_BriefLZ)
              CompilerEndIf
              FreeMemory(source)
              result=#True
            EndIf
          EndIf
        Else
          If ReadData(file,dest,vDBin_Size)=vDBin_Size
            result=#True
          EndIf
        EndIf
        CloseFile(file)
        If result
          result=#False
          file=CreateFile(#PB_Any,save$)
          If file
            If key$
              dest = iDBin_RC4Mem(dest, vDBin_Size,key$)
            EndIf
            WriteData(file,dest,vDBin_Size)
            CloseFile(file)
            result=#True
          EndIf
        EndIf
      EndIf
      FreeMemory(dest)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure
ProcedureDLL DBin_SaveFile_UNICODE(string$,file$,save$,key$); Unpack and decrypted file in DBin to Disk
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  Protected save2$ = PeekS(@save$,#PB_Any,#PB_Unicode)
  Protected key2$ = PeekS(@key$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  save$ = save2$
  key$ = key2$
  ProcedureReturn DBin_SaveFile(string$,file$,save$,key$)
EndProcedure

ProcedureDLL DBin_(string$,file$,key$); Unpacks and decrypted file in DBin and returns Memory Address
  Protected result.l=#False
  Protected pos.l=DBin_FindFile(string$,file$)
  Protected dest.l, file.l, source.l

  If pos
    dest=AllocateMemory(vDBin_Size)

    If dest
      file=ReadFile(#PB_Any,string$)
      If file

        FileSeek(file,pos)
        If vDBin_Compressed
          source=AllocateMemory(vDBin_Compressed)
          If source
            If ReadData(file,source,vDBin_Compressed)=vDBin_Compressed
              CompilerIf #PB_Compiler_Version<510
                UnpackMemory(source,dest)
              CompilerElse
                UncompressMemory(source, vDBin_Compressed, dest, vDBin_Size, #PB_Packer_BriefLZ)
              CompilerEndIf
              FreeMemory(source)
              result=dest
            EndIf
          EndIf
        Else
          If ReadData(file,dest,vDBin_Size)=vDBin_Size
            result=dest
          EndIf
        EndIf
        CloseFile(file)
      EndIf
      If result=#False
        FreeMemory(dest)
      EndIf
    EndIf
  EndIf
  If key$
    iDBin_RC4Mem(result,MemorySize(result),key$)
  EndIf
  ProcedureReturn result
EndProcedure
ProcedureDLL DBin__UNICODE(string$,file$,key$); Unpacks and decrypted file in DBin and returns Memory Address
  Protected string2$ = PeekS(@string$,#PB_Any,#PB_Unicode)
  Protected file2$ = PeekS(@file$,#PB_Any,#PB_Unicode)
  Protected key2$ = PeekS(@key$,#PB_Any,#PB_Unicode)
  string$ = string2$
  file$ = file2$
  key$ = key2$
  ProcedureReturn DBin_(string$,file$,key$)
EndProcedure

ProcedureDLL DBin_Free(mem); Free memory allocated using DBin_ command
  ProcedureReturn FreeMemory(mem)
EndProcedure
ABBKlaus
Addict
Addict
Posts: 1143
Joined: Sat Apr 10, 2004 1:20 pm
Location: Germany

Re: [Done] Bug local labels in user library

Post by ABBKlaus »

User_Russian wrote:Collect a library of code, the first post, with the mode enabled "MultiLib Option".

And try to build the library of this code (this is part of the library PBOSL), enabled mode "MultiLib Option".
This post is not related to the above mentioned bug report and i don´t see any label inside that snippet.

I would consider the procedure naming XXX_UNICODE() as bad coding style, as TailBite creates the required modules internally _UNICODE / _THREAD/ _THREAD_UNICODE (MultiLib-Mode).

[Edit] This compiles fine here :

Code: Select all

; Autor: DoubleDutch
; some extensions by ts-soft

Global vDBin_Size,vDBin_Compressed,vDBin_CRC

CompilerIf #PB_Compiler_Version>=510
  UseBriefLZPacker()
CompilerEndIf

Procedure.l i_RC4Mem(Mem.l, memLen.l, key.s)
  ; based on source from Pille (German-Forum)
  Protected I.l, t.l, x.l, j.l , y.l, l.l, *Sp.LONG, *KeyP.BYTE, *Memm.BYTE
  If key
    Dim S.l(255)
    Dim K.l(255)
    I=0: j=0: t=0: x=0
    y=0
    j = 1
    l.l      = Len(key)
    *Sp      = @S()
    *KeyP    = @key
    For I = 0 To 255
      *Sp\l = I
      *Sp + 4
      If *KeyP\b = 0
        *KeyP = @key
      EndIf
      K(I) = *KeyP\b
      *KeyP+1
    Next I
    j = 0
    For I = 0 To 255
      j = (j + S(I) + K(I)) & 255
      Swap S(I),S(j)
    Next I
    I = 0
    j = 0
    *Memm = Mem
    For x = 0 To memLen-1
      I = (I+1) & 255
      j = (j + S(I)) & 255
      Swap S(I),S(j)
      t = (S(I) + (S(j) & 255)) & 255
      y = S(t)
      *Memm\b ! y
      *Memm + 1
    Next
  EndIf
  ProcedureReturn Mem
EndProcedure

Procedure i_Header(file,string$,Size,compressed,crc)
  Protected len = Len(string$)
  If len
    WriteString(file,string$)
  EndIf
  WriteByte(file,len)   ; filename len
  WriteLong(file,Size)   ; no size
  WriteLong(file,compressed)   ; no pack
  WriteLong(file,crc)   ; crc of data
  WriteLong(file,$DBDBDBDB) ; id string
EndProcedure

Procedure i_CheckHeader(file,pos)
  Protected result=0
  Protected len.l, Size.l, compressed.l, stringpos.l
  If pos>17
    FileSeek(file,pos-4)
    If ReadLong(file)=$DBDBDBDB
      FileSeek(file,pos-17)
      len=ReadByte(file)&$FF
      Size=ReadLong(file)
      compressed=ReadLong(file)
      stringpos=pos-17-len
      If compressed
        result=stringpos-compressed
      Else
        result=stringpos-Size
      EndIf
      FileSeek(file,pos-17)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin_Create(string$,append); Creates an empty DBin
   Protected size.l, file.l
   If append
      size=FileSize(string$)
      If size>0
         file=OpenFile(#PB_Any,string$)
         If file
            FileSeek(file,size)
         EndIf
      EndIf
   Else
      file=CreateFile(#PB_Any,string$)
   EndIf
   If file
      i_Header(file,"",0,0,0)
      CloseFile(file)
   EndIf
   ProcedureReturn file
 EndProcedure
 
ProcedureDLL DBin_AddFile(dest$,string$,key$,comp); Add file to DBin
  Protected result=#False
  Protected endoffile = FileSize(dest$)
  Protected Size.l, source.l, dest.l, file.l, compressed.l, file2.l

  If endoffile>0
    string$=LCase(ReplaceString(string$,"/","\"))
    Size=FileSize(string$)
    If Size>0
      source=AllocateMemory(Size)
      If source
        dest=AllocateMemory(Size+8)
        If dest
          file=ReadFile(#PB_Any,string$)
          If file
            If ReadData(file,source,Size)=Size
              If key$
                i_RC4Mem(source, MemorySize(source), key$)
              EndIf
              
              CompilerIf #PB_Compiler_Version<510
                If comp>=0
                  compressed=PackMemory(source,dest,Size,comp)
                Else
                  compressed=PackMemory(source,dest,Size)
                EndIf
              CompilerElse
                compressed=CompressMemory(source, Size, dest, Size, #PB_Packer_BriefLZ)
              CompilerEndIf
                
              file2=OpenFile(#PB_Any,dest$)
              If file2
                FileSeek(file2,endoffile)
                If compressed
                  WriteData(file2,dest,compressed)
                Else
                  WriteData(file2,source,Size)
                EndIf
                i_Header(file2,string$,Size,compressed,CRC32Fingerprint(source,Size))
                CloseFile(file2)
                result=#True
              EndIf
            EndIf
            CloseFile(file)
          EndIf
          FreeMemory(dest)
        EndIf
        FreeMemory(source)
      EndIf
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin_TotalFiles(string$); Returns total number of files in DBin
  Protected result=0
  Protected endoffile=FileSize(string$)
  Protected file.l
  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile=i_CheckHeader(file,endoffile)
        If endoffile
          result+1
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL.s DBin_Dir(string$,pos); Returns name of file at specified index
  Protected atfile=0
  Protected result$=""
  Protected endoffile=FileSize(string$)
  Protected file.l, len.l, endoffile2.l
  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile2=endoffile
        endoffile=i_CheckHeader(file,endoffile)
        If endoffile
          atfile+1
          If atfile>=pos
            len=ReadByte(file)&$FF
            If len
              result$=Space(len)
              FileSeek(file,endoffile2-17-len)
              ReadData(file,@result$,len)
              ReadByte(file) ; skip string len
              vDBin_Size=ReadLong(file)
              vDBin_Compressed=ReadLong(file)
              vDBin_CRC=ReadLong(file)
            EndIf
            Break
          EndIf
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result$
EndProcedure

ProcedureDLL DBin_FindFile(string$,file$)
  Protected result.l=#False
  Protected endoffile=FileSize(string$)
  Protected file.l, len.l, compare$, endoffile2.l
  file$=LCase(ReplaceString(file$,"/","\"))

  If endoffile>16
    file=ReadFile(#PB_Any,string$)
    If file
      Repeat
        endoffile2=endoffile
        endoffile=i_CheckHeader(file,endoffile)
        If endoffile
          len=ReadCharacter(file)
          If len
            compare$ = Space(len)
            FileSeek(file,endoffile2-17-len)
            ReadData(file, @compare$, len)
            If file$=compare$
              ReadByte(file) ; skip string len
              vDBin_Size=ReadLong(file)
              vDBin_Compressed=ReadLong(file)
              vDBin_CRC=ReadLong(file)
              result=endoffile
              Break
            EndIf
          EndIf
        EndIf
      Until Not endoffile
      CloseFile(file)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin_OriginalSize(string$,file$); Returns Original size of file in DBin
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_Size
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL DBin_CompressedSize(string$,file$); Returns Compressed size of file in DBin
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_Compressed
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL DBin_CRC32(string$,file$)
  If DBin_FindFile(string$,file$)
    ProcedureReturn vDBin_CRC
  Else
    ProcedureReturn 0
  EndIf
EndProcedure

ProcedureDLL DBin_SaveFile(string$,file$,save$,key$); Unpack and decrypted file in DBin to Disk
  Protected result=#False
  Protected pos=DBin_FindFile(string$,file$)
  Protected dest.l, file.l, source.l
  If pos
    dest=AllocateMemory(vDBin_Size)
    If dest
      file=ReadFile(#PB_Any,string$)
      If file
        FileSeek(file,pos)
        If vDBin_Compressed
          source=AllocateMemory(vDBin_Compressed)
          If source
            If ReadData(file,source,vDBin_Compressed)=vDBin_Compressed
              CompilerIf #PB_Compiler_Version<510
                UnpackMemory(source,dest)
              CompilerElse
                UncompressMemory(source, vDBin_Compressed, dest, vDBin_Size, #PB_Packer_BriefLZ)
              CompilerEndIf
              FreeMemory(source)
              result=#True
            EndIf
          EndIf
        Else
          If ReadData(file,dest,vDBin_Size)=vDBin_Size
            result=#True
          EndIf
        EndIf
        CloseFile(file)
        If result
          result=#False
          file=CreateFile(#PB_Any,save$)
          If file
            If key$
              dest = i_RC4Mem(dest, vDBin_Size,key$)
            EndIf
            WriteData(file,dest,vDBin_Size)
            CloseFile(file)
            result=#True
          EndIf
        EndIf
      EndIf
      FreeMemory(dest)
    EndIf
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin(string$,file$,key$); Unpacks and decrypted file in DBin and returns Memory Address
  Protected result.l=#False
  Protected pos.l=DBin_FindFile(string$,file$)
  Protected dest.l, file.l, source.l

  If pos
    dest=AllocateMemory(vDBin_Size)

    If dest
      file=ReadFile(#PB_Any,string$)
      If file

        FileSeek(file,pos)
        If vDBin_Compressed
          source=AllocateMemory(vDBin_Compressed)
          If source
            If ReadData(file,source,vDBin_Compressed)=vDBin_Compressed
              CompilerIf #PB_Compiler_Version<510
                UnpackMemory(source,dest)
              CompilerElse
                UncompressMemory(source, vDBin_Compressed, dest, vDBin_Size, #PB_Packer_BriefLZ)
              CompilerEndIf
              FreeMemory(source)
              result=dest
            EndIf
          EndIf
        Else
          If ReadData(file,dest,vDBin_Size)=vDBin_Size
            result=dest
          EndIf
        EndIf
        CloseFile(file)
      EndIf
      If result=#False
        FreeMemory(dest)
      EndIf
    EndIf
  EndIf
  If key$
    i_RC4Mem(result,MemorySize(result),key$)
  EndIf
  ProcedureReturn result
EndProcedure

ProcedureDLL DBin_Free(mem); Free memory allocated using DBin_ command
  ProcedureReturn FreeMemory(mem)
EndProcedure
BR Klaus
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: [Done] Bug local labels in user library

Post by User_Russian »

ABBKlaus wrote:This post is not related to the above mentioned bug report and i don´t see any label inside that snippet.
The code in the first post is a label?
From this code, it is impossible to create a working library, with the option build "MultiLib Option" in PB 5.10 and TailBite V 1.4.9.
ABBKlaus wrote:I would consider the procedure naming XXX_UNICODE() as bad coding style, as TailBite creates the required modules internally _UNICODE / _THREAD/ _THREAD_UNICODE (MultiLib-Mode).
The code of the library PBOSL.
I'm not the author, and not me, it redone.
ABBKlaus wrote:[Edit] This compiles fine here :
Thank you.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: [Done] Bug local labels in user library

Post by ts-soft »

PBOSL Libs outdated and no more supported.
None of PBOSL Libs designed to work with the /MULTILIB flag.

Greetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply