WinRar Free UnPack DLL and EXE

Just starting out? Need help? Post your questions and find answers here.
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

WinRar Free UnPack DLL and EXE

Post by codeman »

Hello,
i have found a DLL and an Exe on this Site: http://www.rarlab.com/rar_add.htm. With this tool you can unpack Rar files... I find this very interesting. Of course they haven't a PureBasic example for the DLL. But they have examples for C, C#, Delphi, Free Pascal, MASM, VB.NET, Virtual Pascal and VBasic! Can anybody translate one of this code to PureBasic!

DOWNLOAD Dll + Sourcescode

And I have found an EXE who unpack automatic but they haven't a list with the commands :( !

yours, codeman
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

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
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Thank you!
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Sorry but this Example doesen't work. Or I use the wrong unrar.dll.
Know anybody an other example to unpack rar archives?

Yours codeman
atomo
User
User
Posts: 65
Joined: Thu May 22, 2008 10:32 pm

Post by atomo »

Hi, try this as an include pbi file.

Code: Select all

;PB_unRAR - Paul Leischow, Sept.6, 2002 
;RAR Archive extractor that uses the free UNRAR.DLL 

#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_HEADERFLAG_ENCRYPTED               = %00000100 
#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         = 4 

Structure RARHeaderData 
  ArcName.b[260] 
  FileName.b[260] 
  Flags.l 
  PackSize.l 
  UnpSize.l 
  HostOS.l 
  FileCRC.l 
  FileTime.l 
  UnpVer.l 
  Method.l 
  FileAttr.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
EndStructure 

Structure RARHeaderDataEx 
  ArcName.b[1024] 
  ArcNameW.w[1024] 
  FileName.b[1024] 
  FileNameW.w[1024] 
  Flags.l 
  PackSize.l 
  PackSizeHigh.l 
  UnpSize.l 
  UnpSizeHigh.l 
  HostOS.l 
  FileCRC.l 
  FileTime.l 
  UnpVer.l 
  Method.l 
  FileAttr.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
  Reserved.l[1024] 
EndStructure 

Structure RAROpenArchiveData 
  *ArcName.l 
  OpenMode.l 
  OpenResult.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
EndStructure 

Structure RAROpenArchiveDataEx 
  *ArcName.l 
  *ArcNameW.l 
  OpenMode.l 
  OpenResult.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
  Flags.l 
  Reserved.l[32] 
EndStructure 

Global RarLib.l 
Global RAROpenArchive.l 
Global RARCloseArchive.l 
Global RARReadHeader.l 
Global RARProcessFile.l 
Global RARSetCallback.l 
Global RARSetChangeVolProc.l 
Global RARSetProcessDataProc.l 
Global RARSetPassword.l 
Global RARGetDllVersion.l 

Prototype.l Prot_RAROpenArchive(a.l) 
Prototype.l Prot_RARCloseArchive(a.l) 
Prototype.l Prot_RARReadHeader(a.l,b.l) 
CompilerIf #PB_Compiler_Unicode=0 
  Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-ascii,d.p-ascii) 
CompilerElse 
  Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-unicode,d.p-unicode) 
CompilerEndIf 
Prototype.l Prot_RARSetCallback(a.l,b.l,c.l) 
Prototype.l Prot_RARSetChangeVolProc(a.l,b.l) 
Prototype.l Prot_RARSetProcessDataProc(a.l,b.l) 
CompilerIf #PB_Compiler_Unicode=0 
  Prototype.l Prot_RARSetPassword(a.l,b.p-ascii) 
CompilerElse 
  Prototype.l Prot_RARSetPassword(a.l,b.p-unicode) 
CompilerEndIf 
Prototype.l Prot_RARGetDllVersion() 

ProcedureDLL Rar_Init() 
  RarLib=OpenLibrary(#PB_Any,"unrar.dll") 
  If RarLib 
    CompilerIf #PB_Compiler_Unicode=0 
      RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchive") 
      RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeader") 
      RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFile") 
    CompilerElse 
      RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchiveEx") 
      RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeaderEx") 
      RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFileW") 
    CompilerEndIf 
    RARCloseArchive.Prot_RARCloseArchive = GetFunction(RarLib, "RARCloseArchive") 
    RARSetCallback.Prot_RARSetCallback = GetFunction(RarLib, "RARSetCallback") 
    RARSetChangeVolProc.Prot_RARSetChangeVolProc = GetFunction(RarLib, "RARSetChangeVolProc") 
    RARSetProcessDataProc.Prot_RARSetProcessDataProc = GetFunction(RarLib, "RARSetProcessDataProc") 
    RARSetPassword.Prot_RARSetPassword = GetFunction(RarLib, "RARSetPassword") 
    RARGetDllVersion.Prot_RARGetDllVersion = GetFunction(RarLib, "RARGetDllVersion")
  Else
    MessageRequester("Erreur", "unrar.dll est introuvable.", #MB_ICONERROR)
    End
  EndIf 
EndProcedure 

ProcedureDLL Rar_End() 
  If RarLib 
    CloseLibrary(RarLib) 
    RarLib=0 
  EndIf 
EndProcedure 

Procedure UnRar(File$) 
  CompilerIf #PB_Compiler_Unicode=0 
    rarheader.RARHeaderData 
    raropen.RAROpenArchiveData 
    raropen\ArcName= @File$ 
  CompilerElse 
    rarheader.RARHeaderDataEx 
    raropen.RAROpenArchiveDataEx 
    raropen\ArcNameW = @File$ 
  CompilerEndIf 
  raropen\CmtBuf = 0 
  raropen\CmtBufSize = 0 
  raropen\OpenMode=#RAR_OM_EXTRACT 
  hRAR=RAROpenArchive(@raropen) 
  file.s="" 
  filelist.s="" 
  If raropen\OpenResult 
    MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR) 
    ProcedureReturn 
  EndIf 
  While RARReadHeader(hRAR,@rarheader)=0 
    CompilerIf #PB_Compiler_Unicode=0 
      file=PeekS(@rarheader\FileName) 
    CompilerElse 
      file=PeekS(@rarheader\FileNameW) 
    CompilerEndIf 
    Debug "File:"+file 
    filelist+file+Chr(10) 
    If rarheader\flags & #RAR_HEADERFLAG_ENCRYPTED 
      ;Debug "#RAR_HEADERFLAG_ENCRYPTED" 
      RARSetPassword(hRAR,"free") 
      ;MessageRequester("Error","file is password protected",#MB_ICONERROR) 
    EndIf 
    res=RARProcessFile(hRAR,#RAR_EXTRACT,"",File$) 
    Select res 
      Case #ERAR_BAD_DATA 
        Debug "File CRC error" 
      Case #ERAR_BAD_ARCHIVE 
        Debug "Volume is not valid RAR archive" 
      Case #ERAR_UNKNOWN_FORMAT 
        Debug "Unknown archive format" 
      Case #ERAR_EOPEN 
        Debug "Volume open error" 
      Case #ERAR_ECREATE 
        Debug "File create error" 
      Case #ERAR_ECLOSE 
        Debug "File close error" 
      Case #ERAR_EREAD 
        Debug "Read error" 
      Case #ERAR_EWRITE 
        Debug "Write error" 
    EndSelect 
  Wend 
  
  If RARCloseArchive(hRAR)=#ERAR_ECLOSE 
    MessageRequester("RARCloseArchive","Archive close error",#MB_ICONINFORMATION) 
  EndIf 
EndProcedure 

Rar_Init()
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Sorry but I doesen't understand how I must use this?
atomo
User
User
Posts: 65
Joined: Thu May 22, 2008 10:32 pm

Post by atomo »

The main file :

Code: Select all

XIncludeFile "Rar.pbi"

File.s = OpenFileRequester("Select Rar file", "C:\", "Rar (*.rar)|*.rar", 0)
If File
  unrar(File)
EndIf
and the include :

Code: Select all

;PB_unRAR - Paul Leischow, Sept.6, 2002 
;RAR Archive extractor that uses the free UNRAR.DLL 

#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_HEADERFLAG_ENCRYPTED               = %00000100 
#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         = 4 

Structure RARHeaderData 
  ArcName.b[260] 
  FileName.b[260] 
  Flags.l 
  PackSize.l 
  UnpSize.l 
  HostOS.l 
  FileCRC.l 
  FileTime.l 
  UnpVer.l 
  Method.l 
  FileAttr.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
EndStructure 

Structure RARHeaderDataEx 
  ArcName.b[1024] 
  ArcNameW.w[1024] 
  FileName.b[1024] 
  FileNameW.w[1024] 
  Flags.l 
  PackSize.l 
  PackSizeHigh.l 
  UnpSize.l 
  UnpSizeHigh.l 
  HostOS.l 
  FileCRC.l 
  FileTime.l 
  UnpVer.l 
  Method.l 
  FileAttr.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
  Reserved.l[1024] 
EndStructure 

Structure RAROpenArchiveData 
  *ArcName.l 
  OpenMode.l 
  OpenResult.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
EndStructure 

Structure RAROpenArchiveDataEx 
  *ArcName.l 
  *ArcNameW.l 
  OpenMode.l 
  OpenResult.l 
  *CmtBuf.l 
  CmtBufSize.l 
  CmtSize.l 
  CmtState.l 
  Flags.l 
  Reserved.l[32] 
EndStructure 

Global RarLib.l 
Global RAROpenArchive.l 
Global RARCloseArchive.l 
Global RARReadHeader.l 
Global RARProcessFile.l 
Global RARSetCallback.l 
Global RARSetChangeVolProc.l 
Global RARSetProcessDataProc.l 
Global RARSetPassword.l 
Global RARGetDllVersion.l 

Prototype.l Prot_RAROpenArchive(a.l) 
Prototype.l Prot_RARCloseArchive(a.l) 
Prototype.l Prot_RARReadHeader(a.l,b.l) 
CompilerIf #PB_Compiler_Unicode=0 
  Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-ascii,d.p-ascii) 
CompilerElse 
  Prototype.l Prot_RARProcessFile(a.l,b.l,c.p-unicode,d.p-unicode) 
CompilerEndIf 
Prototype.l Prot_RARSetCallback(a.l,b.l,c.l) 
Prototype.l Prot_RARSetChangeVolProc(a.l,b.l) 
Prototype.l Prot_RARSetProcessDataProc(a.l,b.l) 
CompilerIf #PB_Compiler_Unicode=0 
  Prototype.l Prot_RARSetPassword(a.l,b.p-ascii) 
CompilerElse 
  Prototype.l Prot_RARSetPassword(a.l,b.p-unicode) 
CompilerEndIf 
Prototype.l Prot_RARGetDllVersion() 

ProcedureDLL Rar_Init() 
  RarLib=OpenLibrary(#PB_Any,"unrar.dll") 
  If RarLib 
    CompilerIf #PB_Compiler_Unicode=0 
      RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchive") 
      RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeader") 
      RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFile") 
    CompilerElse 
      RAROpenArchive.Prot_RAROpenArchive = GetFunction(RarLib, "RAROpenArchiveEx") 
      RARReadHeader.Prot_RARReadHeader = GetFunction(RarLib, "RARReadHeaderEx") 
      RARProcessFile.Prot_RARProcessFile = GetFunction(RarLib, "RARProcessFileW") 
    CompilerEndIf 
    RARCloseArchive.Prot_RARCloseArchive = GetFunction(RarLib, "RARCloseArchive") 
    RARSetCallback.Prot_RARSetCallback = GetFunction(RarLib, "RARSetCallback") 
    RARSetChangeVolProc.Prot_RARSetChangeVolProc = GetFunction(RarLib, "RARSetChangeVolProc") 
    RARSetProcessDataProc.Prot_RARSetProcessDataProc = GetFunction(RarLib, "RARSetProcessDataProc") 
    RARSetPassword.Prot_RARSetPassword = GetFunction(RarLib, "RARSetPassword") 
    RARGetDllVersion.Prot_RARGetDllVersion = GetFunction(RarLib, "RARGetDllVersion") 
  Else 
    MessageRequester("Erreur", "unrar.dll est introuvable.", #MB_ICONERROR) 
    End 
  EndIf 
EndProcedure 

ProcedureDLL Rar_End() 
  If RarLib 
    CloseLibrary(RarLib) 
    RarLib=0 
  EndIf 
EndProcedure 

Procedure UnRar(File$)
  CompilerIf #PB_Compiler_Unicode=0 
    rarheader.RARHeaderData 
    raropen.RAROpenArchiveData 
    raropen\ArcName= @File$ 
  CompilerElse 
    rarheader.RARHeaderDataEx 
    raropen.RAROpenArchiveDataEx 
    raropen\ArcNameW = @File$ 
  CompilerEndIf 
  raropen\CmtBuf = 0 
  raropen\CmtBufSize = 0 
  raropen\OpenMode=#RAR_OM_EXTRACT 
  hRAR=RAROpenArchive(@raropen) 
  file.s="" 
  filelist.s="" 
  If raropen\OpenResult 
    MessageRequester("Error","Could Not Open RAR File",#MB_ICONERROR) 
    ProcedureReturn 
  EndIf 
  While RARReadHeader(hRAR,@rarheader)=0 
    CompilerIf #PB_Compiler_Unicode=0 
      file=PeekS(@rarheader\FileName) 
    CompilerElse 
      file=PeekS(@rarheader\FileNameW) 
    CompilerEndIf 
    Debug "File:"+file 
    filelist+file+Chr(10) 
    If rarheader\flags & #RAR_HEADERFLAG_ENCRYPTED 
      ;Debug "#RAR_HEADERFLAG_ENCRYPTED" 
      RARSetPassword(hRAR,"free") 
      ;MessageRequester("Error","file is password protected",#MB_ICONERROR) 
    EndIf 
    res=RARProcessFile(hRAR,#RAR_EXTRACT,"",file) 
    Select res 
      Case #ERAR_BAD_DATA 
        Debug "File CRC error" 
      Case #ERAR_BAD_ARCHIVE 
        Debug "Volume is not valid RAR archive" 
      Case #ERAR_UNKNOWN_FORMAT 
        Debug "Unknown archive format" 
      Case #ERAR_EOPEN 
        Debug "Volume open error" 
      Case #ERAR_ECREATE 
        Debug "File create error" 
      Case #ERAR_ECLOSE 
        Debug "File close error" 
      Case #ERAR_EREAD 
        Debug "Read error" 
      Case #ERAR_EWRITE 
        Debug "Write error" 
    EndSelect 
  Wend 
  
  If RARCloseArchive(hRAR)=#ERAR_ECLOSE 
    MessageRequester("RARCloseArchive","Archive close error",#MB_ICONINFORMATION) 
  EndIf 
EndProcedure 

Rar_Init()
It should work but you must have the unrar.dll.
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Thank you! :D
User_Russian
Addict
Addict
Posts: 1519
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Post by User_Russian »

codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Thank you! The Lib Commads are good but the language... Have anybody a englisch or german Help?

Yours codeman
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

In the Forum is the langue Russian! I have translate this but in the help stand things like this:


Ðàñïàêîâêà èëè òåñòèðîâàíèå àðõèâà

H_RAR - èäåíòèôèêàòîð àðõèâà, ïîëó÷åíûé ñ ïîìîùüþ RAR_OpenArchive
Operation - ×òî äåëàòü ñ ôàéëîì.
#RAR_SKIP - Ïðîïóñòèòü ôàéë ïðè ðàñïàêîâêå
#RAR_TEST - Òåñòèðîâàíèå
#RAR_EXTRACT - Ðàñïàêîâàòü
DestPath - ????
DestName - Èìÿ ôàéëà è ïóòü êóäà ðàñïàêîâàòü ôàéë

 êà÷åñòâå ðåçóëüòàòà ìîæåò áûòü -1 åñëè ïðîèçîøëè ïðîáëåìû ïðè èíèöèàëèçàöèè áèáëèîòåêè èëè ñëåäóþùåå ñîîáùåíèå
#RAR_BAD_DATA - Îøèáêà â CRC
#RAR_BAD_ARCHIVE - Ïîâðåæä¸ííûé èëè íåïîääåðæèâàåìûé ôîðìàò àðõèâà
#RAR_UNKNOWN_FORMAT - Íåèçâåñòíûé ôîðìàò àðõèâà. Âîçìîæíî ôàéë íå ÿâëÿåòñÿ àðõèâîì
#RAR_EOPEN - Ïðîèçîøëà îøèáêà ïðè èçâëå÷åíèè ôàéëà
#RAR_ECREATE - Íå óäàëîñü ñîçäàòü ôàéë
#RAR_ECLOSE - Îøèáêà ïðè çàêðûòèè ôàéëà
#RAR_EREAD - Îøèáêà ÷òåíèÿ
#ERAR_EWRITE - Îøèáêà çàïèñè



I think my help isn't compatible with Russian!

Can anybody help me?
User_Russian
Addict
Addict
Posts: 1519
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Post by User_Russian »

Well, translate help
User_Russian
Addict
Addict
Posts: 1519
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Post by User_Russian »

codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Thank you very much!

This is perfect!

Yours codeman
codeman
User
User
Posts: 27
Joined: Thu Feb 19, 2009 7:12 am

Post by codeman »

Sorry but by the command: RAR_SetCallback(H_RAR, *CallbackProc, UserData) the help doesen't say anything! Can anybody give me an example for a callback in a ProgressBar?
Yours codeman
Post Reply