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