This commit is contained in:
Igor Pavlov
2003-12-11 00:00:00 +00:00
committed by Kornel Lesiński
commit 8c1b5c7b7e
982 changed files with 118799 additions and 0 deletions

69
7zip/Compress/Branch/ARM.cpp Executable file
View File

@@ -0,0 +1,69 @@
// ARM.cpp
#include "StdAfx.h"
#include "ARM.h"
#include "Windows/Defs.h"
static HRESULT BC_ARM_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 4)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
{
if (buffer[bufferPos + 3] == 0xeb)
{
UINT32 src =
(buffer[bufferPos + 2] << 16) |
(buffer[bufferPos + 1] << 8) |
(buffer[bufferPos + 0]);
src <<= 2;
UINT32 dest;
if (encoding)
dest = nowPos + bufferPos + 8 + src;
else
dest = src - (nowPos + bufferPos + 8);
dest >>= 2;
buffer[bufferPos + 2] = (dest >> 16);
buffer[bufferPos + 1] = (dest >> 8);
buffer[bufferPos + 0] = dest;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_ARM)

12
7zip/Compress/Branch/ARM.h Executable file
View File

@@ -0,0 +1,12 @@
// ARM.h
#pragma once
#ifndef __ARM_H
#define __ARM_H
#include "Coder.h"
MyClass(BC_ARM, 0x05, 1)
#endif

View File

@@ -0,0 +1,76 @@
// ARMThumb.cpp
#include "StdAfx.h"
#include "ARMThumb.h"
#include "Windows/Defs.h"
static HRESULT BC_ARMThumb_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 4)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 2)
{
if ((buffer[bufferPos + 1] & 0xF8) == 0xF0 &&
(buffer[bufferPos + 3] & 0xF8) == 0xF8)
{
UINT32 src =
((buffer[bufferPos + 1] & 0x7) << 19) |
(buffer[bufferPos + 0] << 11) |
((buffer[bufferPos + 3] & 0x7) << 8) |
(buffer[bufferPos + 2]);
src <<= 1;
UINT32 dest;
if (encoding)
dest = nowPos + bufferPos + 4 + src;
else
dest = src - (nowPos + bufferPos + 4);
dest >>= 1;
buffer[bufferPos + 1] = 0xF0 | ((dest >> 19) & 0x7);
buffer[bufferPos + 0] = (dest >> 11);
buffer[bufferPos + 3] = 0xF8 | ((dest >> 8) & 0x7);
buffer[bufferPos + 2] = (dest);
bufferPos += 2;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_ARMThumb)

12
7zip/Compress/Branch/ARMThumb.h Executable file
View File

@@ -0,0 +1,12 @@
// ARMThumb.h
#pragma once
#ifndef __ARMTHUMB_H
#define __ARMTHUMB_H
#include "Coder.h"
MyClass(BC_ARMThumb, 0x07, 1)
#endif

75
7zip/Compress/Branch/Alpha.cpp Executable file
View File

@@ -0,0 +1,75 @@
// Alpha.cpp
#include "StdAfx.h"
#include "Alpha.h"
#include "Windows/Defs.h"
static HRESULT BC_Alpha_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 4)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
{
// if (buffer[bufferPos + 3] == 0xc3 && (buffer[bufferPos + 2] >> 5) == 7) // its jump
// if (buffer[bufferPos + 3] == 0xd3 && (buffer[bufferPos + 2] >> 5) == 2)
// if (buffer[bufferPos + 3] == 0xd3)
if ((buffer[bufferPos + 3] >> 2) == 0x34)
{
UINT32 src =
((buffer[bufferPos + 2] & 0x1F) << 16) |
(buffer[bufferPos + 1] << 8) |
(buffer[bufferPos + 0]);
src <<= 2;
UINT32 dest;
if (encoding)
dest = (nowPos + bufferPos + 4) + src;
else
dest = src - (nowPos + bufferPos + 4);
dest >>= 2;
dest &= 0x1FFFFF;
buffer[bufferPos + 2] &= (~0x1F);
buffer[bufferPos + 2] |= (dest >> 16);
buffer[bufferPos + 1] = (dest >> 8);
buffer[bufferPos + 0] = dest;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_Alpha)

12
7zip/Compress/Branch/Alpha.h Executable file
View File

@@ -0,0 +1,12 @@
// Alpha.h
#pragma once
#ifndef __ALPHA_H
#define __ALPHA_H
#include "Coder.h"
MyClass(BC_Alpha, 0x03, 1)
#endif

View File

@@ -0,0 +1,9 @@
; Branch.def
LIBRARY Branch.dll
EXPORTS
CreateObject PRIVATE
GetNumberOfMethods PRIVATE
GetMethodProperty PRIVATE

310
7zip/Compress/Branch/Branch.dsp Executable file
View File

@@ -0,0 +1,310 @@
# Microsoft Developer Studio Project File - Name="Branch" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=Branch - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Branch.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Branch.mak" CFG="Branch - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "Branch - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "Branch - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "Branch - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /c
# ADD CPP /nologo /Gz /MD /W3 /GX /O2 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /FD /c
# SUBTRACT CPP /YX /Yc /Yu
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 1
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /YX /FD /GZ /c
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /Yu"StdAfx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-Zip\Codecs\Branch.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "Branch - Win32 Release"
# Name "Branch - Win32 Debug"
# Begin Group "Spec"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Branch.def
# End Source File
# Begin Source File
SOURCE=.\DllExports.cpp
# End Source File
# Begin Source File
SOURCE=.\resource.h
# End Source File
# Begin Source File
SOURCE=.\resource.rc
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"StdAfx.h"
# End Source File
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "Methods"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\Alpha.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\Alpha.h
# End Source File
# Begin Source File
SOURCE=.\ARM.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\ARM.h
# End Source File
# Begin Source File
SOURCE=.\ARMThumb.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\ARMThumb.h
# End Source File
# Begin Source File
SOURCE=.\Coder.h
# End Source File
# Begin Source File
SOURCE=.\IA64.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\IA64.h
# End Source File
# Begin Source File
SOURCE=.\M68.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\M68.h
# End Source File
# Begin Source File
SOURCE=.\PPC.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\PPC.h
# End Source File
# Begin Source File
SOURCE=.\x86.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\x86.h
# End Source File
# Begin Source File
SOURCE=.\x86_2.cpp
!IF "$(CFG)" == "Branch - Win32 Release"
# ADD CPP /O2
# SUBTRACT CPP /YX /Yc /Yu
!ELSEIF "$(CFG)" == "Branch - Win32 Debug"
!ENDIF
# End Source File
# Begin Source File
SOURCE=.\x86_2.h
# End Source File
# End Group
# Begin Group "Stream"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\..\Common\InBuffer.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\InBuffer.h
# End Source File
# Begin Source File
SOURCE=..\..\Common\OutBuffer.cpp
# End Source File
# Begin Source File
SOURCE=..\..\Common\OutBuffer.h
# End Source File
# End Group
# Begin Group "RangeCoder"
# PROP Default_Filter ""
# Begin Source File
SOURCE=..\RangeCoder\RangeCoder.h
# End Source File
# Begin Source File
SOURCE=..\RangeCoder\RangeCoderBit.h
# End Source File
# End Group
# Begin Group "Common"
# PROP Default_Filter ""
# End Group
# End Target
# End Project

29
7zip/Compress/Branch/Branch.dsw Executable file
View File

@@ -0,0 +1,29 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "Branch"=.\Branch.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

66
7zip/Compress/Branch/Coder.h Executable file
View File

@@ -0,0 +1,66 @@
// Branch/Coder.h
#pragma once
#ifndef __CallPowerPC_CODER_H
#define __CallPowerPC_CODER_H
#include "Common/MyCom.h"
#include "Common/Types.h"
#include "../../ICoder.h"
const int kBufferSize = 1 << 17;
class CDataBuffer
{
protected:
BYTE *_buffer;
public:
CDataBuffer()
{ _buffer = new BYTE[kBufferSize]; }
~CDataBuffer()
{ delete []_buffer; }
};
#define MyClass3(Name) \
class C ## Name: \
public ICompressCoder, \
public CDataBuffer, \
public CMyUnknownImp \
{ \
public: \
MY_UNKNOWN_IMP \
STDMETHOD(Code)(ISequentialInStream *inStream, \
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
ICompressProgressInfo *progress); \
};
// {23170F69-40C1-278B-0303-010100000100}
#define MyClass2(Name, id, subId, encodingId) \
DEFINE_GUID(CLSID_CCompressConvert ## Name, \
0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00); \
MyClass3(Name) \
#define MyClass(Name, id, subId) \
MyClass2(Name ## _Encoder, id, subId, 0x01) \
MyClass2(Name ## _Decoder, id, subId, 0x00)
#define MyClassImp(Name) \
STDMETHODIMP C ## Name ## _Encoder::Code(ISequentialInStream *inStream, \
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
ICompressProgressInfo *progress) \
{ \
return Name ## _Code(inStream, outStream, inSize, outSize, \
progress, _buffer, true); \
} \
STDMETHODIMP C ## Name ## _Decoder::Code(ISequentialInStream *inStream, \
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize, \
ICompressProgressInfo *progress) \
{ \
return Name ## _Code(inStream, outStream, inSize, outSize, \
progress, _buffer, false); \
}
#endif

View File

@@ -0,0 +1,178 @@
// DLLExports.cpp
#include "StdAfx.h"
#define INITGUID
#include "Common/ComTry.h"
#include "Coder.h"
#include "x86.h"
#include "PPC.h"
#include "Alpha.h"
#include "IA64.h"
#include "ARM.h"
#include "ARMThumb.h"
#include "M68.h"
#include "x86_2.h"
#include "../../ICoder.h"
#define MY_CreateClass(n) \
if (*clsid == CLSID_CCompressConvert ## n ## _Encoder) { \
if (!correctInterface) \
return E_NOINTERFACE; \
coder = (ICompressCoder *)new C ## n ## _Encoder(); \
} else if (*clsid == CLSID_CCompressConvert ## n ## _Decoder){ \
if (!correctInterface) \
return E_NOINTERFACE; \
coder = (ICompressCoder *)new C ## n ## _Decoder(); \
}
/*
#define MyOBJECT_ENTRY(Name) \
OBJECT_ENTRY(CLSID_CCompressConvert ## Name ## _Encoder, C ## Name ## _Encoder) \
OBJECT_ENTRY(CLSID_CCompressConvert ## Name ## _Decoder, C ## Name ## _Decoder) \
BEGIN_OBJECT_MAP(ObjectMap)
MyOBJECT_ENTRY(BCJ_x86)
MyOBJECT_ENTRY(BCJ2_x86)
MyOBJECT_ENTRY(BC_PPC_B)
MyOBJECT_ENTRY(BC_Alpha)
MyOBJECT_ENTRY(BC_IA64)
MyOBJECT_ENTRY(BC_ARM)
MyOBJECT_ENTRY(BC_ARMThumb)
MyOBJECT_ENTRY(BC_M68_B)
END_OBJECT_MAP()
*/
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
return TRUE;
}
STDAPI CreateObject(
const GUID *clsid,
const GUID *interfaceID,
void **outObject)
{
COM_TRY_BEGIN
*outObject = 0;
int correctInterface = (*interfaceID == IID_ICompressCoder);
CMyComPtr<ICompressCoder> coder;
MY_CreateClass(BCJ_x86)
else
MY_CreateClass(BC_PPC_B)
else
MY_CreateClass(BC_Alpha)
else
MY_CreateClass(BC_IA64)
else
MY_CreateClass(BC_ARM)
else
MY_CreateClass(BC_ARMThumb)
else
MY_CreateClass(BC_M68_B)
else
{
CMyComPtr<ICompressCoder2> coder2;
correctInterface = (*interfaceID == IID_ICompressCoder2);
if (*clsid == CLSID_CCompressConvertBCJ2_x86_Encoder)
{
if (!correctInterface)
return E_NOINTERFACE;
coder2 = (ICompressCoder2 *)new CBCJ2_x86_Encoder();
}
else if (*clsid == CLSID_CCompressConvertBCJ2_x86_Decoder)
{
if (!correctInterface)
return E_NOINTERFACE;
coder2 = (ICompressCoder2 *)new CBCJ2_x86_Decoder();
}
else
return CLASS_E_CLASSNOTAVAILABLE;
*outObject = coder2.Detach();
return S_OK;
}
*outObject = coder.Detach();
return S_OK;
COM_TRY_END
}
struct CBranchMethodItem
{
char ID[4];
const wchar_t *UserName;
const GUID *Decoder;
const GUID *Encoder;
UINT32 NumInStreams;
};
#define METHOD_ITEM(Name, id, subId, UserName, NumInStreams) \
{ { 0x03, 0x03, id, subId }, UserName, \
&CLSID_CCompressConvert ## Name ## _Decoder, \
&CLSID_CCompressConvert ## Name ## _Encoder, NumInStreams }
static CBranchMethodItem g_Methods[] =
{
METHOD_ITEM(BCJ_x86, 0x01, 0x03, L"BCJ", 1),
METHOD_ITEM(BCJ2_x86, 0x01, 0x1B, L"BCJ2", 4),
METHOD_ITEM(BC_PPC_B, 0x02, 0x05, L"BC_PPC_B", 1),
METHOD_ITEM(BC_Alpha, 0x03, 1, L"BC_Alpha", 1),
METHOD_ITEM(BC_IA64, 0x04, 1, L"BC_IA64", 1),
METHOD_ITEM(BC_ARM, 0x05, 1, L"BC_ARM", 1),
METHOD_ITEM(BC_M68_B, 0x06, 5, L"BC_M68_B", 1),
METHOD_ITEM(BC_ARMThumb, 0x07, 1, L"BC_ARMThumb", 1)
};
STDAPI GetNumberOfMethods(UINT32 *numMethods)
{
*numMethods = sizeof(g_Methods) / sizeof(g_Methods[1]);
return S_OK;
}
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
{
if (index > sizeof(g_Methods) / sizeof(g_Methods[1]))
return E_INVALIDARG;
VariantClear((tagVARIANT *)value);
const CBranchMethodItem &method = g_Methods[index];
switch(propID)
{
case NMethodPropID::kID:
if ((value->bstrVal = ::SysAllocStringByteLen(method.ID,
sizeof(method.ID))) != 0)
value->vt = VT_BSTR;
return S_OK;
case NMethodPropID::kName:
if ((value->bstrVal = ::SysAllocString(method.UserName)) != 0)
value->vt = VT_BSTR;
return S_OK;
case NMethodPropID::kDecoder:
if ((value->bstrVal = ::SysAllocStringByteLen(
(const char *)method.Decoder, sizeof(GUID))) != 0)
value->vt = VT_BSTR;
return S_OK;
case NMethodPropID::kEncoder:
if ((value->bstrVal = ::SysAllocStringByteLen(
(const char *)method.Encoder, sizeof(GUID))) != 0)
value->vt = VT_BSTR;
return S_OK;
case NMethodPropID::kInStreams:
{
if (method.NumInStreams != 1)
{
value->vt = VT_UI4;
value->ulVal = method.NumInStreams;
}
return S_OK;
}
}
return S_OK;
}

103
7zip/Compress/Branch/IA64.cpp Executable file
View File

@@ -0,0 +1,103 @@
// IA64.cpp
#include "StdAfx.h"
#include "IA64.h"
#include "Windows/Defs.h"
const BYTE kBranchTable[32] =
{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 6, 6, 0, 0, 7, 7,
4, 4, 0, 0, 4, 4, 0, 0
};
static HRESULT BC_IA64_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 16)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 16; bufferPos += 16)
{
UINT32 instrTemplate = buffer[bufferPos] & 0x1F;
// ofs << hex << setw(4) << instrTemplate << endl;
UINT32 mask = kBranchTable[instrTemplate];
UINT32 bitPos = 5;
for (int slot = 0; slot < 3; slot++, bitPos += 41)
{
if (((mask >> slot) & 1) == 0)
continue;
UINT32 bytePos = (bitPos >> 3);
UINT32 bitRes = bitPos & 0x7;
UINT64 instruction = *(UINT64 *)(buffer + bufferPos + bytePos);
UINT64 instNorm = instruction >> bitRes;
if (((instNorm >> 37) & 0xF) == 0x5
&& ((instNorm >> 9) & 0x7) == 0
// && (instNorm & 0x3F)== 0
)
{
UINT32 src = UINT32((instNorm >> 13) & 0xFFFFF);
src |= ((instNorm >> 36) & 1) << 20;
src <<= 4;
UINT32 dest;
if (encoding)
dest = nowPos + bufferPos + src;
else
dest = src - (nowPos + bufferPos);
dest >>= 4;
UINT64 instNorm2 = instNorm;
instNorm &= ~(UINT64(0x8FFFFF) << 13);
instNorm |= (UINT64(dest & 0xFFFFF) << 13);
instNorm |= (UINT64(dest & 0x100000) << (36 - 20));
instruction &= (1 << bitRes) - 1;
instruction |= (instNorm << bitRes);
*(UINT64 *)(buffer + bufferPos + bytePos) = instruction;
}
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_IA64)

14
7zip/Compress/Branch/IA64.h Executable file
View File

@@ -0,0 +1,14 @@
// IA64.h
#pragma once
#ifndef __IA64_H
#define __IA64_H
#include "Coder.h"
MyClass(BC_IA64, 0x04, 1)
// MyClass(IA64_Parse, 0x08, 1)
#endif

69
7zip/Compress/Branch/M68.cpp Executable file
View File

@@ -0,0 +1,69 @@
// M68.cpp
#include "StdAfx.h"
#include "M68.h"
#include "Windows/Defs.h"
static HRESULT BC_M68_B_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 4)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 4;)
{
if (buffer[bufferPos] == 0x61 && buffer[bufferPos + 1] == 0x00)
{
UINT32 src =
(buffer[bufferPos + 2] << 8) |
(buffer[bufferPos + 3]);
UINT32 dest;
if (encoding)
dest = nowPos + bufferPos + 2 + src;
else
dest = src - (nowPos + bufferPos + 2);
buffer[bufferPos + 2] = (dest >> 8);
buffer[bufferPos + 3] = dest;
bufferPos += 4;
}
else
bufferPos += 2;
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_M68_B)

12
7zip/Compress/Branch/M68.h Executable file
View File

@@ -0,0 +1,12 @@
// M68.h
#pragma once
#ifndef __M68_H
#define __M68_H
#include "Coder.h"
MyClass(BC_M68_B, 0x06, 5)
#endif

76
7zip/Compress/Branch/PPC.cpp Executable file
View File

@@ -0,0 +1,76 @@
// PPC.cpp
#include "StdAfx.h"
#include "PPC.h"
#include "Windows/Defs.h"
static HRESULT BC_PPC_B_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 4)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
for (bufferPos = 0; bufferPos <= endPos - 4; bufferPos += 4)
{
// PowerPC branch 6(48) 24(Offset) 1(Abs) 1(Link)
if ((buffer[bufferPos] >> 2) == 0x12 &&
(
(buffer[bufferPos + 3] & 3) == 1
// || (buffer[bufferPos+3] & 3) == 3
)
)
{
UINT32 src = ((buffer[bufferPos + 0] & 3) << 24) |
(buffer[bufferPos + 1] << 16) |
(buffer[bufferPos + 2] << 8) |
(buffer[bufferPos + 3] & (~3));
UINT32 dest;
if (encoding)
dest = nowPos + bufferPos + src;
else
dest = src - (nowPos + bufferPos);
buffer[bufferPos + 0] = 0x48 | ((dest >> 24) & 0x3);
buffer[bufferPos + 1] = (dest >> 16);
buffer[bufferPos + 2] = (dest >> 8);
buffer[bufferPos + 3] &= 0x3;
buffer[bufferPos + 3] |= dest;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BC_PPC_B)

12
7zip/Compress/Branch/PPC.h Executable file
View File

@@ -0,0 +1,12 @@
// PPC.h
#pragma once
#ifndef __PPC_H
#define __PPC_H
#include "Coder.h"
MyClass(BC_PPC_B, 0x02, 5)
#endif

View File

@@ -0,0 +1,3 @@
// StdAfx.cpp
#include "stdafx.h"

8
7zip/Compress/Branch/StdAfx.h Executable file
View File

@@ -0,0 +1,8 @@
// stdafx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#endif

15
7zip/Compress/Branch/resource.h Executable file
View File

@@ -0,0 +1,15 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by resource.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

121
7zip/Compress/Branch/resource.rc Executable file
View File

@@ -0,0 +1,121 @@
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,9,2,0
PRODUCTVERSION 3,9,2,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", "Igor Pavlov\0"
VALUE "FileDescription", "Branch converter\0"
VALUE "FileVersion", "3, 9, 2, 0\0"
VALUE "InternalName", "Branch\0"
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "Branch.dll\0"
VALUE "PrivateBuild", "\0"
VALUE "ProductName", "7-Zip\0"
VALUE "ProductVersion", "3, 9, 2, 0\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

124
7zip/Compress/Branch/x86.cpp Executable file
View File

@@ -0,0 +1,124 @@
// x86.h
#include "StdAfx.h"
#include "x86.h"
#include "Windows/Defs.h"
static bool inline Test86MSByte(BYTE b)
{
return (b == 0 || b == 0xFF);
}
const bool kMaskToAllowedStatus[8] = {true, true, true, false, true, false, false, false};
const BYTE kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
static HRESULT BCJ_x86_Code(ISequentialInStream *inStream,
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
ICompressProgressInfo *progress, BYTE *buffer, bool encoding)
{
UINT64 nowPos64 = 0;
UINT32 nowPos = 0;
UINT32 bufferPos = 0;
UINT32 prevMask = 0;
UINT32 prevPos = (- 5);
while(true)
{
UINT32 processedSize;
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 5)
{
if (endPos > 0)
{
RINOK(outStream->Write(buffer, endPos, &processedSize));
if (endPos != processedSize)
return E_FAIL;
}
return S_OK;
}
bufferPos = 0;
if (nowPos - prevPos > 5)
prevPos = nowPos - 5;
UINT32 limit = endPos - 5;
while(bufferPos <= limit)
{
if (buffer[bufferPos] != 0xE8 && buffer[bufferPos] != 0xE9)
{
bufferPos++;
continue;
}
UINT32 offset = (nowPos + bufferPos - prevPos);
prevPos = (nowPos + bufferPos);
if (offset > 5)
prevMask = 0;
else
{
for (UINT32 i = 0; i < offset; i++)
{
prevMask &= 0x77;
prevMask <<= 1;
}
}
BYTE &nextByte = buffer[bufferPos + 4];
if (Test86MSByte(nextByte) && kMaskToAllowedStatus[(prevMask >> 1) & 0x7] &&
(prevMask >> 1) < 0x10)
{
UINT32 src =
(UINT32(nextByte) << 24) |
(UINT32(buffer[bufferPos + 3]) << 16) |
(UINT32(buffer[bufferPos + 2]) << 8) |
(buffer[bufferPos + 1]);
UINT32 dest;
while(true)
{
if (encoding)
dest = (nowPos + bufferPos + 5) + src;
else
dest = src - (nowPos + bufferPos + 5);
if (prevMask == 0)
break;
UINT32 index = kMaskToBitNumber[prevMask >> 1];
if (!Test86MSByte(dest >> (24 - index * 8)))
break;
src = dest ^ ((1 << (32 - index * 8)) - 1);
// src = dest;
}
nextByte = ~(((dest >> 24) & 1) - 1);
buffer[bufferPos + 3] = (dest >> 16);
buffer[bufferPos + 2] = (dest >> 8);
buffer[bufferPos + 1] = dest;
bufferPos += 5;
prevMask = 0;
}
else
{
bufferPos++;
prevMask |= 1;
if (Test86MSByte(nextByte))
prevMask |= 0x10;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
RINOK(outStream->Write(buffer, bufferPos, &processedSize));
if (bufferPos != processedSize)
return E_FAIL;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, &nowPos64));
}
UINT32 i = 0;
while(bufferPos < endPos)
buffer[i++] = buffer[bufferPos++];
bufferPos = i;
}
}
MyClassImp(BCJ_x86)

13
7zip/Compress/Branch/x86.h Executable file
View File

@@ -0,0 +1,13 @@
// x86.h
#pragma once
#ifndef __X86_H
#define __X86_H
#include "Coder.h"
MyClass(BCJ_x86, 0x01, 3)
// MyClass(x86_J, 0x01, 2)
#endif

331
7zip/Compress/Branch/x86_2.cpp Executable file
View File

@@ -0,0 +1,331 @@
// x86_2.cpp
#include "StdAfx.h"
#include "x86_2.h"
#include "Windows/Defs.h"
#include "../../ICoder.h"
inline UINT32 Swap4(UINT32 value)
{
return (value << 24) | (value >> 24) |
( (value >> 8) & 0xFF00) | ( (value << 8) & 0xFF0000);
}
inline bool IsJcc(BYTE b0, BYTE b1)
{
return (b0 == 0x0F && (b1 & 0xF0) == 0x80);
}
#ifndef EXTRACT_ONLY
static bool inline Test86MSByte(BYTE b)
{
return (b == 0 || b == 0xFF);
}
HRESULT CBCJ2_x86_Encoder::Flush()
{
RINOK(_mainStream.Flush());
RINOK(_callStream.Flush());
RINOK(_jumpStream.Flush());
_rangeEncoder.FlushData();
return _rangeEncoder.FlushStream();
}
const UINT32 kDefaultLimit = (1 << 24);
HRESULT CBCJ2_x86_Encoder::CodeReal(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress)
{
if (numInStreams != 1 || numOutStreams != 4)
return E_INVALIDARG;
bool sizeIsDefined = false;
UINT64 inSize;
if (inSizes != NULL)
if (inSizes[0] != NULL)
{
inSize = *inSizes[0];
if (inSize <= kDefaultLimit)
sizeIsDefined = true;
}
ISequentialInStream *inStream = inStreams[0];
_mainStream.Init(outStreams[0]);
_callStream.Init(outStreams[1]);
_jumpStream.Init(outStreams[2]);
_rangeEncoder.Init(outStreams[3]);
for (int i = 0; i < 256; i++)
_statusE8Encoder[i].Init();
_statusE9Encoder.Init();
_statusJccEncoder.Init();
// CCoderReleaser releaser(this);
CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;
{
inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);
}
UINT32 nowPos = 0;
UINT64 nowPos64 = 0;
UINT32 bufferPos = 0;
UINT32 processedSize;
BYTE prevByte = 0;
UINT64 subStreamIndex = 0;
UINT64 subStreamStartPos = 0;
UINT64 subStreamEndPos = 0;
while(true)
{
UINT32 size = kBufferSize - bufferPos;
RINOK(inStream->Read(_buffer + bufferPos, size, &processedSize));
UINT32 endPos = bufferPos + processedSize;
if (endPos < 5)
{
// change it
for (bufferPos = 0; bufferPos < endPos; bufferPos++)
{
BYTE b = _buffer[bufferPos];
_mainStream.WriteByte(b);
if (b == 0xE8)
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);
else if (b == 0xE9)
_statusE9Encoder.Encode(&_rangeEncoder, 0);
else if (IsJcc(prevByte, b))
_statusJccEncoder.Encode(&_rangeEncoder, 0);
prevByte = b;
}
return Flush();
}
bufferPos = 0;
UINT32 limit = endPos - 5;
while(bufferPos <= limit)
{
BYTE b = _buffer[bufferPos];
_mainStream.WriteByte(b);
if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))
{
bufferPos++;
prevByte = b;
continue;
}
BYTE nextByte = _buffer[bufferPos + 4];
UINT32 src =
(UINT32(nextByte) << 24) |
(UINT32(_buffer[bufferPos + 3]) << 16) |
(UINT32(_buffer[bufferPos + 2]) << 8) |
(_buffer[bufferPos + 1]);
UINT32 dest = (nowPos + bufferPos + 5) + src;
// if (Test86MSByte(nextByte))
bool convert;
if (getSubStreamSize != NULL)
{
UINT64 currentPos = (nowPos64 + bufferPos);
while (subStreamEndPos < currentPos)
{
UINT64 subStreamSize;
HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);
if (result == S_OK)
{
subStreamStartPos = subStreamEndPos;
subStreamEndPos += subStreamSize;
subStreamIndex++;
}
else if (result == S_FALSE || result == E_NOTIMPL)
{
getSubStreamSize.Release();
subStreamStartPos = 0;
subStreamEndPos = subStreamStartPos - 1;
}
else
return result;
}
if (getSubStreamSize == NULL)
{
if (sizeIsDefined)
convert = (dest < inSize);
else
convert = Test86MSByte(nextByte);
}
else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)
convert = Test86MSByte(nextByte);
else
{
UINT64 dest64 = (currentPos + 5) + INT64(INT32(src));
convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);
}
}
else if (sizeIsDefined)
convert = (dest < inSize);
else
convert = Test86MSByte(nextByte);
if (convert)
{
if (b == 0xE8)
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 1);
else if (b == 0xE9)
_statusE9Encoder.Encode(&_rangeEncoder, 1);
else
_statusJccEncoder.Encode(&_rangeEncoder, 1);
dest = Swap4(dest);
bufferPos += 5;
if (b == 0xE8)
_callStream.WriteBytes(&dest, sizeof(dest));
else
_jumpStream.WriteBytes(&dest, sizeof(dest));
prevByte = nextByte;
}
else
{
if (b == 0xE8)
_statusE8Encoder[prevByte].Encode(&_rangeEncoder, 0);
else if (b == 0xE9)
_statusE9Encoder.Encode(&_rangeEncoder, 0);
else
_statusJccEncoder.Encode(&_rangeEncoder, 0);
bufferPos++;
prevByte = b;
}
}
nowPos += bufferPos;
nowPos64 += bufferPos;
if (progress != NULL)
{
RINOK(progress->SetRatioInfo(&nowPos64, NULL));
}
UINT32 i = 0;
while(bufferPos < endPos)
_buffer[i++] = _buffer[bufferPos++];
bufferPos = i;
}
}
STDMETHODIMP CBCJ2_x86_Encoder::Code(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress)
{
try
{
return CodeReal(inStreams, inSizes, numInStreams,
outStreams, outSizes,numOutStreams, progress);
}
catch(const COutBufferException &e) { return e.ErrorCode; }
catch(...) { return S_FALSE; }
}
#endif
HRESULT CBCJ2_x86_Decoder::CodeReal(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress)
{
if (numInStreams != 4 || numOutStreams != 1)
return E_INVALIDARG;
_mainInStream.Init(inStreams[0]);
_callStream.Init(inStreams[1]);
_jumpStream.Init(inStreams[2]);
_rangeDecoder.Init(inStreams[3]);
for (int i = 0; i < 256; i++)
_statusE8Decoder[i].Init();
_statusE9Decoder.Init();
_statusJccDecoder.Init();
_outStream.Init(outStreams[0]);
// CCoderReleaser releaser(this);
BYTE prevByte = 0;
UINT32 processedBytes = 0;
while(true)
{
if (processedBytes > (1 << 20) && progress != NULL)
{
UINT64 nowPos64 = _outStream.GetProcessedSize();
RINOK(progress->SetRatioInfo(NULL, &nowPos64));
processedBytes = 0;
}
processedBytes++;
BYTE b;
if (!_mainInStream.ReadByte(b))
return Flush();
_outStream.WriteByte(b);
if (b != 0xE8 && b != 0xE9 && !IsJcc(prevByte, b))
{
prevByte = b;
continue;
}
bool status;
if (b == 0xE8)
status = (_statusE8Decoder[prevByte].Decode(&_rangeDecoder) == 1);
else if (b == 0xE9)
status = (_statusE9Decoder.Decode(&_rangeDecoder) == 1);
else
status = (_statusJccDecoder.Decode(&_rangeDecoder) == 1);
if (status)
{
UINT32 src;
if (b == 0xE8)
{
if (!_callStream.ReadBytes(&src, sizeof(src)))
return S_FALSE;
}
else
{
if (!_jumpStream.ReadBytes(&src, sizeof(src)))
return S_FALSE;
}
src = Swap4(src);
UINT32 dest = src - (UINT32(_outStream.GetProcessedSize()) + 4) ;
_outStream.WriteBytes(&dest, sizeof(dest));
prevByte = (dest >> 24);
processedBytes += 4;
}
else
prevByte = b;
}
}
STDMETHODIMP CBCJ2_x86_Decoder::Code(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress)
{
try
{
return CodeReal(inStreams, inSizes, numInStreams,
outStreams, outSizes,numOutStreams, progress);
}
catch(const COutBufferException &e) { return e.ErrorCode; }
catch(...) { return S_FALSE; }
}

147
7zip/Compress/Branch/x86_2.h Executable file
View File

@@ -0,0 +1,147 @@
// x86_2.h
#pragma once
#ifndef __X86_2_H
#define __X86_2_H
#include "Common/MyCom.h"
#include "Coder.h"
#include "../RangeCoder/RangeCoderBit.h"
// #include "../../Common/InBuffer.h"
// {23170F69-40C1-278B-0303-010100000100}
#define MyClass2_a(Name, id, subId, encodingId) \
DEFINE_GUID(CLSID_CCompressConvert ## Name, \
0x23170F69, 0x40C1, 0x278B, 0x03, 0x03, id, subId, 0x00, 0x00, encodingId, 0x00);
#define MyClass_a(Name, id, subId) \
MyClass2_a(Name ## _Encoder, id, subId, 0x01) \
MyClass2_a(Name ## _Decoder, id, subId, 0x00)
MyClass_a(BCJ2_x86, 0x01, 0x1B)
const int kNumMoveBits = 5;
#ifndef EXTRACT_ONLY
class CBCJ2_x86_Encoder:
public ICompressCoder2,
public CDataBuffer,
public CMyUnknownImp
{
public:
CBCJ2_x86_Encoder(): _mainStream(1 << 16) {}
COutBuffer _mainStream;
COutBuffer _callStream;
COutBuffer _jumpStream;
NCompress::NRangeCoder::CEncoder _rangeEncoder;
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE8Encoder[256];
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusE9Encoder;
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusJccEncoder;
HRESULT Flush();
/*
void ReleaseStreams()
{
_mainStream.ReleaseStream();
_callStream.ReleaseStream();
_jumpStream.ReleaseStream();
_rangeEncoder.ReleaseStream();
}
class CCoderReleaser
{
CBCJ2_x86_Encoder *_coder;
public:
CCoderReleaser(CBCJ2_x86_Encoder *aCoder): _coder(aCoder) {}
~CCoderReleaser()
{
_coder->ReleaseStreams();
}
};
friend class CCoderReleaser;
*/
public:
MY_UNKNOWN_IMP
HRESULT CodeReal(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress);
STDMETHOD(Code)(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress);
};
#endif
class CBCJ2_x86_Decoder:
public ICompressCoder2,
public CMyUnknownImp
{
public:
CBCJ2_x86_Decoder(): _outStream(1 << 16), _mainInStream(1 << 16) {}
CInBuffer _mainInStream;
CInBuffer _callStream;
CInBuffer _jumpStream;
NCompress::NRangeCoder::CDecoder _rangeDecoder;
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE8Decoder[256];
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusE9Decoder;
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusJccDecoder;
COutBuffer _outStream;
/*
void ReleaseStreams()
{
_mainInStream.ReleaseStream();
_callStream.ReleaseStream();
_jumpStream.ReleaseStream();
_rangeDecoder.ReleaseStream();
_outStream.ReleaseStream();
}
*/
HRESULT Flush() { return _outStream.Flush(); }
/*
class CCoderReleaser
{
CBCJ2_x86_Decoder *_coder;
public:
CCoderReleaser(CBCJ2_x86_Decoder *aCoder): _coder(aCoder) {}
~CCoderReleaser() { _coder->ReleaseStreams(); }
};
friend class CCoderReleaser;
*/
public:
MY_UNKNOWN_IMP
HRESULT CodeReal(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress);
STDMETHOD(Code)(ISequentialInStream **inStreams,
const UINT64 **inSizes,
UINT32 numInStreams,
ISequentialOutStream **outStreams,
const UINT64 **outSizes,
UINT32 numOutStreams,
ICompressProgressInfo *progress);
};
#endif