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