|
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 |
|
18 #if defined(__MSVCDOTNET__) || defined(__TOOLS2__) |
|
19 #include <iostream> |
|
20 using namespace std; |
|
21 #endif |
|
22 |
|
23 #include <stdio.h> |
|
24 #include <stdlib.h> |
|
25 #include <e32std.h> |
|
26 #include <e32std_private.h> |
|
27 #include <e32uid.h> |
|
28 |
|
29 // Get round the privateness of the checksum etc. |
|
30 // See also PE_TRAN.CPP TE32ImageUids |
|
31 |
|
32 class TCheckedUidX : public TCheckedUid |
|
33 { |
|
34 public: |
|
35 inline TCheckedUidX(TUint uids[3]) |
|
36 : TCheckedUid(TUidType(TUid::Uid(uids[1]),TUid::Uid(uids[2]),TUid::Uid(uids[3]))) |
|
37 {} |
|
38 inline TUint CRC() |
|
39 { return Check(); } |
|
40 }; |
|
41 |
|
42 int usage() |
|
43 { |
|
44 fprintf(stderr, "uidcrc <uid1> <uid2> <uid3> [ <outputfile> ]\n"); |
|
45 return -1; |
|
46 } |
|
47 |
|
48 int main(int argc, char* argv[]) |
|
49 { |
|
50 if (argc<4 || argc>5) |
|
51 return usage(); |
|
52 |
|
53 TUint uids[5]; |
|
54 int i=0; |
|
55 |
|
56 for (i=1; i<4; i++) |
|
57 { |
|
58 char* endptr = "failed"; |
|
59 uids[i] = strtoul(argv[i],&endptr,0); |
|
60 if (*endptr!='\0') |
|
61 { |
|
62 fprintf(stderr, "invalid uid%d >%s<\n",i,argv[i]); |
|
63 return -1; |
|
64 } |
|
65 } |
|
66 |
|
67 TCheckedUidX checked(uids); |
|
68 uids[4] = checked.CRC(); |
|
69 |
|
70 if (argc==5) |
|
71 { |
|
72 FILE* fp=fopen(argv[4], "wb"); |
|
73 if (fp==0) |
|
74 { |
|
75 fprintf(stderr, "cannot open %s for writing\n", argv[4]); |
|
76 return -1; |
|
77 } |
|
78 for (i=1; i<5; i++) |
|
79 { |
|
80 TUint word=uids[i]; |
|
81 unsigned char bytes[4]; |
|
82 bytes[0] = (unsigned char)( word &0xFF); |
|
83 bytes[1] = (unsigned char)((word>> 8)&0xFF); |
|
84 bytes[2] = (unsigned char)((word>>16)&0xFF); |
|
85 bytes[3] = (unsigned char)((word>>24)&0xFF); |
|
86 fwrite(bytes, 4, 1, fp); |
|
87 } |
|
88 fclose(fp); |
|
89 return 0; |
|
90 } |
|
91 |
|
92 printf("0x%08x 0x%08x 0x%08x 0x%08x\n", uids[1], uids[2], uids[3], uids[4]); |
|
93 return 0; |
|
94 } |