e32tools/uidcrc/src/uidcrc.cpp
author y4jin
Thu, 18 Nov 2010 13:43:06 +0800
changeset 704 0f8b90f18a21
parent 600 6d08f4a05d93
permissions -rw-r--r--
Fix the illegal word scanned by sfchecksource tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
/*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
* Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
* All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
* Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
* Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
* Description: 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
*/
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <iostream>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
using namespace std;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <stdio.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <stdlib.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include <e32std.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include <e32std_private.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include <e32uid.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
// Get round the privateness of the checksum etc.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
// See also PE_TRAN.CPP TE32ImageUids
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
class TCheckedUidX : public TCheckedUid
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	inline TCheckedUidX(TUint uids[3])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
		: TCheckedUid(TUidType(TUid::Uid(uids[1]),TUid::Uid(uids[2]),TUid::Uid(uids[3]))) 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
		{}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
	inline TUint CRC() 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
		{ return Check(); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
int usage()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
	fprintf(stderr, "uidcrc <uid1> <uid2> <uid3> [ <outputfile> ]\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	return -1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
int main(int argc, char* argv[])
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	if (argc<4 || argc>5)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
		return usage();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	TUint uids[5];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	int i=0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	for (i=1; i<4; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
		char* endptr = "failed";
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
		uids[i] = strtoul(argv[i],&endptr,0);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
		if (*endptr!='\0')
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
			fprintf(stderr, "invalid uid%d >%s<\n",i,argv[i]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
			return -1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	TCheckedUidX checked(uids);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	uids[4] = checked.CRC();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	if (argc==5)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
		{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
		FILE* fp=fopen(argv[4], "wb");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
		if (fp==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
			fprintf(stderr, "cannot open %s for writing\n", argv[4]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
			return -1;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
		for (i=1; i<5; i++)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
			{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
			TUint word=uids[i];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
			unsigned char bytes[4];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
			bytes[0] = (unsigned char)( word     &0xFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
			bytes[1] = (unsigned char)((word>> 8)&0xFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
			bytes[2] = (unsigned char)((word>>16)&0xFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
			bytes[3] = (unsigned char)((word>>24)&0xFF);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
			fwrite(bytes, 4, 1, fp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
			}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
		fclose(fp);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
		return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
		}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	printf("0x%08x 0x%08x 0x%08x 0x%08x\n", uids[1], uids[2], uids[3], uids[4]);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
	return 0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	}