Ejemplo n.º 1
0
static void
check_trigger(packet_info_t *packet, iprecord_t *rec)
{
	trigger_t *i;
	flowdata_t *flow;

	flow = ipstate_lookup_flowdata(rec, packet->ip_type);
	if (flow == NULL)
		return;

	for (i = t_list[packet->ip_type]; i != NULL; i = i->next)
	{
		int pps, mbps;
		int do_trigger = 0, nullable_trigger = 0, threshold_trigger = 0;

		DPRINTF("check trigger packet %p record %p protocol %d pktproto %d\n", packet, rec, i->protocol, packet->ip_type);

		mbps = (int) floor((flow->flow / 1000000.));
		pps = flow->pps;

		DPRINTF("... pps %d mbps %d target_pps %d target_mbps %d\n", pps, mbps, i->target_pps, i->target_mbps);

		if (i->target_pps && (pps > i->target_pps))
			do_trigger = 1;

		if (i->target_mbps && (mbps > i->target_mbps))
			do_trigger = 1;

		if (i->target_mbps && (mbps < i->target_mbps))
			do_trigger = 0;

		if (i->below_mbps && (mbps > i->below_mbps))
			do_trigger = 0;

		if (i->tcp_synonly && packet->tcp_flags != TCP_SYN)
			do_trigger = 0;

		if (i->target_flowcount && flow->count < i->target_flowcount)
			do_trigger = 0;

		DPRINTF("trigger %p conditions %s for flow %p\n", i, do_trigger == 1 ? "met" : "not met", rec);

		if (do_trigger)
			HOOK_CALL(HOOK_CHECK_EXEMPT, packet, rec, &do_trigger);
			DPRINTF("HOOK_CHECK_EXEMPT result %d\n", do_trigger);
			HOOK_CALL(HOOK_CHECK_NULLABLE, packet, rec, &nullable_trigger);
			DPRINTF("HOOK_CHECK_NULLABLE result %d\n", nullable_trigger);
			HOOK_CALL(HOOK_CHECK_THRES, packet, rec, &threshold_trigger, pps, mbps, i->target_pps, i->target_mbps);
			DPRINTF("HOOK_CHECK_THRES result %d\n", threshold_trigger);

		if (do_trigger && nullable_trigger && !threshold_trigger)
			trigger_ban(i, packet, rec);
	}
}
Ejemplo n.º 2
0
static void
check_trigger(packet_info_t *packet, iprecord_t *rec)
{
	trigger_t *i;
	flowdata_t *flow;

	flow = ipstate_lookup_flowdata(rec, packet->ip_type);
	if (flow == NULL)
		return;

	for (i = t_list[packet->ip_type]; i != NULL; i = i->next)
	{
		int pps, mbps;
		int do_trigger = 0;
		float mbps_ratio, pps_ratio;

		DPRINTF("check trigger packet %p record %p protocol %d pktproto %d\n", packet, rec, i->protocol, packet->ip_type);

		mbps = (int) floor((flow->flow / 1000000.));
		pps = flow->pps;

		mbps_ratio = (float) ((flow->count + 1) / (mbps + 1));
		pps_ratio = (float) ((flow->count + 1) / (pps + 1));

		if (i->flow_mbps_ratio > 0.0 && i->flow_mbps_ratio < mbps_ratio)
			do_trigger = 1;

		if (i->flow_pps_ratio > 0.0 && i->flow_pps_ratio < pps_ratio)
			do_trigger = 1;

		if (i->minimum_flows && i->minimum_flows > flow->count)
			do_trigger = 0;

		if (i->minimum_mbps && i->minimum_mbps > mbps)
			do_trigger = 0;

		if (i->minimum_pps && i->minimum_pps > pps)
			do_trigger = 0;

		DPRINTF("trigger %p conditions %s for flow %p\n", i, do_trigger == 1 ? "met" : "not met", rec);

		if (do_trigger)
			HOOK_CALL(HOOK_CHECK_EXEMPT, packet, rec, &do_trigger);

		DPRINTF("HOOK_CHECK_EXEMPT result %d\n", do_trigger);

		if (do_trigger)
			trigger_ban(i, packet, rec);
	}
}
Ejemplo n.º 3
0
	void Unload(){
		
		HOOK_CALL( 0x004018A0, 0x00401C8A ); // ReferencedPortraits
		HOOK_CALL( 0x004018A0, 0x00401E21 ); // ReferencedPortraits
		HOOK_CALL( 0x0041EC00, 0x0042A3C6 ); // PortraitShutdown
		HOOK_CALL( 0x0041EB40, 0x00428A1F ); // PortraitInit
		*((BYTE*)0x0041EE08) = 0x3F; // max head_db entries
		*((BYTE*)0x0041EC9B) = 0x3F; // max head_db entries

		memcpy( (void*)0x004184B0, "\x8B\x44\x24\x04\x8D", 5 );
		memcpy( (void*)0x004184D0, "\x8B\x44\x24\x04\x8D", 5 );
		memcpy( (void*)0x004184F0, "\x8B\x44\x24\x04\x8D", 5 );
		memcpy( (void*)0x00418510, "\x56\x57\x66\x33\xF6", 5 ); 
		memcpy( (void*)0x00418540, "\x8B\x44\x24\x04\x8D", 5 );
		memcpy( (void*)0x0042B510, "\x81\xEC\x00\x01\x00", 5 ); 
		memcpy( (void*)0x0042B600, "\xB8\x78\xEB\x4C\x00", 5 ); 
		memcpy( (void*)0x0042B9E0, "\x81\xEC\x00\x01\x00", 5 );
		*((DWORD*)0x004018DF) = 0x004CFBD0; // Portrait_First
		*((DWORD*)0x00401910) = 0x004D09E8; // Portrait_Last
		*((DWORD*)0x0041D3A5) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0042459C) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0042BD81) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0042BEDD) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0042E238) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0042B705) = 0x004CEB78; // &(SpriteTable[0].loaded_index)
		*((DWORD*)0x0047FE01) = 0x004EBC88; // offset_table
		*((DWORD*)0x00526D24) = 0; // Loaded_Sprite_Array 	
		*((DWORD*)0x00526D2C) = 0; // Loaded_Banner_Array
		*((DWORD*)0x00409F11) = 0x004C0940; // troop_book_unit_pic
		*((DWORD*)0x00409F52) = 0x004C0940; // troop_book_unit_pic
		*((DWORD*)0x0040C0CC) = 0x004C0940; // troop_book_unit_pic
		*((DWORD*)0x0040C108) = 0x004C0940; // troop_book_unit_pic
		*((DWORD*)0x00409DE3) = 0x004C0A80; // troop_book_leader_pic
		*((DWORD*)0x0040BD24) = 0x004C0A80; // troop_book_leader_pic
		*((DWORD*)0x00409EC2) = 0x004E2640; // unit name
		*((DWORD*)0x0040B876) = 0x004E2640; // unit name
		*((DWORD*)0x0040BE4A) = 0x004E2640; // unit name
		*((DWORD*)0x0040C20F) = 0x004E2640; // unit name
		*((DWORD*)0x0040C461) = 0x004E2640; // unit name
		*((DWORD*)0x0040D213) = 0x004E2640; // unit name
		*((DWORD*)0x0040D9C3) = 0x004E2640; // unit name
		*((DWORD*)0x0041985C) = 0x004E2640; // unit name
		*((DWORD*)0x0041A5E4) = 0x004E2640; // unit name
		*((DWORD*)0x0041B1B0) = 0x004E2640; // unit name
		*((DWORD*)0x0041B4CA) = 0x004E2640; // unit name
		*((DWORD*)0x0042671A) = 0x004E2640; // unit name
		*((DWORD*)0x004286E1) = 0x004E2640; // unit name
		*((DWORD*)0x00409E63) = 0x004E2780; // unit_desc
		*((DWORD*)0x0040BDE0) = 0x004E2780; // unit_desc
		*((DWORD*)0x004099B5) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x00409DAD) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040B83D) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040BCE0) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040C1D5) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040C413) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040D97C) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0040E1E9) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x004192A4) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0041981E) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0041A39E) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0041A5A6) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0041B172) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x0041B48C) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x00425B26) = 0x004C0BC0; // small_banner_index
		*((DWORD*)0x00426DEB) = 0x004C0BC0; // small_banner_index

		for( int i = 80; i < 180; i++ ){
			if( troop_book_leader_pic[i] != NULL ){ 
				HeapFree( GetProcessHeap(), 0, troop_book_leader_pic[i] );
				troop_book_leader_pic[i] = NULL;
			}
			if( troop_book_unit_pic[i] != NULL ){ 
				HeapFree( GetProcessHeap(), 0, troop_book_unit_pic[i] );
				troop_book_unit_pic[i] = NULL; 
			}
			if( troop_book_unit_desc[i] != NULL ){ 
				HeapFree( GetProcessHeap(), 0, troop_book_unit_desc[i] );
				troop_book_unit_desc[i] = NULL;
			}
		}

	}
Ejemplo n.º 4
0
	void Load()
	{
		
		// parse text file
		std::string path = darkomen::modmenu::getCurrentModPath();

		if (path.empty())
		{
			return;
		}

		path += "\\PRG_ENG\\xslots.txt";

		if( 0xFFFFFFFF == getFileAttributes_orig( path.c_str() ) ) return;
		char* readbuf = ReadInFile( path.c_str() );
		if( readbuf == NULL ) return;		
		char* text = readbuf;
		int line = 1;
		while( *text != '\0' )
		{	
			// temp vars
			DWORD slot_id;
			char buf[ 12 ]; 
			DWORD len; 
			DWORD required_len;
			
			// scan till some content is found
			SkipWhiteSpaceAndComments( text );
			if( *text == '\r' ) text++;
			if( *text == '\n' ){ text++; line++; continue; }

			// 
			required_len = ReadOutWord( buf, sizeof(buf), text, &len );
			if( ( required_len > sizeof(buf) ) || ( required_len <= 1 ) ){
				Log( "xslot: Error ( line %d )", line );
				goto the_end;
			}
			text += len;
			SkipWhiteSpaceAndComments( text );
			//
			slot_id = ReadOutInteger( text, &len );
			if( len == 0 ){		
				Log( "xslot: Error expected slot_id ( line %d )", line );
				goto the_end;
			}
			text += len;
			SkipWhiteSpaceAndComments( text );
			//
			if( 0 == strcmp( buf, "SPRITE" ) ){
				if( slot_id > ( X_SPRITE_LAST - X_SPRITE_FIRST ) ){
					Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_SPRITE_LAST - X_SPRITE_FIRST ), line );
					goto the_end;
				}
				SPRITE_SLOT* p = &SpriteTable[ slot_id + X_SPRITE_FIRST ];
				//
				required_len = ReadOutWord( p->name, sizeof(p->name), text, &len );
				if( required_len > sizeof(p->name) ){
					Log( "xslot: Error %s exceeds max of %d ( line %d )", "sprite_file_name", sizeof(p->name), line );
					goto the_end;
				}
				if( len == 0 ){	continue; }
				text += len;
				SkipWhiteSpaceAndComments( text );
				//
				DWORD off = ReadOutInteger( text, &len );
				text += len;
				if( len == 0 ){	
					Log( "xslot: Error missing sprite_type_offset ( line %d )", line );
					goto the_end;
				}
				if( ( off > 0x0000023E ) || ( ( off % 0x000000E ) != 0 ) ){
					Log( "xslot: Error invalid value (0x%08X) for sprite_type_offset ( line %d )", off, line );
					goto the_end;
				}
				p->type_id = 8; // troop sprite
				offset_table[ slot_id + X_SPRITE_FIRST ] = (WORD)off;
			}
			else {
				if( 0 == strcmp( buf, "NAME" ) ){
					if( slot_id > ( X_NAME_LAST - X_NAME_FIRST ) ){
						Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_NAME_LAST - X_NAME_FIRST ), line );
						goto the_end;
					}
					required_len = ReadOutWord( &x_names[slot_id][0], 64, text, &len );
					if( len == 0 ){	continue; }
					text += len;
					if( required_len > 64 ){
						Log( "xslot: Error %s exceeds max of %d ( line %d )", "name", 64, line );
						goto the_end;
					}
					unit_name[ slot_id + X_NAME_FIRST ] = &x_names[slot_id][0];
				}
				else {
					if( 0 == strcmp( buf, "BANNER" ) ){
						if( slot_id > ( X_BANNER_LAST - X_BANNER_FIRST ) ){
							Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_BANNER_LAST - X_BANNER_FIRST ), line );
							goto the_end;
						}
						SPRITE_SLOT* p = &SpriteTable[ slot_id + X_BANNER_FIRST ];
						//
						required_len = ReadOutWord( p->name, sizeof(p->name), text, &len );
						if( required_len > sizeof(p->name) ){
							Log( "xslot: Error %s exceeds max of %d ( line %d )", "sprite_file_name", sizeof(p->name), line );
							goto the_end;
						}
						if( len == 0 ){	continue; }
						text += len;
						SkipWhiteSpaceAndComments( text );
						//
						DWORD shape = ReadOutInteger( text, &len );
						if( len == 0 ){	
							Log( "xslot: Error missing banner_shape_id ( line %d )", line );
							goto the_end;
						}
						text += len;
						p->banner_bkgrnd_id = shape;
					}
					else {
						if( 0 == strcmp( buf, "BOOK" ) ){
							if( slot_id > ( X_BOOK_LAST - X_BOOK_FIRST ) ){
								Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_BOOK_LAST - X_BOOK_FIRST ), line );
								goto the_end;
							}
							//
							troop_book_banner_index[ slot_id + X_BOOK_FIRST ] = (char) ReadOutInteger( text, &len );
							if( len == 0 ){	continue; }
							text += len;
							SkipWhiteSpaceAndComments( text );
							//
							required_len = ReadOutWord( 0, 0, text, &len );
							if( len == 0 ){
								Log( "xslot: Error missing leader_pic ( line %d )", line );
							}
							troop_book_leader_pic[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len );
							if( troop_book_leader_pic[ slot_id + X_BOOK_FIRST ] == NULL ){
								Log( "xslot: Alloc Failed ( line %d )", line );
								goto the_end;
							}
							ReadOutWord( troop_book_leader_pic[ slot_id + X_BOOK_FIRST ], required_len, text, &len );
							text += len;
							SkipWhiteSpaceAndComments( text );
							//
							required_len = ReadOutWord( 0, 0, text, &len );
							if( len == 0 ){
								Log( "xslot: Error missing troop_pic ( line %d )", line );
								goto the_end;
							}
							troop_book_unit_pic[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len );
							if( troop_book_unit_pic[ slot_id + X_BOOK_FIRST ] == NULL ){
								Log( "xslot: Alloc Failed ( line %d )", line );
								goto the_end;
							}
							ReadOutWord( troop_book_unit_pic[ slot_id + X_BOOK_FIRST ], required_len, text, &len );
							text += len;
							SkipWhiteSpaceAndComments( text );
							//
							required_len = ReadOutWord( 0, 0, text, &len );
							if( len == 0 ){
								Log( "xslot: Error missing troop_desc ( line %d )", line );
								goto the_end;
							}
							troop_book_unit_desc[ slot_id + X_BOOK_FIRST ] = (char*) HeapAlloc( GetProcessHeap(), 0, required_len );
							if( troop_book_unit_desc[ slot_id + X_BOOK_FIRST ] == NULL ){
								Log( "xslot: Alloc Failed ( line %d )", line );
								goto the_end;
							}
							ReadOutWord( troop_book_unit_desc[ slot_id + X_BOOK_FIRST ], required_len, text, &len );
							text += len;
						}
						else{
							if( 0 == strcmp( buf, "PORTRAIT" ) ){
								if( slot_id > ( X_PORTRAIT_LAST - X_PORTRAIT_FIRST ) ){
									Log( "xslot: Error %s exceeds max of %d ( line %d )", "slot_id", ( X_PORTRAIT_LAST - X_PORTRAIT_FIRST ), line );
									goto the_end;
								}
								DWORD m3d_id = ReadOutInteger( text, &len );
								if( len == 0 ){		
									Log( "xslot: Error expected m3d_id ( line %d )", line );
									goto the_end;
								}
								text += len;
								
								SPRITE_SLOT* p = &SpriteTable[ slot_id + X_PORTRAIT_FIRST ];
								p->loaded_index = m3d_id;
							}
							else {
								Log( "xslot: Error unrecognized command \"%s\" ( line %d )", buf, line );
								goto the_end;
							}
						}
					}
				}
			}
		} // while
		

		// copy original data in from the game executable
		memcpy( SpriteTable, (void*)0x004CEB50, 257 * sizeof( SPRITE_SLOT ) );
		memcpy( offset_table, (void*)0x004EBC88, 96 * sizeof( WORD ) );
		memcpy( unit_name, (void*)0x004E2640, 0x50 * sizeof( char* ) );
		memcpy( troop_book_unit_pic, (void*)0x004C0940, 0x50 * sizeof( char* ) );
		memcpy( troop_book_leader_pic, (void*)0x004C0A80, 0x50 * sizeof( char* ) );
		memcpy( troop_book_unit_desc, (void*)0x004E2780, 0x50 * sizeof( char* ) );
		memcpy( troop_book_banner_index,  (void*)0x004C0BC0, 0x50 * sizeof( char ) );

		// install hooks
		HOOK_CALL( &ReferencedPortraits, 0x00401C8A );
		HOOK_CALL( &ReferencedPortraits, 0x00401E21 );
		HOOK_CALL( PortraitShutdown, 0x0042A3C6 );
		HOOK_CALL( PortraitInit, 0x00428A1F );
		*((BYTE*)0x0041EE08) = 0x7F; // override max head_db entries (0x3F)
		*((BYTE*)0x0041EC9B) = 0x7F; // override max head_db entries (0x3F)
		WRITE_JMP( GetType, 0x004184B0 );
		WRITE_JMP( AddRef, 0x004184D0 );
		WRITE_JMP( Release, 0x004184F0 );
		WRITE_JMP( ZeroRef, 0x00418510 );
		WRITE_JMP( GetLoadedIndex, 0x00418540 );
		WRITE_JMP( LoadReferencedSprites, 0x0042B510 );
		WRITE_JMP( LoadedSpriteArrayUnloaded, 0x0042B600 );
		WRITE_JMP( LoadReferencedBanners, 0x0042B9E0 );
		*((SPRITE_SLOT**)0x004018DF) = &SpriteTable[ PORTRAIT_FIRST ]; // sub_4018A0 ( PortraitsInit )
		*((SPRITE_SLOT**)0x00401910) = &SpriteTable[ PORTRAIT_LAST ]; // sub_4018A0 ( PortraitsInit )
		*((DWORD**)0x0041D3A5) = &(SpriteTable[0].loaded_index); // sub_41D360 ( WHMTG_SpeakNoWait )
		*((DWORD**)0x0042459C) = &(SpriteTable[0].loaded_index); // sub_424530 ( ?? )
		*((DWORD**)0x0042BD81) = &(SpriteTable[0].loaded_index); // sub_42BCC0 ( ?? )
		*((DWORD**)0x0042BEDD) = &(SpriteTable[0].loaded_index); // sub_42BCC0 ( ?? )
		*((DWORD**)0x0042E238) = &(SpriteTable[0].loaded_index); // sub_42E1E0 ( ?? )
		*((DWORD**)0x0042B705) = &(SpriteTable[0].loaded_index); // sub_42B6A0 ( ?? )
		*((WORD**) 0x0047FE01) = offset_table; // sub_47FDF0 ( get sprite type info by id...? )
		*((DWORD*)0x00526D24) = (DWORD)&Loaded_Sprite_Array; 	
		*((DWORD*)0x00526D2C) = (DWORD)&Loaded_Banner_Array;
		*((DWORD*)0x00409F11) = (DWORD)troop_book_unit_pic;
		*((DWORD*)0x00409F52) = (DWORD)troop_book_unit_pic; 
		*((DWORD*)0x0040C0CC) = (DWORD)troop_book_unit_pic; 
		*((DWORD*)0x0040C108) = (DWORD)troop_book_unit_pic; 
		*((DWORD*)0x00409DE3) = (DWORD)troop_book_leader_pic;
		*((DWORD*)0x0040BD24) = (DWORD)troop_book_leader_pic;
		*((DWORD*)0x00409EC2) = (DWORD)unit_name;
		*((DWORD*)0x0040B876) = (DWORD)unit_name;
		*((DWORD*)0x0040BE4A) = (DWORD)unit_name;
		*((DWORD*)0x0040C20F) = (DWORD)unit_name;
		*((DWORD*)0x0040C461) = (DWORD)unit_name;
		*((DWORD*)0x0040D213) = (DWORD)unit_name;
		*((DWORD*)0x0040D9C3) = (DWORD)unit_name;
		*((DWORD*)0x0041985C) = (DWORD)unit_name;
		*((DWORD*)0x0041A5E4) = (DWORD)unit_name;
		*((DWORD*)0x0041B1B0) = (DWORD)unit_name;
		*((DWORD*)0x0041B4CA) = (DWORD)unit_name;
		*((DWORD*)0x0042671A) = (DWORD)unit_name;
		*((DWORD*)0x004286E1) = (DWORD)unit_name;
		*((DWORD*)0x00409E63) = (DWORD)troop_book_unit_desc; 
		*((DWORD*)0x0040BDE0) = (DWORD)troop_book_unit_desc;
		*((DWORD*)0x004099B5) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x00409DAD) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040B83D) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040BCE0) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040C1D5) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040C413) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040D97C) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0040E1E9) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x004192A4) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0041981E) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0041A39E) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0041A5A6) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0041B172) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x0041B48C) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x00425B26) = (DWORD)troop_book_banner_index;
		*((DWORD*)0x00426DEB) = (DWORD)troop_book_banner_index;

	the_end:
		VirtualFree( readbuf, 0, MEM_RELEASE );
		return;
	}