Oops. Last change 34 (10771bc49d01) did not include removal of superflous copy of
e32image from e32tools
--- a/e32tools/e32lib/e32image/deflate/compress.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\compress.cpp
-//
-//
-
-#include "deflate.h"
-
-#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
-#include <fstream>
-#else //__MSVCDOTNET__
-#include <fstream.h>
-#endif //__MSVCDOTNET__
-
-#include <assert.h>
-#include "h_utl.h"
-
-class TFileOutput : public TBitOutput
- {
- enum {KBufSize=0x1000};
-public:
- TFileOutput(ostream& os);
- void FlushL();
- TUint32 iDataCount;
-private:
- void OverflowL();
-private:
- ostream& iOutStream;
- TUint8 iBuf[KBufSize];
- };
-
-TFileOutput::TFileOutput(ostream& os)
- :iOutStream(os)
- {
- Set(iBuf,KBufSize);
- }
-
-void TFileOutput::OverflowL()
-//
-// empty the buffer and reset the pointers
-//
- {
- FlushL();
- Set(iBuf,KBufSize);
- }
-
-void TFileOutput::FlushL()
-//
-// write out the contents of the buffer
-//
- {
- TInt len=Ptr()-iBuf;
- if (len)
- {
- iOutStream.write(reinterpret_cast<char *>(iBuf), len); // write extended header
- iDataCount += len;
- }
- }
-
-void DeflateCompress(char *bytes,TInt size,ostream &os)
- {
- TFileOutput* output=new TFileOutput(os);
- output->iDataCount = 0;
- DeflateL((TUint8*)bytes,size,*output);
- output->FlushL();
- delete output;
- }
-
-TUint32 DeflateCompressCheck(char *bytes,TInt size,ostream &os)
- {
- TUint32 r = 0;
- TFileOutput* output=new TFileOutput(os);
- output->iDataCount = 0;
- DeflateL((TUint8*)bytes,size,*output);
- output->FlushL();
-
- r = output->iDataCount; // Preserve the compressed count
- delete output;
- return r; // Return the compressed size
- }
-
-class TFileInput : public TBitInput
- {
-public:
- TFileInput(unsigned char* source,int size);
-
-private:
- void UnderflowL();
-private:
- TUint8* iReadBuf;
- TInt iSize;
- };
-
-TFileInput::TFileInput(unsigned char* source,int size)
- :iReadBuf(source),iSize(size)
- {
- Set(source,iSize*8);
- }
-
-
-void TFileInput::UnderflowL()
- {
- Print(ESevereError,"Buffer underflow on deflate\n");
- }
-
-void InflateUnCompress(unsigned char* source, int sourcesize,unsigned char* dest, int destsize)
- {
- TFileInput* input = new TFileInput(source, sourcesize);
- CInflater* inflater=CInflater::NewLC(*input);
- inflater->ReadL(dest,destsize);
- delete input;
- //delete inflater;
- }
-
-
--- a/e32tools/e32lib/e32image/deflate/decode.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,412 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\decode.cpp
-//
-//
-
-#include "huffman.h"
-#include "panic.h"
-#include <cpudefs.h>
-#include "h_utl.h"
-#include "farray.h"
-
-
-const TInt KHuffTerminate=0x0001;
-const TUint32 KBranch1=sizeof(TUint32)<<16;
-
-TUint32* HuffmanSubTree(TUint32* aPtr,const TUint32* aValue,TUint32** aLevel)
-//
-// write the subtree below aPtr and return the head
-//
- {
- TUint32* l=*aLevel++;
- if (l>aValue)
- {
- TUint32* sub0=HuffmanSubTree(aPtr,aValue,aLevel); // 0-tree first
- aPtr=HuffmanSubTree(sub0,aValue-(aPtr-sub0)-1,aLevel); // 1-tree
- TInt branch0=(TUint8*)sub0-(TUint8*)(aPtr-1);
- *--aPtr=KBranch1|branch0;
- }
- else if (l==aValue)
- {
- TUint term0=*aValue--; // 0-term
- aPtr=HuffmanSubTree(aPtr,aValue,aLevel); // 1-tree
- *--aPtr=KBranch1|(term0>>16);
- }
- else // l<iNext
- {
- TUint term0=*aValue--; // 0-term
- TUint term1=*aValue--;
- *--aPtr=(term1>>16<<16)|(term0>>16);
- }
- return aPtr;
- }
-
-void Huffman::Decoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aDecodeTree[],TInt aSymbolBase)
-/** Create a canonical Huffman decoding tree
-
- This generates the huffman decoding tree used by TBitInput::HuffmanL() to read huffman
- encoded data. The input is table of code lengths, as generated by Huffman::HuffmanL()
- and must represent a valid huffman code.
-
- @param "const TUint32 aHuffman[]" The table of code lengths as generated by Huffman::HuffmanL()
- @param "TInt aNumCodes" The number of codes in the table
- @param "TUint32 aDecodeTree[]" The space for the decoding tree. This must be the same
- size as the code-length table, and can safely be the same memory
- @param "TInt aSymbolBase" the base value for the output 'symbols' from the decoding tree, by default
- this is zero.
-
- @panic "USER ???" If the provided code is not a valid Huffman coding
-
- @see IsValid()
- @see HuffmanL()
-*/
- {
- if(!IsValid(aHuffman,aNumCodes))
- Panic(EHuffmanInvalidCoding);
-//
- TFixedArray<TInt,KMaxCodeLength> counts;
- counts.Reset();
- TInt codes=0;
- TInt ii;
- for (ii=0;ii<aNumCodes;++ii)
- {
- TInt len=aHuffman[ii];
- aDecodeTree[ii]=len;
- if (--len>=0)
- {
- ++counts[len];
- ++codes;
- }
- }
-//
- TFixedArray<TUint32*,KMaxCodeLength> level;
- TUint32* lit=aDecodeTree+codes;
- for (ii=0;ii<KMaxCodeLength;++ii)
- {
- level[ii]=lit;
- lit-=counts[ii];
- }
- aSymbolBase=(aSymbolBase<<17)+(KHuffTerminate<<16);
- for (ii=0;ii<aNumCodes;++ii)
- {
- TUint len=TUint8(aDecodeTree[ii]);
- if (len)
- *--level[len-1]|=(ii<<17)+aSymbolBase;
- }
- if (codes==1) // codes==1 special case: the tree is not complete
- {
- TUint term=aDecodeTree[0]>>16;
- aDecodeTree[0]=term|(term<<16); // 0- and 1-terminate at root
- }
- else if (codes>1)
- HuffmanSubTree(aDecodeTree+codes-1,aDecodeTree+codes-1,&level[0]);
- }
-
-// The decoding tree for the externalised code
-const TUint32 HuffmanDecoding[]=
- {
- 0x0004006c,
- 0x00040064,
- 0x0004005c,
- 0x00040050,
- 0x00040044,
- 0x0004003c,
- 0x00040034,
- 0x00040021,
- 0x00040023,
- 0x00040025,
- 0x00040027,
- 0x00040029,
- 0x00040014,
- 0x0004000c,
- 0x00040035,
- 0x00390037,
- 0x00330031,
- 0x0004002b,
- 0x002f002d,
- 0x001f001d,
- 0x001b0019,
- 0x00040013,
- 0x00170015,
- 0x0004000d,
- 0x0011000f,
- 0x000b0009,
- 0x00070003,
- 0x00050001
- };
-
-void Huffman::InternalizeL(TBitInput& aInput,TUint32 aHuffman[],TInt aNumCodes)
-/** Restore a canonical huffman encoding from a bit stream
-
- The encoding must have been stored using Huffman::ExternalizeL(). The resulting
- code-length table can be used to create an encoding table using Huffman::Encoding()
- or a decoding tree using Huffman::Decoding().
-
- @param "TBitInput& aInput" The input stream with the encoding
- @param "TUint32 aHuffman[]" The internalized code-length table is placed here
- @param "TInt aNumCodes" The number of huffman codes in the table
-
- @leave "TBitInput::HuffmanL()"
-
- @see ExternalizeL()
-*/
-// See ExternalizeL for a description of the format
- {
- // initialise move-to-front list
- TFixedArray<TUint8,Huffman::KMetaCodes> list;
- for (TInt i=0;i<list.Count();++i)
- list[i]=TUint8(i);
- TInt last=0;
- // extract codes, reverse rle-0 and mtf encoding in one pass
- TUint32* p=aHuffman;
- const TUint32* end=aHuffman+aNumCodes;
- TInt rl=0;
- while (p+rl<end)
- {
- TInt c=aInput.HuffmanL(HuffmanDecoding);
- if (c<2)
- {
- // one of the zero codes used by RLE-0
- // update he run-length
- rl+=rl+c+1;
- }
- else
- {
- while (rl>0)
- {
- if (p>end)
- {
- Panic(EHuffmanCorruptFile);
- }
- *p++=last;
- --rl;
- }
- --c;
- list[0]=TUint8(last);
- last=list[c];
- HMem::Copy(&list[1],&list[0],c);
- if (p>end)
- {
- Panic(EHuffmanCorruptFile);
- }
- *p++=last;
- }
- }
- while (rl>0)
- {
- if (p>end)
- {
- Panic(EHuffmanCorruptFile);
- }
- *p++=last;
- --rl;
- }
- }
-
-// bit-stream input class
-
-inline TUint reverse(TUint aVal)
-//
-// Reverse the byte-order of a 32 bit value
-// This generates optimal ARM code (4 instructions)
-//
- {
- TUint v=(aVal<<16)|(aVal>>16);
- v^=aVal;
- v&=0xff00ffff;
- aVal=(aVal>>8)|(aVal<<24);
- return aVal^(v>>8);
- }
-
-TBitInput::TBitInput()
-/** Construct a bit stream input object
-
- Following construction the bit stream is ready for reading bits, but will
- immediately call UnderflowL() as the input buffer is empty.
-*/
- :iCount(0),iRemain(0)
- {}
-
-TBitInput::TBitInput(const TUint8* aPtr, TInt aLength, TInt aOffset)
-/** Construct a bit stream input object over a buffer
-
- Following construction the bit stream is ready for reading bits from
- the specified buffer.
-
- @param "const TUint8* aPtr" The address of the buffer containing the bit stream
- @param "TInt aLength" The length of the bitstream in bits
- @param "TInt aOffset" The bit offset from the start of the buffer to the bit stream (defaults to zero)
-*/
- {
- Set(aPtr,aLength,aOffset);
- }
-
-void TBitInput::Set(const TUint8* aPtr, TInt aLength, TInt aOffset)
-/** Set the memory buffer to use for input
-
- Bits will be read from this buffer until it is empty, at which point
- UnderflowL() will be called.
-
- @param "const TUint8* aPtr" The address of the buffer containing the bit stream
- @param "TInt aLength" The length of the bitstream in bits
- @param "TInt aOffset" The bit offset from the start of the buffer to the bit stream (defaults to zero)
-*/
- {
- TUint p=(TUint)aPtr;
- p+=aOffset>>3; // nearest byte to the specified bit offset
- aOffset&=7; // bit offset within the byte
- const TUint32* ptr=(const TUint32*)(p&~3); // word containing this byte
- aOffset+=(p&3)<<3; // bit offset within the word
- if (aLength==0)
- iCount=0;
- else
- {
- // read the first few bits of the stream
- iBits=reverse(*ptr++)<<aOffset;
- aOffset=32-aOffset;
- aLength-=aOffset;
- if (aLength<0)
- aOffset+=aLength;
- iCount=aOffset;
- }
- iRemain=aLength;
- iPtr=ptr;
- }
-
-#ifndef __HUFFMAN_MACHINE_CODED__
-
-TUint TBitInput::ReadL()
-/** Read a single bit from the input
-
- Return the next bit in the input stream. This will call UnderflowL() if
- there are no more bits available.
-
- @return The next bit in the stream
-
- @leave "UnderflowL()" It the bit stream is exhausted more UnderflowL is called
- to get more data
-*/
- {
- TInt c=iCount;
- TUint bits=iBits;
- if (--c<0)
- return ReadL(1);
- iCount=c;
- iBits=bits<<1;
- return bits>>31;
- }
-
-TUint TBitInput::ReadL(TInt aSize)
-/** Read a multi-bit value from the input
-
- Return the next few bits as an unsigned integer. The last bit read is
- the least significant bit of the returned value, and the value is
- zero extended to return a 32-bit result.
-
- A read of zero bits will always reaturn zero.
-
- This will call UnderflowL() if there are not enough bits available.
-
- @param "TInt aSize" The number of bits to read
-
- @return The bits read from the stream
-
- @leave "UnderflowL()" It the bit stream is exhausted more UnderflowL is called
- to get more data
-*/
- {
- if (!aSize)
- return 0;
- TUint val=0;
- TUint bits=iBits;
- iCount-=aSize;
- while (iCount<0)
- {
- // need more bits
-#ifdef __CPU_X86
- // X86 does not allow shift-by-32
- if (iCount+aSize!=0)
- val|=bits>>(32-(iCount+aSize))<<(-iCount); // scrub low order bits
-#else
- val|=bits>>(32-(iCount+aSize))<<(-iCount); // scrub low order bits
-#endif
- aSize=-iCount; // bits still required
- if (iRemain>0)
- {
- bits=reverse(*iPtr++);
- iCount+=32;
- iRemain-=32;
- if (iRemain<0)
- iCount+=iRemain;
- }
- else
- {
- UnderflowL();
- bits=iBits;
- iCount-=aSize;
- }
- }
-#ifdef __CPU_X86
- // X86 does not allow shift-by-32
- iBits=aSize==32?0:bits<<aSize;
-#else
- iBits=bits<<aSize;
-#endif
- return val|(bits>>(32-aSize));
- }
-
-TUint TBitInput::HuffmanL(const TUint32* aTree)
-/** Read and decode a Huffman Code
-
- Interpret the next bits in the input as a Huffman code in the specified
- decoding. The decoding tree should be the output from Huffman::Decoding().
-
- @param "const TUint32* aTree" The huffman decoding tree
-
- @return The symbol that was decoded
-
- @leave "UnderflowL()" It the bit stream is exhausted more UnderflowL is called
- to get more data
-*/
- {
- TUint huff=0;
- do
- {
- aTree=PtrAdd(aTree,huff>>16);
- huff=*aTree;
- if (ReadL()==0)
- huff<<=16;
- } while ((huff&0x10000u)==0);
- return huff>>17;
- }
-
-#endif
-
-void TBitInput::UnderflowL()
-/** Handle an empty input buffer
-
- This virtual function is called when the input buffer is empty and
- more bits are required. It should reset the input buffer with more
- data using Set().
-
- A derived class can replace this to read the data from a file
- (for example) before reseting the input buffer.
-
- @leave "KErrUnderflow" The default implementation leaves
-*/
- {
- Panic(EHuffmanBufferOverflow);
- }
-
--- a/e32tools/e32lib/e32image/deflate/deflate.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,325 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\deflate.cpp
-//
-//
-
-#include "deflate.h"
-#include "h_utl.h"
-#include "panic.h"
-
-class HDeflateHash
- {
-public:
- inline static HDeflateHash* NewLC(TInt aLinks);
-//
- inline TInt First(const TUint8* aPtr,TInt aPos);
- inline TInt Next(TInt aPos,TInt aOffset) const;
-private:
- inline HDeflateHash();
- inline static TInt Hash(const TUint8* aPtr);
-private:
- typedef TUint16 TOffset;
-private:
- TInt iHash[256];
- TOffset iOffset[1]; // or more
- };
-
-class MDeflater
- {
-public:
- void DeflateL(const TUint8* aBase,TInt aLength);
- inline virtual ~MDeflater() { };
-private:
- const TUint8* DoDeflateL(const TUint8* aBase,const TUint8* aEnd,HDeflateHash& aHash);
- static TInt Match(const TUint8* aPtr,const TUint8* aEnd,TInt aPos,HDeflateHash& aHas);
- void SegmentL(TInt aLength,TInt aDistance);
- virtual void LitLenL(TInt aCode) =0;
- virtual void OffsetL(TInt aCode) =0;
- virtual void ExtraL(TInt aLen,TUint aBits) =0;
- };
-
-class TDeflateStats : public MDeflater
- {
-public:
- inline TDeflateStats(TEncoding& aEncoding);
- inline virtual ~TDeflateStats() { }
-private:
-// from MDeflater
- void LitLenL(TInt aCode);
- void OffsetL(TInt aCode);
- void ExtraL(TInt aLen,TUint aBits);
-private:
- TEncoding& iEncoding;
- };
-
-class TDeflater : public MDeflater
- {
-public:
- inline TDeflater(TBitOutput& aOutput,const TEncoding& aEncoding);
- inline virtual ~TDeflater() { };
-private:
-// from MDeflater
- void LitLenL(TInt aCode);
- void OffsetL(TInt aCode);
- void ExtraL(TInt aLen,TUint aBits);
-private:
- TBitOutput& iOutput;
- const TEncoding& iEncoding;
- };
-
-
-// Class HDeflateHash
-
-inline HDeflateHash::HDeflateHash()
- {TInt* p=iHash+256;do *--p=-KDeflateMaxDistance-1; while (p>iHash);}
-
-inline HDeflateHash* HDeflateHash::NewLC(TInt aLinks)
- {
- return new(HMem::Alloc(0,_FOFF(HDeflateHash,iOffset[0]) + (sizeof(TOffset) * Min(aLinks,KDeflateMaxDistance)))) HDeflateHash;
- }
-
-inline TInt HDeflateHash::Hash(const TUint8* aPtr)
- {
- TUint x=aPtr[0]|(aPtr[1]<<8)|(aPtr[2]<<16);
- return (x*KDeflateHashMultiplier)>>KDeflateHashShift;
- }
-
-inline TInt HDeflateHash::First(const TUint8* aPtr,TInt aPos)
- {
- TInt h=Hash(aPtr);
- TInt offset=Min(aPos-iHash[h],KDeflateMaxDistance<<1);
- iHash[h]=aPos;
- iOffset[aPos&(KDeflateMaxDistance-1)]=TOffset(offset);
- return offset;
- }
-
-inline TInt HDeflateHash::Next(TInt aPos,TInt aOffset) const
- {return aOffset+iOffset[(aPos-aOffset)&(KDeflateMaxDistance-1)];}
-
-
-// Class TDeflater
-//
-// generic deflation algorithm, can do either statistics and the encoder
-
-TInt MDeflater::Match(const TUint8* aPtr,const TUint8* aEnd,TInt aPos,HDeflateHash& aHash)
- {
- TInt offset=aHash.First(aPtr,aPos);
- if (offset>KDeflateMaxDistance)
- return 0;
- TInt match=0;
- aEnd=Min(aEnd,aPtr+KDeflateMaxLength);
- TUint8 c=*aPtr;
- do
- {
- const TUint8* p=aPtr-offset;
- if (p[match>>16]==c)
- { // might be a better match
- const TUint8* m=aPtr;
- for (;;)
- {
- if (*p++!=*m++)
- break;
- if (m<aEnd)
- continue;
- return ((m-aPtr)<<16)|offset;
- }
- TInt l=m-aPtr-1;
- if (l>match>>16)
- {
- match=(l<<16)|offset;
- c=m[-1];
- }
- }
- offset=aHash.Next(aPos,offset);
- } while (offset<=KDeflateMaxDistance);
- return match;
- }
-
-const TUint8* MDeflater::DoDeflateL(const TUint8* aBase,const TUint8* aEnd,HDeflateHash& aHash)
-//
-// Apply the deflation algorithm to the data [aBase,aEnd)
-// Return a pointer after the last byte that was deflated (which may not be aEnd)
-//
- {
- const TUint8* ptr=aBase;
- TInt prev=0; // the previous deflation match
- do
- {
- TInt match=Match(ptr,aEnd,ptr-aBase,aHash);
-// Extra deflation applies two optimisations which double the time taken
-// 1. If we have a match at p, then test for a better match at p+1 before using it
-// 2. When we have a match, add the hash links for all the data which will be skipped
- if (match>>16 < prev>>16)
- { // use the previous match--it was better
- TInt len=prev>>16;
- SegmentL(len,prev-(len<<16));
- // fill in missing hash entries for better compression
- const TUint8* e=ptr+len-2;
- do
- {
- ++ptr;
- if (ptr + 2 < aEnd)
- aHash.First(ptr,ptr-aBase);
- } while (ptr<e);
- prev=0;
- }
- else if (match<=(KDeflateMinLength<<16))
- LitLenL(*ptr); // no deflation match here
- else
- { // save this match and test the next position
- if (prev) // we had a match at ptr-1, but this is better
- LitLenL(ptr[-1]);
- prev=match;
- }
- ++ptr;
- } while (ptr+KDeflateMinLength-1<aEnd);
- if (prev)
- { // emit the stored match
- TInt len=prev>>16;
- SegmentL(len,prev-(len<<16));
- ptr+=len-1;
- }
- return ptr;
- }
-
-void MDeflater::DeflateL(const TUint8* aBase,TInt aLength)
-//
-// The generic deflation algorithm
-//
- {
- const TUint8* end=aBase+aLength;
- if (aLength>KDeflateMinLength)
- { // deflation kicks in if there is enough data
- HDeflateHash* hash=HDeflateHash::NewLC(aLength);
- if(hash==NULL)
- Panic(EHuffmanOutOfMemory);
-
- aBase=DoDeflateL(aBase,end,*hash);
- delete hash;
- }
- while (aBase<end) // emit remaining bytes
- LitLenL(*aBase++);
- LitLenL(TEncoding::EEos); // eos marker
- }
-
-void MDeflater::SegmentL(TInt aLength,TInt aDistance)
-//
-// Turn a (length,offset) pair into the deflation codes+extra bits before calling
-// the specific LitLen(), Offset() and Extra() functions.
-//
- {
- aLength-=KDeflateMinLength;
- TInt extralen=0;
- TUint len=aLength;
- while (len>=8)
- {
- ++extralen;
- len>>=1;
- }
- LitLenL((extralen<<2)+len+TEncoding::ELiterals);
- if (extralen)
- ExtraL(extralen,aLength);
-//
- aDistance--;
- extralen=0;
- TUint dist=aDistance;
- while (dist>=8)
- {
- ++extralen;
- dist>>=1;
- }
- OffsetL((extralen<<2)+dist);
- if (extralen)
- ExtraL(extralen,aDistance);
- }
-
-// Class TDeflateStats
-//
-// This class analyses the data stream to generate the frequency tables
-// for the deflation algorithm
-
-inline TDeflateStats::TDeflateStats(TEncoding& aEncoding)
- :iEncoding(aEncoding)
- {}
-
-void TDeflateStats::LitLenL(TInt aCode)
- {
- ++iEncoding.iLitLen[aCode];
- }
-
-void TDeflateStats::OffsetL(TInt aCode)
- {
- ++iEncoding.iDistance[aCode];
- }
-
-void TDeflateStats::ExtraL(TInt,TUint)
- {}
-
-// Class TDeflater
-//
-// Extends MDeflater to provide huffman encoding of the output
-
-inline TDeflater::TDeflater(TBitOutput& aOutput,const TEncoding& aEncoding)
-//
-// construct for encoding
-//
- :iOutput(aOutput),iEncoding(aEncoding)
- {}
-
-void TDeflater::LitLenL(TInt aCode)
- {
- iOutput.HuffmanL(iEncoding.iLitLen[aCode]);
- }
-
-void TDeflater::OffsetL(TInt aCode)
- {
- iOutput.HuffmanL(iEncoding.iDistance[aCode]);
- }
-
-void TDeflater::ExtraL(TInt aLen,TUint aBits)
- {
- iOutput.WriteL(aBits,aLen);
- }
-
-void DoDeflateL(const TUint8* aBuf,TInt aLength,TBitOutput& aOutput,TEncoding& aEncoding)
- {
-// analyse the data for symbol frequency
- TDeflateStats analyser(aEncoding);
- analyser.DeflateL(aBuf,aLength);
-
-// generate the required huffman encodings
- Huffman::HuffmanL(aEncoding.iLitLen,TEncoding::ELitLens,aEncoding.iLitLen);
- Huffman::HuffmanL(aEncoding.iDistance,TEncoding::EDistances,aEncoding.iDistance);
-
-// Store the encoding table
- Huffman::ExternalizeL(aOutput,aEncoding.iLitLen,KDeflationCodes);
-
-// generate the tables
- Huffman::Encoding(aEncoding.iLitLen,TEncoding::ELitLens,aEncoding.iLitLen);
- Huffman::Encoding(aEncoding.iDistance,TEncoding::EDistances,aEncoding.iDistance);
-
-// now finally deflate the data with the generated encoding
- TDeflater deflater(aOutput,aEncoding);
- deflater.DeflateL(aBuf,aLength);
- aOutput.PadL(1);
- }
-
-void DeflateL(const TUint8* aBuf, TInt aLength, TBitOutput& aOutput)
- {
- TEncoding* encoding=new TEncoding;
- HMem::FillZ(encoding,sizeof(TEncoding));
- DoDeflateL(aBuf,aLength,aOutput,*encoding);
- }
-
--- a/e32tools/e32lib/e32image/deflate/deflate.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,78 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\deflate.h
-//
-//
-
-#ifndef __DECODE_H__
-#define __DECODE_H__
-
-#include "huffman.h"
-#include <e32base.h>
-
-// deflation constants
-const TInt KDeflateLengthMag=8;
-const TInt KDeflateDistanceMag=12;
-//
-const TInt KDeflateMinLength=3;
-const TInt KDeflateMaxLength=KDeflateMinLength-1 + (1<<KDeflateLengthMag);
-const TInt KDeflateMaxDistance=(1<<KDeflateDistanceMag);
-const TInt KDeflateDistCodeBase=0x200;
-// hashing
-const TUint KDeflateHashMultiplier=0xAC4B9B19u;
-const TInt KDeflateHashShift=24;
-
-class TEncoding
- {
-public:
- enum {ELiterals=256,ELengths=(KDeflateLengthMag-1)*4,ESpecials=1,EDistances=(KDeflateDistanceMag-1)*4};
- enum {ELitLens=ELiterals+ELengths+ESpecials};
- enum {EEos=ELiterals+ELengths};
-public:
- TUint32 iLitLen[ELitLens];
- TUint32 iDistance[EDistances];
- };
-
-const TInt KDeflationCodes=TEncoding::ELitLens+TEncoding::EDistances;
-
-class CInflater
- {
-public:
- enum {EBufSize = 0x800, ESafetyZone=8};
-public:
- static CInflater* NewLC(TBitInput& aInput);
- ~CInflater();
-//
- TInt ReadL(TUint8* aBuffer,TInt aLength);
- TInt SkipL(TInt aLength);
-private:
- CInflater(TBitInput& aInput);
- void ConstructL();
- void InitL();
- TInt InflateL();
-private:
- TBitInput* iBits;
- const TUint8* iRptr; // partial segment
- TInt iLen;
- const TUint8* iAvail; // available data
- const TUint8* iLimit;
- TEncoding* iEncoding;
- TUint8* iOut; // circular buffer for distance matches
- TUint8 iHuff[EBufSize+ESafetyZone]; // huffman data
- };
-
-void DeflateL(const TUint8* aBuf, TInt aLength, TBitOutput& aOutput);
-
-#endif
-
--- a/e32tools/e32lib/e32image/deflate/encode.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,491 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\encode.cpp
-//
-//
-
-#include "huffman.h"
-#include "panic.h"
-#include <e32base.h>
-#include "h_utl.h"
-#include <assert.h>
-#include "farray.h"
-#include <stdlib.h>
-
-void User::Invariant()
- {
- fprintf(stderr, "User::Invariant() called\n");
- exit(1);
- }
-
-// local definitions used for Huffman code generation
-typedef TUint16 THuff; /** @internal */
-const THuff KLeaf=0x8000; /** @internal */
-struct TNode
-/** @internal */
- {
- TUint iCount;
- THuff iLeft;
- THuff iRight;
- };
-
-void HuffmanLengthsL(TUint32* aLengths,const TNode* aNodes,TInt aNode,TInt aLen)
-/** recursive function to calculate the code lengths from the node tree
-
- @internal
-*/
- {
- if (++aLen>Huffman::KMaxCodeLength)
- Panic(EHuffmanBufferOverflow);
-
- const TNode& node=aNodes[aNode];
- TUint x=node.iLeft;
- if (x&KLeaf)
- aLengths[x&~KLeaf]=aLen;
- else
- HuffmanLengthsL(aLengths,aNodes,x,aLen);
- x=node.iRight;
- if (x&KLeaf)
- aLengths[x&~KLeaf]=aLen;
- else
- HuffmanLengthsL(aLengths,aNodes,x,aLen);
- }
-
-void InsertInOrder(TNode* aNodes, TInt aSize, TUint aCount, TInt aVal)
-/** Insert the {aCount,aValue} pair into the already sorted array of nodes
-
- @internal
-*/
- {
- // Uses Insertion sort following a binary search...
- TInt l=0, r=aSize;
- while (l < r)
- {
- TInt m = (l+r) >> 1;
- if (aNodes[m].iCount<aCount)
- r=m;
- else
- l=m+1;
- }
- HMem::Copy(aNodes+l+1,aNodes+l,sizeof(TNode)*(aSize-l));
- aNodes[l].iCount=aCount;
- aNodes[l].iRight=TUint16(aVal);
- }
-
-void Huffman::HuffmanL(const TUint32 aFrequency[],TInt aNumCodes,TUint32 aHuffman[])
-/** Generate a Huffman code
-
- This generates a Huffman code for a given set of code frequencies. The output
- is a table of code lengths which can be used to build canonincal encoding tables
- or decoding trees for use with the TBitInput and TBitOutput classes.
-
- Entries in the table with a frequency of zero will have a zero code length
- and thus no associated huffman encoding. If each such symbol should have a
- maximum length encoding, they must be given at least a frequency of 1.
-
- For an alphabet of n symbols, this algorithm has a transient memory overhead
- of 8n, and a time complexity of O(n*log(n)).
-
- @param "const TUint32 aFrequency[]" The table of code frequencies
- @param "TInt aNumCodes" The number of codes in the table
- @param "TUint32 aHuffman[]" The table for the output code-length table. This must be
- the same size as the frequency table, and can safely be the same table
-
- @leave "KErrNoMemory" If memory used for code generation cannot be allocated
-
- @panic "USER ???" If the number of codes exceeds Huffman::KMaxCodes
-*/
- {
- if(TUint(aNumCodes)>TUint(KMaxCodes))
- Panic(EHuffmanTooManyCodes);
-
- // Sort the values into decreasing order of frequency
- //
- TNode* nodes = new TNode[aNumCodes];
- if(nodes==NULL)
- Panic(EHuffmanOutOfMemory);
-
- TInt lCount=0;
-
- for (TInt ii=0;ii<aNumCodes;++ii)
- {
- TInt c=aFrequency[ii];
- if (c!=0)
- InsertInOrder(nodes,lCount++,c,ii|KLeaf);
- }
-
- // default code length is zero
- HMem::FillZ(aHuffman,aNumCodes*sizeof(TUint32));
-
- if (lCount==0)
- {
- // no codes with frequency>0. No code has a length
- }
- else if (lCount==1)
- {
- // special case for a single value (always encode as "0")
- aHuffman[nodes[0].iRight&~KLeaf]=1;
- }
- else
- {
- // Huffman algorithm: pair off least frequent nodes and reorder
- //
- do
- {
- --lCount;
- TUint c=nodes[lCount].iCount + nodes[lCount-1].iCount;
- nodes[lCount].iLeft=nodes[lCount-1].iRight;
- // re-order the leaves now to reflect new combined frequency 'c'
- InsertInOrder(nodes,lCount-1,c,lCount);
- } while (lCount>1);
- // generate code lengths in aHuffman[]
- HuffmanLengthsL(aHuffman,nodes,1,0);
- }
-
- delete [] nodes;
-
- if(!IsValid(aHuffman,aNumCodes))
- Panic(EHuffmanInvalidCoding);
- }
-
-TBool Huffman::IsValid(const TUint32 aHuffman[],TInt aNumCodes)
-/** Validate a Huffman encoding
-
- This verifies that a Huffman coding described by the code lengths is valid.
- In particular, it ensures that no code exceeds the maximum length and
- that it is possible to generate a canonical coding for the specified lengths.
-
- @param "const TUint32 aHuffman[]" The table of code lengths as generated by Huffman::HuffmanL()
- @param "TInt aNumCodes" The number of codes in the table
-
- @return True if the code is valid, otherwise false
-*/
- {
- // The code is valid if one of the following holds:
- // (a) the code exactly fills the 'code space'
- // (b) there is only a single symbol with code length 1
- // (c) there are no encoded symbols
- //
- TUint remain=1<<KMaxCodeLength;
- TInt totlen=0;
- for (const TUint32* p=aHuffman+aNumCodes; p>aHuffman;)
- {
- TInt len=*--p;
- if (len>0)
- {
- totlen+=len;
- if (len>KMaxCodeLength)
- return EFalse;
- TUint c=1<<(KMaxCodeLength-len);
- if (c>remain)
- return EFalse;
- remain-=c;
- }
- }
-
- return remain==0 || totlen<=1;
- }
-
-void Huffman::Encoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aEncodeTable[])
-/** Create a canonical Huffman encoding table
-
- This generates the huffman codes used by TBitOutput::HuffmanL() to write huffman
- encoded data. The input is table of code lengths, as generated by Huffman::HuffmanL()
- and must represent a valid huffman code.
-
- @param "const TUint32 aHuffman[]" The table of code lengths as generated by Huffman::HuffmanL()
- @param "TInt aNumCodes" The number of codes in the table
- @param "TUint32 aEncodeTable[]" The table for the output huffman codes. This must be
- the same size as the code-length table, and can safely be the same table
-
- @panic "USER ???" If the provided code is not a valid Huffman coding
-
- @see IsValid()
- @see HuffmanL()
-*/
- {
- __ASSERT_ALWAYS(IsValid(aHuffman,aNumCodes),Panic(EHuffmanInvalidCoding));
-
- TFixedArray<TInt,KMaxCodeLength> lenCount;
- lenCount.Reset();
-
- TInt ii;
- for (ii=0;ii<aNumCodes;++ii)
- {
- TInt len=aHuffman[ii]-1;
- if (len>=0)
- ++lenCount[len];
- }
-
- TFixedArray<TUint,KMaxCodeLength> nextCode;
- TUint code=0;
- for (ii=0;ii<KMaxCodeLength;++ii)
- {
- code<<=1;
- nextCode[ii]=code;
- code+=lenCount[ii];
- }
-
- for (ii=0;ii<aNumCodes;++ii)
- {
- TInt len=aHuffman[ii];
- if (len==0)
- aEncodeTable[ii]=0;
- else
- {
- aEncodeTable[ii] = (nextCode[len-1]<<(KMaxCodeLength-len))|(len<<KMaxCodeLength);
- ++nextCode[len-1];
- }
- }
- }
-
-/** the encoding table for the externalised code
- @internal
-*/
-const TUint32 HuffmanEncoding[]=
- {
- 0x10000000,
- 0x1c000000,
- 0x12000000,
- 0x1d000000,
- 0x26000000,
- 0x26800000,
- 0x2f000000,
- 0x37400000,
- 0x37600000,
- 0x37800000,
- 0x3fa00000,
- 0x3fb00000,
- 0x3fc00000,
- 0x3fd00000,
- 0x47e00000,
- 0x47e80000,
- 0x47f00000,
- 0x4ff80000,
- 0x57fc0000,
- 0x5ffe0000,
- 0x67ff0000,
- 0x77ff8000,
- 0x7fffa000,
- 0x7fffb000,
- 0x7fffc000,
- 0x7fffd000,
- 0x7fffe000,
- 0x87fff000,
- 0x87fff800
- };
-
-void EncodeRunLengthL(TBitOutput& aOutput, TInt aLength)
-/** encode 0a as '0' and 0b as '1', return number of symbols created
-
- @internal
-*/
- {
- if (aLength>0)
- {
- EncodeRunLengthL(aOutput,(aLength-1)>>1);
- aOutput.HuffmanL(HuffmanEncoding[1-(aLength&1)]);
- }
- }
-
-void Huffman::ExternalizeL(TBitOutput& aOutput,const TUint32 aHuffman[],TInt aNumCodes)
-/** Store a canonical huffman encoding in compact form
-
- As the encoding is canonical, only the code lengths of each code needs to be saved.
-
- Due to the nature of code length tables, these can usually be stored very compactly
- by encoding the encoding itself, hence the use of the bit output stream.
-
- @param "TBitOutput& aOutput" The output stream for the encoding
- @param "const TUint32 aHuffman[]" The table of code lengths as generated by Huffman::HuffmanL()
- @param "TInt aNumCodes" The number of huffman codes in the table
-
- @leave "TBitOutput::HuffmanL()"
-*/
- {
- // We assume that the code length table is generated by the huffman generator,
- // in which case the maxmimum code length is 27 bits.
- //
- // We apply three transformations to the data:
- // 1. the data goes through a move-to-front coder
- // 2. apply a rle-0 coder which replace runs of '0' with streams of '0a' and '0b'
- // 3. encode the result using a predefined (average) huffman coding
- //
- // This can be done in a single pass over the data, avoiding the need for additional
- // memory.
- //
- // initialise the list for the MTF coder
- TFixedArray<TUint8,Huffman::KMetaCodes> list;
- TInt i;
- for (i=0;i<list.Count();++i)
- list[i]=TUint8(i);
- TInt last=0;
-
- TInt rl=0;
- const TUint32* p32=aHuffman;
- const TUint32* e32=p32+aNumCodes;
- while (p32<e32)
- {
- TInt c=*p32++;
- if (c==last)
- ++rl; // repeat of last symbol
- else
- {
- // encode run-length
- EncodeRunLengthL(aOutput,rl);
- rl=0;
- // find code in MTF list
- TInt j;
- for (j=1;list[j]!=c;++j)
- ;
- // store this code
- aOutput.HuffmanL(HuffmanEncoding[j+1]);
- // adjust list for MTF algorithm
- while (--j>0)
- list[j+1]=list[j];
- list[1]=TUint8(last);
- last=c;
- }
- }
- // encod any remaining run-length
- EncodeRunLengthL(aOutput,rl);
- }
-
-
-TBitOutput::TBitOutput()
-/** Construct a bit stream output object
-
- Following construction the bit stream is ready for writing bits, but will first call
- OverflowL() as the output buffer is 'full'. A derived class can detect this state as
- Ptr() will return null.
-*/
- :iCode(0),iBits(-8),iPtr(0),iEnd(0)
- {}
-
-TBitOutput::TBitOutput(TUint8* aBuf,TInt aSize)
-/** Construct a bit stream output object over a buffer
-
- Data will be written to the buffer until it is full, at which point OverflowL() will
- be called. This should handle the data and then can Set() again to reset the buffer
- for further output.
-
- @param "TUint8* aBuf" The buffer for output
- @param "TInt aSize" The size of the buffer in bytes
-*/
- :iCode(0),iBits(-8),iPtr(aBuf),iEnd(aBuf+aSize)
- {}
-
-void TBitOutput::HuffmanL(TUint aHuffCode)
-/** Write a huffman code
-
- This expects a huffman code value as generated by Huffman::Encoding()
-
- @param "TUint aHuffCode" The huffman code write to the stream
-
- @leave "OverflowL()" If the output buffer is full, OverflowL() is called
-*/
- {
- DoWriteL(aHuffCode<<(32-Huffman::KMaxCodeLength),aHuffCode>>Huffman::KMaxCodeLength);
- }
-
-void TBitOutput::WriteL(TUint aValue,TInt aLength)
-/** Write an arbitrary integer value
-
- Write an unsigned integer using the number of bits specified. Only
- the low order bits of the value are written to the output, most
- significant bit first.
-
- @param "TUint aValue" The value to write to the stream
- @param "TUint aLength" The number of bits to output
-
- @leave "OverflowL()" If the output buffer is full, OverflowL() is called
-*/
- {
- if (aLength)
- DoWriteL(aValue<<=32-aLength,aLength);
- }
-
-void TBitOutput::PadL(TUint aPadding)
-/** Pad the bitstream to the next byte boundary
-
- Terminate the bitstream by padding the last byte with the requested value.
- Following this operation the bitstream can continue to be used, the data will
- start at the next byte.
-
- @param "TUint aPadding" The bit value to pad the final byte with
-
- @leave "OverflowL()" If the output buffer is full, OverflowL() is called
-*/
- {
- if (iBits>-8)
- WriteL(aPadding?0xffffffffu:0,-iBits);
- }
-
-void TBitOutput::DoWriteL(TUint aBits,TInt aSize)
-/** Write the higher order bits to the stream
-
- @internal
-*/
- {
- if (aSize>25)
- {
- // cannot process >25 bits in a single pass
- // so do the top 8 bits first
- ASSERT(aSize<=32);
- DoWriteL(aBits&0xff000000u,8);
- aBits<<=8;
- aSize-=8;
- }
-
- TInt bits=iBits;
- TUint code=iCode|(aBits>>(bits+8));
- bits+=aSize;
- if (bits>=0)
- {
- TUint8* p=iPtr;
- do
- {
- if (p==iEnd)
- {
- // run out of buffer space so invoke the overflow handler
- iPtr=p;
- OverflowL();
- p=iPtr;
- ASSERT(p!=iEnd);
- }
- *p++=TUint8(code>>24);
- code<<=8;
- bits-=8;
- } while (bits>=0);
- iPtr=p;
- }
- iCode=code;
- iBits=bits;
- }
-
-void TBitOutput::OverflowL()
-/** Handle a full output buffer
-
- This virtual function is called when the output buffer is full. It should deal
- with the data in the buffer before reseting the buffer using Set(), allowing
- further data to be written.
-
- A derived class can replace this to write the data to a file (for example)
- before marking the buffer as empty.
-
- @leave "KErrOverflow" The default implementation leaves
-*/
- {
- Panic(EHuffmanBufferOverflow);
- }
--- a/e32tools/e32lib/e32image/deflate/farray.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,104 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\farray.h
-//
-//
-
-#ifndef __FARRAY_H__
-#define __FARRAY_H__
-#include <assert.h>
-
-template <class T,TInt S>
-class TFixedArray
-// Range checking wrapper+ class for C++ arrays
-// Can be embedded in C-objects, or used on the stack: use Reset() to zero it
- {
- typedef TFixedArray<T,S> ThisClass;
-public:
- inline TFixedArray();
- inline TFixedArray(const T* aList, TInt aLength);
- //
- inline void Copy(const T* aList, TInt aLength);
- inline void Reset(); // zero fill
- inline void DeleteAll();
- //
- inline TInt Count() const;
- inline TInt Length() const;
- // Accessors - debug range checking
- inline T& operator[](TInt aIndex);
- inline const T& operator[] (TInt aIndex) const;
- // Accessors - always range checking
- inline T& At(TInt aIndex);
- inline const T& At(TInt aIndex) const;
- // Provides pointers to the beginning and end of the array
- inline T* Begin();
- inline T* End();
- inline const T* Begin() const;
- inline const T* End() const;
- //
-protected:
- inline static TBool InRange(TInt aIndex);
-protected:
- T iRep[S];
- };
-
-// Template class TFixedArray
-IMPORT_C void PanicTFixedArray();
-
-template <class T,TInt S>
-inline TFixedArray<T,S>::TFixedArray()
- {}
-template <class T,TInt S>
-inline void TFixedArray<T,S>::Copy(const T* aList,TInt aLength)
- {assert(TUint(aLength)<=TUint(S));HMem::Copy(iRep,aList,aLength*sizeof(T));}
-template <class T,TInt S>
-inline TFixedArray<T,S>::TFixedArray(const T* aList,TInt aLength)
- {Copy(aList,aLength);}
-template <class T,TInt S>
-inline void TFixedArray<T,S>::Reset()
- {HMem::FillZ(iRep,sizeof(iRep));}
-template <class T,TInt S>
-inline TInt TFixedArray<T,S>::Count() const
- {return S;}
-template <class T,TInt S>
-inline TInt TFixedArray<T,S>::Length() const
- {return sizeof(T);}
-template <class T,TInt S>
-inline TBool TFixedArray<T,S>::InRange(TInt aIndex)
- {return TUint(aIndex)<S;}
-template <class T,TInt S>
-inline T& TFixedArray<T,S>::operator[](TInt aIndex)
- {assert(InRange(aIndex));return iRep[aIndex];}
-template <class T,TInt S>
-inline const T& TFixedArray<T,S>::operator[](TInt aIndex) const
- {return const_cast<ThisClass&>(*this)[aIndex];}
-template <class T,TInt S>
-inline T& TFixedArray<T,S>::At(TInt aIndex)
- {verify(InRange(aIndex));return iRep[aIndex];}
-template <class T,TInt S>
-inline const T& TFixedArray<T,S>::At(TInt aIndex) const
- {return const_cast<ThisClass&>(*this).At(aIndex);}
-template <class T,TInt S>
-inline T* TFixedArray<T,S>::Begin()
- {return &iRep[0];}
-template <class T,TInt S>
-inline T* TFixedArray<T,S>::End()
- {return &iRep[S];}
-template <class T,TInt S>
-inline const T* TFixedArray<T,S>::Begin() const
- {return &iRep[0];}
-template <class T,TInt S>
-inline const T* TFixedArray<T,S>::End() const
- {return &iRep[S];}
-#endif
--- a/e32tools/e32lib/e32image/deflate/huffman.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,140 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\huffman.h
-//
-//
-
-#ifndef __HUFFMAN_H__
-#define __HUFFMAN_H__
-
-#include <e32std.h>
-
-/** Bit output stream.
- Good for writing bit streams for packed, compressed or huffman data algorithms.
-
- This class must be derived from and OverflowL() reimplemented if the bitstream data
- cannot be generated into a single memory buffer.
-
- @since 8.0
- @library euser.lib
-*/
-class TBitOutput
- {
-public:
- TBitOutput();
- TBitOutput(TUint8* aBuf,TInt aSize);
- inline virtual ~TBitOutput() { }
- inline void Set(TUint8* aBuf,TInt aSize);
- inline const TUint8* Ptr() const;
- inline TInt BufferedBits() const;
-//
- void WriteL(TUint aValue, TInt aLength);
- void HuffmanL(TUint aHuffCode);
- void PadL(TUint aPadding);
-private:
- void DoWriteL(TUint aBits, TInt aSize);
- virtual void OverflowL();
-private:
- TUint iCode; // code in production
- TInt iBits;
- TUint8* iPtr;
- TUint8* iEnd;
- };
-
-/** Set the memory buffer to use for output
-
- Data will be written to this buffer until it is full, at which point OverflowL() will
- be called. This should handle the data and then can Set() again to reset the buffer
- for further output.
-
- @param "TUint8* aBuf" The buffer for output
- @param "TInt aSize" The size of the buffer in bytes
-*/
-inline void TBitOutput::Set(TUint8* aBuf,TInt aSize)
- {iPtr=aBuf;iEnd=aBuf+aSize;}
-/** Get the current write position in the output buffer
-
- In conjunction with the address of the buffer, which should be known to the
- caller, this describes the data in the bitstream.
-*/
-inline const TUint8* TBitOutput::Ptr() const
- {return iPtr;}
-/** Get the number of bits that are buffered
-
- This reports the number of bits that have not yet been written into the
- output buffer. It will always lie in the range 0..7. Use PadL() to
- pad the data out to the next byte and write it to the buffer.
-*/
-inline TInt TBitOutput::BufferedBits() const
- {return iBits+8;}
-
-
-/** Bit input stream.
- Good for reading bit streams for packed, compressed or huffman data algorithms.
- @since 8.0
- @library euser.lib
-*/
-class TBitInput
- {
-public:
- TBitInput();
- TBitInput(const TUint8* aPtr, TInt aLength, TInt aOffset=0);
- void Set(const TUint8* aPtr, TInt aLength, TInt aOffset=0);
- inline virtual ~TBitInput() { }
- TUint ReadL();
- TUint ReadL(TInt aSize);
- TUint HuffmanL(const TUint32* aTree);
-private:
- virtual void UnderflowL();
-private:
- TInt iCount;
- TUint iBits;
- TInt iRemain;
- const TUint32* iPtr;
- };
-
-/** Huffman code toolkit.
-
- This class builds a huffman encoding from a frequency table and builds
- a decoding tree from a code-lengths table
-
- The encoding generated is based on the rule that given two symbols s1 and s2, with
- code length l1 and l2, and huffman codes h1 and h2:
-
- if l1<l2 then h1<h2 when compared lexicographically
- if l1==l2 and s1<s2 then h1<h2 ditto
-
- This allows the encoding to be stored compactly as a table of code lengths
-
- @since 8.0
- @library euser.lib
-*/
-class Huffman
- {
-public:
- enum {KMaxCodeLength=27};
- enum {KMetaCodes=KMaxCodeLength+1};
- enum {KMaxCodes=0x8000};
-public:
- static void HuffmanL(const TUint32 aFrequency[],TInt aNumCodes,TUint32 aHuffman[]);
- static void Encoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aEncodeTable[]);
- static void Decoding(const TUint32 aHuffman[],TInt aNumCodes,TUint32 aDecodeTree[],TInt aSymbolBase=0);
- static TBool IsValid(const TUint32 aHuffman[],TInt aNumCodes);
-//
- static void ExternalizeL(TBitOutput& aOutput,const TUint32 aHuffman[],TInt aNumCodes);
- static void InternalizeL(TBitInput& aInput,TUint32 aHuffman[],TInt aNumCodes);
- };
-
-#endif
-
--- a/e32tools/e32lib/e32image/deflate/inflate.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,169 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\inflate.cpp
-//
-//
-
-#include "deflate.h"
-#include "panic.h"
-#include "h_utl.h"
-
-// Class RInflater
-//
-// The inflation algorithm, complete with huffman decoding
-
-inline CInflater::CInflater(TBitInput& aInput)
- :iBits(&aInput),iEncoding(0),iOut(0)
- {}
-
-void CInflater::ConstructL()
- {
- iEncoding=new TEncoding;
- if(iEncoding==NULL)
- Panic(EHuffmanOutOfMemory);
- InitL();
- iLen=0;
- iOut=new TUint8[KDeflateMaxDistance];
- if(iOut==NULL)
- Panic(EHuffmanOutOfMemory);
-
- iAvail=iLimit=iOut;
- }
-
-CInflater* CInflater::NewLC(TBitInput& aInput)
- {
- CInflater* self=new CInflater(aInput);
- if(self==NULL)
- Panic(EHuffmanOutOfMemory);
- self->ConstructL();
- return self;
- }
-
-CInflater::~CInflater()
- {
- delete iEncoding;
- delete [] iOut;
- }
-
-TInt CInflater::ReadL(TUint8* aBuffer,TInt aLength)
- {
- TInt tfr=0;
- for (;;)
- {
- TInt len=Min(aLength,iLimit-iAvail);
- if (len && aBuffer)
- {
- HMem::Copy(aBuffer,iAvail,len);
- aBuffer+=len;
- }
- aLength-=len;
- iAvail+=len;
- tfr+=len;
- if (aLength==0)
- return tfr;
- len=InflateL();
- if (len==0)
- return tfr;
- iAvail=iOut;
- iLimit=iAvail+len;
- }
- }
-
-TInt CInflater::SkipL(TInt aLength)
- {
- return ReadL(0,aLength);
- }
-
-void CInflater::InitL()
- {
-// read the encoding
- Huffman::InternalizeL(*iBits,iEncoding->iLitLen,KDeflationCodes);
-// validate the encoding
- if (!Huffman::IsValid(iEncoding->iLitLen,TEncoding::ELitLens) ||
- !Huffman::IsValid(iEncoding->iDistance,TEncoding::EDistances))
- Panic(EHuffmanCorruptFile);
-// convert the length tables into huffman decoding trees
- Huffman::Decoding(iEncoding->iLitLen,TEncoding::ELitLens,iEncoding->iLitLen);
- Huffman::Decoding(iEncoding->iDistance,TEncoding::EDistances,iEncoding->iDistance,KDeflateDistCodeBase);
- }
-
-TInt CInflater::InflateL()
-//
-// consume all data lag in the history buffer, then decode to fill up the output buffer
-// return the number of available bytes in the output buffer. This is only ever less than
-// the buffer size if the end of stream marker has been read
-//
- {
-// empty the history buffer into the output
- TUint8* out=iOut;
- TUint8* const end=out+KDeflateMaxDistance;
- const TUint32* tree=iEncoding->iLitLen;
- if (iLen<0) // EOF
- return 0;
- if (iLen>0)
- goto useHistory;
-//
- while (out<end)
- {
- // get a huffman code
- {
- TInt val=iBits->HuffmanL(tree)-TEncoding::ELiterals;
- if (val<0)
- {
- *out++=TUint8(val);
- continue; // another literal/length combo
- }
- if (val==TEncoding::EEos-TEncoding::ELiterals)
- { // eos marker. we're done
- iLen=-1;
- break;
- }
- // get the extra bits for the code
- TInt code=val&0xff;
- if (code>=8)
- { // xtra bits
- TInt xtra=(code>>2)-1;
- code-=xtra<<2;
- code<<=xtra;
- code|=iBits->ReadL(xtra);
- }
- if (val<KDeflateDistCodeBase-TEncoding::ELiterals)
- { // length code... get the code
- iLen=code+KDeflateMinLength;
- tree=iEncoding->iDistance;
- continue; // read the huffman code
- }
- // distance code
- iRptr=out-(code+1);
- if (iRptr+KDeflateMaxDistance<end)
- iRptr+=KDeflateMaxDistance;
- }
-useHistory:
- TInt tfr=Min(end-out,iLen);
- iLen-=tfr;
- const TUint8* from=iRptr;
- do
- {
- *out++=*from++;
- if (from==end)
- from-=KDeflateMaxDistance;
- } while (--tfr!=0);
- iRptr=from;
- tree=iEncoding->iLitLen;
- };
- return out-iOut;
- }
-
-
-
--- a/e32tools/e32lib/e32image/deflate/panic.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\panic.cpp
-//
-//
-
-#include "panic.h"
-#include "h_utl.h"
-#include <stdlib.h>
-
-char* HuffmanError[]= {
- "Huffman: Too many codes\n",
- "Huffman: Invalid coding\n",
- "Huffman: Buffer overflow\n",
- "Huffman: Out Of Memory\n",
- "Huffman: Corrupt File\n",
- };
-
-const TInt KHuffmanErrorBase=700;
-
-void Panic(TPanic aPanic)
- {
- Print(ESevereError,HuffmanError[TInt(aPanic)]);
- exit(KHuffmanErrorBase+TInt(aPanic));
- }
--- a/e32tools/e32lib/e32image/deflate/panic.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools\petran\Szip\panic.h
-//
-//
-
-#ifndef __PANIC_H__
-#define __PANIC_H__
-
-#include <e32std.h>
-
-enum TPanic
- {
- EHuffmanTooManyCodes=0,
- EHuffmanInvalidCoding=1,
- EHuffmanBufferOverflow=2,
- EHuffmanOutOfMemory=3,
- EHuffmanCorruptFile=4,
-
- };
-
-void Panic(TPanic aPanic);
-
-#endif
-
--- a/e32tools/e32lib/e32image/e32image.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,866 +0,0 @@
-// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools/e32image/e32image.cpp
-// Basic operations on E32Image files which are used by ROMBUILD.
-// These are independent of the original file format from which the
-// E32Image file was derived.
-//
-//
-
-#include <time.h>
-#include <malloc.h>
-#include <string.h>
-#include <stdlib.h>
-#include "h_utl.h"
-
-
-#if defined (__MSVCDOTNET__) || defined(__TOOLS2__)
-#include <fstream>
-#else //!__MSVCDOTNET__
-#include <fstream.h>
-#endif //__MSVCDOTNET__
-
-#include <assert.h>
-#ifndef __LINUX__
- #include <io.h>
-#endif
-#include "h_ver.h"
-
-// get E32ImageHeader class...
-#define INCLUDE_E32IMAGEHEADER_IMPLEMENTATION
-#define RETURN_FAILURE(_r) return (fprintf(stderr, "line %d\n", __LINE__),_r)
-//#define E32IMAGEHEADER_TRACE(_t) printf _t
-#include "e32image.h"
-#include "byte_pair.h"
-
-void DeflateCompress(char* bytes, TInt size, ostream& os);
-void InflateUnCompress(unsigned char* source, int sourcesize, unsigned char* dest, int destsize);
-void CompressPages(TUint8 * bytes, TInt size, ostream &os, CBytePair *aBPE);
-int DecompressPages(TUint8 * bytes, istream& is, CBytePair *aBPE);
-
-// needed by E32ImageHeaderV::ValidateHeader...
-void Mem::Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength)
- {
- HMem::Crc32(aCrc, aPtr, aLength);
- }
-
-//
-// E32 Image files
-//
-E32ImageFile::E32ImageFile()
- : iData(NULL), iSize(0), iOrigHdr(NULL), iHdr(NULL), iFileName(NULL)
-#ifndef __LINUX__
- , iWideFileName(NULL)
-#endif
-, iError(0), iSource(EE32Image), iOrigHdrOffsetAdj(0), iExportBitMap(0)
- {}
-
-E32ImageFile::~E32ImageFile()
- {
-
- free(iData);
- delete [] iFileName;
-#ifndef __LINUX__
- delete [] iWideFileName;
-#endif
- if (iHdr && iHdr != iOrigHdr)
- delete iHdr;
- free(iExportBitMap);
- }
-
-// dummy implementation
-TBool E32ImageFile::Translate(const char*, TUint, TBool, TBool)
- {
- return EFalse;
- }
-
-Int64 timeToInt64(TInt aTime)
- {
- aTime-=(30*365*24*60*60+7*24*60*60); // seconds since midnight Jan 1st, 2000
- Int64 daysTo2000AD=730497;
- Int64 t=daysTo2000AD*24*3600+aTime; // seconds since 0000
- t=t+3600; // BST (?)
- return t*1000000; // milliseconds
- }
-
-class TE32ImageUids : public TCheckedUid
- {
-public:
- TE32ImageUids(TUint32 aUid1, TUint32 aUid2, TUint32 aUid3) : TCheckedUid(TUidType(TUid::Uid(aUid1), TUid::Uid(aUid2), TUid::Uid(aUid3))) {}
- TUint Check() { return TCheckedUid::Check(); }
- };
-
-void E32ImageFile::SetDefaultHeader()
- {
- iHdr = (E32ImageHeaderV*)iOrigHdr;
- iHdr->iUid1 = 0;
- iHdr->iUid2 = 0;
- iHdr->iUid3 = 0;
- iHdr->iHeaderCrc = 0;
- iHdr->iSignature = 0x434f5045u;
- iHdr->iModuleVersion = 0x00010000u;
- iHdr->iCompressionType = 0;
- iHdr->iToolsVersion = TVersion(MajorVersion, MinorVersion, Build);
- Int64 time1(timeToInt64(time(0)));
- iHdr->iTimeLo=(TUint32)time1;
- iHdr->iTimeHi=(TUint32)(time1>>32);
- iHdr->iFlags = KImageHdrFmt_V;
- iHdr->iCodeSize = 0;
- iHdr->iDataSize = 0;
- iHdr->iHeapSizeMin = 0;
- iHdr->iHeapSizeMax = 0;
- iHdr->iStackSize = 0;
- iHdr->iBssSize = 0;
- iHdr->iEntryPoint = 0;
- iHdr->iCodeBase = 0;
- iHdr->iDataBase = 0;
- iHdr->iDllRefTableCount = 0;
- iHdr->iExportDirOffset = 0;
- iHdr->iExportDirCount = 0;
- iHdr->iTextSize = 0;
- iHdr->iCodeOffset = 0;
- iHdr->iDataOffset = 0;
- iHdr->iImportOffset = 0;
- iHdr->iCodeRelocOffset = 0;
- iHdr->iDataRelocOffset = 0;
- iHdr->iProcessPriority = (TUint16)EPriorityForeground;
- iHdr->iUncompressedSize = 0;
- iHdr->iS.iSecureId = 0;
- iHdr->iS.iVendorId = 0;
- iHdr->iExceptionDescriptor = 0;
- iHdr->iSpare2 = 0;
-
- iHdr->iExportDescSize = 0;
- iHdr->iExportDescType = KImageHdr_ExpD_NoHoles;
- iHdr->iExportDesc[0] = 0;
- }
-
-void E32ImageFile::SetCallEntryPoints(TInt aBool)
- {
-
- if (aBool)
- iHdr->iFlags&=~KImageNoCallEntryPoint;
- else
- iHdr->iFlags|=KImageNoCallEntryPoint;
- }
-
-void E32ImageFile::SetFixedAddress(TInt aBool)
- {
-
- if (aBool)
- iHdr->iFlags|=KImageFixedAddressExe;
- else
- iHdr->iFlags&=~KImageFixedAddressExe;
- }
-
-void E32ImageFile::SetPriority(TProcessPriority aPri)
- {
-
- iHdr->iProcessPriority = (TUint16)aPri;
- }
-
-void E32ImageFile::SetCapability(SCapabilitySet& aCapabilities)
- {
- iHdr->iS.iCaps = aCapabilities;
- }
-
-void E32ImageFile::SetFPU(unsigned int aFPU)
- {
- iHdr->iFlags &=~ KImageHWFloatMask;
-
- if (aFPU == 1)
- iHdr->iFlags |= KImageHWFloat_VFPv2;
- }
-
-void E32ImageFile::Adjust(TInt aSize, TBool aAllowShrink)
-//
-// Adjust the size of allocated data and fix the member data
-//
- {
-
- TInt asize = ALIGN4(aSize);
- if (asize == iSize)
- return;
- if (iSize == 0)
- {
- iSize = asize;
- iData = (char*)malloc(iSize);
- memset(iData, 0, iSize);
- }
- else if (aAllowShrink || asize > iSize)
- {
- TInt oldsize = iSize;
- iSize = asize;
- iData = (char*)realloc(iData, iSize);
- if (iSize > oldsize)
- memset(iData+oldsize, 0, iSize-oldsize);
- }
- if (!iData)
- iSize = 0;
- if (iHdr && iHdr == iOrigHdr)
- iHdr = (E32ImageHeaderV*)iData;
- iOrigHdr = (E32ImageHeader*)iData;
- }
-
-TInt E32ImageFile::ReadHeader(ifstream& is)
- {
- Adjust(sizeof(E32ImageHeader), EFalse);
- is.read(iData, sizeof(E32ImageHeader));
- TInt hdrsz = iOrigHdr->TotalSize();
- if (hdrsz > 0x10000 || hdrsz <= 0)
- return KErrCorrupt; // sanity check
- if (hdrsz > (TInt)sizeof(E32ImageHeader))
- {
- Adjust(hdrsz, EFalse);
- is.read(iData+sizeof(E32ImageHeader), hdrsz-sizeof(E32ImageHeader));
- }
- TUint32 uncompressedSize;
- TInt r = iOrigHdr->ValidateHeader(iFileSize,uncompressedSize);
- if (r != KErrNone)
- {
- fprintf(stderr, "Integrity check failed %d\n", r);
- return r;
- }
- iHdr = (E32ImageHeaderV*)iOrigHdr;
- return KErrNone;
- }
-
-void E32ImageFile::SetStackSize(TInt aSize)
- {
- iHdr->iStackSize=aSize;
- }
-
-void E32ImageFile::SetHeapSizeMin(TInt aSize)
- {
- iHdr->iHeapSizeMin=aSize;
- }
-
-void E32ImageFile::SetHeapSizeMax(TInt aSize)
- {
- iHdr->iHeapSizeMax=aSize;
- }
-
-TUint E32ImageFile::TextOffset()
-//
-// Return the offset of the text section
-//
- {
- return 0;
- }
-
-TUint E32ImageFile::DataOffset()
-//
-// return the offset of the initialised data
-//
- {
- return iHdr->iCodeSize;
- }
-
-TUint E32ImageFile::BssOffset()
-//
-// return the offset from the start of code where the bss is linked
-//
- {
- return DataOffset()+iHdr->iDataSize;
- }
-
-
-TInt E32ImageFile::IsDll()
-//
-//
-//
- {
- return iHdr->iFlags&KImageDll;
- }
-
-
-void E32ImageFile::RelocateSection(char* aPtr, char* aRelocs, TUint aCodeDelta, TUint aDataDelta, char* aImagePtr, TLinAddr** aIATRefs, TBool keepIAT)
-//
-// Relocates the section data at aPtr
-//
- {
-
- TUint codeStart=iHdr->iCodeBase;
- TUint codeFinish=codeStart+iHdr->iCodeSize;
- TUint iatStart = aIATRefs ? codeStart+iHdr->iTextSize : 0;
- TUint iatFinish = aIATRefs ? iatStart+NumberOfImports()*sizeof(TUint) : 0;
-// Print(ELog,"IAT: %x->%x\n",iatStart,iatFinish);
- char* relocs=aRelocs;
- TUint page=0;
- TInt size=0;
- TInt i=((E32RelocSection *)relocs)->iNumberOfRelocs;
- relocs+=sizeof(E32RelocSection);
- while (i>0)
- {
- if (size>0)
- {
- TUint offset=*(TUint16 *)relocs;
- relocs+=2;
- if (offset!=0)
- { // its a reloc
- TUint va=page+(offset&0x0fff);
- TUint relocType=offset&0xf000;
- TUint *dataptr=(TUint *)(aPtr+va);
- assert((char *)dataptr < aRelocs);
- TUint data=*dataptr;
-// Print(ELog,"data %x\n",data);
- if (relocType == KTextRelocType)
- *dataptr=data+aCodeDelta; // points to text/rdata section
- else if (relocType == KDataRelocType)
- *dataptr=data+aDataDelta;
- else
- {
- if (relocType != KInferredRelocType)
- Print(EError,"Unrecognized relocation type %x\n",relocType);
-
- if (data>=iatStart && data<iatFinish)
- {
-
- TUint iatNum = (data-iatStart)/sizeof(TLinAddr);
-
- // If "keepIAT" is used then the importing instruction must import through the IAT entry,
- // but otherwise we change the IAT entry to point to the bit of code doing the importing
- // and do the real fix-up later on in TRomBuilderEntry::FixupImports.
- // NB: We always want to do this for X86 or data exports dont work.
- if (keepIAT || (iHdr->iCpuIdentifier & 0x1000) /*denotes X86*/)
- *dataptr=data+aCodeDelta;
- else
- {
- if ((TUint)aIATRefs[iatNum]>65535)
- Print(EWarning, "Multiple relocations for IAT entry %d (0x%x, 0x%x)\n",
- iatNum, aIATRefs[iatNum], dataptr);
- else
- aIATRefs[iatNum] = (TLinAddr*)(aImagePtr+va); // ROM image address of importing pointer
- }
- }
- else if (data>=codeStart && data<codeFinish)
- *dataptr=data+aCodeDelta; // points to text/rdata section
- else
- *dataptr=data+aDataDelta; // points to data section
- }
- --i;
- }
- size-=2;
- }
- else
- { // next page of relocs
- page=*(TUint *)relocs;
- relocs+=4;
- size=*(TUint *)relocs;
- relocs+=4;
- size-=8;
- }
- }
- }
-
-void E32ImageFile::SetUids(TUid aUid1, TUid aUid2, TUid aUid3)
- {
- iHdr->iUid1=aUid1.iUid;
- iHdr->iUid2=aUid2.iUid;
- iHdr->iUid3=aUid3.iUid;
- }
-
-void E32ImageFile::SetSecureId(TUint32 aId)
- {
- ((E32ImageHeaderV*)iHdr)->iS.iSecureId = aId;
- }
-
-void E32ImageFile::SetVendorId(TUint32 aId)
- {
- ((E32ImageHeaderV*)iHdr)->iS.iVendorId = aId;
- }
-
-void E32ImageFile::UpdateHeaderCrc()
- {
- TE32ImageUids u(iHdr->iUid1, iHdr->iUid2, iHdr->iUid3);
- iHdr->iUidChecksum = u.Check();
- TInt hdrsz = iHdr->TotalSize();
- TInt orighdrsz = iOrigHdr->TotalSize();
- iHdr->iUncompressedSize = iSize - orighdrsz;
- iHdr->iHeaderCrc = KImageCrcInitialiser;
- TUint32 crc = 0;
- HMem::Crc32(crc, iHdr, hdrsz);
- iHdr->iHeaderCrc = crc;
- }
-
-TInt E32ImageFile::NumberOfImports()
-//
-// Return the number of imports made by this image
-//
- {
-
- if (iHdr->iDllRefTableCount==0 || iHdr->iImportOffset==0)
- return 0;
-
- TUint impfmt = iHdr->ImportFormat();
- const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset);
- TInt d;
- TInt nImports = 0;
- const E32ImportBlock* b = (const E32ImportBlock*)(isection+1);
- for (d=0; d<iHdr->iDllRefTableCount; d++)
- {
- nImports += b->iNumberOfImports;
- b = b->NextBlock(impfmt);
- }
-
- if (impfmt==KImageImpFmt_PE || impfmt==KImageImpFmt_PE2)
- {
- TUint *imports=(TUint *)(iData + iOrigHdr->iCodeOffset + iHdr->iTextSize);
- TInt i=0;
- while (*imports++)
- i++;
- assert(i==nImports);
- }
-
- return nImports;
- }
-
-// Work out which exports are missing from the export directory
-void E32ImageFile::CreateExportBitMap()
- {
- TInt nexp = iOrigHdr->iExportDirCount;
- TInt memsz = (nexp + 7) >> 3;
- iExportBitMap = (TUint8*)malloc(memsz);
- memset(iExportBitMap, 0xff, memsz);
- TUint* exports = (TUint*)(iData + iOrigHdr->iExportDirOffset);
- TUint absoluteEntryPoint = iOrigHdr->iEntryPoint + iOrigHdr->iCodeBase;
- TUint impfmt = iOrigHdr->ImportFormat();
- TUint hdrfmt = iOrigHdr->HeaderFormat();
- TUint absentVal = (impfmt == KImageImpFmt_ELF) ? absoluteEntryPoint : iOrigHdr->iEntryPoint;
- TInt i;
- iMissingExports = 0;
- for (i=0; i<nexp; ++i)
- {
- if (exports[i] == absentVal)
- {
- iExportBitMap[i>>3] &= ~(1u << (i & 7));
- ++iMissingExports;
- }
- }
- if (hdrfmt < KImageHdrFmt_V && iMissingExports)
- {
- fprintf(stderr, "Bad exports\n");
- exit(999);
- }
- }
-
-// Append an export description to the E32ImageHeader if necessary
-void E32ImageFile::AddExportDescription()
- {
- if (iMissingExports == 0)
- return; // nothing to do
- TInt nexp = iOrigHdr->iExportDirCount;
- TInt memsz = (nexp + 7) >> 3; // size of complete bitmap
- TInt mbs = (memsz + 7) >> 3; // size of meta-bitmap
- TInt nbytes = 0;
- TInt i;
- for (i=0; i<memsz; ++i)
- if (iExportBitMap[i] != 0xff)
- ++nbytes; // number of groups of 8
- TUint8 edt = KImageHdr_ExpD_FullBitmap;
- TInt extra_space = memsz - 1;
- if (mbs + nbytes < memsz)
- {
- edt = KImageHdr_ExpD_SparseBitmap8;
- extra_space = mbs + nbytes - 1;
- }
- extra_space = (extra_space + sizeof(TUint) - 1) &~ (sizeof(TUint) - 1);
- TInt hdrsz = sizeof(E32ImageHeaderV) + extra_space;
- iHdr = (E32ImageHeaderV*)malloc(hdrsz);
- memcpy(iHdr, iOrigHdr, sizeof(E32ImageHeaderV));
- iHdr->iExportDescType = edt;
- if (edt == KImageHdr_ExpD_FullBitmap)
- {
- iHdr->iExportDescSize = (TUint16)memsz;
- memcpy(iHdr->iExportDesc, iExportBitMap, memsz);
- }
- else
- {
- iHdr->iExportDescSize = (TUint16)(mbs + nbytes);
- memset(iHdr->iExportDesc, 0, extra_space + 1);
- TUint8* mptr = iHdr->iExportDesc;
- TUint8* gptr = mptr + mbs;
- for (i=0; i<memsz; ++i)
- {
- if (iExportBitMap[i] != 0xff)
- {
- mptr[i>>3] |= (1u << (i&7));
- *gptr++ = iExportBitMap[i];
- }
- }
- }
- iHdr->iCodeOffset += extra_space;
- if (iHdr->iDataOffset)
- iHdr->iDataOffset += extra_space;
- if (iHdr->iCodeRelocOffset)
- iHdr->iCodeRelocOffset += extra_space;
- if (iHdr->iDataRelocOffset)
- iHdr->iDataRelocOffset += extra_space;
- if (iHdr->iImportOffset)
- iHdr->iImportOffset += extra_space;
- if (iHdr->iExportDirOffset)
- iHdr->iExportDirOffset += extra_space;
- }
-
-// Check the export description is consistent with the export directory
-TInt E32ImageFile::CheckExportDescription()
- {
- TUint hdrfmt = iOrigHdr->HeaderFormat();
- if (hdrfmt < KImageHdrFmt_V && iMissingExports)
- return KErrCorrupt;
- if (iHdr->iExportDescType == KImageHdr_ExpD_NoHoles)
- {
- return iMissingExports ? KErrCorrupt : KErrNone;
- }
- TInt nexp = iOrigHdr->iExportDirCount;
- TInt memsz = (nexp + 7) >> 3; // size of complete bitmap
- TInt mbs = (memsz + 7) >> 3; // size of meta-bitmap
- TInt eds = iHdr->iExportDescSize;
- if (iHdr->iExportDescType == KImageHdr_ExpD_FullBitmap)
- {
- if (eds != memsz)
- return KErrCorrupt;
- if (memcmp(iHdr->iExportDesc, iExportBitMap, eds) == 0)
- return KErrNone;
- return KErrCorrupt;
- }
- if (iHdr->iExportDescType != KImageHdr_ExpD_SparseBitmap8)
- return KErrNotSupported;
- TInt nbytes = 0;
- TInt i;
- for (i=0; i<memsz; ++i)
- if (iExportBitMap[i] != 0xff)
- ++nbytes; // number of groups of 8
- TInt exp_extra = mbs + nbytes;
- if (eds != exp_extra)
- return KErrCorrupt;
- const TUint8* mptr = iHdr->iExportDesc;
- const TUint8* gptr = mptr + mbs;
- for (i=0; i<memsz; ++i)
- {
- TUint mbit = mptr[i>>3] & (1u << (i&7));
- if (iExportBitMap[i] != 0xff)
- {
- if (!mbit || *gptr++ != iExportBitMap[i])
- return KErrCorrupt;
- }
- else if (mbit)
- return KErrCorrupt;
- }
- return KErrNone;
- }
-
-
-TInt E32ImageFile::Validate()
- {
- TInt orighdrsz = iOrigHdr->TotalSize();
- TInt r = iHdr->ValidateWholeImage(iData+orighdrsz,iSize-orighdrsz);
- if(r!=KErrNone)
- return r;
- return r;
- }
-
-
-ostream& operator<<(ostream& os, const E32ImageFile& aImage)
-//
-// Output an E32ImageFile
-//
- {
- CBytePair bpe(EFalse);
- E32ImageHeaderV* h = aImage.iHdr;
- TUint hdrfmt = h->HeaderFormat();
- if (hdrfmt != KImageHdrFmt_V)
- return os; // don't generate old binary formats
- TInt hdrsz = h->TotalSize();
- TInt orighdrsz = aImage.iOrigHdr->TotalSize();
-
- os.write((const char*)aImage.iHdr, hdrsz);
-
- TUint compression = h->CompressionType();
- if (compression == KUidCompressionDeflate)
- {
- int srcsize = aImage.iSize - orighdrsz;
- DeflateCompress(aImage.iData + orighdrsz, srcsize, os);
- }
- else if (compression == KUidCompressionBytePair)
- {
- // Compress and write out code part
- int srcStart = orighdrsz;
- CompressPages( (TUint8*)aImage.iData + srcStart, aImage.iOrigHdr->iCodeSize, os, &bpe);
-
-
- // Compress and write out data part
- srcStart += aImage.iOrigHdr->iCodeSize;
- int srcLen = aImage.iSize - srcStart;
- //Print(EWarning," Data part start:0x%08x, len:%d (0x%08x)\n", srcStart, aImage.iOrigHdr->iDataSize, aImage.iOrigHdr->iDataSize);
- //CompressPages((TUint8*)aImage.iData + srcStart, aImage.iOrigHdr->iDataSize, os);
-
- CompressPages((TUint8*)aImage.iData + srcStart, srcLen, os, &bpe);
-
- }
- else if (compression == KFormatNotCompressed)
- {
- int srcsize = aImage.iSize - orighdrsz;
- os.write(aImage.iData + orighdrsz, srcsize); // image not to be compressed
- }
- return os;
- }
-
-ifstream& operator>>(ifstream& is, E32ImageFile& aImage)
-//
-// Input an E32ImageFile
-//
- {
- CBytePair bpe(EFalse);
- aImage.iError = aImage.ReadHeader(is);
- if (aImage.iError != KErrNone)
- return is;
- E32ImageHeader* oh = aImage.iOrigHdr;
- TInt orighdrsz = oh->TotalSize();
- int remainder = aImage.iSize - orighdrsz;
- TUint compression = oh->CompressionType();
- if (compression == 0)
- {
- is.read(aImage.iData + orighdrsz, remainder);
- }
- else if (compression == KUidCompressionDeflate)
- { //Uncompress
- aImage.iError = KErrNoMemory;
- unsigned int uncompsize = ((E32ImageHeaderComp*)aImage.iOrigHdr)->iUncompressedSize;
- aImage.Adjust(uncompsize + orighdrsz);
- if (aImage.iData==NULL)
- return is;
- oh = aImage.iOrigHdr;
- unsigned char* compressedData = new unsigned char[remainder];
- if (compressedData==NULL)
- return is;
- is.read(reinterpret_cast<char *>(compressedData), remainder);
- unsigned int destsize = uncompsize;
- InflateUnCompress( compressedData, remainder, (unsigned char*)(aImage.iData + orighdrsz), destsize);
- if (destsize != uncompsize)
- Print(EWarning, "Inconsistent sizes discovered during uncompression.\n");
- delete [] compressedData;
- if ((TUint)orighdrsz > oh->iCodeOffset)
- {
- // need to adjust code offsets in original
- aImage.iOrigHdrOffsetAdj = (TUint)orighdrsz - oh->iCodeOffset;
- aImage.OffsetAdjust(oh->iCodeOffset);
- aImage.OffsetAdjust(oh->iDataOffset);
- aImage.OffsetAdjust(oh->iCodeRelocOffset);
- aImage.OffsetAdjust(oh->iDataRelocOffset);
- aImage.OffsetAdjust(oh->iImportOffset);
- aImage.OffsetAdjust(oh->iExportDirOffset);
- }
- aImage.iError = KErrNone;
- }
- else if(compression == KUidCompressionBytePair)
- { // Uncompress
- aImage.iError = KErrNoMemory;
- unsigned int uncompsize = ((E32ImageHeaderComp*)aImage.iOrigHdr)->iUncompressedSize;
- aImage.Adjust(uncompsize + orighdrsz);
- if (aImage.iData==NULL)
- return is;
- oh = aImage.iOrigHdr;
-
- // Read and decompress code part of the image
-
- unsigned int uncompressedCodeSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz), is, &bpe);
-
-
- // Read and decompress data part of the image
-
- unsigned int uncompressedDataSize = DecompressPages((TUint8 *) (aImage.iData + orighdrsz + uncompressedCodeSize), is, &bpe);
-
- if (uncompressedCodeSize + uncompressedDataSize != uncompsize)
- Print(EWarning, "Inconsistent sizes discovered during uncompression.\n");
-
- if ((TUint)orighdrsz > oh->iCodeOffset)
- {
- // need to adjust code offsets in original
- aImage.iOrigHdrOffsetAdj = (TUint)orighdrsz - oh->iCodeOffset;
- aImage.OffsetAdjust(oh->iCodeOffset);
- aImage.OffsetAdjust(oh->iDataOffset);
- aImage.OffsetAdjust(oh->iCodeRelocOffset);
- aImage.OffsetAdjust(oh->iDataRelocOffset);
- aImage.OffsetAdjust(oh->iImportOffset);
- aImage.OffsetAdjust(oh->iExportDirOffset);
- }
- aImage.iError = KErrNone;
- }
- aImage.CreateExportBitMap();
- return is;
- }
-
-TInt E32ImageFile::IsE32ImageFile(char *aFileName)
- {
-
-#ifdef __LINUX__
- E32ImageFile f;
- struct stat buf;
- if (stat(aFileName, &buf) < 0)
- {
- return FALSE;
- }
- f.iFileSize = buf.st_size;
-#else
- _finddata_t fileinfo;
- int ret=_findfirst((char *)aFileName,&fileinfo);
- if (ret==-1)
- return FALSE;
- E32ImageFile f;
- f.iFileSize = fileinfo.size;
-#endif
- ifstream ifile(aFileName, ios::in | ios::binary);
- if(!ifile.is_open())
- return FALSE;
- TInt r = f.ReadHeader(ifile);
- ifile.close();
- return (r == KErrNone);
- }
-
-TInt E32ImageFile::IsValid()
- {
- return (iError == KErrNone);
- }
-
-TInt E32ImageFile::Open(const char* aFileName)
-//
-// Open an E32 Image file
-//
- {
-#ifdef __LINUX__
- struct stat buf;
- if (stat(aFileName, &buf) < 0)
- {
- Print(EError,"Cannot open %s for input.\n",aFileName);
- return 1;
- }
- iFileSize = buf.st_size;
-#else
- _finddata_t fileinfo;
- int ret=_findfirst((char *)aFileName,&fileinfo);
- if (ret==-1)
- {
- Print(EError,"Cannot open %s for input.\n",aFileName);
- return 1;
- }
- iFileSize = fileinfo.size;
-#endif
- Adjust(iFileSize);
- ifstream ifile((char *)aFileName, ios::in | ios::binary);
- if(!ifile.is_open())
- {
- Print(EError,"Cannot open %s for input.\n",aFileName);
- return 1;
- }
- ifile >> *this;
- ifile.close();
- if (iError != KErrNone)
- return iError;
- iFileName=strdup((char *)aFileName);
- if (iFileName==NULL)
- return KErrNoMemory;
- return KErrNone;
- }
-
-#ifndef __LINUX__
-TInt E32ImageFile::Open(const wchar_t* aFileName)
-//
-// Open an E32 Image file
-//
- {
- _wfinddata_t fileinfo;
- int ret=_wfindfirst(aFileName,&fileinfo);
- if (ret==-1)
- {
- Print(EError,"Cannot open %ls for input.\n",aFileName);
- return 1;
- }
- iFileSize = fileinfo.size;
- Adjust(iFileSize);
-
- FILE* file = _wfopen(aFileName, L"rb");
-
- if(!file)
- {
- Print(EError,"Cannot open %ls for input.\n",aFileName);
- return 1;
- }
-
- #ifdef __TOOLS2__
- char *tmp; // Convert wide character name to char *, then open a file.
- wcstombs(tmp,aFileName,100);
- ifstream ifile(tmp, ios::in | ios::binary);
- #else
- ifstream ifile(fileno(file));
- #endif
-
- if(!ifile.is_open())
- {
- Print(EError,"Cannot open %ls for input,\n",aFileName);
- return 1;
- }
-
- ifile >> *this;
- ifile.close();
- fclose(file);
- if (iError != KErrNone)
- return iError;
- iWideFileName=wcsdup(aFileName);
- if (iWideFileName==NULL)
- return KErrNoMemory;
- return KErrNone;
- }
-#endif
-
-TUint E32ImageFile::VaOfOrdinal(TUint aOrdinal)
-// return the offset of the exported symbol
- {
- TUint* exportdir = (TUint*)(iData + iOrigHdr->iExportDirOffset);
- return exportdir[aOrdinal-KOrdinalBase];
- }
-
-// Determine the type of entry point in this module and set the flags
-// in the E32Image header accordingly.
-TInt E32ImageFile::DetermineEntryPointType()
- {
- TUint cpu = iHdr->CpuIdentifier();
- if (cpu != ECpuArmV4 && cpu != ECpuArmV5)
- return KErrNone; // if not ARM, leave EPT as 0
- TUint epOffset = iHdr->iEntryPoint;
- if (epOffset & 3)
- return KErrNone; // if entry point not 4 byte aligned, must be old style
- TUint fileOffset = epOffset + iHdr->iCodeOffset;
- if (fileOffset+4 > (TUint)iSize)
- return KErrCorrupt; // entry point is past the end of the file??
- TInt ept = 0; // old style if first instruction not recognised
- unsigned char* p = (unsigned char*)iData + fileOffset + 4;
- TUint32 x = *--p;
- x<<=8;
- x|=*--p;
- x<<=8;
- x|=*--p;
- x<<=8;
- x|=*--p;
- if ((x & 0xffffff00) == 0xe31f0000)
- {
- // starts with tst pc, #n - new entry point
- ept = (x & 0xff) + 1;
- }
- if (ept>7)
- return KErrNotSupported;
- iHdr->iFlags |= (ept<<KImageEptShift);
- return KErrNone;
- }
-
--- a/e32tools/e32lib/e32image/imgdump.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,512 +0,0 @@
-// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools/e32image/imgdump.cpp
-//
-//
-
-#define __REFERENCE_CAPABILITY_NAMES__
-
-#include <e32image.h>
-#include <h_utl.h>
-#include <string.h>
-
-void PriorityToStr(TProcessPriority aPri, char *aStr)
- {
-
- if (aPri==EPrioritySupervisor)
- strcpy(aStr,"Supervisor");
-
- else if (aPri>EPriorityRealTimeServer)
- sprintf(aStr, "RealTime+%d", aPri-EPriorityRealTimeServer);
- else if (aPri==EPriorityRealTimeServer)
- strcpy(aStr,"RealTime");
-
- else if (aPri>EPriorityFileServer)
- sprintf(aStr, "FileServer+%d", aPri-EPriorityFileServer);
- else if (aPri==EPriorityFileServer)
- strcpy(aStr,"FileServer");
-
- else if (aPri>EPriorityWindowServer)
- sprintf(aStr, "WindowServer+%d", aPri-EPriorityWindowServer);
- else if (aPri==EPriorityWindowServer)
- strcpy(aStr,"WindowServer");
-
- else if (aPri>EPriorityHigh)
- sprintf(aStr, "High+%d", aPri-EPriorityHigh);
- else if (aPri==EPriorityHigh)
- strcpy(aStr,"High");
-
- else if (aPri>EPriorityForeground)
- sprintf(aStr, "Foreground+%d", aPri-EPriorityForeground);
- else if (aPri==EPriorityForeground)
- strcpy(aStr,"Foreground");
-
- else if (aPri>EPriorityBackground)
- sprintf(aStr, "Background+%d", aPri-EPriorityBackground);
- else if (aPri==EPriorityBackground)
- strcpy(aStr,"Background");
-
- else if (aPri>EPriorityLow)
- sprintf(aStr, "Low+%d", aPri-EPriorityLow);
- else if (aPri==EPriorityLow)
- strcpy(aStr,"Low");
-
- else
- sprintf(aStr, "Illegal (%d)", aPri);
- }
-
-void nl()
- {
- Print(EAlways, "\n");
- }
-
-void E32ImageFile::Dump(TText *aFileName,TInt aDumpFlags)
- {
- if (IsValid())
- {
- Print(EAlways, "E32ImageFile '%s'\n", aFileName);
- DumpHeader(aDumpFlags);
- DumpData(aDumpFlags);
- }
- else
- Print(EAlways, "This is not an E32 image file (error %d).\n", iError);
- }
-
-void E32ImageFile::DumpHeader(TInt aDumpFlags)
- {
- TUint flags = iOrigHdr->iFlags;
- TUint abi = E32ImageHeader::ABIFromFlags(flags);
- TUint hdrfmt = E32ImageHeader::HdrFmtFromFlags(flags);
- TUint impfmt = E32ImageHeader::ImpFmtFromFlags(flags);
- TUint ept = E32ImageHeader::EptFromFlags(flags);
- TBool isARM = EFalse;
-
- if(aDumpFlags&EDumpHeader)
- {
- Print(EAlways, "V%d.%02d(%03d)", iOrigHdr->iToolsVersion.iMajor,iOrigHdr->iToolsVersion.iMinor,iOrigHdr->iToolsVersion.iBuild);
- Print(EAlways, "\tTime Stamp: %08x,%08x\n", iOrigHdr->iTimeHi, iOrigHdr->iTimeLo);
- char sig[5];
- memcpy(sig, (const char*)&iOrigHdr->iSignature, 4);
- sig[4]=0;
- Print(EAlways, sig);
- if (iOrigHdr->iFlags&KImageDll)
- Print(EAlways, " Dll for ");
- else
- Print(EAlways, " Exe for ");
- switch (iOrigHdr->CpuIdentifier())
- {
- case ECpuX86:
- Print(EAlways, "X86 CPU\n");
- break;
- case ECpuArmV4:
- isARM = ETrue;
- Print(EAlways, "ARMV4 CPU\n");
- break;
- case ECpuArmV5:
- isARM = ETrue;
- Print(EAlways, "ARMV5 CPU\n");
- break;
- case ECpuMCore:
- Print(EAlways, "M*Core CPU\n");
- break;
- case ECpuUnknown:
- Print(EAlways, "Unknown CPU\n");
- break;
- default:
- Print(EAlways, "something or other\n");
- break;
- }
-
- Print(EAlways, "Flags:\t%08x\n", flags);
-
- if (!(flags & KImageDll))
- {
- char str[80];
- PriorityToStr(iOrigHdr->ProcessPriority(), str);
- Print(EAlways, "Priority %s\n", str);
- if (flags & KImageFixedAddressExe)
- Print(EAlways, "Fixed process\n");
- }
- if (flags & KImageNoCallEntryPoint)
- Print(EAlways, "Entry points are not called\n");
- Print(EAlways, "Image header is format %d\n", hdrfmt>>24);
- TUint compression = iOrigHdr->CompressionType();
- switch (compression)
- {
- case KFormatNotCompressed:
- Print(EAlways, "Image is not compressed\n");
- break;
- case KUidCompressionDeflate:
- Print(EAlways, "Image is compressed using the DEFLATE algorithm\n");
- break;
- case KUidCompressionBytePair:
- Print(EAlways, "Image is compressed using the BYTEPAIR algorithm\n");
- break;
- default:
- Print(EAlways, "Image compression type UNKNOWN (%08x)\n", compression);
- }
- if (compression)
- {
- Print(EAlways, "Uncompressed size %08x\n", iOrigHdr->UncompressedFileSize());
- }
-
- TUint FPU = flags & KImageHWFloatMask;
-
- if (FPU == KImageHWFloat_None)
- Print(EAlways, "Image FPU support : Soft VFP\n");
- else if (FPU == KImageHWFloat_VFPv2)
- Print(EAlways, "Image FPU support : VFPv2\n");
- else
- Print(EAlways, "Image FPU support : Unknown\n");
-
- if (flags & KImageCodeUnpaged)
- {
- Print(EAlways, "Code Paging : Unpaged\n");
- }
- else if (flags & KImageCodePaged)
- {
- Print(EAlways, "Code Paging : Paged\n");
- }
- else
- {
- Print(EAlways, "Code Paging : Default\n");
- }
-
- if (flags & KImageDataUnpaged)
- {
- Print(EAlways, "Data Paging : Unpaged\n");
- }
- else if (flags & KImageDataPaged)
- {
- Print(EAlways, "Data Paging : Paged\n");
- }
- else
- {
- Print(EAlways, "Data Paging : Default\n");
- }
-
- if(flags & KImageDebuggable)
- {
- Print(EAlways, "Debuggable : True\n");
- }
- else
- {
- Print(EAlways, "Debuggable : False\n");
- }
-
- if(flags & KImageSMPSafe)
- {
- Print(EAlways, "SMP Safe : True\n");
- }
- else
- {
- Print(EAlways, "SMP Safe : False\n");
- }
- }
-
- if (hdrfmt >= KImageHdrFmt_V && (aDumpFlags&(EDumpHeader|EDumpSecurityInfo)))
- {
- //
- // Important. Don't change output format of following security info
- // because this is relied on by used by "Symbian Signed".
- //
- E32ImageHeaderV* v = iHdr;
- Print(EAlways, "Secure ID: %08x\n", v->iS.iSecureId);
- Print(EAlways, "Vendor ID: %08x\n", v->iS.iVendorId);
- Print(EAlways, "Capabilities: %08x %08x\n", v->iS.iCaps[1], v->iS.iCaps[0]);
- if(aDumpFlags&EDumpSecurityInfo)
- {
- TInt i;
- for(i=0; i<ECapability_Limit; i++)
- if(v->iS.iCaps[i>>5]&(1<<(i&31)))
- Print(EAlways, " %s\n", CapabilityNames[i]);
- Print(EAlways, "\n");
- }
- }
-
- if(aDumpFlags&EDumpHeader)
- {
- if (hdrfmt >= KImageHdrFmt_V)
- {
- E32ImageHeaderV* v = iHdr;
- TUint32 xd = v->iExceptionDescriptor;
- if ((xd & 1) && (xd != 0xffffffffu))
- {
- xd &= ~1;
- Print(EAlways, "Exception Descriptor Offset: %08x\n", v->iExceptionDescriptor);
- TExceptionDescriptor * aED = (TExceptionDescriptor * )(iData + v->iCodeOffset + xd);
- Print(EAlways, "Exception Index Table Base: %08x\n", aED->iExIdxBase);
- Print(EAlways, "Exception Index Table Limit: %08x\n", aED->iExIdxLimit);
- Print(EAlways, "RO Segment Base: %08x\n", aED->iROSegmentBase);
- Print(EAlways, "RO Segment Limit: %08x\n", aED->iROSegmentLimit);
- }
- else
- Print(EAlways, "No Exception Descriptor\n");
-
- Print(EAlways, "Export Description: Size=%03x, Type=%02x\n", v->iExportDescSize, v->iExportDescType);
- if (v->iExportDescType != KImageHdr_ExpD_NoHoles)
- {
- TInt nb = v->iExportDescSize;
- TInt i;
- TInt j = 0;
- for (i=0; i<nb; ++i)
- {
- if (++j == 8)
- {
- j = 0;
- Print(EAlways,"\n");
- }
- Print(EAlways," %02x", v->iExportDesc[i]);
- }
- Print(EAlways,"\n");
- }
- TInt r = CheckExportDescription();
- if (r == KErrNone)
- Print(EAlways,"Export description consistent\n");
- else if (r == KErrNotSupported)
- Print(EAlways,"Export description type not recognised\n");
- else
- Print(EAlways,"!! Export description inconsistent !!\n");
- }
-
- TUint32 mv = iOrigHdr->ModuleVersion();
- Print(EAlways, "Module Version: %d.%d\n", mv>>16, mv&0xffff);
- if (impfmt == KImageImpFmt_PE)
- {
- Print(EAlways, "Imports are PE-style\n");
- }
- else if (impfmt == KImageImpFmt_ELF)
- {
- Print(EAlways, "Imports are ELF-style\n");
- }
- else if (impfmt == KImageImpFmt_PE2)
- {
- Print(EAlways, "Imports are PE-style without redundant ordinal lists\n");
- }
- if (isARM)
- {
- if (abi == KImageABI_GCC98r2)
- {
- Print(EAlways, "GCC98r2 ABI\n");
- }
- else if (abi == KImageABI_EABI)
- {
- Print(EAlways, "ARM EABI\n");
- }
- if (ept == KImageEpt_Eka1)
- {
- Print(EAlways, "Built against EKA1\n");
- }
- else if (ept == KImageEpt_Eka2)
- {
- Print(EAlways, "Built against EKA2\n");
- }
- }
-
- Print(EAlways, "Uids:\t\t%08x %08x %08x (%08x)\n", iOrigHdr->iUid1, iOrigHdr->iUid2, iOrigHdr->iUid3, iOrigHdr->iUidChecksum);
- if (hdrfmt >= KImageHdrFmt_V)
- Print(EAlways, "Header CRC:\t%08x\n", iHdr->iHeaderCrc);
- Print(EAlways, "File Size:\t%08x\n", iSize);
- Print(EAlways, "Code Size:\t%08x\n", iOrigHdr->iCodeSize);
- Print(EAlways, "Data Size:\t%08x\n", iOrigHdr->iDataSize);
- Print(EAlways, "Compression:\t%08x\n", iOrigHdr->iCompressionType);
- Print(EAlways, "Min Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMin);
- Print(EAlways, "Max Heap Size:\t%08x\n", iOrigHdr->iHeapSizeMax);
- Print(EAlways, "Stack Size:\t%08x\n", iOrigHdr->iStackSize);
- Print(EAlways, "Code link addr:\t%08x\n", iOrigHdr->iCodeBase);
- Print(EAlways, "Data link addr:\t%08x\n", iOrigHdr->iDataBase);
- Print(EAlways, "Code reloc offset:\t%08x\n", OrigCodeRelocOffset());
- Print(EAlways, "Data reloc offset:\t%08x\n", OrigDataRelocOffset());
- Print(EAlways, "Dll ref table count: %d\n", iOrigHdr->iDllRefTableCount);
-
- if (iOrigHdr->iCodeSize || iOrigHdr->iDataSize || iOrigHdr->iBssSize || iOrigHdr->iImportOffset)
- Print(EAlways, " Offset Size Relocs #Relocs\n");
-
- Print(EAlways, "Code %06x %06x", OrigCodeOffset(), iOrigHdr->iCodeSize);
- if (iOrigHdr->iCodeRelocOffset)
- {
- E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iCodeRelocOffset);
- Print(EAlways, " %06x %06x", OrigCodeRelocOffset(), r->iNumberOfRelocs);
- }
- else
- Print(EAlways, " ");
- Print(EAlways, " +%06x (entry pnt)", iOrigHdr->iEntryPoint);
- nl();
-
- Print(EAlways, "Data %06x %06x", OrigDataOffset(), iOrigHdr->iDataSize);
- if (iOrigHdr->iDataRelocOffset)
- {
- E32RelocSection *r=(E32RelocSection *)(iData + iOrigHdr->iDataRelocOffset);
- Print(EAlways, " %06x %06x", OrigDataRelocOffset(), r->iNumberOfRelocs);
- }
- nl();
-
- Print(EAlways, "Bss %06x\n", iOrigHdr->iBssSize);
-
- if (iOrigHdr->iExportDirOffset)
- Print(EAlways, "Export %06x %06x (%d entries)\n", OrigExportDirOffset(), iOrigHdr->iExportDirCount*4, iOrigHdr->iExportDirCount);
- if (iOrigHdr->iImportOffset)
- Print(EAlways, "Import %06x\n", OrigImportOffset());
- }
- }
-
-void dump(TUint *aData, TInt aLength)
- {
- TUint *p=aData;
- TInt i=0;
- char line[256];
- char *cp=(char*)aData;
- TInt j=0;
- memset(line,' ',sizeof(line));
- while (i<aLength)
- {
- TInt ccount=0;
- char* linep=&line[8*9+2];
- Print(EAlways, "%06x:", i);
- while (i<aLength && ccount<8)
- {
- Print(EAlways," %08x", *p++);
- i+=4;
- ccount++;
- for (j=0; j<4; j++)
- {
- unsigned char c=*cp++;
- if (c<32 || c>127)
- {
- c = '.';
- }
- *linep++ = c;
- }
- }
- *linep='\0';
- Print(EAlways, "%s", line+(ccount*9));
- nl();
- }
- }
-
-void dumprelocs(char *aRelocs)
- {
-
- TInt num=((E32RelocSection *)aRelocs)->iNumberOfRelocs;
- Print(EAlways, "%d relocs\n", num);
- aRelocs+=sizeof(E32RelocSection);
- TInt printed=0;
- while (num>0)
- {
- TInt page=*(TUint *)aRelocs;
- TInt size=*(TUint *)(aRelocs+4);
- TInt pagesize=size;
- size-=8;
- TUint16 *p=(TUint16 *)(aRelocs+8);
- while (size>0)
- {
- TUint a=*p++;
- TUint relocType = a >> 12;
- if (relocType==3 || relocType==1)
- {
- Print(EAlways, "%08x(%1x) ", page+(a&0x0fff), relocType);
- printed++;
- if (printed>3)
- {
- nl();
- printed=0;
- }
- }
- size-=2;
- num--;
- }
- aRelocs+=pagesize;
- }
- nl();
- }
-
-
-void E32ImageFile::DumpData(TInt aDumpFlags)
- {
- if(aDumpFlags&EDumpCode)
- {
- Print(EAlways, "\nCode (text size=%08x)\n", iOrigHdr->iTextSize);
- dump((TUint *)(iData + iOrigHdr->iCodeOffset), iOrigHdr->iCodeSize);
- if (iOrigHdr->iCodeRelocOffset)
- dumprelocs(iData + iOrigHdr->iCodeRelocOffset);
- }
-
- if((aDumpFlags&EDumpData) && iOrigHdr->iDataOffset)
- {
- Print(EAlways, "\nData\n");
- dump((TUint *)(iData + iOrigHdr->iDataOffset), iOrigHdr->iDataSize);
- if (iOrigHdr->iDataRelocOffset)
- dumprelocs(iData + iOrigHdr->iDataRelocOffset);
- }
-
- if(aDumpFlags&EDumpExports)
- {
- Print(EAlways, "\nNumber of exports = %d\n", iOrigHdr->iExportDirCount);
- TInt i;
- TUint* exports = (TUint*)(iData + iOrigHdr->iExportDirOffset);
- TUint absoluteEntryPoint = iOrigHdr->iEntryPoint + iOrigHdr->iCodeBase;
- TUint impfmt = iOrigHdr->ImportFormat();
- TUint absentVal = (impfmt == KImageImpFmt_ELF) ? absoluteEntryPoint : iOrigHdr->iEntryPoint;
- for (i=0; i<iOrigHdr->iExportDirCount; ++i)
- {
- TUint exp = exports[i];
- if (exp == absentVal)
- Print(EAlways, "\tOrdinal %5d:\tABSENT\n", i+1);
- else
- Print(EAlways, "\tOrdinal %5d:\t%08x\n", i+1, exp);
- }
- }
-
- //
- // Important. Don't change output format of following inport info
- // because this is relied on by tools used by "Symbian Signed".
- //
- if((aDumpFlags&EDumpImports) && iOrigHdr->iImportOffset)
- {
- const E32ImportSection* isection = (const E32ImportSection*)(iData + iOrigHdr->iImportOffset);
- TUint* iat = (TUint*)((TUint8*)iData + iOrigHdr->iCodeOffset + iOrigHdr->iTextSize);
- Print(EAlways, "\nIdata\tSize=%08x\n", isection->iSize);
- Print(EAlways, "Offset of import address table (relative to code section): %08x\n", iOrigHdr->iTextSize);
- TInt d;
- const E32ImportBlock* b = (const E32ImportBlock*)(isection + 1);
- for (d=0; d<iOrigHdr->iDllRefTableCount; d++)
- {
- char* dllname = iData + iOrigHdr->iImportOffset + b->iOffsetOfDllName;
- TInt n = b->iNumberOfImports;
- Print(EAlways, "%d imports from %s\n", b->iNumberOfImports, dllname);
- const TUint* p = b->Imports();
- TUint impfmt = iOrigHdr->ImportFormat();
- if (impfmt == KImageImpFmt_ELF)
- {
- while (n--)
- {
- TUint impd_offset = *p++;
- TUint impd = *(TUint*)(iData + iOrigHdr->iCodeOffset + impd_offset);
- TUint ordinal = impd & 0xffff;
- TUint offset = impd >> 16;
- if (offset)
- Print(EAlways, "%10d offset by %d\n", ordinal, offset);
- else
- Print(EAlways, "%10d\n", ordinal);
- }
- }
- else
- {
- while (n--)
- Print(EAlways, "\t%d\n", *iat++);
- }
- b = b->NextBlock(impfmt);
- }
- }
- }
--- a/e32tools/e32lib/e32image/inc/e32image.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#ifndef __E32IMAGE_H__
-#define __E32IMAGE_H__
-
-#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
-#include <fstream>
-using namespace std;
-#else //!__MSVCDOTNET__
-#include <fstream.h>
-#endif //__MSVCDOTNET__
-
-#include <e32std.h>
-#include <e32ldr.h>
-#include <f32image.h>
-
-enum TFileSource
- {
- EE32Image=0,
- EPeFile=1,
- EElfFile=2,
- };
-
-class E32ImageFile
- {
-public:
- static E32ImageFile* New();
- E32ImageFile();
- virtual ~E32ImageFile();
- virtual TBool Translate(const char* aFileName, TUint aDataBase, TBool aAllowDllData, TBool aSymLkupEnabled = FALSE);
- TInt ReadHeader(ifstream& is);
- TInt Open(const char* aFileName);
-#ifndef __LINUX__
- TInt Open(const wchar_t* aFileName);
-#endif
- void Adjust(TInt aSize, TBool aAllowShrink=ETrue);
- TUint VaOfOrdinal(TUint aOrdinal);
- void RelocateSection(char* aPtr, char *aRelocs, TUint aCodeDelta, TUint aDataDelta, char* aImagePtr, TLinAddr** aIATRefs, TBool keepIAT=EFalse);
- //
- TUint TextOffset();
- TUint DataOffset();
- TUint BssOffset();
- TUint32 Capability();
- TUint32 Format();
- TInt NumberOfImports();
-
- TInt IsValid();
- TInt IsDll();
- enum TDumpFlags
- {
- EDumpHeader = 1<<0,
- EDumpSecurityInfo = 1<<1,
- EDumpCode = 1<<2,
- EDumpData = 1<<3,
- EDumpExports = 1<<4,
- EDumpImports = 1<<5,
- EDumpDefaults = EDumpHeader|EDumpCode|EDumpData|EDumpExports|EDumpImports
- };
- void Dump(TText *aFileName,TInt aDumpFlags);
- void DumpHeader(TInt aDumpFlags);
- void DumpData(TInt aDumpFlags);
- void SetStackSize(TInt aSize);
- void SetHeapSizeMin(TInt aSize);
- void SetHeapSizeMax(TInt aSize);
- void SetUids(TUid aUid1, TUid aUid2, TUid aUid3);
- void SetSecureId(TUint32 aId);
- void SetVendorId(TUint32 aId);
- void SetCallEntryPoints(TInt aBool);
- void SetFixedAddress(TInt aBool);
- void SetPriority(TProcessPriority aPri);
- void SetCapability(SCapabilitySet& aCapabilities);
- void SetFPU(unsigned int aFPU);
- static TInt IsE32ImageFile(char *aFileName);
- TInt DetermineEntryPointType();
- void UpdateHeaderCrc();
- void SetDefaultHeader();
- void CreateExportBitMap();
- void AddExportDescription();
- TInt CheckExportDescription();
- TInt Validate();
-public:
- inline TUint OrigCodeOffset() const {return OffsetUnadjust(iOrigHdr->iCodeOffset);}
- inline TUint OrigDataOffset() const {return OffsetUnadjust(iOrigHdr->iDataOffset);}
- inline TUint OrigCodeRelocOffset() const {return OffsetUnadjust(iOrigHdr->iCodeRelocOffset);}
- inline TUint OrigDataRelocOffset() const {return OffsetUnadjust(iOrigHdr->iDataRelocOffset);}
- inline TUint OrigImportOffset() const {return OffsetUnadjust(iOrigHdr->iImportOffset);}
- inline TUint OrigExportDirOffset() const {return OffsetUnadjust(iOrigHdr->iExportDirOffset);}
- inline TUint OffsetUnadjust(TUint a) const {return a ? a-iOrigHdrOffsetAdj : 0;}
- inline void OffsetAdjust(TUint& a) { if (a) a+=iOrigHdrOffsetAdj; }
-public:
- char* iData;
- TInt iSize;
- E32ImageHeader* iOrigHdr;
- E32ImageHeaderV* iHdr;
- char* iFileName;
-#ifndef __LINUX__
- wchar_t* iWideFileName;
-#endif
- TInt iError;
- TFileSource iSource;
- TUint iOrigHdrOffsetAdj;
- TInt iFileSize;
- TUint8* iExportBitMap;
- TInt iMissingExports;
- };
-
-#ifdef __VC32__
-ostream &operator<<(ostream &os, const E32ImageFile &aImage);
-#else
-ostream &operator<<(ostream &os, const E32ImageFile &aImage);
-#endif
-ifstream &operator>>(ifstream &is, E32ImageFile &aImage);
-
-#endif
--- a/e32tools/e32lib/e32image/inc/h_utl.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,216 +0,0 @@
-// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#if !defined(__H_UTL_H__)
-#define __H_UTL_H__
-//
-#include <stdio.h>
-
-#ifdef __VC32__
- #ifdef __MSVCDOTNET__
- #include <iostream>
- #include <strstream>
- #include <fstream>
- using namespace std;
- #else //!__MSVCDOTNET__
- #include <iostream.h>
- #include <strstrea.h>
- #include <fstream.h>
- #endif //__MSVCDOTNET__
-#else //!__VC32__
-#ifdef __TOOLS2__
-#include <fstream>
-#include <iostream>
-#include <sstream>
-#include <iomanip>
-using namespace std;
-#else // !__TOOLS2__ OR __VC32__ OR __MSVCDOTNET__
- #include <iostream.h>
- #include <strstream.h>
- #include <fstream.h>
-#endif
-#endif
-
-#ifdef __LINUX__
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <ctype.h>
-
-
-#define _close close
-#define _filelength filelength
-#define _lseek lseek
-#define _read read
-#define _snprintf snprintf
-#define _vsnprintf vsnprintf
-
-// linux case insensitive stromg comparisons have different names
-#define stricmp strcasecmp
-#define _stricmp strcasecmp
-#define strnicmp strncasecmp
-
-// to fix the linux problem: memcpy does not work with overlapped areas.
-#define memcpy memmove
-
-// hand-rolled strupr function for converting a string to all uppercase
-char* strupr(char *a);
-
-// return the length of a file
-off_t filelength (int filedes);
-#endif
-
-
-#include <e32cmn.h>
-#include <e32def.h>
-#include <e32def_private.h>
-
-#define ALIGN4K(a) ((a+0xfff)&0xfffff000)
-#define ALIGN4(a) ((a+0x3)&0xfffffffc)
-
-
-#ifdef HEAPCHK
-#define NOIMAGE
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-void HeapCheck();
-#endif
-#define Print H.PrintString
-//
-const TInt KMaxStringLength=0x400;
-//
-class HFile
- {
-public:
- static TBool Open(const TText * const aFileName, TInt32 * const aFileHandle);
- static TBool Read(const TInt32 aFileHandle, TAny * const aBuffer, const TUint32 aCount);
- static TBool Seek(const TInt32 aFileHandle, const TUint32 aOffset);
- static TUint32 GetPos(const TInt32 aFileHandle);
- static TAny Close(const TInt32 aFileHandle);
- static TUint32 GetLength(const TInt32 aFileHandle);
- static TUint32 GetLength(TText *aName);
- static TUint32 Read(TText *aName, TAny *someMem);
- };
-//
-//inline TAny* operator new(TUint /*aSize*/, TAny* aBase)
-// {return aBase;}
-
-class HMem
- {
-public:
- static TAny *Alloc(TAny * const aBaseAddress,const TUint32 aImageSize);
- static void Free(TAny * const aMem);
- static void Copy(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength);
- static void Move(TAny * const aDestAddr,const TAny * const aSourceAddr,const TUint32 aLength);
- static void Set(TAny * const aDestAddr, const TUint8 aFillChar, const TUint32 aLength);
- static void FillZ(TAny * const aDestAddr, const TUint32 aLength);
-
- static TUint CheckSum(TUint *aPtr, TInt aSize);
- static TUint CheckSum8(TUint8 *aPtr, TInt aSize);
- static TUint CheckSumOdd8(TUint8 *aPtr, TInt aSize);
- static TUint CheckSumEven8(TUint8 *aPtr, TInt aSize);
-
- static void Crc32(TUint32& aCrc, const TAny* aPtr, TInt aLength);
- };
-//
-enum TPrintType {EAlways, EScreen, ELog, EWarning, EError, EPeError, ESevereError, EDiagnostic};
-//
-class HPrint
- {
-public:
- ~HPrint();
- void SetLogFile(TText *aFileName);
- void CloseLogFile(); // Added to close intermediate log files.
- TInt PrintString(TPrintType aType,const char *aFmt,...);
-public:
- TText iText[KMaxStringLength];
- TBool iVerbose;
-private:
- ofstream iLogFile;
- };
-//
-extern HPrint H;
-extern TBool PVerbose;
-//
-TAny *operator new(TUint aSize);
-void operator delete(TAny *aPtr);
-//
-#ifdef __TOOLS2__
-istringstream &operator>>(istringstream &is, TVersion &aVersion);
-#else
-istrstream &operator>>(istrstream &is, TVersion &aVersion);
-#endif
-//
-TInt StringToTime(TInt64 &aTime, char *aString);
-
-void ByteSwap(TUint &aVal);
-void ByteSwap(TUint16 &aVal);
-void ByteSwap(TUint *aPtr, TInt aSize);
-
-extern TBool gLittleEndian;
-
-
-/**
- Convert string to number.
-*/
-template <class T>
-TInt Val(T& aVal, char* aStr)
- {
-
- T x;
- #ifdef __TOOLS2__
- istringstream val(aStr);
- #else
- istrstream val(aStr,strlen(aStr));
- #endif
- #if defined(__MSVCDOTNET__) || defined (__TOOLS2__)
- val >> setbase(0);
- #endif //__MSVCDOTNET__
- val >> x;
- if (!val.eof() || val.fail())
- return KErrGeneral;
- aVal=x;
- return KErrNone;
- }
-
-// Filename decompose routines
-enum TDecomposeFlag
- {
- EUidPresent=1,
- EVerPresent=2
- };
-
-class TFileNameInfo
- {
-public:
- TFileNameInfo(const char* aFileName, TBool aLookForUid);
-public:
- const char* iFileName;
- TInt iTotalLength;
- TInt iBaseLength;
- TInt iExtPos;
- TUint32 iUid3;
- TUint32 iModuleVersion;
- TUint32 iFlags;
- };
-
-extern char* NormaliseFileName(const char* aName);
-extern char* SplitFileName(const char* aName, TUint32& aUid, TUint32& aModuleVersion, TUint32& aFlags);
-extern char* SplitFileName(const char* aName, TUint32& aModuleVersion, TUint32& aFlags);
-extern TInt ParseCapabilitiesArg(SCapabilitySet& aCapabilities, const char *aText);
-extern TInt ParseBoolArg(TBool& aValue, const char *aText);
-
-#endif
-
--- a/e32tools/e32lib/e32image/inc/h_ver.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,22 +0,0 @@
-// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-//
-
-#ifndef __H_VER_H__
-#define __H_VER_H__
-const TInt MajorVersion=2;
-const TInt MinorVersion=1;
-const TInt Build=600;
-#endif
-
--- a/e32tools/e32lib/e32image/inc/seclib.h Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,41 +0,0 @@
-// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools/inc/seclib.h
-// Get the capabilities of an emulator / e32image.
-// Image security information structure.
-//
-//
-
-/**
- @internalTechnology
- @prototype
-*/
-struct SBinarySecurityInfo
- {
- TUint32 iSecureId;
- TUint32 iVendorId;
- TUint8 iCapabilities[KCapabilitySetMaxSize];
- TBool iE32Image;
- };
-
-/**
- * Extracts security information from an image.
- *
- * @internalTechnology
- * @prototype
- */
-TInt GetSecurityInfo(const char* aFileName, SBinarySecurityInfo& aInfo);
-#ifndef __LINUX__
-TInt GetSecurityInfo(const wchar_t* aFileName, SBinarySecurityInfo& aInfo);
-#endif
--- a/e32tools/e32lib/e32image/tr_main.cpp Thu Nov 04 09:07:09 2010 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,997 +0,0 @@
-// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
-// All rights reserved.
-// This component and the accompanying materials are made available
-// under the terms of "Eclipse Public License v1.0"
-// which accompanies this distribution, and is available
-// at the URL "http://www.eclipse.org/legal/epl-v10.html".
-//
-// Initial Contributors:
-// Nokia Corporation - initial contribution.
-//
-// Contributors:
-//
-// Description:
-// e32tools/e32image/tr_main.cpp
-// Translate X->E32Image top level
-//
-//
-
-#ifndef __LINUX__
- #include <io.h>
-#endif
-#include <string.h>
-
-#ifdef __VC32__
- #ifdef __MSVCDOTNET__
- #include <strstream>
- #include <iomanip>
- #else //!__MSVCDOTNET__
- #include <strstrea.h>
- #include <iomanip.h>
- #endif //__MSVCDOTNET__
-#else // !__VC32__*/
-#ifdef __TOOLS2__
- #include <sstream>
- #include <iomanip>
- #else
- #include <strstream.h>
- #include <iomanip.h>
-#endif // __VC32__
-#endif
-
-#include <e32std.h>
-
-#ifdef __SUPPORT_PE_FILES__
-#include "pe_file.h"
-#endif
-#ifdef __SUPPORT_ELF_FILES__
-#include "elftran.h"
-#endif
-
-#include <h_utl.h>
-#include <h_ver.h>
-#include <stdio.h>
-
-extern int gAlignConstSection;
-extern TUint gConstSectionAddressMask;
-
-int gVerbose=0;
-char *gFile1=NULL;
-char *gFile2=NULL;
-unsigned int gStack=0;
-unsigned int gHeapMin=0;
-unsigned int gHeapMax=0;
-TUid gUid1=KNullUid;
-TUid gUid2=KNullUid;
-TUid gUid3=KNullUid;
-unsigned int gSecureId=0;
-unsigned int gVendorId=0;
-unsigned int gVersionWord=0x00010000u;
-int gCallEntryPoints=TRUE;
-int gFixedAddress=FALSE;
-int gPriority=EPriorityForeground;
-SCapabilitySet gCapability={0};
-int gAllowDllData=FALSE;
-// fix warning for Linux warning: 0 instead of NULL
-TUint gDataBase=0;
-int gCompress=TRUE;
-unsigned int gFPU=0;
-
-int gCodePaged=FALSE;
-int gCodeUnpaged=FALSE;
-int gCodeDefaultPaged=FALSE;
-
-int gDataPaged=FALSE;
-int gDataUnpaged=FALSE;
-int gDataDefaultPaged=FALSE;
-
-int gDebuggable=FALSE;
-int gSmpSafe=FALSE;
-
-int gSetStack=FALSE;
-int gSetHeap=FALSE;
-int gSetUid1=FALSE;
-int gSetUid2=FALSE;
-int gSetUid3=FALSE;
-int gSetCallEntryPoints=FALSE;
-int gSetFixedAddress=FALSE;
-int gSetPriority=FALSE;
-int gSetCapability=FALSE;
-int gSetCompress=FALSE;
-int gSetVersion=FALSE;
-int gSetSecureId=FALSE;
-int gSetVendorId=FALSE;
-int gSetFPU=FALSE;
-
-int gSetCodePaged=FALSE;
-int gSetDataPaged=FALSE;
-
-int gSetSymLkup=FALSE;
-int gSetDebuggable=FALSE;
-int gSetSmpSafe=FALSE;
-
-enum CompressionMethods
-{
- ENoCompression = 0,
- EDeflate = 1,
- EBytePair = 2,
-};
-
-int gCompressionMethod = EDeflate;
-int gSuppressComprMethod = FALSE;
-
-#ifdef __SUPPORT_PE_FILES__
-char* gX86imp=NULL;
-int gX86num_imp_dlls=0;
-int gX86imp_size=0;
-int gX86num_imports=0;
-#endif
-
-TBool gLittleEndian=ETrue;
-
-class E32ImageFileRef
- {
-public:
- E32ImageFileRef() {iPtr = E32ImageFile::New();}
- ~E32ImageFileRef() {delete iPtr;}
- class E32ImageFile& Ref() {return *iPtr;}
-private:
- E32ImageFileRef(const E32ImageFileRef&);
- E32ImageFileRef& operator=(const E32ImageFileRef&);
-private:
- E32ImageFile* iPtr;
- };
-
-int setPagedFlags(E32ImageFile& f)
- {
- unsigned check1 = gCodePaged + gCodeUnpaged + gCodeDefaultPaged;
- unsigned check2 = gDataPaged + gDataUnpaged + gDataDefaultPaged;
-
- if (check1 > 1 || check2 > 1)
- {
- Print(EError, "Conflicting paging options.\n");
- return KErrArgument;
- }
-
- if (gCodePaged)
- {
- f.iHdr->iFlags |= KImageCodePaged;
- f.iHdr->iFlags &= ~KImageCodeUnpaged;
- }
- else if (gCodeUnpaged)
- {
- f.iHdr->iFlags |= KImageCodeUnpaged;
- f.iHdr->iFlags &= ~KImageCodePaged;
- }
- else if (gCodeDefaultPaged)
- {
- f.iHdr->iFlags &= ~KImageCodePaged;
- f.iHdr->iFlags &= ~KImageCodeUnpaged;
- }
-
- if (gDataPaged)
- {
- f.iHdr->iFlags |= KImageDataPaged;
- f.iHdr->iFlags &= ~KImageDataUnpaged;
- }
- else if (gDataUnpaged)
- {
- f.iHdr->iFlags |= KImageDataUnpaged;
- f.iHdr->iFlags &= ~KImageDataPaged;
- }
- else if (gDataDefaultPaged)
- {
- f.iHdr->iFlags &= ~KImageDataPaged;
- f.iHdr->iFlags &= ~KImageDataUnpaged;
- }
-
- return KErrNone;
- }
-
-void setDebuggableFlags(E32ImageFile& f)
- {
- if (gDebuggable)
- {
- f.iHdr->iFlags |= KImageDebuggable;
- }
- else
- {
- f.iHdr->iFlags &= ~KImageDebuggable;
- }
- }
-
-void setSmpSafeFlags(E32ImageFile& f)
- {
- if (gSmpSafe)
- {
- f.iHdr->iFlags |= KImageSMPSafe;
- }
- else
- {
- f.iHdr->iFlags &= ~KImageSMPSafe;
- }
- }
-
-int dotran(const char* ifilename, const char* ofilename)
- {
- E32ImageFileRef fRef;
- E32ImageFile& f = fRef.Ref();
- int r=f.Translate(ifilename, gDataBase, gAllowDllData, gSetSymLkup);
- if (r!=KErrNone)
- return r;
- if (gSetStack)
- f.SetStackSize(gStack);
- if (gSetHeap)
- {
- f.SetHeapSizeMin(gHeapMin);
- f.SetHeapSizeMax(gHeapMax);
- }
- if (!gSetUid1)
- gUid1=TUid::Uid(f.iHdr->iUid1);
- if (!gSetUid2)
- gUid2=TUid::Uid(f.iHdr->iUid2);
- if (!gSetUid3)
- gUid3=TUid::Uid(f.iHdr->iUid3);
- if (!gSetSecureId)
- gSecureId = f.iHdr->iUid3;
- if (!gSetVendorId)
- gVendorId = 0;
- f.SetUids(gUid1, gUid2, gUid3);
- f.SetSecureId(gSecureId);
- f.SetVendorId(gVendorId);
- if (gSetCallEntryPoints)
- f.SetCallEntryPoints(gCallEntryPoints);
- if (gSetCapability)
- f.SetCapability(gCapability);
- if (gSetPriority)
- {
- if (f.iHdr->iFlags&KImageDll)
- Print(EWarning,"Cannot set priority of a DLL.\n");
- else
- f.SetPriority((TProcessPriority)gPriority);
- }
- if (gSetFixedAddress)
- {
- if (f.iHdr->iFlags&KImageDll)
- Print(EWarning,"Cannot set fixed address for DLL.\n");
- else
- f.SetFixedAddress(gFixedAddress);
- }
- if (gSetVersion)
- f.iHdr->iModuleVersion = gVersionWord;
-
- if(gCompress)
- {
- switch(gCompressionMethod)
- {
- case ENoCompression:
- f.iHdr->iCompressionType = KFormatNotCompressed;
- break;
-
- case EDeflate:
- f.iHdr->iCompressionType = KUidCompressionDeflate;
-
- break;
-
- case EBytePair:
- f.iHdr->iCompressionType = KUidCompressionBytePair;
-
- break;
-
- default:
- Print(EError, "Unknown compression method:%d", gCompressionMethod);
- return 1;
-
- } // End of switch()
-
- }
- else
- {
- f.iHdr->iCompressionType = KFormatNotCompressed;
- }
-
-
- if (gSetFPU)
- f.SetFPU(gFPU);
-
- r = setPagedFlags(f);
- if (r != KErrNone)
- {
- return r;
- }
-
- setDebuggableFlags(f);
-
- setSmpSafeFlags(f);
-
- f.CreateExportBitMap();
- f.AddExportDescription();
- f.UpdateHeaderCrc();
- r = f.Validate();
- if (r!=KErrNone)
- return r;
-
- ofstream ofile(ofilename, ios::binary);
- if (!ofile)
- {
- Print(EError,"Cannot open %s for output.\n",ofilename);
- return 1;
- }
- ofile << f;
- ofile.close();
- if (gVerbose)
- f.Dump((TText*)ofilename,gVerbose);
- return KErrNone;
- }
-
-
-int dodump(const char* ifilename)
- {
- E32ImageFile f;
- TInt r = f.Open(ifilename);
- if (r>0)
- return 1;
- else if (r==KErrCorrupt || r==KErrNotSupported)
- {
- Print(EError,"%s is not a valid E32Image file.\n",ifilename);
- return 1;
- }
- else if (r!=0)
- {
- Print(EError,"Error %d reading %s.\n",r,ifilename);
- return 1;
- }
- f.Dump((TText*)ifilename, gVerbose ? gVerbose : E32ImageFile::EDumpDefaults);
- return KErrNone;
- }
-
-int doalter(const char* ifilename)
- {
- E32ImageFile f;
- TInt r = f.Open(ifilename);
- if (r>0)
- return 1;
- else if (r==KErrCorrupt || r==KErrNotSupported)
- {
- Print(EError,"%s is not a valid E32Image file.\n",ifilename);
- return 1;
- }
- else if (r!=0)
- {
- Print(EError,"Error %d reading %s.\n",r,ifilename);
- return 1;
- }
-
- TUint hdrfmt = f.iHdr->HeaderFormat();
- if (hdrfmt != KImageHdrFmt_V)
- {
- Print(EError,"Can't modify old format binaries\n");
- return 1;
- }
-
- if (gDataBase)
- {
- Print(EWarning, "Ignoring -datalinkaddress Switch");
- }
- if (gSetStack)
- f.SetStackSize(gStack);
- if (gSetHeap)
- {
- f.SetHeapSizeMin(gHeapMin);
- f.SetHeapSizeMax(gHeapMax);
- }
- if (!gSetUid1)
- gUid1=TUid::Uid(f.iHdr->iUid1);
- if (!gSetUid2)
- gUid2=TUid::Uid(f.iHdr->iUid2);
- if (!gSetUid3)
- gUid3=TUid::Uid(f.iHdr->iUid3);
- f.SetUids(gUid1, gUid2, gUid3);
- if (gSetSecureId)
- f.SetSecureId(gSecureId);
- if (gSetVendorId)
- f.SetVendorId(gVendorId);
- if (gSetCallEntryPoints)
- f.SetCallEntryPoints(gCallEntryPoints);
- if (gSetCapability)
- f.SetCapability(gCapability);
- if (gSetPriority)
- {
- if (f.iHdr->iFlags&KImageDll)
- Print(EWarning,"Cannot set priority of a DLL.\n");
- else
- f.SetPriority((TProcessPriority)gPriority);
- }
- if (gSetFixedAddress)
- {
- if (f.iHdr->iFlags&KImageDll)
- Print(EWarning,"Cannot set fixed address for DLL.\n");
- else
- f.SetFixedAddress(gFixedAddress);
- }
- if (gSetVersion)
- f.iHdr->iModuleVersion = gVersionWord;
-
- if(gCompress)
- {
- switch(gCompressionMethod)
- {
- case ENoCompression:
- f.iHdr->iCompressionType = KFormatNotCompressed;
- break;
-
- case EDeflate:
- f.iHdr->iCompressionType = KUidCompressionDeflate;
-
- break;
-
- case EBytePair:
- f.iHdr->iCompressionType = KUidCompressionBytePair;
-
- break;
-
- default:
- Print(EError, "Unknown compression method:%d", gCompressionMethod);
- return 1;
-
- } // End of switch()
- }
- else
- f.iHdr->iCompressionType = KFormatNotCompressed;
-
- if (gSetFPU)
- f.SetFPU(gFPU);
-
- r = setPagedFlags(f);
- if (r != KErrNone)
- {
- return r;
- }
-
- setDebuggableFlags(f);
-
- setSmpSafeFlags(f);
-
- f.UpdateHeaderCrc();
- r = f.Validate();
- if (r!=KErrNone)
- return r;
-
- ofstream ofile(ifilename, ios::binary);
- if (!ofile)
- {
- Print(EError,"Cannot open %s for output.\n",ifilename);
- return 1;
- }
- ofile << f;
- ofile.close();
- if (gVerbose)
- f.Dump((TText *)ifilename,gVerbose);
- return KErrNone;
- }
-
-int helpme(char *aStr)
- {
- Print(EAlways,"Syntax: %s [options] inputfile outputfile\n",aStr);
- Print(EAlways," %s [options] e32imagefile\n",aStr);
- Print(EAlways,"option: [-v] [[-no]call[entrypoint]] [-priority <priority>]\n");
- Print(EAlways," [-stack <size>] [-heap <min> <max>] [-uid<n> <uid>]\n");
- Print(EAlways," [-allowdlldata] [-datalinkaddress <base>] [-fixed] [-moving]\n");
- Print(EAlways," [-align-const-section] [-const-section-address-mask <mask>]\n");
- Print(EAlways," [-[no]compress] [-compressionmethod none|deflate|bytepair]\n");
- Print(EAlways," [-capability \"<list>\"] [-version M.m] [-vid <id>]\n");
- Print(EAlways," [-fpu <softvfp|vfpv2>]\n");
- Print(EAlways," [-codepaging <paged|unpaged|default>]\n");
- Print(EAlways," [-datapaging <paged|unpaged|default>]\n");
- Print(EAlways," [-debuggable]\n");
- Print(EAlways," [-smpsafe]\n");
- Print(EAlways," [-sym_name_lkup]\n");
- Print(EAlways," [-dump [h][s][c][d][e][i]]\n");
- Print(EAlways,"flags for dump: h Header\n");
- Print(EAlways," s Security info\n");
- Print(EAlways," c Code section\n");
- Print(EAlways," d Data section\n");
- Print(EAlways," e Export info\n");
- Print(EAlways," i Import table\n");
- return KErrArgument;
- }
-
-int isNumber(char *aStr)
- {
- return (aStr[0]>='0') && (aStr[0]<='9');
- }
-
-int getUIntArg(unsigned int &aVal, int argc, char *argv[], int i)
- {
- if (i>=argc)
- return KErrArgument;
- if (!isNumber(argv[i]))
- return KErrArgument;
-#ifdef __LINUX__
- int n;
- sscanf(argv[i], "%i", &n);
- aVal = n;
-#else
-#ifdef __TOOLS2__
-istringstream s(argv[i]/*, strlen(argv[i])*/);
-#else
-istrstream s(argv[i], strlen(argv[i]));
-#endif
-
-#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
- s >> setbase(0);
-#endif //__MSVCDOTNET__
-
- s >> aVal;
-#endif // __LINUX__
- return KErrNone;
- }
-
-int getCapabilitiesArg(SCapabilitySet& aVal, int argc, char *argv[], int i)
- {
- memset(&aVal,0,sizeof(aVal));
- if (i>=argc)
- return KErrArgument;
- if (isNumber(argv[i]))
- return getUIntArg(*(TUint*)&aVal[0], argc, argv, i);
- return ParseCapabilitiesArg(aVal,argv[i]);
- }
-
-int getPriorityArg(int &aVal, int argc, char *argv[], int i)
- {
-
- if (i>=argc)
- return KErrArgument;
- if (isNumber(argv[i]))
- {
-#ifdef __LINUX__
- int n;
- sscanf(argv[i], "%i", &n);
- aVal = n;
-#else
-#ifdef __TOOLS2__
-istringstream s(argv[i]);
-#else
-istrstream s(argv[i], strlen(argv[i]));
-#endif
-
-#if defined(__MSVCDOTNET__) || defined(__TOOLS2__)
- s >> setbase(0);
-#endif //__MSVCDOTNET__
-
- s>>aVal;
-#endif // __LINUX__
- }
- else
- {
- if (stricmp(argv[i], "low")==0)
- aVal=EPriorityLow;
- else if (strnicmp(argv[i], "background",4)==0)
- aVal=EPriorityBackground;
- else if (strnicmp(argv[i], "foreground",4)==0)
- aVal=EPriorityForeground;
- else if (stricmp(argv[i], "high")==0)
- aVal=EPriorityHigh;
- else if (strnicmp(argv[i], "windowserver",3)==0)
- aVal=EPriorityWindowServer;
- else if (strnicmp(argv[i], "fileserver",4)==0)
- aVal=EPriorityFileServer;
- else if (strnicmp(argv[i], "realtime",4)==0)
- aVal=EPriorityRealTimeServer;
- else if (strnicmp(argv[i], "supervisor",3)==0)
- aVal=EPrioritySupervisor;
- else
- {
- Print(EError, "Unrecognised priority\n");
- return KErrArgument;
- }
- }
- if (aVal<EPriorityLow || aVal>EPrioritySupervisor)
- {
- Print(EError, "Priority out of range\n");
- return KErrArgument;
- }
- return KErrNone;
- }
-
-int getVersionArg(unsigned int& aVal, const char* aArg)
- {
- const char* s = aArg;
- unsigned int major = 0;
- unsigned int minor = 0;
- for (; major<=6553 && *s>='0' && *s<='9'; ++s)
- major = major*10 + (*s - '0');
- if (*s == '.')
- {
- for (++s; minor<=6553 && *s>='0' && *s<='9'; ++s)
- minor = minor*10 + (*s - '0');
- if (*s==0 && major<32768 && minor<32768)
- {
- aVal = (major << 16) | minor;
- return KErrNone;
- }
- }
- Print(EError, "Bad argument to -version\n");
- return KErrArgument;
- }
-
-int getFPUArg(unsigned int &aVal, int argc, char *argv[], int i)
- {
- if (i>=argc)
- return KErrArgument;
- else if (strnicmp(argv[i], "softvfp", 7)==0)
- aVal = 0;
- else if (strnicmp(argv[i], "vfpv2", 5)==0)
- aVal = 1;
- else
- {
- Print(EError, "Bad argument to -fpu\n");
- return KErrArgument;
- }
-
- return KErrNone;
- }
-
-int getCompressionMethod(int &aVal, int argc, char *argv[], int i)
-{
- if( i >= argc || argv[i] == NULL)
- {
- Print(EError, "Missing argument to -compressionmethod\n");
- return KErrArgument;
- }
- else if (strnicmp(argv[i], "none", 2) == 0)
- {
- aVal = ENoCompression;
- }
- else if (strnicmp(argv[i], "deflate", 7) == 0)
- {
- aVal = EDeflate;
- }
- else if (strnicmp(argv[i], "bytepair", 8) == 0)
- {
- aVal = EBytePair;
- }
- else
- {
- Print(EError, "Bad argument '%s' to -compressionmethod\n", argv[i]);
- return KErrArgument;
- }
-
- return KErrNone;
-
-}
-
-
-int processCL(int argc, char *argv[])
- {
-
- int r=KErrNone;
- int i=1;
- while (i<argc)
- {
- if (stricmp("-v", argv[i])==0)
- gVerbose |= E32ImageFile::EDumpDefaults;
- else if (stricmp("-dump", argv[i])==0)
- {
- i++;
- if (i>=argc)
- return KErrArgument;
- char* s=argv[i];
- while(char c = *(s++))
- {
- if(c<'a')
- c += 'a'-'A';
- switch(c)
- {
- case 'h': gVerbose |= E32ImageFile::EDumpHeader; break;
- case 's': gVerbose |= E32ImageFile::EDumpSecurityInfo; break;
- case 'c': gVerbose |= E32ImageFile::EDumpCode; break;
- case 'd': gVerbose |= E32ImageFile::EDumpData; break;
- case 'e': gVerbose |= E32ImageFile::EDumpExports; break;
- case 'i': gVerbose |= E32ImageFile::EDumpImports; break;
- default: return KErrArgument;
- }
- }
- }
- else if (stricmp("-stack", argv[i])==0)
- {
- i++;
- gSetStack=TRUE;
- r=getUIntArg(gStack, argc, argv, i);
- }
- else if (stricmp("-uid1", argv[i])==0)
- {
- i++;
- gSetUid1=TRUE;
- unsigned int id;
- r=getUIntArg(id, argc, argv, i);
- gUid1=TUid::Uid(id);
- }
- else if (stricmp("-uid2", argv[i])==0)
- {
- i++;
- gSetUid2=TRUE;
- unsigned int id;
- r=getUIntArg(id, argc, argv, i);
- gUid2=TUid::Uid(id);
- }
- else if (stricmp("-uid3", argv[i])==0)
- {
- i++;
- gSetUid3=TRUE;
- unsigned int id;
- r=getUIntArg(id, argc, argv, i);
- gUid3=TUid::Uid(id);
- }
- else if (stricmp("-version", argv[i])==0)
- {
- i++;
- r=getVersionArg(gVersionWord, argv[i]);
- gSetVersion=TRUE;
- }
- else if (stricmp("-sid", argv[i])==0)
- {
- i++;
- r=getUIntArg(gSecureId, argc, argv, i);
- gSetSecureId=TRUE;
- }
- else if (stricmp("-vid", argv[i])==0)
- {
- i++;
- r=getUIntArg(gVendorId, argc, argv, i);
- gSetVendorId=TRUE;
- }
- else if (strnicmp("-nocall", argv[i], 7)==0)
- {
- gSetCallEntryPoints=TRUE;
- gCallEntryPoints=FALSE;
- }
- else if (strnicmp("-call", argv[i], 5)==0)
- {
- gSetCallEntryPoints=TRUE;
- gCallEntryPoints=TRUE;
- }
- else if (strnicmp("-fixed", argv[i], 3)==0)
- {
- gSetFixedAddress=TRUE;
- gFixedAddress=TRUE;
- }
- else if (strnicmp("-moving", argv[i], 3)==0)
- {
- gSetFixedAddress=TRUE;
- gFixedAddress=FALSE;
- }
- else if (strnicmp("-priority", argv[i], 4)==0)
- {
- i++;
- gSetPriority=TRUE;
- r=getPriorityArg(gPriority,argc,argv,i);
- }
- else if (strnicmp("-capability", argv[i], 10)==0)
- {
- i++;
- gSetCapability=TRUE;
- r=getCapabilitiesArg(gCapability, argc, argv, i);
- }
- else if (strnicmp("-heap", argv[i], 4)==0)
- {
- i++;
- gSetHeap=TRUE;
- r=getUIntArg(gHeapMin, argc, argv, i);
- if (r==KErrNone)
- r=getUIntArg(gHeapMax, argc, argv, ++i);
- }
- else if (strnicmp("-allow", argv[i], 6)==0) // Note, toolchain passes 'allow' for 'allowdlldata'
- {
- gAllowDllData=TRUE;
- }
- else if( strnicmp("-compressionmethod", argv[i], 18) == 0)
- {
- if(!gSuppressComprMethod)
- {
- gCompress = TRUE;
- gSetCompress = TRUE;
- r = getCompressionMethod(gCompressionMethod, argc, argv, ++i);
- }
- else
- {
- ++i; // Skip the compression method because compessionmethod suppressed.
- }
- }
- else if (strnicmp("-compress", argv[i], 9)==0)
- {
- gCompress=TRUE;
- gSetCompress=TRUE;
- gSuppressComprMethod=FALSE;
- }
- else if (strnicmp("-nocompress", argv[i], 11)==0)
- {
- gCompress=FALSE;
- gSetCompress=TRUE;
- gSuppressComprMethod = TRUE;
- gCompressionMethod = ENoCompression;
- }
- else if (strnicmp("-datalinkaddress", argv[i], 16)==0)
- {
- i++;
- r=getUIntArg(gDataBase, argc, argv, i);
- }
- else if (strnicmp("-align-const-section", argv[i], 20)==0)
- {
- gAlignConstSection=TRUE;
- }
- else if (strnicmp("-const-section-address-mask", argv[i], 27)==0)
- {
- i++;
- r=getUIntArg(gConstSectionAddressMask, argc, argv, i);
- }
- else if (strnicmp("-fpu", argv[i], 4)==0)
- {
- i++;
- r=getFPUArg(gFPU, argc, argv, i);
- gSetFPU=TRUE;
- }
- else if (strnicmp("-paged", argv[i], 6) == 0)
- {
- gCodePaged=TRUE;
- gSetCodePaged=TRUE;
- }
- else if (strnicmp("-unpaged", argv[i], 8) == 0)
- {
- gCodeUnpaged=TRUE;
- gSetCodePaged=TRUE;
- }
- else if (strnicmp("-defaultpaged", argv[i], 13) == 0)
- {
- gCodeDefaultPaged=TRUE;
- gSetCodePaged=TRUE;
- }
- else if (strnicmp("-codepaging", argv[i], 11)==0)
- {
- i++;
-
- if (i>=argc)
- {
- r = KErrArgument;
- }
- else if ( strnicmp(argv[i], "paged", 5) == 0 )
- {
- gCodePaged=TRUE;
- }
- else if ( strnicmp(argv[i], "unpaged", 7) == 0 )
- {
- gCodeUnpaged=TRUE;
- }
- else if ( strnicmp(argv[i], "default", 7) == 0 )
- {
- gCodeDefaultPaged=TRUE;
- }
- else
- {
- Print(EError, "Bad argument to -codepaging\n");
- r = KErrArgument;
- }
-
- gSetCodePaged=TRUE;
- }
- else if (strnicmp("-datapaging", argv[i], 11)==0)
- {
- i++;
-
- if (i>=argc)
- {
- r = KErrArgument;
- }
- else if ( strnicmp(argv[i], "paged", 5) == 0 )
- {
- gDataPaged=TRUE;
- }
- else if ( strnicmp(argv[i], "unpaged", 7) == 0 )
- {
- gDataUnpaged=TRUE;
- }
- else if ( strnicmp(argv[i], "default", 7) == 0 )
- {
- gDataDefaultPaged=TRUE;
- }
- else
- {
- Print(EError, "Bad argument to -datapaging\n");
- r = KErrArgument;
- }
-
- gSetDataPaged=TRUE;
- }
- else if (strnicmp("-sym_name_lkup", argv[i], 14) == 0)
- {
- gSetSymLkup=TRUE;
- }
- else if (strnicmp("-debuggable", argv[i], 11) == 0)
- {
- gDebuggable=TRUE;
- gSetDebuggable=TRUE;
- }
- else if (strnicmp("-smpsafe", argv[i], 8) == 0)
- {
- gSmpSafe=TRUE;
- gSetSmpSafe=TRUE;
- }
-#ifdef __SUPPORT_PE_FILES__
- else if (strnicmp("-x86imp=", argv[i], 8)==0)
- {
- const char* x86impfile=argv[i]+8;
-// printf("%s\n",x86impfile);
- FILE* f=fopen(x86impfile,"rb");
- if (!f)
- r=KErrArgument;
- else
- {
- fseek(f,0,SEEK_END);
- long size=ftell(f);
- fseek(f,0,SEEK_SET);
- if (size>4)
- {
- gX86imp=new char[size];
- fread(gX86imp,1,size,f);
- }
- fclose(f);
- r=KErrNone;
- if (gX86imp)
- {
- gX86imp_size=ALIGN4(size);
- // printf("size %d\n",size);
- int i;
- int* p=(int*)gX86imp;
- gX86num_imp_dlls=*p++;
- for (i=0; i<gX86num_imp_dlls; ++i)
- {
- ++p;
- int n=*p++;
- gX86num_imports+=n;
- p+=n;
- }
- // fprintf(stderr,"#imports=%d\n",gX86num_imports);
- }
- }
- }
-#endif
- else if (gFile1==NULL)
- {
- gFile1 = NormaliseFileName(argv[i]);
- }
- else if (gFile2==NULL)
- {
- gFile2 = NormaliseFileName(argv[i]);
- }
- else
- r=KErrArgument;
- if (r!=KErrNone)
- return r;
- i++;
- }
- return KErrNone;
- }
-
-int main(int argc, char *argv[])
- {
-#ifdef __SUPPORT_PE_FILES__
- Print(EAlways,"\nPETRAN - PE file preprocessor");
-#endif
-#ifdef __SUPPORT_ELF_FILES__
- Print(EAlways,"\nELFTRAN - ELF file preprocessor");
-#endif
- Print(EAlways," V%02d.%02d (Build %03d)\n",MajorVersion,MinorVersion,Build);
- int r=processCL(argc, argv);
- if (r!=KErrNone)
- return helpme(argv[0]);
- if (gFile2)
- return dotran(gFile1, gFile2);
- if ((gSetStack || gSetUid1 || gSetUid2 || gSetUid3 || gSetCallEntryPoints || gSetPriority
- || gSetCapability || gSetCompress || gSetHeap || gSetVersion || gSetSecureId
- || gSetVendorId || gSetFixedAddress || gSetFPU || gSetCodePaged || gSetDataPaged || gSetDebuggable || gSetSmpSafe) && gFile1)
- return doalter(gFile1);
- if (gFile1)
- return dodump(gFile1);
- helpme(argv[0]);
- return KErrArgument;
- }