Skip to content

Commit

Permalink
Added unrar 3.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cataphract committed Jan 13, 2011
1 parent 89c4cbe commit a9631cf
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 29 deletions.
2 changes: 1 addition & 1 deletion unrar/filcreat.cpp
Expand Up @@ -111,7 +111,7 @@ bool GetAutoRenamedName(char *Name)
Ext=Name+strlen(Name);
for (int FileVer=1;;FileVer++)
{
sprintf(NewName,"%.*s(%d)%s",Ext-Name,Name,FileVer,Ext);
sprintf(NewName,"%.*s(%d)%s",int(Ext-Name),Name,FileVer,Ext);
if (!FileExist(NewName))
{
strcpy(Name,NewName);
Expand Down
10 changes: 5 additions & 5 deletions unrar/makefile.unix
Expand Up @@ -49,11 +49,11 @@ DESTDIR=/usr
#DESTDIR=/usr

# Solaris using CC
CXX=CC
CXXFLAGS=-fast -erroff=wvarhidemem
DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
STRIP=strip
DESTDIR=/usr
#CXX=CC
#CXXFLAGS=-fast -erroff=wvarhidemem
#DEFINES=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
#STRIP=strip
#DESTDIR=/usr

# Solaris using GCC (optimized for UltraSPARC 1 CPU)
#CXX=g++
Expand Down
2 changes: 1 addition & 1 deletion unrar/model.hpp
Expand Up @@ -104,7 +104,7 @@ class ModelPPM
private:
friend struct PPM_CONTEXT;

_PACK_ATTR SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;
SEE2_CONTEXT SEE2Cont[25][16], DummySEE2Cont;

struct PPM_CONTEXT *MinContext, *MedContext, *MaxContext;
STATE* FoundState; // found next state transition
Expand Down
35 changes: 32 additions & 3 deletions unrar/rdwrfn.cpp
Expand Up @@ -111,8 +111,16 @@ int ComprDataIO::UnpRead(byte *Addr,size_t Count)
}


#if defined(RARDLL) && defined(_MSC_VER) && !defined(_M_X64)
// Disable the run time stack check for unrar.dll, so we can manipulate
// with ProcessDataProc call type below. Run time check would intercept
// a wrong ESP before we restore it.
#pragma runtime_checks( "s", off )
#endif

void ComprDataIO::UnpWrite(byte *Addr,size_t Count)
{

#ifdef RARDLL
RAROptions *Cmd=((Archive *)SrcFile)->GetRAROptions();
if (Cmd->DllOpMode!=RAR_SKIP)
Expand All @@ -122,18 +130,34 @@ void ComprDataIO::UnpWrite(byte *Addr,size_t Count)
ErrHandler.Exit(USER_BREAK);
if (Cmd->ProcessDataProc!=NULL)
{
#if defined(_WIN_32) && !defined(_MSC_VER) && !defined(__MINGW32__)
// Here we preserve ESP value. It is necessary for those developers,
// who still define ProcessDataProc callback as "C" type function,
// even though in year 2001 we announced in unrar.dll whatsnew.txt
// that it will be PASCAL type (for compatibility with Visual Basic).
#if defined(_MSC_VER)
#ifndef _M_X64
__asm mov ebx,esp
#endif
#elif defined(_WIN_32) && defined(__BORLANDC__)
_EBX=_ESP;
#endif
int RetCode=Cmd->ProcessDataProc(Addr,(int)Count);
#if defined(_WIN_32) && !defined(_MSC_VER) && !defined(__MINGW32__)

// Restore ESP after ProcessDataProc with wrongly defined calling
// convention broken it.
#if defined(_MSC_VER)
#ifndef _M_X64
__asm mov esp,ebx
#endif
#elif defined(_WIN_32) && defined(__BORLANDC__)
_ESP=_EBX;
#endif
if (RetCode==0)
ErrHandler.Exit(USER_BREAK);
}
}
#endif
#endif // RARDLL

UnpWrAddr=Addr;
UnpWrSize=Count;
if (UnpackToMemory)
Expand All @@ -160,6 +184,11 @@ void ComprDataIO::UnpWrite(byte *Addr,size_t Count)
Wait();
}

#if defined(RARDLL) && defined(_MSC_VER) && !defined(_M_X64)
// Restore the run time stack check for unrar.dll.
#pragma runtime_checks( "s", restore )
#endif




Expand Down
66 changes: 51 additions & 15 deletions unrar/suballoc.cpp
Expand Up @@ -34,14 +34,15 @@ inline void* SubAllocator::RemoveNode(int indx)

inline uint SubAllocator::U2B(int NU)
{
return /*8*NU+4*NU*/UNIT_SIZE*NU;
// We calculate the size of units in bytes based on real UNIT_SIZE.
// In original implementation it was 8*NU+4*NU.
return UNIT_SIZE*NU;
}


/*
calculate RAR_MEM_BLK + Items address. Real RAR_MEM_BLK size must be
equal to UNIT_SIZE, so we cannot just add Items to RAR_MEM_BLK address
*/

// Calculate RAR_MEM_BLK+Items address. Real RAR_MEM_BLK size must be
// equal to UNIT_SIZE, so we cannot just add Items to RAR_MEM_BLK address.
inline RAR_MEM_BLK* SubAllocator::MBPtr(RAR_MEM_BLK *BasePtr,int Items)
{
return((RAR_MEM_BLK*)( ((byte *)(BasePtr))+U2B(Items) ));
Expand Down Expand Up @@ -80,16 +81,22 @@ bool SubAllocator::StartSubAllocator(int SASize)
if (SubAllocatorSize == t)
return TRUE;
StopSubAllocator();
uint AllocSize=t/FIXED_UNIT_SIZE*UNIT_SIZE+UNIT_SIZE;
#ifdef STRICT_ALIGNMENT_REQUIRED
AllocSize+=UNIT_SIZE;
#endif

// Original algorithm expects FIXED_UNIT_SIZE, but actual structure size
// can be larger. So let's recalculate the allocated size and add two more
// units: one as reserve for HeapEnd overflow checks and another
// to provide the space to correctly align UnitsStart.
uint AllocSize=t/FIXED_UNIT_SIZE*UNIT_SIZE+2*UNIT_SIZE;
if ((HeapStart=(byte *)rarmalloc(AllocSize)) == NULL)
{
ErrHandler.MemoryError();
return FALSE;
}

// HeapEnd did not present in original algorithm. We added it to control
// invalid memory access attempts when processing corrupt archived data.
HeapEnd=HeapStart+AllocSize-UNIT_SIZE;

SubAllocatorSize=t;
return TRUE;
}
Expand All @@ -100,17 +107,46 @@ void SubAllocator::InitSubAllocator()
int i, k;
memset(FreeList,0,sizeof(FreeList));
pText=HeapStart;

// Original algorithm operates with 12 byte FIXED_UNIT_SIZE, but actual
// size of RAR_MEM_BLK and PPM_CONTEXT structures can exceed this value
// because of alignment and larger pointer fields size.
// So we define UNIT_SIZE for this larger size and adjust memory
// pointers accordingly.

// Size2 is (HiUnit-LoUnit) memory area size to allocate as originally
// supposed by compression algorithm. It is 7/8 of total allocated size.
uint Size2=FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7);

// RealSize2 is the real adjusted size of (HiUnit-LoUnit) memory taking
// into account that our UNIT_SIZE can be larger than FIXED_UNIT_SIZE.
uint RealSize2=Size2/FIXED_UNIT_SIZE*UNIT_SIZE;

// Size1 is the size of memory area from HeapStart to FakeUnitsStart
// as originally supposed by compression algorithm. This area can contain
// different data types, both single symbols and structures.
uint Size1=SubAllocatorSize-Size2;
uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+Size1%FIXED_UNIT_SIZE;
#ifdef STRICT_ALIGNMENT_REQUIRED
if (Size1%FIXED_UNIT_SIZE!=0)
RealSize1+=UNIT_SIZE-Size1%FIXED_UNIT_SIZE;
#endif
HiUnit=HeapStart+SubAllocatorSize;

// Real size of this area. We correct it according to UNIT_SIZE vs
// FIXED_UNIT_SIZE difference. Also we add one more UNIT_SIZE
// to compensate a possible reminder from Size1/FIXED_UNIT_SIZE,
// which would be lost otherwise. We add UNIT_SIZE instead of
// this Size1%FIXED_UNIT_SIZE reminder, because it allows to align
// UnitsStart easily and adding more than reminder is ok for algorithm.
uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+UNIT_SIZE;

// RealSize1 must be divided by UNIT_SIZE without a reminder, so UnitsStart
// is aligned to UNIT_SIZE. It is important for those architectures,
// where a proper memory alignment is mandatory. Since we produce RealSize1
// multiplying by UNIT_SIZE, this condition is always true. So LoUnit,
// UnitsStart, HeapStart are properly aligned,
LoUnit=UnitsStart=HeapStart+RealSize1;

// When we reach FakeUnitsStart, we restart the model. It is where
// the original algorithm expected to see UnitsStart. Real UnitsStart
// can have a larger value.
FakeUnitsStart=HeapStart+Size1;

HiUnit=LoUnit+RealSize2;
for (i=0,k=1;i < N1 ;i++,k += 1)
Indx2Units[i]=k;
Expand Down
4 changes: 2 additions & 2 deletions unrar/version.hpp
@@ -1,6 +1,6 @@
#define RARVER_MAJOR 3
#define RARVER_MINOR 90
#define RARVER_BETA 1
#define RARVER_DAY 26
#define RARVER_MONTH 4
#define RARVER_DAY 4
#define RARVER_MONTH 5
#define RARVER_YEAR 2009
31 changes: 29 additions & 2 deletions unrar/volume.cpp
Expand Up @@ -3,6 +3,13 @@



#if defined(RARDLL) && defined(_MSC_VER) && !defined(_M_X64)
// Disable the run time stack check for unrar.dll, so we can manipulate
// with ChangeVolProc call type below. Run time check would intercept
// a wrong ESP before we restore it.
#pragma runtime_checks( "s", off )
#endif

bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,char Command)
{
RAROptions *Cmd=Arc.GetRAROptions();
Expand Down Expand Up @@ -72,11 +79,26 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,char Comman
}
if (Cmd->ChangeVolProc!=NULL)
{
#if defined(_WIN_32) && !defined(_MSC_VER) && !defined(__MINGW32__)
// Here we preserve ESP value. It is necessary for those developers,
// who still define ChangeVolProc callback as "C" type function,
// even though in year 2001 we announced in unrar.dll whatsnew.txt
// that it will be PASCAL type (for compatibility with Visual Basic).
#if defined(_MSC_VER)
#ifndef _M_X64
__asm mov ebx,esp
#endif
#elif defined(_WIN_32) && defined(__BORLANDC__)
_EBX=_ESP;
#endif
int RetCode=Cmd->ChangeVolProc(NextName,RAR_VOL_ASK);
#if defined(_WIN_32) && !defined(_MSC_VER) && !defined(__MINGW32__)

// Restore ESP after ChangeVolProc with wrongly defined calling
// convention broken it.
#if defined(_MSC_VER)
#ifndef _M_X64
__asm mov esp,ebx
#endif
#elif defined(_WIN_32) && defined(__BORLANDC__)
_ESP=_EBX;
#endif
if (RetCode==0)
Expand Down Expand Up @@ -200,6 +222,11 @@ bool MergeArchive(Archive &Arc,ComprDataIO *DataIO,bool ShowFileName,char Comman
return(true);
}

#if defined(RARDLL) && defined(_MSC_VER) && !defined(_M_X64)
// Restore the run time stack check for unrar.dll.
#pragma runtime_checks( "s", restore )
#endif




Expand Down

0 comments on commit a9631cf

Please sign in to comment.