mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 08:08:10 +00:00
UnRAR: Use our own buffers and memory allocations
This commit is contained in:
parent
9f380afa13
commit
c9c03dd191
2
deps/unrar/getbits.hpp
vendored
2
deps/unrar/getbits.hpp
vendored
@ -4,7 +4,7 @@
|
||||
class BitInput
|
||||
{
|
||||
public:
|
||||
enum BufferSize {MAX_SIZE=0x8000}; // Size of input buffer.
|
||||
enum BufferSize {MAX_SIZE=0x50000}; // Size of input buffer.
|
||||
|
||||
int InAddr; // Curent byte position in the buffer.
|
||||
int InBit; // Current bit position in the current byte.
|
||||
|
6
deps/unrar/model.cpp
vendored
6
deps/unrar/model.cpp
vendored
@ -566,14 +566,17 @@ void ModelPPM::CleanUp()
|
||||
}
|
||||
|
||||
|
||||
bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar)
|
||||
bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar,byte *hcppm)
|
||||
{
|
||||
int MaxOrder=UnpackRead->GetChar();
|
||||
bool Reset=(MaxOrder & 0x20)!=0;
|
||||
|
||||
int MaxMB;
|
||||
if (Reset)
|
||||
{
|
||||
MaxMB=UnpackRead->GetChar();
|
||||
if (MaxMB>128) return(false);
|
||||
}
|
||||
else
|
||||
if (SubAlloc.GetAllocatedMemory()==0)
|
||||
return(false);
|
||||
@ -590,6 +593,7 @@ bool ModelPPM::DecodeInit(Unpack *UnpackRead,int &EscChar)
|
||||
SubAlloc.StopSubAllocator();
|
||||
return(false);
|
||||
}
|
||||
SubAlloc.SetHeapStartFixed(hcppm);
|
||||
SubAlloc.StartSubAllocator(MaxMB+1);
|
||||
StartModelRare(MaxOrder);
|
||||
}
|
||||
|
2
deps/unrar/model.hpp
vendored
2
deps/unrar/model.hpp
vendored
@ -115,7 +115,7 @@ class ModelPPM : RARPPM_DEF
|
||||
public:
|
||||
ModelPPM();
|
||||
void CleanUp(); // reset PPM variables after data error
|
||||
bool DecodeInit(Unpack *UnpackRead,int &EscChar);
|
||||
bool DecodeInit(Unpack *UnpackRead,int &EscChar,byte *hcppm);
|
||||
int DecodeChar();
|
||||
};
|
||||
|
||||
|
2
deps/unrar/rdwrfn.cpp
vendored
2
deps/unrar/rdwrfn.cpp
vendored
@ -201,7 +201,7 @@ void ComprDataIO::UnpWrite(byte *Addr,size_t Count)
|
||||
{
|
||||
if (Count <= UnpackToMemorySize)
|
||||
{
|
||||
memcpy(UnpackToMemoryAddr,Addr,Count);
|
||||
//memcpy(UnpackToMemoryAddr,Addr,Count);
|
||||
UnpackToMemoryAddr+=Count;
|
||||
UnpackToMemorySize-=Count;
|
||||
}
|
||||
|
5
deps/unrar/suballoc.cpp
vendored
5
deps/unrar/suballoc.cpp
vendored
@ -71,7 +71,7 @@ void SubAllocator::StopSubAllocator()
|
||||
if ( SubAllocatorSize )
|
||||
{
|
||||
SubAllocatorSize=0;
|
||||
free(HeapStart);
|
||||
//free(HeapStart);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +88,8 @@ bool SubAllocator::StartSubAllocator(int SASize)
|
||||
// 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 *)malloc(AllocSize)) == NULL)
|
||||
//if ((HeapStart=(byte *)malloc(AllocSize)) == NULL)
|
||||
if ((HeapStart=(byte *)HeapStartFixed) == NULL)
|
||||
{
|
||||
ErrHandler.MemoryError();
|
||||
return false;
|
||||
|
3
deps/unrar/suballoc.hpp
vendored
3
deps/unrar/suballoc.hpp
vendored
@ -80,6 +80,9 @@ class SubAllocator
|
||||
long GetAllocatedMemory() {return(SubAllocatorSize);}
|
||||
|
||||
byte *pText, *UnitsStart,*HeapEnd,*FakeUnitsStart;
|
||||
|
||||
byte *HeapStartFixed;
|
||||
void SetHeapStartFixed(byte *p) {HeapStartFixed=p;}
|
||||
};
|
||||
|
||||
|
||||
|
31
deps/unrar/unpack.cpp
vendored
31
deps/unrar/unpack.cpp
vendored
@ -16,7 +16,7 @@
|
||||
#include "unpack50frag.cpp"
|
||||
|
||||
Unpack::Unpack(ComprDataIO *DataIO)
|
||||
:Inp(true),VMCodeInp(true)
|
||||
:Inp(false),VMCodeInp(false)
|
||||
{
|
||||
UnpIO=DataIO;
|
||||
Window=NULL;
|
||||
@ -49,8 +49,8 @@ Unpack::~Unpack()
|
||||
{
|
||||
InitFilters30(false);
|
||||
|
||||
if (Window!=NULL)
|
||||
free(Window);
|
||||
//if (Window!=NULL)
|
||||
// free(Window);
|
||||
#ifdef RAR_SMP
|
||||
delete UnpThreadPool;
|
||||
delete[] ReadBufMT;
|
||||
@ -69,6 +69,21 @@ void Unpack::SetThreads(uint Threads)
|
||||
}
|
||||
#endif
|
||||
|
||||
void Unpack::SetWin(void *win)
|
||||
{
|
||||
hcwin=(byte *)win;
|
||||
}
|
||||
|
||||
void Unpack::SetPPM(void *ppm)
|
||||
{
|
||||
hcppm=(byte *)ppm;
|
||||
}
|
||||
|
||||
void Unpack::SetExternalBuffer(byte *InpBuf,byte *VMCodeBuf)
|
||||
{
|
||||
Inp.SetExternalBuffer(InpBuf);
|
||||
VMCodeInp.SetExternalBuffer(VMCodeBuf);
|
||||
}
|
||||
|
||||
void Unpack::Init(size_t WinSize,bool Solid)
|
||||
{
|
||||
@ -102,7 +117,7 @@ void Unpack::Init(size_t WinSize,bool Solid)
|
||||
if (Grow && Fragmented)
|
||||
throw std::bad_alloc();
|
||||
|
||||
byte *NewWindow=Fragmented ? NULL : (byte *)malloc(WinSize);
|
||||
byte *NewWindow=Fragmented ? NULL : (byte *)hcwin;
|
||||
|
||||
if (NewWindow==NULL)
|
||||
if (Grow || WinSize<0x1000000)
|
||||
@ -115,7 +130,7 @@ void Unpack::Init(size_t WinSize,bool Solid)
|
||||
{
|
||||
if (Window!=NULL) // If allocated by preceding files.
|
||||
{
|
||||
free(Window);
|
||||
//free(Window);
|
||||
Window=NULL;
|
||||
}
|
||||
FragWindow.Init(WinSize);
|
||||
@ -126,7 +141,7 @@ void Unpack::Init(size_t WinSize,bool Solid)
|
||||
{
|
||||
// Clean the window to generate the same output when unpacking corrupt
|
||||
// RAR files, which may access unused areas of sliding dictionary.
|
||||
memset(NewWindow,0,WinSize);
|
||||
//memset(NewWindow,0,WinSize);
|
||||
|
||||
// If Window is not NULL, it means that window size has grown.
|
||||
// In solid streams we need to copy data to a new window in such case.
|
||||
@ -136,8 +151,8 @@ void Unpack::Init(size_t WinSize,bool Solid)
|
||||
for (size_t I=1;I<=MaxWinSize;I++)
|
||||
NewWindow[(UnpPtr-I)&(WinSize-1)]=Window[(UnpPtr-I)&(MaxWinSize-1)];
|
||||
|
||||
if (Window!=NULL)
|
||||
free(Window);
|
||||
//if (Window!=NULL)
|
||||
// free(Window);
|
||||
Window=NewWindow;
|
||||
}
|
||||
|
||||
|
6
deps/unrar/unpack.hpp
vendored
6
deps/unrar/unpack.hpp
vendored
@ -375,6 +375,9 @@ class Unpack:PackDef
|
||||
public:
|
||||
Unpack(ComprDataIO *DataIO);
|
||||
~Unpack();
|
||||
void SetWin(void *win);
|
||||
void SetPPM(void *PPM);
|
||||
void SetExternalBuffer(byte *InpBuf,byte *VMCodeBuf);
|
||||
void Init(size_t WinSize,bool Solid);
|
||||
void DoUnpack(uint Method,bool Solid);
|
||||
bool IsFileExtracted() {return(FileExtracted);}
|
||||
@ -386,6 +389,9 @@ class Unpack:PackDef
|
||||
void UnpackDecode(UnpackThreadData &D);
|
||||
#endif
|
||||
|
||||
byte *hcwin;
|
||||
byte *hcppm;
|
||||
|
||||
size_t MaxWinSize;
|
||||
size_t MaxWinMask;
|
||||
|
||||
|
2
deps/unrar/unpack30.cpp
vendored
2
deps/unrar/unpack30.cpp
vendored
@ -637,7 +637,7 @@ bool Unpack::ReadTables30()
|
||||
if (BitField & 0x8000)
|
||||
{
|
||||
UnpBlockType=BLOCK_PPM;
|
||||
return(PPM.DecodeInit(this,PPMEscChar));
|
||||
return(PPM.DecodeInit(this,PPMEscChar,hcppm));
|
||||
}
|
||||
UnpBlockType=BLOCK_LZ;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user