Exemple #1
0
void *HookAPI(LPVOID lpFunc,LPVOID lpHandler)
{
    void *lpRet=NULL;
    if (GetHookInfo(lpFunc))
        UnhookAPI(lpFunc);

    if (NumOfHooks < MAX_HOOKS-1)
    {
        void *lpBackup=MemAlloc(JUMP_SIZE*4);
        ULONG_PTR *lpTable=0;
#ifdef _AMD64_
        lpTable=(ULONG_PTR *)MemAlloc(sizeof(ULONG_PTR)*MAX_JUMPS);
        LPVOID lpRelay=malloc_SomewhereAroundHere(lpFunc,sizeof(JMP_REL));
        if (!lpRelay)
        {
            MemFree(lpBackup);
            return lpRet;
        }
#endif
        SIZE_T dwBackupCodeSize=0;
        void *lpBridge=CreateBridge(lpFunc,lpBackup,&dwBackupCodeSize,&lpTable[1]);
        if (lpBridge)
        {
            EnterCriticalSection(&csHookApi);

                hooks[NumOfHooks].lpRealFunc=lpFunc;
                hooks[NumOfHooks].lpBridge=lpBridge;
                hooks[NumOfHooks].lpHandler=lpHandler;
                hooks[NumOfHooks].lpBackup=lpBackup;
                hooks[NumOfHooks].dwCodeSize=dwBackupCodeSize;
#ifdef _AMD64_
                hooks[NumOfHooks].lpRelay=lpRelay;
                hooks[NumOfHooks].lpTable=lpTable;
                WriteAbsoluteJump(lpRelay,lpHandler,lpTable);
                WriteRelativeJump(lpFunc,lpRelay);
#else
                WriteRelativeJump(lpFunc,lpHandler);
#endif
                NumOfHooks++;
                lpRet=lpBridge;

            LeaveCriticalSection(&csHookApi);
        }
    }
    return lpRet;
}
Exemple #2
0
stdc
BOOL __cdecl HookFunction(ULONG_PTR OriginalFunction, ULONG_PTR NewFunction, char *name, hookType ht)
{

	lastErrorCode = he_None;
	specificError = hs_None;
    lastError[0] = 0;

	if(!initilized){
		if( !InitHookEngine() ){
			lastErrorCode = he_cantInit;
			strcpy(lastError,"Can not Initilize HookEngine.");
			dbgmsg(1,lastError);
			return FALSE;
		}
	}

	HOOK_INFO *hinfo = GetHookInfoFromFunction(OriginalFunction);

	if (hinfo) return TRUE; //already hooked...

	if (g_NumberOfHooks == (MAX_HOOKS - 1)){
		lastErrorCode = he_maxHooks;
		strcpy(lastError,"Maximum number of hooks reached.");
		dbgmsg(1,lastError);
		return FALSE;
	}

	if(ht > ht_auto){
	   sprintf(lastError, "Unimplemented hook type asked for");
	   lastErrorCode = he_UnknownHookType;
	   return false;
	}

	hinfo = &g_HookInfo[g_NumberOfHooks];

	hinfo->Function = OriginalFunction;
	hinfo->Hook = NewFunction;
    hinfo->hooktype = ht;
	hinfo->index = g_NumberOfHooks;
	hinfo->ApiName = strdup(name);
	hinfo->preAlignBytes = CountPreAlignBytes( (BYTE*)OriginalFunction );
    hinfo->hookableBytes = HookableBytes( OriginalFunction );

	dbgmsg(1, "Hooking %s (0x%llx) -> 0x%llx, pre=%d avail=%d\n", hinfo->ApiName, hinfo->Function , hinfo->Hook , hinfo->preAlignBytes, hinfo->hookableBytes);

	if( ht == ht_auto ){
		if(!AutoChooseHookType(hinfo)){
			lastErrorCode = he_cantHook;
			dbgmsg(1, lastError);
			ZeroHookInfo(hinfo->index);
			return FALSE;
		}
		dbgmsg(1, "AutoChooseHookType selected %s for %s\n", hook_name[(int)hinfo->hooktype], hinfo->ApiName );
	}

	if( !ValidateHookType(hinfo) ){
		lastErrorCode = he_cantHook;
		dbgmsg(1, lastError);
		ZeroHookInfo(hinfo->index);
		return FALSE;
	}

	VOID *pBridge = CreateBridge(hinfo);

	if (pBridge == NULL){
		ZeroHookInfo(g_NumberOfHooks);
		return FALSE;
	}

	hinfo->Bridge = (ULONG_PTR) pBridge;
	hinfo->Enabled = true;

	OverWriteScratchPad((VOID *)OriginalFunction, hinfo); //make pad were going to overwrite all 0xCC for debugging sake..

	if(!WriteJump((VOID *) OriginalFunction, NewFunction, hinfo->hooktype, g_NumberOfHooks)){ //activates hook in api prolog..
		ZeroHookInfo(g_NumberOfHooks);
		return FALSE;
	}

	g_NumberOfHooks++; //now its complete..
	return TRUE;
}
Exemple #3
0
//----------------------------------------------------------------------------
void Castle::CreateScene ()
{
    mScene = new0 Node();
    mTrnNode = new0 Node();
    mScene->AttachChild(mTrnNode);
    mWireState = new0 WireState();
    mRenderer->SetOverrideWireState(mWireState);

    CreateLights();
    CreateEffects();
    CreateTextures();
    CreateSharedMeshes();

    CreateWallTurret02();
    CreateWallTurret01();
    CreateWall02();
    CreateWall01();
    CreateQuadPatch01();
    CreateMainGate01();
    CreateMainGate();
    CreateExterior();
    CreateFrontHall();
    CreateFrontRamp();
    CreateDrawBridge();
    CreateCylinder02();
    CreateBridge();
    CreateLargePort();
    CreateSmallPort(1);
    CreateSmallPort(2);
    CreateRope(1);
    CreateRope(2);

    int i;
    for (i = 1; i <= 7; ++i)
    {
        CreateWoodShield(i);
    }
    for (i = 1; i <= 17; ++i)
    {
        CreateTorch(i);
    }
    for (i = 1; i <= 3; ++i)
    {
        CreateKeg(i);
    }
    for (i = 2; i <= 37; ++i)
    {
        CreateBarrel(i);
    }
    for (i = 1; i <= 48; ++i)
    {
        CreateDoorFrame(i);
    }
    for (i = 49; i <= 60; ++i)
    {
        CreateDoorFramePivotTrn(i);
    }
    CreateDoorFrame(61);
    CreateDoorFrameScalePivotTrn(62);
    CreateDoorFrameScalePivotTrn(63);
    for (i = 64; i <= 68; ++i)
    {
        CreateDoorFrame(i);
    }
    for (i = 69; i <= 78; ++i)
    {
        CreateDoorFramePivotTrn(i);
    }
    CreateDoorFrame(79);
    CreateDoorFrameScalePivotTrn(80);
    CreateDoorFrameScalePivotTrn(81);
    CreateDoorFramePivotTrn(82);
    CreateDoorFramePivotTrn(83);
    CreateDoorFramePivotTrn(73);

    CreateBunk(1);
    for (i = 4; i <= 20; ++i)
    {
        CreateBunk(i);
    }
    for (i = 1; i <= 36; ++i)
    {
        CreateBench(i);
    }
    for (i = 1; i <= 9; ++i)
    {
        CreateTable(i);
    }
    for (i = 1; i <= 4; ++i)
    {
        CreateBarrelRack(i);
    }
    for (i = 1; i <= 36; ++i)
    {
        CreateChest(i);
    }
    for (i = 1; i <= 3; ++i)
    {
        CreateCeilingLight(i);
    }
    for (i = 1; i <= 7; ++i)
    {
        CreateSquareTable(i);
    }
    for (i = 1; i <= 27; ++i)
    {
        CreateSimpleChair(i);
    }
    for (i = 1; i <= 42; ++i)
    {
        CreateMug(i);
    }
    for (i = 1; i <= 9; ++i)
    {
        CreateDoor(i);
    } 

    CreateTerrain();
    CreateSkyDome();
    CreateWater();
    CreateWater2();
}