Exemplo n.º 1
0
DWORD CChangeGroup::GetChangeSurroundHash()
{
	DWORD dwHash = 0;
	int iSize =  (x64_int_cast)theChanges.size();
	
	for (int i = 0; i<iSize; i++)
	{
		dwHash = _rotl(dwHash,1) ^ theChanges[i]->GetHash();
	}
	
	return dwHash;
}
Exemplo n.º 2
0
void serpent256_set_key(const unsigned char *key, serpent256_key *skey)
{
	unsigned long W[140], i;

	__movsb((unsigned char*)&W, key, SERPENT_KEY_SIZE);

	for(i = 8; i != 140; ++i) {
		W[i] = _rotl(W[i-8] ^ W[i-5] ^ W[i-3] ^ W[i-1] ^ PHI ^ (i-8), 11);
	}
	for (i = 8; i <= 136; i += 4) {
		se_tab[7 - (((i / 4) + 2) % 8)](&W[i]);
	}
	__movsb((unsigned char*)&skey->expkey, (unsigned char*)(W+8), (SERPENT_EXPKEY_WORDS * sizeof(unsigned long)));
}
Exemplo n.º 3
0
DWORD CChangeGroup::GetChangeHash()
{
	DWORD dwHash = 0;
	int iSize =  (x64_int_cast)theChanges.size();

	for (int i = 0; i<iSize; i++)
	{
		if (theChanges[i]->GetNumber()>0)
		{
			dwHash = _rotl(dwHash,1) ^ theChanges[i]->GetHash();
		}
	}
	return dwHash;
}
Exemplo n.º 4
0
/*
* SfuDecodeStream
*
* Purpose:
*
* Decode ZeroAccess stream using given key.
*
*/
VOID SfuDecodeStream(
	_Inout_ unsigned char *stream,
	_In_ size_t size,
	_In_ unsigned long key
	)
{
	unsigned long *p = (unsigned long *)stream;

	size >>= 2;
	while (size > 0) {
		*p ^= key;
		key = _rotl(key, 1);
		p++;
		size--;
	}
}
Exemplo n.º 5
0
hashValueType String::hashValue() const

// Summary -----------------------------------------------------------------
//
//      Returns the hash value of a string object.
//
// End ---------------------------------------------------------------------
{
    hashValueType	value = hashValueType(0);

    for( int i = 0; i < len; i++ )
    {
        value ^= theString[i];
        value = _rotl( value, 1 );
    }
    return value;
}
Exemplo n.º 6
0
void HashFunctions()
{
    for (vector<Function>::iterator iter = functions.begin(); iter!=functions.end(); iter++)
    {
        Function &f=*iter;
        u32 hash = 0x1337babe;
        for (u32 addr = f.start; addr <= f.end; addr++)
        {
            u32 validbits = 0xFFFFFFFF;
            u32 instr = Memory::Read_Instruction(addr);
            u32 flags = MIPSGetInfo(instr);
            if (flags & IN_IMM16)
                validbits&=~0xFFFF;
            if (flags & IN_IMM26)
                validbits&=~0x3FFFFFF;
            hash = _rotl(hash,13);
            hash ^= (instr&validbits);
        }
        f.hash=hash;
        f.hasHash=true;
    }
}
Exemplo n.º 7
0
Bool CTextHandler::Init(PVoid lpBuffer, UInt32 BufferSize)
{
    UInt32 TextLength;
    STextHeader *h;

    if (BufferSize == 0)
        return False;

    m_pbBuffer = (PByte)m_mem.Alloc(BufferSize);
    if (m_pbBuffer == NULL)
        return False;
    m_pIndex = (STextHeader **)m_mem.Alloc(m_MaxIndexCount * sizeof(*m_pIndex));
    if (m_pIndex == NULL)
        return False;

    m_BufferSize = BufferSize;
    memcpy(m_pbBuffer, lpBuffer, BufferSize);

    for (UInt32 i = 0, j = BufferSize; i < j; )
    {
        h = (STextHeader *)&m_pbBuffer[i];
        TextLength = h->Hash[2] ^ h->Hash[0] ^ h->Length;
        if (m_IndexCount == m_MaxIndexCount)
        {
            m_MaxIndexCount += m_MaxIndexCount / 2;
            m_pIndex = (STextHeader **)m_mem.ReAlloc(m_pIndex, m_MaxIndexCount * sizeof(*m_pIndex));
            if (m_pIndex == NULL)
                return False;
        }

        m_pIndex[m_IndexCount] = (STextHeader *)_rotl((Int_Ptr)h ^ m_Key, m_IndexCount + 1);

        ++m_IndexCount;
        i += ((TextLength + 3) & ~3) + sizeof(*h);
    }

    return True;
}
Exemplo n.º 8
0
DWORD ToppyFramework::GetStartClusterHash(const CString& filename)
{
	CString sName = MakePath(filename);
	sName.Replace("\\", "/");
	sName.Replace("//", "/");
	if (sName.Right(2) == "/.")
		sName = sName.Left(sName.GetLength()-2);
	if (sName.Right(3) == "/..")
	{
		sName = sName.Left(sName.GetLength()-3);
		int iIndex = sName.ReverseFind('/');
		sName = sName.Left(iIndex);
	}

	DWORD result = 0;
	for (int i=0; i<sName.GetLength(); i++)
	{
		result = _rotl(result,1) ^ sName[i];
	}

	return result;

}
Exemplo n.º 9
0
//need improvement
static u32 hasher(u32 last, u32 value)
{
    return _rotl(last,3) ^ value;
}
Exemplo n.º 10
0
static int EnterDict( unsigned char *bucketsP, unsigned short ndicpages, unsigned char *entry, unsigned entrylen )
{
    unsigned short      uStartIndex;
    unsigned short      uStep;
    unsigned short      uStartPage;
    unsigned short      uPageStep;
    unsigned short      uIndex;
    unsigned short      uPage;
    unsigned short      n;
    unsigned            u;
    unsigned            nbytes;
    unsigned char       *aP;
    unsigned char       *zP;

    aP = entry;
    zP = aP + entrylen;         // point at last char in identifier

    uStartPage  = 0;
    uPageStep   = 0;
    uStartIndex = 0;
    uStep       = 0;

    u = entrylen;
    while ( u-- )
    {
        uStartPage  = _rotl( uStartPage,  2 ) ^ ( *aP   | 0x20 );
        uStep       = _rotr( uStep,       2 ) ^ ( *aP++ | 0x20 );
        uStartIndex = _rotr( uStartIndex, 2 ) ^ ( *zP   | 0x20 );
        uPageStep   = _rotl( uPageStep,   2 ) ^ ( *zP-- | 0x20 );
    }

    uStartPage %= ndicpages;
    uPageStep  %= ndicpages;
    if ( uPageStep == 0 )
        uPageStep++;
    uStartIndex %= HASHMOD;
    uStep       %= HASHMOD;
    if ( uStep == 0 )
        uStep++;

    uPage = uStartPage;
    uIndex = uStartIndex;

    // number of bytes in entry
    nbytes = 1 + entrylen + 2;
    if (entrylen > 255)
        nbytes += 2;

    while (1)
    {
        aP = &bucketsP[uPage * BUCKETPAGE];
        uStartIndex = uIndex;
        while (1)
        {
            if ( 0 == aP[ uIndex ] )
            {
                // n = next available position in this page
                n = aP[ HASHMOD ] << 1;
                assert(n > HASHMOD);

                // if off end of this page
                if (n + nbytes > BUCKETPAGE )
                {   aP[ HASHMOD ] = 0xFF;
                    break;                      // next page
                }
                else
                {
                    aP[ uIndex ] = n >> 1;
                    memcpy( (aP + n), entry, nbytes );
                    aP[ HASHMOD ] += (nbytes + 1) >> 1;
                    if (aP[HASHMOD] == 0)
                        aP[HASHMOD] = 0xFF;
                    return 1;
                }
            }
            uIndex += uStep;
            uIndex %= 0x25;
            /*if (uIndex > 0x25)
                uIndex -= 0x25;*/
            if( uIndex == uStartIndex )
                break;
        }
        uPage += uPageStep;
        if (uPage >= ndicpages)
            uPage -= ndicpages;
        if( uPage == uStartPage )
            break;
    }
Exemplo n.º 11
0
void save()
{
	int stocks = 0;
	FILE *save = fopen("save.ns3", "wb");

	for (now = head->next; now; now = now->next) stocks++;
	fprintf(save, "%d ", _rotl(stocks, 1));

	for (now = head->next; now; now = now->next)
		fprintf(save, "%d %d ", _rotl(now->company, 1), _rotl(now->price, 1));

	for (int i = 0; i < MAX_COMPANY; i++)
		fprintf(save, "%d ", _rotl(StockPrice[i], 1));

	for (int i = 0; i < MAX_COMPANY; i++)
		fprintf(save, "%d ", _rotl(ifGood[i], 1));

	fprintf(save, "%d %d %d %d %d %d %d %d %d", _rotl(Money, 1), _rotl(loanMoney, 1), _rotl(Stocks, 1), _rotl(StockDeal, 1),
		_rotl(month, 1), _rotl(day, 1), _rotl(hour, 1), viewmode, timemode);

	fclose(save);
}
Exemplo n.º 12
0
int xcrush_compute_chunks(XCRUSH_CONTEXT* xcrush, BYTE* data, UINT32 size, UINT32* pIndex)
{
	UINT32 i = 0;
	UINT32 offset = 0;
	UINT32 rotation = 0;
	UINT32 accumulator = 0;

	*pIndex = 0;
	xcrush->SignatureIndex = 0;

	if (size < 128)
		return 0;

	for (i = 0; i < 32; i++)
	{
		rotation = _rotl(accumulator, 1);
		accumulator = data[i] ^ rotation;
	}

	for (i = 0; i < size - 64; i++)
	{
		rotation = _rotl(accumulator, 1);
		accumulator = data[i + 32] ^ data[i] ^ rotation;

		if (!(accumulator & 0x7F))
		{
			if (!xcrush_append_chunk(xcrush, data, &offset, i + 32))
				return 0;
		}
		i++;

		rotation = _rotl(accumulator, 1);
		accumulator = data[i + 32] ^ data[i] ^ rotation;

		if (!(accumulator & 0x7F))
		{
			if (!xcrush_append_chunk(xcrush, data, &offset, i + 32))
				return 0;
		}
		i++;

		rotation = _rotl(accumulator, 1);
		accumulator = data[i + 32] ^ data[i] ^ rotation;

		if (!(accumulator & 0x7F))
		{
			if (!xcrush_append_chunk(xcrush, data, &offset, i + 32))
				return 0;
		}
		i++;

		rotation = _rotl(accumulator, 1);
		accumulator = data[i + 32] ^ data[i] ^ rotation;

		if (!(accumulator & 0x7F))
		{
			if (!xcrush_append_chunk(xcrush, data, &offset, i + 32))
				return 0;
		}
	}

	if ((size == offset) || xcrush_append_chunk(xcrush, data, &offset, size))
	{
		*pIndex = xcrush->SignatureIndex;
		return 1;
	}

	return 0;
}
Exemplo n.º 13
0
BOOL
FASTCALL
GetCharOutline(
    IN     LONG            Unknown,
           PVOID,
    IN     PVOID           pThis,
    IN     ULONG           Height,
    IN     WCHAR           uChar,
    OUT    PULONG          pBitsPerRow,
    IN OUT PULONG          pDescent,
    IN OUT ALICE_MEMORY   *pMem
)
{
    HDC   hDC;
    HFONT hFont;
    ULONG FontIndex, OutlineSize, BytesPerRow, BitsOfLeftSpace;
    GLYPHMETRICS GlyphMetrics;
    BYTE  Buffer[0x5000];
    PBYTE pbOutline, pbBuffer;
    FONT_OUTLINE_INFO *pOutlineInfo;

    static FONT_OUTLINE_INFO *s_pOutlineInfo;
    static MAT2  mat = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };

    pOutlineInfo = s_pOutlineInfo;
    if (s_pOutlineInfo == NULL)
    {
        HANDLE hHeap = CMem::GetGlobalHeap();
        if (hHeap == NULL)
        {
            hHeap = CMem::CreateGlobalHeap();
            if (hHeap == NULL)
                goto DEFAULT_PROC;
        }

        pOutlineInfo = (FONT_OUTLINE_INFO *)HeapAlloc(hHeap, 0, sizeof(*pOutlineInfo));
        if (pOutlineInfo == NULL)
            goto DEFAULT_PROC;

        s_pOutlineInfo = pOutlineInfo;

        pOutlineInfo->hDC = NULL;
        pOutlineInfo->LastFontIndex = -1;
        ZeroMemory(pOutlineInfo->hFont, sizeof(pOutlineInfo->hFont));
        FillMemory(pOutlineInfo->Descent, sizeof(pOutlineInfo->Descent), -1);
    }

    if (Unknown < 0 || IsCharSpec(uChar))
        goto DEFAULT_PROC;

    FontIndex = Height / FONT_STEP;
    if (FontIndex > countof(pOutlineInfo->hFont))
        goto DEFAULT_PROC;

    hDC = pOutlineInfo->hDC;
    if (hDC == NULL)
    {
        hDC = CreateCompatibleDC(NULL);
        if (hDC == NULL)
            goto DEFAULT_PROC;

        pOutlineInfo->hDC = hDC;
    }

    hFont = pOutlineInfo->hFont[FontIndex];
    if (hFont == NULL)
    {
        LOGFONTW lf;

        ZeroMemory(&lf, sizeof(lf));
        lf.lfHeight = Height;
        lf.lfWeight = FW_NORMAL;
        lf.lfCharSet = GB2312_CHARSET;
        lf.lfQuality = CLEARTYPE_QUALITY;
        lf.lfPitchAndFamily = FIXED_PITCH;
        CopyStruct(lf.lfFaceName, g_szFaceName, sizeof(g_szFaceName));

        hFont = CreateFontIndirectW(&lf);
        if (hFont == NULL)
            goto DEFAULT_PROC;

        pOutlineInfo->hFont[FontIndex] = hFont;
    }

    if (FontIndex != pOutlineInfo->LastFontIndex)
    {
        if (SelectObject(hDC, hFont) == HGDI_ERROR)
            goto DEFAULT_PROC;

        pOutlineInfo->LastFontIndex = FontIndex;
    }

    if (pDescent != NULL)
    {
        TEXTMETRICW tm;

        tm.tmDescent = pOutlineInfo->Descent[FontIndex];
        if (tm.tmDescent == -1)
        {
            if (GetTextMetricsW(hDC, &tm))
                pOutlineInfo->Descent[FontIndex] = tm.tmDescent;
            else
                ++tm.tmDescent;
        }

        *pDescent = tm.tmDescent;
        if (pBitsPerRow == NULL)
            return TRUE;
    }

    uChar = MBCharToUnicode(uChar);
    OutlineSize = GetGlyphOutlineW(
                    hDC,
                    uChar,
                    GGO_BITMAP,
                    &GlyphMetrics,
                    sizeof(Buffer),
                    pThis == NULL ? NULL : Buffer,
                    &mat);
    if (OutlineSize == GDI_ERROR)
        goto DEFAULT_PROC;

#if 0
    ULONG DwordOfLeftSpace, BytesPerRowRaw, Mask;
    static BYTE Bits[FONT_COUNT] = 
    {
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x16,
        0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
        0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
        0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
        0x29, 0x2A, 0x2B, 0x2C
    };

    BitsOfLeftSpace = Bits[FontIndex];
    BitsOfLeftSpace = 4;
    DwordOfLeftSpace = BitsOfLeftSpace / 8 / 4;
    if (pBitsPerRow != NULL)
        *pBitsPerRow = GlyphMetrics.gmBlackBoxX + BitsOfLeftSpace % bitsof(DWORD) + DwordOfLeftSpace * 4 * 8;

    if (pDescent != NULL)
    {
        TEXTMETRICW tm;

        tm.tmDescent = s_Descent[FontIndex];
        if (tm.tmDescent == -1)
        {
            if (GetTextMetricsW(hDC, &tm))
                s_Descent[FontIndex] = tm.tmDescent;
            else
                ++tm.tmDescent;
        }

        *pDescent = tm.tmDescent;
    }

    if (pThis == NULL)
        return TRUE;

    BytesPerRow = GlyphMetrics.gmBlackBoxX + BitsOfLeftSpace;
    BytesPerRow = ROUND_UP(BytesPerRow, bitsof(DWORD)) / 8;
    BitsOfLeftSpace %= bitsof(DWORD);

    ChipSpriteEngAllocMemory(pMem, BytesPerRow * Height);
    if (pMem->pvBufferEnd == pMem->pvBuffer)
        goto DEFAULT_PROC;

    ZeroMemory(pMem->pvBuffer, BytesPerRow * Height);

    BytesPerRowRaw = ROUND_UP(GlyphMetrics.gmBlackBoxX, bitsof(DWORD)) / 8;

    pbBuffer   = Buffer;
    pbOutline  = (PBYTE)pMem->pvBuffer;
    pbOutline += (GlyphMetrics.gmBlackBoxY - 1) * BytesPerRow;
    pbOutline += ((Height - GlyphMetrics.gmBlackBoxY) / 2 - 1) * BytesPerRow;
    pbOutline += DwordOfLeftSpace * 4;
    Mask = _rotl(1, BitsOfLeftSpace) - 1;

    for (ULONG i = GlyphMetrics.gmBlackBoxY; i; --i)
    {
        PBYTE pbOutline2, pbBuffer2;
        DWORD BitsHigh, BitsLow;

        BitsHigh = 0;
        BitsLow = 0;
        pbBuffer2 = pbBuffer;
        pbOutline2 = pbOutline;
        for (ULONG Count = BytesPerRowRaw / 4; Count; --Count)
        {
            DWORD v = *(PDWORD)pbBuffer2;

            BitsHigh = _rotl(v, BitsOfLeftSpace) & Mask;
            v = (v << BitsOfLeftSpace) | BitsLow;
            BitsLow = BitsHigh;
            *(PDWORD)pbOutline2 = v;
            pbOutline2 += 4;
            pbBuffer2  += 4;
        }
//        *(PDWORD)pbOutline2 = BitsLow;

        pbOutline -= BytesPerRow;
        pbBuffer  += BytesPerRowRaw;
    }

    WCHAR buf[0x500];
    wsprintfW(
        buf - 1 + GetTextFaceW(hDC, countof(buf),
        buf),
        L" Char = %c Index = %02u Bits = %02X",
        uChar,
        FontIndex + 1,
        BitsOfLeftSpace);
    SetWindowTextW(GetActiveWindow(), buf);

#else
    ULONG BytesPerRowRaw;
    static BYTE Bits[FONT_COUNT] = 
    {
        0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x16,
        0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
        0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E,
        0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
        0x29, 0x2A, 0x2B, 0x2C
    };

    BitsOfLeftSpace = Bits[FontIndex];

    if (pBitsPerRow != NULL)
        *pBitsPerRow = GlyphMetrics.gmBlackBoxX + BitsOfLeftSpace;


    if (pThis == NULL)
        return TRUE;

    BytesPerRow = GlyphMetrics.gmBlackBoxX + BitsOfLeftSpace;
    BytesPerRow = ROUND_UP(BytesPerRow, bitsof(DWORD)) / 8;

    ChipSpriteEngAllocMemory(pMem, BytesPerRow * Height);
    if (pMem->pvBufferEnd == pMem->pvBuffer)
        goto DEFAULT_PROC;

    ZeroMemory(pMem->pvBuffer, BytesPerRow * Height);

    BytesPerRowRaw = ROUND_UP(GlyphMetrics.gmBlackBoxX, bitsof(DWORD)) / 8;

    pbBuffer   = Buffer;
    pbOutline  = (PBYTE)pMem->pvBuffer;
    pbOutline += (GlyphMetrics.gmBlackBoxY - 1) * BytesPerRow;
    pbOutline += ((Height - GlyphMetrics.gmBlackBoxY) / 2 - 1) * BytesPerRow;

    for (ULONG i = GlyphMetrics.gmBlackBoxY; i; --i)
    {
        __movsd(pbOutline, pbBuffer, BytesPerRowRaw / 4);
        pbOutline -= BytesPerRow;
        pbBuffer  += BytesPerRowRaw;
    }
#endif

    return TRUE;

DEFAULT_PROC:
    if (pThis == NULL)
        return FALSE;

    return OldGetCharOutline(Unknown, 0, pThis, Height, uChar, pBitsPerRow, pDescent, pMem);
}
Exemplo n.º 14
0
void Renderer::SetForeground(COLOR _color) { SetConsoleTextAttribute(_output, (_foreground = _rotl(_color, 4)) | _background); }