-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathC.CommonCrypto.js
executable file
·239 lines (152 loc) · 7.09 KB
/
C.CommonCrypto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
'use strict';
function ba2hex(bufArray) {
var uint8arr = new Uint8Array(bufArray);
if (!uint8arr) {
return '';
}
var hexStr = '';
for (var i = 0; i < uint8arr.length; i++) {
var hex = (uint8arr[i] & 0xff).toString(16);
hex = (hex.length === 1) ? '0' + hex : hex;
hexStr += hex;
}
return hexStr.toUpperCase();
};
var CCOperation = {
0: "kCCEncrypt",
1: "kCCDecrypt"
};
var CCAlgorithm = {
0: { name: "kCCAlgorithmAES128", blocksize: 16 },
1: { name: "kCCAlgorithmDES", blocksize: 8 },
2: { name: "kCCAlgorithm3DES", blocksize: 8 },
3: { name: "kCCAlgorithmCAST", blocksize: 8 },
4: { name: "kCCAlgorithmRC4", blocksize: 8 },
5: { name: "kCCAlgorithmRC2", blocksize: 8 }
};
// CCCryptorStatus
// CCCryptorCreate(CCOperation op, CCAlgorithm alg, CCOptions options,
// const void *key, size_t keyLength, const void *iv,
// CCCryptorRef *cryptorRef);
Interceptor.attach(Module.findExportByName(null, "CCCryptorCreate"), {
onEnter: function (args) {
var op = args[0].toInt32();
var alg = args[1].toInt32();
var options = args[2].toInt32();
var key = args[3];
var keyLength = args[4].toInt32();
var iv = args[5];
var strKey = ba2hex(Memory.readByteArray(key, keyLength));
if (iv == 0) {
var strIV = "null";
} else {
var strIV = ba2hex(Memory.readByteArray(iv, CCAlgorithm[alg].blocksize));
}
console.log("CCCryptorCreate " + CCOperation[op] + " " + CCAlgorithm[alg].name + " key:" + strKey + " keyLength:" + keyLength*8 + " iv:" + strIV);
}
});
// CCCryptorStatus
// CCCrypt(CCOperation op, CCAlgorithm alg, CCOptions options,
// const void *key, size_t keyLength, const void *iv,
// const void *dataIn, size_t dataInLength, void *dataOut,
// size_t dataOutAvailable, size_t *dataOutMoved);
Interceptor.attach(Module.findExportByName(null, "CCCrypt"), {
onEnter: function (args) {
var op = args[0].toInt32();
var alg = args[1].toInt32();
var options = args[2].toInt32();
var key = args[3];
var keyLength = args[4].toInt32();
var iv = args[5];
var dataIn = args[6];
var dataInLength = args[7].toInt32();
var dataOut = args[8];
var dataOutAvailable = args[9];
var strKey = ba2hex(Memory.readByteArray(key, keyLength));
if (iv == 0) {
var strIV = "null";
} else {
var strIV = ba2hex(Memory.readByteArray(iv, CCAlgorithm[alg].blocksize));
}
var strDataIn = ba2hex(Memory.readByteArray(dataIn, dataInLength));
console.log("CCCrypt " + CCOperation[op] + " " + CCAlgorithm[alg].name + " key:" + strKey + " keyLength:" + keyLength*8 + " iv:" + strIV + " dataIn:" + strDataIn);
}
});
// void replaced_CCHmac (CCHmacAlgorithm algorithm, const void *key, size_t keyLength, const void *data, size_t dataLength, void *macOut)
// {
// NSString *nsstring_data = NSData2Hex([NSData dataWithBytes:data length:dataLength]);
// DDLogVerbose(@"CCHmac data: %@", nsstring_data);
// DDLogVerbose(@"CCHmac alg: %s, key: %@, keyLength: %lu bits", getHMACAlgorithmName(algorithm), NSData2Hex([NSData dataWithBytes:key length:keyLength]), keyLength*8);
// orig_CCHmac(algorithm, key, keyLength, data, dataLength, macOut);
// }
/*
Common HMAC Algorithm Interfaces
This interface provides access to a number of HMAC algorithms. The following algorithms are available:
kCCHmacAlgSHA1 - HMAC with SHA1 digest
kCCHmacAlgMD5 - HMAC with MD5 digest
kCCHmacAlgSHA256 - HMAC with SHA256 digest
kCCHmacAlgSHA384 - HMAC with SHA384 digest
kCCHmacAlgSHA224 - HMAC with SHA224 digest
kCCHmacAlgSHA512 - HMAC with SHA512 digest
The object declared in this interface, CCHmacContext, provides a handle
for use with the CCHmacInit() CCHmacUpdate() and CCHmacFinal() calls to
complete the HMAC operation. In addition there is a one shot function,
CCHmac() that performs a complete HMAC on a single piece of data.
void CCHmacInit(CCHmacContext *ctx, CCHmacAlgorithm algorithm, const void *key, size_t keyLength);
void CCHmacUpdate(CCHmacContext *ctx, const void *data, size_t dataLength);
void CCHmacFinal(CCHmacContext *ctx, void *macOut);
void CCHmac(CCHmacAlgorithm algorithm, const void *key, size_t keyLength, const void *data, size_t dataLength, void *macOut);
*/
var CCHmacAlgorithm = {
0: { name: "kCCHmacAlgSHA1"},
1: { name: "kCCHmacAlgMD5"},
2: { name: "kCCHmacAlgSHA256"},
3: { name: "kCCHmacAlgSHA384"},
4: { name: "kCCHmacAlgSHA512"},
5: { name: "kCCHmacAlgSHA224"}
};
Interceptor.attach(Module.findExportByName(null, "CCHmac"), {
onEnter: function (args) {
var algorithm = args[0].toInt32();
var key = args[1];
var keyLength = args[2].toInt32();
var data = args[3];
var dataLength = args[4].toInt32();
var macOut = args[5];
var strKey = ba2hex(Memory.readByteArray(key, keyLength));
var strData = ba2hex(Memory.readByteArray(data, dataLength));
console.log("CCHmac " + CCHmacAlgorithm[algorithm].name + " key:" + strKey + " keyLength:" + keyLength*8 + " data:" + strData);
}
});
// extern int CC_SHA1_Init(CC_SHA1_CTX *c);
// extern int CC_SHA1_Update(CC_SHA1_CTX *c, const void *data, CC_LONG len);
// extern int CC_SHA1_Final(unsigned char *md, CC_SHA1_CTX *c);
// extern unsigned char *CC_SHA1(const void *data, CC_LONG len, unsigned char *md);
// extern int CC_SHA224_Init(CC_SHA256_CTX *c);
// extern int CC_SHA224_Update(CC_SHA256_CTX *c, const void *data, CC_LONG len);
// extern int CC_SHA224_Final(unsigned char *md, CC_SHA256_CTX *c);
// extern unsigned char *CC_SHA224(const void *data, CC_LONG len, unsigned char *md);
// extern int CC_SHA256_Init(CC_SHA256_CTX *c);
// extern int CC_SHA256_Update(CC_SHA256_CTX *c, const void *data, CC_LONG len);
// extern int CC_SHA256_Final(unsigned char *md, CC_SHA256_CTX *c);
// extern unsigned char *CC_SHA256(const void *data, CC_LONG len, unsigned char *md);
// extern int CC_SHA384_Init(CC_SHA512_CTX *c);
// extern int CC_SHA384_Update(CC_SHA512_CTX *c, const void *data, CC_LONG len);
// extern int CC_SHA384_Final(unsigned char *md, CC_SHA512_CTX *c);
// extern unsigned char *CC_SHA384(const void *data, CC_LONG len, unsigned char *md);
// extern int CC_SHA512_Init(CC_SHA512_CTX *c);
// extern int CC_SHA512_Update(CC_SHA512_CTX *c, const void *data, CC_LONG len);
// extern int CC_SHA512_Final(unsigned char *md, CC_SHA512_CTX *c);
// extern unsigned char *CC_SHA512(const void *data, CC_LONG len, unsigned char *md);
Interceptor.attach(Module.findExportByName(null, "CC_SHA256"), {
onEnter: function (args) {
var data = args[0];
var dataLength = args[1].toInt32();
this.mdOut = args[2];
var strData = ba2hex(Memory.readByteArray(data, dataLength));
console.log("CC_SHA256 dataIn: " + strData);
},
onLeave: function (retval) {
console.log("CC_SHA256 out: " + ba2hex(Memory.readByteArray(this.mdOut, 256/8)));
}
});