It is currently Mon Jun 24, 2019 6:33 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: UnRAR 5 Module/Wrapper Windows
PostPosted: Sun Sep 29, 2013 5:27 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5754
Location: Berlin - Germany
Code:
DeclareModule unrar
  #ERAR_SUCCESS             = 0
  #ERAR_END_ARCHIVE         = 10
  #ERAR_NO_MEMORY           = 11
  #ERAR_BAD_DATA            = 12
  #ERAR_BAD_ARCHIVE         = 13
  #ERAR_UNKNOWN_FORMAT      = 14
  #ERAR_EOPEN               = 15
  #ERAR_ECREATE             = 16
  #ERAR_ECLOSE              = 17
  #ERAR_EREAD               = 18
  #ERAR_EWRITE              = 19
  #ERAR_SMALL_BUF           = 20
  #ERAR_UNKNOWN             = 21
  #ERAR_MISSING_PASSWORD    = 22
 
  #RAR_OM_LIST              = 0
  #RAR_OM_EXTRACT           = 1
  #RAR_OM_LIST_INCSPLIT     = 2
 
  #RAR_SKIP                 = 0
  #RAR_TEST                 = 1
  #RAR_EXTRACT              = 2
 
  #RAR_VOL_ASK              = 0
  #RAR_VOL_NOTIFY           = 1
 
  #RAR_DLL_VERSION          = 6
 
  #RAR_HASH_NONE            = 0
  #RAR_HASH_CRC32           = 1
  #RAR_HASH_BLAKE2          = 2
 
  #RHDF_SPLITBEFORE         = $01
  #RHDF_SPLITAFTER          = $02
  #RHDF_ENCRYPTED           = $04
  #RHDF_SOLID               = $10
  #RHDF_DIRECTORY           = $20

  Enumeration
    #UCM_CHANGEVOLUME
    #UCM_PROCESSDATA
    #UCM_NEEDPASSWORD
    #UCM_CHANGEVOLUMEW
    #UCM_NEEDPASSWORDW
  EndEnumeration
 
  Structure RARHeaderDataEx
    ArcName.b[1024]
    ArcNameW.w[1024]
    FileName.b[1024]
    FileNameW.w[1024]
    Flags.l
    PackSize.q
    UnpSize.q
    HostOS.l
    FileCRC.l
    FileTime.l
    UnpVer.l
    Method.l
    FileAttr.l
    *CmtBuf
    CmtBufSize.l
    CmtSize.l
    CmtState.l
    DictSize.l
    HashType.l
    Hash.b[32]
    Reserved.l[1014]
  EndStructure
 
  Structure RAROpenArchiveDataEx
    *ArcName
    *ArcNameW
    OpenMode.l
    OpenResult.l
    *CmtBuf
    CmtBufSize.l
    CmtSize.l
    CmtState.l
    Flags.l
    *Callback
    UserData.i
    Reserved.l[28]
  EndStructure

  Prototype UNRARCALLBACK(msg, UserData, P1, P2)
  Prototype CHANGEVOLPROC(ArcName.s, Mode)
  Prototype PROCESSDATAPROC(*Addr, Size)
  Prototype RAROpenArchive(*ArchiveData.RAROpenArchiveDataEx)
  Prototype RARCloseArchive(hArcData)
  Prototype RARReadHeader(hArcData, *HeaderData.RARHeaderDataEx)
  Prototype RARProcessFile(hArcData, Operation, DestPath.s, DestName.s)
  Prototype RARSetCallback(hArcData, *Callback.UNRARCALLBACK, UserData)
  Prototype RARSetChangeVolProc(hArcData, *ChangeVolProc.CHANGEVOLPROC)
  Prototype RARSetProcessDataProc(hArcData, *ProcessDataProc.PROCESSDATAPROC)
  Prototype RARSetPassword(hArcData, Password.p-ascii)
  Prototype RARGetDllVersion()
 
  Global RAROpenArchive.RAROpenArchive
  Global RARProcessFile.RARProcessFile
  Global RAROpenArchive.RAROpenArchive
  Global RARProcessFile.RARProcessFile
  Global RARReadHeader.RARReadHeader
  Global RARCloseArchive.RARCloseArchive
  Global RARSetCallback.RARSetCallback
  Global RARSetChangeVolProc.RARSetChangeVolProc
  Global RARSetProcessDataProc.RARSetProcessDataProc
  Global RARSetPassword.RARSetPassword
  Global RARGetDllVersion.RARGetDllVersion
 
  Declare RARUnpackArchiv(FileName.s, DestPath.s = "", Password.s = "", *Callback = 0)
EndDeclareModule

Module unrar
  EnableExplicit

  Define DLL
 
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    DLL = OpenLibrary(#PB_Any, "unrar64.dll")
  CompilerElse
    DLL = OpenLibrary(#PB_Any, "unrar.dll")
  CompilerEndIf
 
  If DLL
    RAROpenArchive        = GetFunction(DLL, "RAROpenArchiveEx")
    CompilerIf #PB_Compiler_Unicode
    RARProcessFile        = GetFunction(DLL, "RARProcessFileW")
    CompilerElse
    RARProcessFile        = GetFunction(DLL, "RARProcessFile")
    CompilerEndIf
    RARReadHeader         = GetFunction(DLL, "RARReadHeaderEx")
    RARCloseArchive       = GetFunction(DLL, "RARCloseArchive")
    RARSetCallback        = GetFunction(DLL, "RARSetCallback")
    RARSetChangeVolProc   = GetFunction(DLL, "RARSetChangeVolProc")
    RARSetProcessDataProc = GetFunction(DLL, "RARSetProcessDataProc")
    RARSetPassword        = GetFunction(DLL, "RARSetPassword")
    RARGetDllVersion      = GetFunction(DLL, "RARGetDllVersion")
  EndIf
 
  Procedure Callback(msg, UserData, P1, P2)
    Protected PWD.s
   
    If UserData
      PWD = PeekS(UserData)
    EndIf
    Select msg
      Case #UCM_NEEDPASSWORD
        If PWD = ""
          PWD = InputRequester("Password", "Password required:", "", #PB_InputRequester_Password)
        EndIf
        If PWD
          PokeS(P1, PWD, P2, #PB_Ascii)
          ProcedureReturn #True
        EndIf
      Case #UCM_NEEDPASSWORDW
        If PWD = ""
          PWD = InputRequester("Password", "Password required:", "", #PB_InputRequester_Password)
        EndIf
        If PWD
          PokeS(P1, PWD, P2, #PB_Unicode)
          ProcedureReturn #True
        EndIf
    EndSelect
  EndProcedure
 
  Procedure RARUnpackArchiv(FileName.s, DestPath.s = "", Password.s = "", *Callback = 0)
    Protected raropen.RAROpenArchiveDataEx
    Protected rarheader.RARHeaderDataEx
    Protected hRAR, NoError = #True
   
    CompilerIf #PB_Compiler_Unicode
      raropen\ArcNameW = @Filename
    CompilerElse
      raropen\ArcName = @Filename
      If DestPath
        CharToOem_(DestPath, DestPath)
      EndIf
    CompilerEndIf
    raropen\OpenMode = #RAR_OM_EXTRACT
    If Password
      raropen\UserData = @Password
    EndIf
    If *Callback
      raropen\Callback = *Callback
    Else
      raropen\Callback = @Callback()
    EndIf
   
   
    hRAR = RAROpenArchive(raropen)
   
    If hRAR

      While RARReadHeader(hRAR, rarheader) = #ERAR_SUCCESS
        If RARProcessFile(hRAR, #RAR_EXTRACT, DestPath, #NULL$) <> #ERAR_SUCCESS
          NoError = #False
        EndIf
      Wend
      RARCloseArchive(hRAR)
    EndIf
    ProcedureReturn NoError
  EndProcedure
 
EndModule


You can download dlls/docu here: https://dl.dropboxusercontent.com/u/3086026/unrar.zip

Greetings - Thomas

_________________
PureBasic 5.70 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Last edited by ts-soft on Sat Oct 05, 2013 3:31 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sun Sep 29, 2013 9:18 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1657
Location: Uttoxeter, UK
@ts-soft

Great! Works like a dream!
Thank you very much for sharing.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sun Sep 29, 2013 9:31 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 258
Location: France
Fast and furious dude ;) thanks

_________________
~Ar-S~

ResizerGold : The easiest way to resize your pictures and more
My webSite (french) : LDVMULTIMEDIA
PB - 5.4x LTS / 5.6x - W10 x64 - GTX1080 - i5 6600k
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Mon Sep 30, 2013 8:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Aug 09, 2003 3:13 am
Posts: 775
Location: 90-61-92 // EU or ASIA
Code:
#RAR_HASH_BLAKE2 = 2

        Debug rarheader\HashType
       
        For i = 0 To 31
          Debug Hex(rarheader\Hash[i],#PB_Byte)
        Next

Nice module, thanks.

RAR5 format is using BLAKE2sp to protect file data integrity (it doesn't use Keccak :shock: )


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sat Oct 05, 2013 11:22 am 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5754
Location: Berlin - Germany
Update:

enhanced RARUnpackArchiv to use a callback (required for encrypted filenames in archiv)

_________________
PureBasic 5.70 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Mon Oct 14, 2013 8:50 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
This is great, thanks for it!

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Mon Oct 14, 2013 9:24 pm 
Offline
Addict
Addict

Joined: Wed Aug 24, 2005 8:39 am
Posts: 2736
Location: Southwest OH - USA
Your contributions are outstanding.

Thanks for another one.


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sat Dec 14, 2013 9:38 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4453
Location: Not Sydney!!! (Bad water, no goats)
Does Unrar.dll support CAB files? I seem to remember reading somewhere that it might have but trying this code, I can see it not doing anything and thought a flag or something might be missing?

I need to be able to extract these.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sat Dec 14, 2013 11:01 am 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5754
Location: Berlin - Germany
cab <> rar

_________________
PureBasic 5.70 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sat Dec 14, 2013 12:04 pm 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 4453
Location: Not Sydney!!! (Bad water, no goats)
ts-soft wrote:
cab <> rar


What does that nonsense answer mean? WinRAR supports cab files, I assumed the free unrar.dll might somehow but obviously not.

Thank you for your time.

_________________
Amateur Radio, D-STAR/VK3HAF


Top
 Profile  
Reply with quote  
 Post subject: Re: UnRAR 5 Module/Wrapper Windows
PostPosted: Sat Dec 14, 2013 12:16 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5754
Location: Berlin - Germany
This module supports only unrar, so it is only for RAR-Format, no others formats!

WinRAR is a shareware windows packer/unpacker, that supports some other standard-format,
but this have nothing to do with unrar!

Greetings - Thomas

_________________
PureBasic 5.70 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye