Ejemplo n.º 1
0
static inline int read_SMARW()              { return read_dword(1,     23,1); }
Ejemplo n.º 2
0
static inline int read_SMARR()              { return read_dword(1,     21,1); }
Ejemplo n.º 3
0
static inline int read_SMALW()              { return read_dword(1,     22,1); }
GLubyte *                          /* O - Bitmap data */
LoadDIBitmap(const char *filename, /* I - File to load */
             BITMAPINFO **info)    /* O - Bitmap information */
    {
    FILE             *fp;          /* Open file pointer */
    GLubyte          *bits;        /* Bitmap pixel bits */
    GLubyte          *ptr;         /* Pointer into bitmap */
    GLubyte          temp;         /* Temporary variable to swap red and blue */
    int              x, y;         /* X and Y position in image */
    int              length;       /* Line length */
    int              bitsize;      /* Size of bitmap */
    int              infosize;     /* Size of header information */
    BITMAPFILEHEADER header;       /* File header */


    /* Try opening the file; use "rb" mode to read this *binary* file. */
    if ((fp = fopen(filename, "rb")) == NULL)
        return (NULL);

    /* Read the file header and any following bitmap information... */
    header.bfType      = read_word(fp);
    header.bfSize      = read_dword(fp);
    header.bfReserved1 = read_word(fp);
    header.bfReserved2 = read_word(fp);
    header.bfOffBits   = read_dword(fp);

    if (header.bfType != BF_TYPE) /* Check for BM reversed... */
        {
        /* Not a bitmap file - return NULL... */
        fclose(fp);
        return (NULL);
        }

    infosize = header.bfOffBits - 18;
    if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFO))) == NULL)
        {
        /* Couldn't allocate memory for bitmap info - return NULL... */
        fclose(fp);
        return (NULL);
        }

    (*info)->bmiHeader.biSize          = read_dword(fp);
    (*info)->bmiHeader.biWidth         = read_long(fp);
    (*info)->bmiHeader.biHeight        = read_long(fp);
    (*info)->bmiHeader.biPlanes        = read_word(fp);
    (*info)->bmiHeader.biBitCount      = read_word(fp);
    (*info)->bmiHeader.biCompression   = read_dword(fp);
    (*info)->bmiHeader.biSizeImage     = read_dword(fp);
    (*info)->bmiHeader.biXPelsPerMeter = read_long(fp);
    (*info)->bmiHeader.biYPelsPerMeter = read_long(fp);
    (*info)->bmiHeader.biClrUsed       = read_dword(fp);
    (*info)->bmiHeader.biClrImportant  = read_dword(fp);

    if (infosize > 40)
	if (fread((*info)->bmiColors, infosize - 40, 1, fp) < 1)
            {
            /* Couldn't read the bitmap header - return NULL... */
            free(*info);
            fclose(fp);
            return (NULL);
            }

    /* Now that we have all the header info read in, allocate memory for *
     * the bitmap and read *it* in...                                    */
    if ((bitsize = (*info)->bmiHeader.biSizeImage) == 0)
        bitsize = ((*info)->bmiHeader.biWidth *
                   (*info)->bmiHeader.biBitCount + 7) / 8 *
  	           abs((*info)->bmiHeader.biHeight);

    if ((bits = malloc(bitsize)) == NULL)
        {
        /* Couldn't allocate memory - return NULL! */
        free(*info);
        fclose(fp);
        return (NULL);
        }

    if (fread(bits, 1, bitsize, fp) < bitsize)
        {
        /* Couldn't read bitmap - free memory and return NULL! */
        free(*info);
        free(bits);
        fclose(fp);
        return (NULL);
        }

    /* Swap red and blue */
    length = ((*info)->bmiHeader.biWidth * 3 + 3) & ~3;
    for (y = 0; y < (*info)->bmiHeader.biHeight; y ++)
        for (ptr = bits + y * length, x = (*info)->bmiHeader.biWidth;
             x > 0;
	     x --, ptr += 3)
	    {
	    temp   = ptr[0];
	    ptr[0] = ptr[2];
	    ptr[2] = temp;
	    }

    /* OK, everything went fine - return the allocated bitmap... */
    fclose(fp);
    return (bits);
    }
Ejemplo n.º 5
0
HRESULT parse_dxbc(const char *data, SIZE_T data_size,
        HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
{
    const char *ptr = data;
    HRESULT hr = S_OK;
    DWORD chunk_count;
    DWORD total_size;
    unsigned int i;
    DWORD tag;

    if (!data)
    {
        WARN("No data supplied.\n");
        return E_FAIL;
    }

    read_dword(&ptr, &tag);
    TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));

    if (tag != TAG_DXBC)
    {
        WARN("Wrong tag.\n");
        return E_FAIL;
    }

    /* checksum? */
    skip_dword_unknown("DXBC header", &ptr, 4);

    skip_dword_unknown("DXBC header", &ptr, 1);

    read_dword(&ptr, &total_size);
    TRACE("total size: %#x\n", total_size);

    if (data_size != total_size)
    {
        WARN("Wrong size supplied.\n");
        return E_FAIL;
    }

    read_dword(&ptr, &chunk_count);
    TRACE("chunk count: %#x\n", chunk_count);

    for (i = 0; i < chunk_count; ++i)
    {
        DWORD chunk_tag, chunk_size;
        const char *chunk_ptr;
        DWORD chunk_offset;

        read_dword(&ptr, &chunk_offset);
        TRACE("chunk %u at offset %#x\n", i, chunk_offset);

        chunk_ptr = data + chunk_offset;

        read_dword(&chunk_ptr, &chunk_tag);
        read_dword(&chunk_ptr, &chunk_size);

        hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx);
        if (FAILED(hr)) break;
    }

    return hr;
}
Ejemplo n.º 6
0
void d2_client::mcp_thread_function(void * unused)
{
	game_request_id = 0x02;

	std::cout << "Connecting to realm server " << mcp_ip << ":" << mcp_port << std::endl;

	if(mcp_socket.connect(mcp_ip, mcp_port))
		std::cout << "Successfully connected to realm server" << std::endl;
	else
		std::cout << "Failed to connect to the realm server" << std::endl;

	mcp_socket.send("\x01");

	std::string packet = construct_mcp_packet(0x01, mcp_data);
	mcp_socket.send(packet);

	std::string mcp_buffer;
	while(true)
	{
		std::string data;
		if(!get_mcp_packet(mcp_socket, mcp_buffer, data))
			break;
		ulong identifier = read_byte(data, 2);

		//std::cout << "MCP data:" << std::endl;
		//std::cout << data << std::endl;
		//print_data(data);

		if(identifier == 0x01)
		{
			ulong result = read_dword(data, 3);
			switch(result)
			{
				case 0x00:
					std::cout << "Successfully logged on to realm server" << std::endl;
					break;

				case 0x7e:
					std::cout << "Your CD key has been banned from playing on this realm!" << std::endl;
					break;

				case 0x7f:
					std::cout << "Your IP has been banned temporarily!" << std::endl;
					break;

				default:
					std::cout << "Unknown realm server logon error occured (" << std::hex << result << ")" << std::endl;
					break;
			}

			if(result != 0)
				return;

			std::cout << "Requesting character list" << std::endl;

			mcp_socket.send(construct_mcp_packet(0x19, dword_to_string(8)));
		}
		else if(identifier == 0x19)
		{
			ulong count = read_word(data, 9);
			if(count == 0)
			{
				std::cout << "There are no characters on this account." << std::endl;
				return;
			}
			else
			{
				bool found_character = false;
				bool selected_first_character = false;
				std::cout << "List of characters on this account:" << std::endl;
				std::size_t offset = 11;
				for(ulong i = 1; i <= count; i++)
				{
					offset += 4;
					std::string character_name = read_string(data, offset);
					std::string stats = read_string(data, offset);
					ulong character_class = read_byte(stats, 13);
					ulong level = read_byte(stats, 25);
					ulong flags = read_byte(stats, 26);
					bool hardcore = (flags & 0x04) != 0;
					bool dead = (flags & 0x08) != 0;
					bool expansion = (flags & 0x20) != 0;
					std::string character_class_string = get_character_class_string(character_class);
					std::string core_string = hardcore ? "Hardcore" : "Softcore";
					std::string expansion_string = expansion ? "Expansion" : "Classic";
					std::cout << i << ". " << character_name << ", Level " << level << " " << character_class_string << " (" << expansion_string << ", " << core_string;
					if(hardcore && dead)
						std::cout << ", Dead";
					std::cout << ")" << std::endl;
					//print_data(stats);
					if(character.empty() && i == 1)
					{
						selected_first_character = true;
						character = character_name;
					}
					if(character == character_name)
					{
						found_character = true;
						class_byte = character_class - 1;
						character_level = level;
					}
				}
				if(selected_first_character)
					std::cout << "No character was specified in the ini file so the first character is being used" << std::endl;
				if(!found_character)
				{
					std::cout << "Unable to locate character specified in the ini file";
					return;
				}

				std::cout << "Logging into character " << character << std::endl;

				mcp_socket.send(construct_mcp_packet(0x07, character + zero));
			}
		}
		else if(identifier == 0x07)
		{
			ulong result = read_dword(data, 3);
			if(result != 0)
			{
				std::cout << "Failed to log into character (" << std::hex << result << ")" << std::endl;
				return;
			}
			std::cout << "Successfully logged into character" << std::endl;

			std::cout << "Requesting channel list" << std::endl;
			bncs_socket.send(construct_bncs_packet(0x0b, lod_id));

			std::cout << "Entering the chat server" << std::endl;
			bncs_socket.send(construct_bncs_packet(0x0a, character + zero + realm + "," + character + zero));

			std::cout << "Requesting MOTD" << std::endl;
			mcp_socket.send(construct_mcp_packet(0x12, ""));
		}
		else if(identifier == 0x12)
		{
			std::cout << "Received MOTD" << std::endl;
		}
		else if(identifier == 0x03)
		{
			//print_data(data);

			ulong result = read_dword(data, 9);
			switch(result)
			{
				case 0x00:
					std::cout << "Game has been created successfully" << std::endl;
					break;

				case 0x1e:
					std::cout << "Invalid game name specified" << std::endl;
					break;

				case 0x1f:
					std::cout << "This game already exists" << std::endl;
					break;

				case 0x20:
					std::cout << "Game server down (it is probable that you tried to create a nightmare/hell game with a character who doesn't have access to that difficulty yet, or gamename/password were invalid)" << std::endl;
					break;

				case 0x6e:
					std::cout << "Your character can't create a game because it's dead!" << std::endl;
					break;
			}

			if(result == 0)
			{
				std::cout << "Joining the game we just created" << std::endl;
				join_game(game_name, game_password);
			}
		}
		else if(identifier == 0x04)
		{
			//print_data(data);

			ulong result = read_word(data, 17);

			switch(result)
			{
				case 0x00:
					std::cout << "Successfully joined the game" << std::endl;
					break;

				case 0x29:
					std::cout << "Password is incorrect" << std::endl;
					break;

				case 0x2A:
					std::cout << "Game does not exist" << std::endl;
					break;

				case 0x2B:
					std::cout << "Game is full" << std::endl;
					break;

				case 0x2C:
					std::cout << "You do not meet the level requirements for this game" << std::endl;
					break;

				case 0x71:
					std::cout << "A non-hardcore character cannot join a game created by a Hardcore character." << std::endl;
					break;

				case 0x73:
					std::cout << "Unable to join a Nightmare game." << std::endl;
					break;

				case 0x74:
					std::cout << "Unable to join a Hell game." << std::endl;
					break;

				case 0x78:
					std::cout << "A non-expansion character cannot join a game created by an Expansion character." << std::endl;
					break;

				case 0x79:
					std::cout << "A Expansion character cannot join a game created by a non-expansion character." << std::endl;
					break;

				case 0x7D:
					std::cout << "A non-ladder character cannot join a game created by a Ladder character." << std::endl;
					break;
			}

			if(result == 0)
			{
				ulong ip = read_dword(data, 9);
				gs_ip = nil::net::ip_to_string(ip);
				gs_hash = data.substr(13, 4);
				gs_token = data.substr(5, 2);

				bncs_socket.send(construct_bncs_packet(0x22, lod_id + dword_to_string(0xc) + game_name + zero + game_password + zero));
				bncs_socket.send(construct_bncs_packet(0x10, ""));

				gs_thread.start(nil::thread::function_type(*this, &d2_client::gs_thread_function));
			}
		}
	}
	std::cout << "Disconnected from MCP server" << std::endl;
}
Ejemplo n.º 7
0
unsigned long InternalEEPROMClass::IMCheck_read()
{
    return read_dword(IMPointer);
}
Ejemplo n.º 8
0
static inline int read_CSL(int channel)     { return read_dword(7,channel,0); }
Ejemplo n.º 9
0
static inline int read_CCCA(int channel)    { return read_dword(0,channel,1); }
Ejemplo n.º 10
0
static inline int read_VTFT(int channel)    { return read_dword(3,channel,0); }
Ejemplo n.º 11
0
static inline int read_PSST(int channel)    { return read_dword(6,channel,0); }
Ejemplo n.º 12
0
static inline int read_CVCF(int channel)    { return read_dword(2,channel,0); }
Ejemplo n.º 13
0
static inline int read_PTRX(int channel)    { return read_dword(1,channel,0); }
Ejemplo n.º 14
0
/* read_*:
 *  Functions to read information from the AWE32's registers
 *  (abbreviated as in the AEPG).
 */
static inline int read_CPF(int channel)     { return read_dword(0,channel,0); }
Ejemplo n.º 15
0
static zip_error read_ecd(zip_file *zip)
{
	UINT32 buflen = 1024;
	UINT8 *buffer;

	/* we may need multiple tries */
	while (buflen < 65536)
	{
		file_error error;
		UINT32 read_length;
		INT32 offset;

		/* max out the buffer length at the size of the file */
		if (buflen > zip->length)
			buflen = zip->length;

		/* allocate buffer */
		buffer = (UINT8 *)malloc(buflen + 1);
		if (buffer == nullptr)
			return ZIPERR_OUT_OF_MEMORY;

		/* read in one buffers' worth of data */
		error = osd_read(zip->file, buffer, zip->length - buflen, buflen, &read_length);
		if (error != FILERR_NONE || read_length != buflen)
		{
			free(buffer);
			return ZIPERR_FILE_ERROR;
		}

		/* find the ECD signature */
		for (offset = buflen - 22; offset >= 0; offset--)
			if (buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' && buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
				break;

		/* if we found it, fill out the data */
		if (offset >= 0)
		{
			/* reuse the buffer as our ECD buffer */
			zip->ecd.raw = buffer;
			zip->ecd.rawlength = buflen - offset;

			/* append a NULL terminator to the comment */
			memmove(&buffer[0], &buffer[offset], zip->ecd.rawlength);
			zip->ecd.raw[zip->ecd.rawlength] = 0;

			/* extract ecd info */
			zip->ecd.signature            = read_dword(zip->ecd.raw + ZIPESIG);
			zip->ecd.disk_number          = read_word (zip->ecd.raw + ZIPEDSK);
			zip->ecd.cd_start_disk_number = read_word (zip->ecd.raw + ZIPECEN);
			zip->ecd.cd_disk_entries      = read_word (zip->ecd.raw + ZIPENUM);
			zip->ecd.cd_total_entries     = read_word (zip->ecd.raw + ZIPECENN);
			zip->ecd.cd_size              = read_dword(zip->ecd.raw + ZIPECSZ);
			zip->ecd.cd_start_disk_offset = read_dword(zip->ecd.raw + ZIPEOFST);
			zip->ecd.comment_length       = read_word (zip->ecd.raw + ZIPECOML);
			zip->ecd.comment              = (const char *)(zip->ecd.raw + ZIPECOM);
			return ZIPERR_NONE;
		}

		/* didn't find it; free this buffer and expand our search */
		free(buffer);
		if (buflen < zip->length)
			buflen *= 2;
		else
			return ZIPERR_BAD_SIGNATURE;
	}
	return ZIPERR_OUT_OF_MEMORY;
}
Ejemplo n.º 16
0
static inline int read_HWCF4()              { return read_dword(1,      9,1); }
Ejemplo n.º 17
0
void slurp_pe_header(pe_header *header, FILE *fh, int *bytes_read) {
	int btotal = 0;

	header->Signature            = read_dword(fh); btotal += 4;
	header->Machine              = read_word(fh);  btotal += 2;
	header->NumberOfSections     = read_word(fh);  btotal += 2;
	header->TimeDateStamp        = read_dword(fh); btotal += 4;
	header->PointerToSymbolTable = read_dword(fh); btotal += 4;
	header->NumberOfSymbols      = read_dword(fh); btotal += 4;
	header->SizeOfOptionalHeader = read_word(fh);  btotal += 2;
	header->Characteristics      = read_word(fh);  btotal += 2;

	if (header->SizeOfOptionalHeader > 0) {
		int j;

		/* Standard fields */
		header->Magic                       = read_word(fh);  btotal += 2;
		header->MajorLinkerVersion          = read_byte(fh);  btotal += 1;
		header->MinorLinkerVersion          = read_byte(fh);  btotal += 1;
		header->SizeOfCode                  = read_dword(fh); btotal += 4;
		header->SizeOfInitializedData       = read_dword(fh); btotal += 4;
		header->SizeOfUninitializedData     = read_dword(fh); btotal += 4;
		header->AddressOfEntryPoint         = read_dword(fh); btotal += 4;
		header->BaseOfCode                  = read_dword(fh); btotal += 4;
		header->BaseOfData                  = read_dword(fh); btotal += 4;

		/* NT additional fields */
		header->ImageBase                   = read_dword(fh); btotal += 4;
		header->SectionAlignment            = read_dword(fh); btotal += 4;
		header->FileAlignment               = read_dword(fh); btotal += 4;
		header->MajorOperatingSystemVersion = read_word(fh);  btotal += 2;
		header->MinorOperatingSystemVersion = read_word(fh);  btotal += 2;
		header->MajorImageVersion           = read_word(fh);  btotal += 2;
		header->MinorImageVersion           = read_word(fh);  btotal += 2;
		header->MajorSubsystemVersion       = read_word(fh);  btotal += 2;
		header->MinorSubsystemVersion       = read_word(fh);  btotal += 2;
		header->Win32VersionValue           = read_dword(fh); btotal += 4;
		header->SizeOfImage                 = read_dword(fh); btotal += 4;
		header->SizeOfHeaders               = read_dword(fh); btotal += 4;
		header->CheckSum                    = read_dword(fh); btotal += 4;
		header->Subsystem                   = read_word(fh);  btotal += 2;
		header->DllCharacteristics          = read_word(fh);  btotal += 2;
		header->SizeOfStackReserve          = read_dword(fh); btotal += 4;
		header->SizeOfStackCommit           = read_dword(fh); btotal += 4;
		header->SizeOfHeapReserve           = read_dword(fh); btotal += 4;
		header->SizeOfHeapCommit            = read_dword(fh); btotal += 4;
		header->LoaderFlags                 = read_dword(fh); btotal += 4;
		header->NumberOfRvaAndSizes         = read_dword(fh); btotal += 4;

		header->DataDirectories = (pe_data_directory *)
			malloc(sizeof(pe_data_directory) * header->NumberOfRvaAndSizes);
		for (j = 0; j < header->NumberOfRvaAndSizes; ++j) {
			header->DataDirectories[j].VirtualAddress = read_dword(fh); btotal += 4;
			header->DataDirectories[j].Size           = read_dword(fh); btotal += 4;
		}
	}

	*bytes_read = btotal;
}
Ejemplo n.º 18
0
static inline int read_HWCF5()              { return read_dword(1,     10,1); }
Ejemplo n.º 19
0
Archivo: utils.c Proyecto: GranPC/wine
HRESULT parse_dxbc(const char *data, SIZE_T data_size,
        HRESULT (*chunk_handler)(const char *data, DWORD data_size, DWORD tag, void *ctx), void *ctx)
{
    const char *ptr = data;
    HRESULT hr = S_OK;
    DWORD chunk_count;
    DWORD total_size;
    unsigned int i;
    DWORD tag;

    read_dword(&ptr, &tag);
    TRACE("tag: %s.\n", debugstr_an((const char *)&tag, 4));

    if (tag != TAG_DXBC)
    {
        WARN("Wrong tag.\n");
        return E_INVALIDARG;
    }

    /* checksum? */
    skip_dword_unknown(&ptr, 4);

    skip_dword_unknown(&ptr, 1);

    read_dword(&ptr, &total_size);
    TRACE("total size: %#x\n", total_size);

    read_dword(&ptr, &chunk_count);
    TRACE("chunk count: %#x\n", chunk_count);

    for (i = 0; i < chunk_count; ++i)
    {
        DWORD chunk_tag, chunk_size;
        const char *chunk_ptr;
        DWORD chunk_offset;

        read_dword(&ptr, &chunk_offset);
        TRACE("chunk %u at offset %#x\n", i, chunk_offset);

        if (chunk_offset >= data_size || !require_space(chunk_offset, 2, sizeof(DWORD), data_size))
        {
            WARN("Invalid chunk offset %#x (data size %#lx).\n", chunk_offset, data_size);
            return E_FAIL;
        }

        chunk_ptr = data + chunk_offset;

        read_dword(&chunk_ptr, &chunk_tag);
        read_dword(&chunk_ptr, &chunk_size);

        if (!require_space(chunk_ptr - data, 1, chunk_size, data_size))
        {
            WARN("Invalid chunk size %#x (data size %#lx, chunk offset %#x).\n", chunk_size, data_size, chunk_offset);
            return E_FAIL;
        }

        hr = chunk_handler(chunk_ptr, chunk_size, chunk_tag, ctx);
        if (FAILED(hr)) break;
    }

    return hr;
}
Ejemplo n.º 20
0
static inline int read_HWCF6()              { return read_dword(1,     13,1); }
Ejemplo n.º 21
0
static int authenticate_to_floppyd(char fullauth, int sock, char *display, 
				   int protoversion)
{
	off_t filelen=0;
	Byte buf[16];
	const char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 };
	char *xcookie = NULL;
	Dword errcode;
	int bytesRead;

	if (fullauth) {
		command[4] = display;

		filelen=strlen(display);
		filelen += 100;

		xcookie = (char *) safe_malloc(filelen+4);
		filelen = safePopenOut(command, xcookie+4, filelen);
		if(filelen < 1)
		    return AUTH_AUTHFAILED;
	}
	dword2byte(4,buf);
	dword2byte(protoversion,buf+4);
	if(write(sock, buf, 8) < 8)
		return AUTH_IO_ERROR;

	bytesRead = read_dword(sock);

	if (bytesRead != 4 && bytesRead != 12) {
		return AUTH_WRONGVERSION;
	}


	errcode = read_dword(sock);

	if (errcode != AUTH_SUCCESS) {
		return errcode;
	}


	if(bytesRead == 8) {
	    protoversion = read_dword(sock);
	    read_dword(sock);
	}
	
	fprintf(stderr, "Protocol Version=%d\n", protoversion);

	if (fullauth) {
		dword2byte(filelen, (Byte *) xcookie);
		if(write(sock, xcookie, filelen+4) < filelen+4)
			return AUTH_IO_ERROR;

		if (read_dword(sock) != 4) {
			return AUTH_PACKETOVERSIZE;
		}

		errcode = read_dword(sock);
	}

	return errcode;

}
Ejemplo n.º 22
0
static inline int read_SMALR()              { return read_dword(1,     20,1); }
Ejemplo n.º 23
0
void lschunks(FILE *f,int level,unsigned int endpos){
 unsigned int atom_size;
 unsigned int atom_type;
 int pos;

 while(endpos==0 || ftell(f)<endpos){
  pos=ftell(f);
  atom_size=read_dword(f);//  if(fread(&atom_size_b,4,1,f)<=0) break;
  if(fread(&atom_type,4,1,f)<=0) break;
  
  if(atom_size<8) break; // error
  
  printf("%08X:  %*s %.4s (%08X) %05d [%s] (begin: %08X)\n",pos,level*2,"",&atom_type,atom_type,atom_size,
    atom2human_type(atom_type), pos+8); // 8: atom_size fields (4) + atom_type fields (4)

#ifndef NO_SPECIAL
//  if (atom_type == 0x61746475)
//    userdata_info(f, atom_size, pos, level);

  if (atom_type == 0x6468646D)
  {
    char data[4];
    
    fread(&data, 1, 1, f); // char
    printf("mdhd version %d\n", data[0]);
    fread(&data, 3, 1, f); // int24
    fread(&data, 4, 1, f); // int32
    fread(&data, 4, 1, f); // int32
    fread(&data, 4, 1, f); // int32
    time_scale = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
    printf("timescale: %d\n", time_scale);
    fread(&data, 4, 1, f); // int32
    fread(&data, 2, 1, f); // int16
    fread(&data, 2, 1, f); // int16
  }

  if (atom_type == 0x64686D76)
  {
    stream = S_VIDEO;
    printf(" Found VIDEO Stream #%d\n", v_stream++);
  }
  
  if (atom_type == 0x64686D73)
  {
    stream = S_AUDIO;
    printf(" Found AUDIO Stream #%d\n", a_stream++);
  }

  if (atom_type == 0x64686B74) // tkhd - track header
  {
    int i;
    unsigned char data[atom_size];
    int x, y;

    for (i=0; i<atom_size; i++)
	fread(&data[i], 1, 1, f);

    x = data[77];
    y = data[81];
    printf(" Flags: %d\n", data[3]);
    printf(" Picture size: %dx%d\n", x, y);
    if (x == 0 && y == 0)
	printf(" Possible audio stream!\n");
  }
  
  if(atom_type==0x64737473) {  // stsd
    unsigned int tmp;
    unsigned int count;
    int i;
    fread(&tmp,4,1,f);
    count=read_dword(f);//    fread(&count,4,1,f);
    printf("desc count = %d\n",count);
    for(i=0;i<count;i++){
      unsigned int len;
      unsigned int format;
      len=read_dword(f); //      fread(&len,4,1,f);
      fread(&format,4,1,f);
      printf("  desc #%d: %.4s  (%d)\n",i+1,&format,len);
      if (stream == S_VIDEO)
        video_stream_info(f, len);
      if (stream == S_AUDIO)
        audio_stream_info(f, len);
      fseek(f,len-8,SEEK_CUR);
    }
  }
  
  if(atom_type==0x6F637473) {  // stco
    int len,i;
    read_dword(f);
    len=read_dword(f);
    printf("Chunk table size :%d\n",len);
    for(i=0;i<len;i++) printf("  chunk #%d: 0x%X\n",i+1,read_dword(f));
  }


  if(atom_type==0x73747473) {  // stts
    int len,i;
    read_dword(f);
    len=read_dword(f);
    printf("T->S table size :%d\n",len);
    for(i=0;i<len;i++){
      int num=read_dword(f);
      int dur=read_dword(f);
      printf("%5d samples: %d duration", num, dur);
      if (stream == S_AUDIO)
        printf("(rate: %f Hz)\n", (float)time_scale/dur);
      else
	printf("(fps: %f)\n", (float)time_scale/dur);
    }
  }

  if(atom_type==0x63737473) {  // stsc
    int len,i;
    read_dword(f);
    len=read_dword(f);
    printf("S->C table size :%d\n",len);
    for(i=0;i<len;i++){
      int first=read_dword(f);
      int spc=read_dword(f);
      int sdid=read_dword(f);
      printf("  chunk %d...  %d s/c   desc: %d\n",first,spc,sdid);
    }
  }

  if(atom_type==0x7A737473) {  // stsz
    int len,i,ss;
    read_dword(f);
    ss=read_dword(f);
    len=read_dword(f);
    printf("Sample size table len: %d\n",len);
    if(ss){
      printf("  common sample size: %d bytes\n",ss);
    } else {
      for(i=0;i<len;i++) printf("  sample #%d: %d bytes\n",i+1,read_dword(f));
    }
  }
#endif
  
#if 1
  switch(atom_type){
  case 0x7461646D: // mdat  Movie data
  case 0x75716D72: // rmqu
  case 0x65657266: // free  JUNK
  case 0x64686B74: // tkhd  Track header
  case 0x61746475: // udta  User data
  case 0x64737473: // stsd  Sample description
  case 0x6F637473: // stco  Chunk offset table
  case 0x73747473: // stts  Sample time table
  case 0x63737473: // stsc  Sample->Chunk mapping table
  case 0x7A737473: // stsz  Sample size table
  case 0x746f6e70: // pnot
  case 0x54434950: // PICT
  case 0x70797466:
      break;
  default: lschunks(f,level+1,pos+atom_size);
  }
#else
  switch(atom_type){
  case 0x766F6F6D: // moov
  case 0x61726D72: // rmra
  case 0x61646D72: // rmda
    lschunks(f,level+1,pos+atom_size);
  }
#endif
  fseek(f,pos+atom_size,SEEK_SET);
 }
}
Ejemplo n.º 24
0
check_revision_result_type check_revision(std::string const & formula, std::string const & mpq, std::string const & directory, ulong & output)
{
	/*
	Examples:
	std::string const formula = "A=4095648652 B=3744856545 C=4182215876 4 A=A^S B=B+C C=C+A A=A^B";
	std::string const mpq = "ver-IX86-4.mpq";
	*/

	typedef unsigned (*operator_type)(unsigned, unsigned);


	//thanks to Zoxc for noticing the operator count bug
	std::size_t const variable_count = 3;
	std::size_t const operator_count = 4;

	unsigned values[variable_count];
	operator_type operators[operator_count];

	std::vector<std::string> tokens = nil::string::tokenise(formula, " ");

	std::size_t offset;
	for(offset = 0; offset < tokens.size(); offset++)
	{
		std::string const & token = tokens[offset];
		if(token == "4")
		{
			offset++;
			break;
		}
		else if(token.size() < 3)
			return check_revision_result_formula_error;
		char variable_letter = token[0];
		std::string number_string = token.substr(2);
		unsigned number;
		if(!nil::string::string_to_number<unsigned>(number_string, number))
			return check_revision_result_formula_error;
		std::size_t variable_index;
		if(!get_variable_index(variable_letter, variable_index))
			return check_revision_result_formula_error;
		values[variable_index] = number;
	}

	for(std::size_t i = 0; offset < tokens.size(); i++, offset++)
	{
		std::string const & token = tokens[offset];
		if(token.size() != 5)
			return check_revision_result_formula_error;
		operator_type current_operator;
		switch(token[3])
		{
			case '+':
				current_operator = &operator_add;
				break;
			case '-':
				current_operator = &operator_sub;
				break;
			case '^':
				current_operator = &operator_xor;
				break;
			default:
				return check_revision_result_formula_error;
		}
		operators[i] = current_operator;
	}

	std::size_t mpq_index;
	if(!get_mpq_index(mpq, mpq_index))
		return check_revision_result_mpq_error;

	unsigned mpq_hash = mpq_hash_codes[mpq_index];

	unsigned a = values[0];
	unsigned b = values[1];
	unsigned c = values[2];

	a ^= mpq_hash;

	for(std::size_t i = 0; i < CountOf(d2_files); i++)
	{
		std::string content;
		std::string file = directory + d2_files[i];
		//std::cout << "Loading Diablo II binary " << file << " for hashing" << std::endl;
		if(!nil::read_file(file, content))
			return check_revision_result_file_error;
		for(std::size_t j = 0; j < content.length(); j += 4)
		{
			unsigned s = read_dword(content, j);
			//A=A^S B=B+C C=C+A A=A^B
			//the variable positions are fixed
			a = operators[0](a, s);
			b = operators[1](b, c);
			c = operators[2](c, a);
			a = operators[3](a, b);
		}
	}

	output = c;

	return check_revision_result_success;
}