Esempio n. 1
0
void fatal(const char* error, const char* extra)
	{
	if (! cmdlineoptions.unattended)
		// deliberately not capitalized since usually out of our control
		message("Fatal Error", error, 10 * 1000); // 10 seconds
	fatal_log(error, extra); // assume we've lost connection
	}
Esempio n. 2
0
Region get_static_region() {
	char exefile[512];
	GetModuleFileName(NULL, exefile, sizeof(exefile));

	HANDLE hFile = CreateFile(exefile, GENERIC_READ, FILE_SHARE_READ, NULL,
		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
	if (hFile == INVALID_HANDLE_VALUE)
		fatal_log("get_static_region: unable to open exe");

	HANDLE hFileMapping =
		CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
	if (hFileMapping == 0)
		fatal_log("get_static_region: unable to create mappping of exe");

	void* lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
	if (lpFileBase == 0)
		fatal_log("get_static_region: unable to map view of exe");

	IMAGE_DOS_HEADER* dosHeader = (PIMAGE_DOS_HEADER) lpFileBase;
	if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE)
		fatal_log("get_static_region: bad magic");

	IMAGE_NT_HEADERS* pNTHeader =
		(PIMAGE_NT_HEADERS)((DWORD) dosHeader + dosHeader->e_lfanew);
	if (IsBadReadPtr(pNTHeader, sizeof(IMAGE_NT_HEADERS)) ||
		pNTHeader->Signature != IMAGE_NT_SIGNATURE)
		fatal_log("get_static_region: unknown exe type");

	Region region;
	region.start = 0;
	IMAGE_SECTION_HEADER* section = (IMAGE_SECTION_HEADER*) (pNTHeader + 1);
	for (int i = 0; i < pNTHeader->FileHeader.NumberOfSections;
		 ++i, ++section) {
		printf("name: %s address: %x size: %d\n", section->Name,
			(int) section->VirtualAddress, (int) section->Misc.VirtualSize);
		if (0 == strcmp((char*) section->Name, ".data")) {
			region.start = (void*) (0x400000 + section->VirtualAddress);
			region.end =
				(void*) ((char*) region.start + section->Misc.VirtualSize);
			break;
		}
	}
	if (!region.start)
		fatal_log("get_static_region: couldn't find .data section");

	UnmapViewOfFile(lpFileBase);
	CloseHandle(hFileMapping);
	CloseHandle(hFile);

	return region;
}
Esempio n. 3
0
int test_hello()
{
	LOG		*g = NULL ;
	
	char		buffer[ 64 + 1 ] = "" ;
	long		buflen = sizeof(buffer) - 1 ;
	
	g = create_log_handle() ;
	if( g == NULL )
	{
		printf( "create log handle failed , errno[%d]\n" , errno );
		return -1;
	}
	
	printf( "create log handle ok\n" );
	
	set_log_output( g , LOG_OUTPUT_FILE , "$HOME$/log/test_hello.log" , LOG_NO_OUTPUTFUNC );
	set_log_level( g , LOG_LEVEL_INFO );
	set_log_styles( g , LOG_STYLES_HELLO , LOG_NO_STYLEFUNC );
	
	debug_log( g , __FILE__ , __LINE__ , "hello DEBUG" );
	info_log( g , __FILE__ , __LINE__ , "hello INFO" );
	warn_log( g , __FILE__ , __LINE__ , "hello WARN" );
	error_log( g , __FILE__ , __LINE__ , "hello ERROR" );
	fatal_log( g , __FILE__ , __LINE__ , "hello FATAL" );
	
	debug_hex_log( g , __FILE__ , __LINE__ , buffer , buflen , "buflen[%ld]" , buflen );
	info_hex_log( g , __FILE__ , __LINE__ , buffer , buflen , "buflen[%ld]" , buflen );
	warn_hex_log( g , __FILE__ , __LINE__ , buffer , buflen , "buflen[%ld]" , buflen );
	error_hex_log( g , __FILE__ , __LINE__ , buffer , buflen , "buflen[%ld]" , buflen );
	fatal_hex_log( g , __FILE__ , __LINE__ , buffer , buflen , "buflen[%ld]" , buflen );
	
	destroy_log_handle( g );
	printf( "destroy log handle\n" );
	
	return 0;
}