Exemplo n.º 1
0
static BOOL
PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta)
{
    unsigned char *codeBase = module->codeBase;
    PIMAGE_BASE_RELOCATION relocation;

    PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_BASERELOC);
    if (directory->Size == 0) {
        return (delta == 0);
    }

    relocation = (PIMAGE_BASE_RELOCATION) (codeBase + directory->VirtualAddress);
    for (; relocation->VirtualAddress > 0; ) {
        DWORD i;
        unsigned char *dest = codeBase + relocation->VirtualAddress;
        unsigned short *relInfo = (unsigned short*) OffsetPointer(relocation, IMAGE_SIZEOF_BASE_RELOCATION);
        for (i=0; i<((relocation->SizeOfBlock-IMAGE_SIZEOF_BASE_RELOCATION) / 2); i++, relInfo++) {
            // the upper 4 bits define the type of relocation
            int type = *relInfo >> 12;
            // the lower 12 bits define the offset
            int offset = *relInfo & 0xfff;

            switch (type)
            {
            case IMAGE_REL_BASED_ABSOLUTE:
                // skip relocation
                break;

            case IMAGE_REL_BASED_HIGHLOW:
                // change complete 32 bit address
                {
                    DWORD *patchAddrHL = (DWORD *) (dest + offset);
                    *patchAddrHL += (DWORD) delta;
                }
                break;

#ifdef _WIN64
            case IMAGE_REL_BASED_DIR64:
                {
                    ULONGLONG *patchAddr64 = (ULONGLONG *) (dest + offset);
                    *patchAddr64 += (ULONGLONG) delta;
                }
                break;
#endif

            default:
                //printf("Unknown relocation: %d\n", type);
                break;
            }
        }

        // advance to next relocation block
        relocation = (PIMAGE_BASE_RELOCATION) OffsetPointer(relocation, relocation->SizeOfBlock);
    }
    return TRUE;
}
Exemplo n.º 2
0
CTextRec *CTextContainer::Add(const char *text)
{
	if (!text || !*text) return NULL;				// empty text

	if (!filled)
	{	// 1st record - perform initialization
		lastRec = NULL;
		fillPos = 0;
	}

	CTextRec *rec = (CTextRec*) &textBuf[fillPos];
	int len = strlen(text);
	if (!len) return NULL;

	int size = recSize + len + 1;
	if (fillPos + size > bufSize) return NULL;		// out of buffer space

	memset(rec, 0, recSize);
	rec->text = (char*) OffsetPointer(rec, recSize);
	memcpy(rec->text, text, len+1);

	if (lastRec) lastRec->next = rec;
	lastRec = rec;
	fillPos += size;

	filled  = true;

	return rec;
}
Exemplo n.º 3
0
void* FArray::GetItem(int index, int elementSize) const
{
	guard(operator[]);
	assert(index >= 0 && index < DataCount);
	return OffsetPointer(DataPtr, index * elementSize);
	unguardf("%d/%d", index, DataCount);
}
Exemplo n.º 4
0
FArchive& FArray::Serialize(FArchive &Ar, void (*Serializer)(FArchive&, void*), int elementSize)
{
	int i = 0;

	guard(TArray::Serialize);

//-- if (Ar.IsLoading) Empty();	-- cleanup is done in TArray serializer (do not need
//								-- to pass array eraser/destructor to this function)
	// Here:
	// 1) when loading: 'this' array is empty (cleared from TArray's operator<<)
	// 2) when saving : data is not modified by this function

	// serialize data count
	int Count = DataCount;
	if (GameUsesFCompactIndex(Ar))
		Ar << AR_INDEX(Count);
	else
		Ar << Count;

	if (Ar.IsLoading)
	{
		// loading array items - should prepare array
		Empty(Count, elementSize);
		DataCount = Count;
	}
	// perform serialization itself
	void *ptr;
	for (i = 0, ptr = DataPtr; i < Count; i++, ptr = OffsetPointer(ptr, elementSize))
		Serializer(Ar, ptr);
	return Ar;

	unguardf("%d/%d", i, DataCount);
}
Exemplo n.º 5
0
FString& FString::operator+=(const char* text)
{
	int len = strlen(text);
	int oldLen = Data.Num();
	if (oldLen)
	{
		Data.AddUninitialized(len);
		// oldLen-1 -- cut null char, len+1 -- append null char
		memcpy(OffsetPointer(Data.GetData(), oldLen-1), text, len+1);
	}
	else
	{
		Data.AddUninitialized(len+1);	// reserve space for null char
		memcpy(Data.GetData(), text, len+1);
	}
	return *this;
}
Exemplo n.º 6
0
void CMeshViewer::DisplayUV(const CMeshVertex* Verts, int VertexSize, const CBaseMeshLod* Mesh, int UVIndex)
{
	guard(CMeshViewer::DisplayUV);

	int width, height;
	Window->GetWindowSize(width, height);
	int w = min(width, height);

	// add some border
	int x0 = width - w;
	int y0 = 10;
	w -= 20;

	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	for (int MaterialIndex = 0; MaterialIndex < Mesh->Sections.Num(); MaterialIndex++)
	{
		const CMeshSection &Sec = Mesh->Sections[MaterialIndex];
		if (!Sec.NumFaces) continue;

		BindDefaultMaterial(true);
		glDisable(GL_CULL_FACE);
		unsigned color = CMeshInstance::GetMaterialDebugColor(MaterialIndex);
		glColor4ubv((GLubyte*)&color);

		CIndexBuffer::IndexAccessor_t Index = Mesh->Indices.GetAccessor();

		glBegin(GL_TRIANGLES);
		for (int i = Sec.FirstIndex; i < Sec.FirstIndex + Sec.NumFaces * 3; i++)
		{
			int VertIndex = Index(i);
			const CMeshVertex* V = OffsetPointer(Verts, VertIndex * VertexSize);
			const CMeshUVFloat& UV = (UVIndex == 0) ? V->UV : Mesh->ExtraUV[UVIndex-1][VertIndex];
			glVertex2f(UV.U * w + x0, UV.V * w + y0);
		}
		glEnd();
	}

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	unguard;
}
Exemplo n.º 7
0
void ExportSoundNodeWave(const USoundNodeWave *Snd)
{
	// select bulk containing data
	const FByteBulkData *bulk = NULL;
	const char *ext = "unk";
	int extraHeaderSize = 0;

	if (Snd->RawData.ElementCount)
	{
		bulk = &Snd->RawData;
	}
	else if (Snd->CompressedPCData.ElementCount)
	{
		bulk = &Snd->CompressedPCData;
	}
	else if (Snd->CompressedXbox360Data.ElementCount)
	{
		bulk = &Snd->CompressedXbox360Data;
		ext  = "x360audio";
#if XMA_EXPORT
		if (SaveXMASound(Snd, bulk->BulkData, bulk->ElementCount, "xma")) return;
		// else - detect format by data tags, like for PC
#endif
	}
	else if (Snd->CompressedPS3Data.ElementCount)
	{
		bulk = &Snd->CompressedPS3Data;
		ext  = "ps3audio";
		extraHeaderSize = 16;
		//!! note: has up to 4 sounds in single object
		//!! bulk data starts with int32[4] holding sizes of all sounds
		//!! 0 means no data for particular object
		//!! data encoded in MP3 format
	}

	if (bulk)
	{
		SaveSound(Snd, OffsetPointer(bulk->BulkData, extraHeaderSize), bulk->ElementCount - extraHeaderSize, ext);
	}
}
Exemplo n.º 8
0
void* FArray::GetItem(int index, int elementSize) const
{
	if (!IsValidIndex(index)) appError("TArray: index %d is out of range (%d)", index, DataCount);
	return OffsetPointer(DataPtr, index * elementSize);
}
Exemplo n.º 9
0
char *CStringItem::AllocatedName;

// used in conjunction with "CStringItem::operator new" only!
CStringItem::CStringItem()
:	name(AllocatedName)			// properly initialize CStringItem::name field
{}
#endif

void* CStringItem::operator new(size_t size, const char *str)
{
	guardSlow(CStringItem::new);
	MEM_ALLOCATOR(size);
	int len = strlen(str) + 1;
	CStringItem *item = (CStringItem*) appMalloc(size + len);
#ifndef STRING_ITEM_TRICK
	item->name    = (char*) OffsetPointer(item, size);
	memcpy(item->name, str, len);	// faster than strcpy()
#else
	AllocatedName = (char*) OffsetPointer(item, size);
	memcpy(AllocatedName, str, len);
#endif

	return item;
	unguardSlow;
}


void* CStringItem::operator new(size_t size, const char *str, CMemoryChain *chain)
{
	guardSlow(CStringItem::new(chain));
#if 0