本文整理汇总了C++中MemChunk::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ MemChunk::getSize方法的具体用法?C++ MemChunk::getSize怎么用?C++ MemChunk::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemChunk
的用法示例。
在下文中一共展示了MemChunk::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isGobArchive
/* GobArchive::isGobArchive
* Checks if the given data is a valid Dark Forces gob archive
*******************************************************************/
bool GobArchive::isGobArchive(MemChunk& mc)
{
// Check size
if (mc.getSize() < 12)
return false;
// Check magic header
if (mc[0] != 'G' || mc[1] != 'O' || mc[2] != 'B' || mc[3] != 0xA)
return false;
// Get directory offset
uint32_t dir_offset = 0;
mc.seek(4, SEEK_SET);
mc.read(&dir_offset, 4);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
// Check size
if ((unsigned)mc.getSize() < (dir_offset + 4))
return false;
// Get number of lumps
uint32_t num_lumps = 0;
mc.seek(dir_offset, SEEK_SET);
mc.read(&num_lumps, 4);
num_lumps = wxINT32_SWAP_ON_BE(num_lumps);
// Compute directory size
uint32_t dir_size = (num_lumps * 21) + 4;
if ((unsigned)mc.getSize() < (dir_offset + dir_size))
return false;
// If it's passed to here it's probably a gob file
return true;
}
示例2: isPakArchive
/* PakArchive::isPakArchive
* Checks if the given data is a valid Quake pak archive
*******************************************************************/
bool PakArchive::isPakArchive(MemChunk& mc)
{
// Check given data is valid
if (mc.getSize() < 12)
return false;
// Read pak header
char pack[4];
long dir_offset;
long dir_size;
mc.seek(0, SEEK_SET);
mc.read(pack, 4);
mc.read(&dir_offset, 4);
mc.read(&dir_size, 4);
// Byteswap values for big endian if needed
dir_size = wxINT32_SWAP_ON_BE(dir_size);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
// Check header
if (pack[0] != 'P' || pack[1] != 'A' || pack[2] != 'C' || pack[3] != 'K')
return false;
// Check directory is sane
if (dir_offset < 12 || (unsigned)(dir_offset + dir_size) > mc.getSize())
return false;
// That'll do
return true;
}
示例3:
/* Wad2Archive::isWad2Archive
* Checks if the given data is a valid Quake wad2 archive
*******************************************************************/
bool Wad2Archive::isWad2Archive(MemChunk& mc)
{
// Check size
if (mc.getSize() < 12)
return false;
// Check for IWAD/PWAD header
if (mc[0] != 'W' || mc[1] != 'A' || mc[2] != 'D' || (mc[3] != '2' && mc[3] != '3'))
return false;
// Get number of lumps and directory offset
int32_t num_lumps = 0;
int32_t dir_offset = 0;
mc.seek(4, SEEK_SET);
mc.read(&num_lumps, 4);
mc.read(&dir_offset, 4);
// Reset MemChunk (just in case)
mc.seek(0, SEEK_SET);
// Byteswap values for big endian if needed
num_lumps = wxINT32_SWAP_ON_BE(num_lumps);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
// Check directory offset is decent
if ((unsigned)(dir_offset + (num_lumps * 32)) > mc.getSize() ||
dir_offset < 12)
return false;
// If it's passed to here it's probably a wad2 file
return true;
}
示例4: isADatArchive
/* ADatArchive::isADatArchive
* Checks if the given data is a valid Anachronox dat archive
*******************************************************************/
bool ADatArchive::isADatArchive(MemChunk& mc) {
// Check it opened ok
if (mc.getSize() < 16)
return false;
// Read dat header
char magic[4];
long dir_offset;
long dir_size;
long version;
mc.seek(0, SEEK_SET);
mc.read(magic, 4);
mc.read(&dir_offset, 4);
mc.read(&dir_size, 4);
mc.read(&version, 4);
// Byteswap values for big endian if needed
dir_size = wxINT32_SWAP_ON_BE(dir_size);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
// Check version
if (wxINT32_SWAP_ON_BE(version) != 9)
return false;
// Check header
if (magic[0] != 'A' || magic[1] != 'D' || magic[2] != 'A' || magic[3] != 'T')
return false;
// Check directory is sane
if (dir_offset < 16 || (unsigned)(dir_offset + dir_size) > mc.getSize())
return false;
// That'll do
return true;
}
示例5: isChasmBinArchive
/* ChasmBinArchive::isChasmBinArchive
* Checks if the given data is a valid Chasm bin archive
*******************************************************************/
bool ChasmBinArchive::isChasmBinArchive(MemChunk& mc)
{
// Check given data is valid
if (mc.getSize() < HEADER_SIZE)
{
return false;
}
// Read bin header and check it
char magic[4] = {};
mc.read(magic, sizeof magic);
if ( magic[0] != 'C'
|| magic[1] != 'S'
|| magic[2] != 'i'
|| magic[3] != 'd')
{
return false;
}
uint16_t num_entries = 0;
mc.read(&num_entries, sizeof num_entries);
num_entries = wxUINT16_SWAP_ON_BE(num_entries);
return num_entries > MAX_ENTRY_COUNT
|| (HEADER_SIZE + ENTRY_SIZE * MAX_ENTRY_COUNT) <= mc.getSize();
}
示例6: isDatArchive
/* DatArchive::isDatArchive
* Checks if the given data is a valid Shadowcaster dat archive
*******************************************************************/
bool DatArchive::isDatArchive(MemChunk& mc)
{
// Read dat header
mc.seek(0, SEEK_SET);
uint16_t num_lumps;
uint32_t dir_offset, junk;
mc.read(&num_lumps, 2); // Size
mc.read(&dir_offset, 4); // Directory offset
mc.read(&junk, 4); // Unknown value
num_lumps = wxINT16_SWAP_ON_BE(num_lumps);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
junk = wxINT32_SWAP_ON_BE(junk);
if (dir_offset >= mc.getSize())
return false;
// Read the directory
mc.seek(dir_offset, SEEK_SET);
// Read lump info
uint32_t offset = 0;
uint32_t size = 0;
uint16_t nameofs = 0;
uint16_t flags = 0;
mc.read(&offset, 4); // Offset
mc.read(&size, 4); // Size
mc.read(&nameofs, 2); // Name offset
mc.read(&flags, 2); // Flags
// Byteswap values for big endian if needed
offset = wxINT32_SWAP_ON_BE(offset);
size = wxINT32_SWAP_ON_BE(size);
nameofs = wxINT16_SWAP_ON_BE(nameofs);
flags = wxINT16_SWAP_ON_BE(flags);
// The first lump should have a name (subsequent lumps need not have one).
// Also, sanity check the values.
if (nameofs == 0 || nameofs >= mc.getSize() || offset + size >= mc.getSize())
{
return false;
}
size_t len = 1;
size_t start = nameofs+dir_offset;
// Sanity checks again. Make sure there is actually a name.
if (start > mc.getSize() || mc[start] < 33)
return false;
for (size_t i = start; (mc[i] != 0 && i < mc.getSize()); ++i, ++len)
{
// Names should not contain garbage characters
if (mc[i] < 32 || mc[i] > 126)
return false;
}
// Let's be reasonable here. While names aren't limited, if it's too long, it's suspicious.
if (len > 60)
return false;
return true;
}
示例7: DecodeTXB
/* DecodeTXB
* TXB files are text files with a bit shift xor cipher. It makes an exception
* for the newline character probably so that standard string functions will
* continue to work. As an extension we also except the encoded version of 0xA
* in order to produce a lossless conversion. This allows us to semi-effectively
* handle this at the archive level instead of as a filter at the text editor.
*******************************************************************/
void DecodeTXB(MemChunk &mc)
{
const uint8_t* data = mc.getData();
const uint8_t* const dataend = data + mc.getSize();
uint8_t* odata = new uint8_t[mc.getSize()];
uint8_t* const ostart = odata;
while (data != dataend)
{
if (*data != 0xA && *data != 0x8F)
{
*odata++ = (((*data&0x3F)<<2)|((*data&0xC0)>>6))^0xA7;
++data;
}
else
示例8: openMod
/* AudioEntryPanel::openMod
* Opens a Module file for playback
*******************************************************************/
bool AudioEntryPanel::openMod(MemChunk& data)
{
// Attempt to load the mod
if (mod->loadFromMemory(data.getData(), data.getSize()))
{
audio_type = AUTYPE_MOD;
// Enable playback controls
slider_volume->Enable();
btn_play->Enable();
btn_pause->Enable();
btn_stop->Enable();
setAudioDuration(mod->getDuration().asMilliseconds());
return true;
}
else
{
// Disable playback controls
slider_volume->Enable();
btn_play->Enable();
btn_pause->Enable();
btn_stop->Enable();
setAudioDuration(0);
return false;
}
return false;
}
示例9: isHogArchive
/* HogArchive::isHogArchive
* Checks if the given data is a valid Descent hog archive
*******************************************************************/
bool HogArchive::isHogArchive(MemChunk& mc)
{
// Check size
size_t size = mc.getSize();
if (size < 3)
return false;
// Check magic header
if (mc[0] != 'D' || mc[1] != 'H' || mc[2] != 'F')
return false;
// Iterate through files to see if the size seems okay
size_t offset = 3;
while (offset < size)
{
// Enough room for the header?
if (offset + 17 > size)
return false;
// Read entry size to compute next offset
offset += 17 + READ_L32(mc, offset + 13);
}
// We should end on at exactly the end of the file
return (offset == size);
}
示例10: isRffArchive
/* RffArchive::isRffArchive
* Checks if the given data is a valid Duke Nukem 3D grp archive
*******************************************************************/
bool RffArchive::isRffArchive(MemChunk& mc)
{
// Check size
if (mc.getSize() < 12)
return false;
// Read grp header
uint8_t magic[4];
uint32_t version, dir_offset, num_lumps;
mc.seek(0, SEEK_SET);
mc.read(magic, 4); // Should be "RFF\x18"
mc.read(&version, 4); // 0x01 0x03 \x00 \x00
mc.read(&dir_offset, 4); // Offset to directory
mc.read(&num_lumps, 4); // No. of lumps in rff
// Byteswap values for big endian if needed
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
num_lumps = wxINT32_SWAP_ON_BE(num_lumps);
version = wxINT32_SWAP_ON_BE(version);
// Check the header
if (magic[0] != 'R' || magic[1] != 'F' || magic[2] != 'F' || magic[3] != 0x1A || version != 0x301)
return false;
// Compute total size
RFFLump* lumps = new RFFLump[num_lumps];
mc.seek(dir_offset, SEEK_SET);
theSplashWindow->setProgressMessage("Reading rff archive data");
mc.read (lumps, num_lumps * sizeof(RFFLump));
BloodCrypt (lumps, dir_offset, num_lumps * sizeof(RFFLump));
uint32_t totalsize = 12 + num_lumps * sizeof(RFFLump);
uint32_t size = 0;
for (uint32_t a = 0; a < num_lumps; ++a)
{
totalsize += lumps[a].Size;
}
// Check if total size is correct
if (totalsize > mc.getSize())
return false;
// If it's passed to here it's probably a grp file
return true;
}
示例11: openMem
// ----------------------------------------------------------------------------
// Tokenizer::openMem
//
// Opens text from a MemChunk [mc]
// ----------------------------------------------------------------------------
bool Tokenizer::openMem(const MemChunk& mc, const string& source)
{
source_ = source;
data_.assign(mc.getData(), mc.getData() + mc.getSize());
reset();
return true;
}
示例12: isThisFormat
bool isThisFormat(MemChunk& mc)
{
FIMEMORY* mem = FreeImage_OpenMemory((BYTE*)mc.getData(), mc.getSize());
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(mem, 0);
FreeImage_CloseMemory(mem);
if (fif == FIF_UNKNOWN)
return false;
else
return true;
}
示例13: importMemChunk
/* ArchiveEntry::importMemChunk
* Imports data from a MemChunk object into the entry, resizing it
* and clearing any currently existing data.
* Returns false if the MemChunk has no data, or true otherwise.
*******************************************************************/
bool ArchiveEntry::importMemChunk(MemChunk& mc)
{
// Check that the given MemChunk has data
if (mc.hasData())
{
// Copy the data from the MemChunk into the entry
return importMem(mc.getData(), mc.getSize());
}
else
return false;
}
示例14: isResArchive
bool ResArchive::isResArchive(MemChunk& mc, size_t& dir_offset, size_t& num_lumps)
{
// Check size
if (mc.getSize() < 12)
return false;
// Check for "Res!" header
if (!(mc[0] == 'R' && mc[1] == 'e' && mc[2] == 's' && mc[3] == '!'))
return false;
// Get number of lumps and directory offset
uint32_t offset_offset = 0;
uint32_t rel_offset = 0;
uint32_t dir_size = 0;
mc.seek(4, SEEK_SET);
mc.read(&dir_offset, 4);
mc.read(&dir_size, 4);
// Byteswap values for big endian if needed
dir_size = wxINT32_SWAP_ON_BE(dir_size);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset);
// A&A contains nested resource files. The offsets are then always relative to
// the top-level file. This causes problem with the embedded archive system
// used by SLADE3. The solution is to compute the offset offset. :)
offset_offset = dir_offset - (mc.getSize() - dir_size);
rel_offset = dir_offset - offset_offset;
// Check directory offset and size are both decent
if (dir_size % RESDIRENTRYSIZE || (rel_offset + dir_size) > mc.getSize())
return false;
num_lumps = dir_size / RESDIRENTRYSIZE;
// Reset MemChunk (just in case)
mc.seek(0, SEEK_SET);
// If it's passed to here it's probably a res file
return true;
}
示例15: isLfdArchive
/* LfdArchive::isLfdArchive
* Checks if the given data is a valid Dark Forces lfd archive
*******************************************************************/
bool LfdArchive::isLfdArchive(MemChunk& mc)
{
// Check size
if (mc.getSize() < 12)
return false;
// Check magic header
if (mc[0] != 'R' || mc[1] != 'M' || mc[2] != 'A' || mc[3] != 'P')
return false;
// Get offset of first entry
uint32_t dir_offset = 0;
mc.seek(12, SEEK_SET);
mc.read(&dir_offset, 4);
dir_offset = wxINT32_SWAP_ON_BE(dir_offset) + 16;
if (dir_offset % 16) return false;
char type1[5]; char type2[5];
char name1[9]; char name2[9];
uint32_t len1; uint32_t len2;
mc.read(type1, 4); type1[4] = 0;
mc.read(name1, 8); name1[8] = 0;
mc.read(&len1, 4); len1 = wxINT32_SWAP_ON_BE(len1);
// Check size
if ((unsigned)mc.getSize() < (dir_offset + 16 + len1))
return false;
// Compare
mc.seek(dir_offset, SEEK_SET);
mc.read(type2, 4); type2[4] = 0;
mc.read(name2, 8); name2[8] = 0;
mc.read(&len2, 4); len2 = wxINT32_SWAP_ON_BE(len2);
if (strcmp(type1, type2) || strcmp(name1, name2) || len1 != len2)
return false;
// If it's passed to here it's probably a lfd file
return true;
}