-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleEffaceableStorage.c
66 lines (58 loc) · 1.8 KB
/
AppleEffaceableStorage.c
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
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "AppleEffaceableStorage.h"
#include "IOKit.h"
int AppleEffaceableStorage__getLocker(uint32_t lockerId, uint8_t* buffer, size_t len) {
uint64_t outScalar = 0;
uint32_t one = 1;
uint64_t inScalar = lockerId;
return IOKit_call("AppleEffaceableStorage",
kAppleEffaceableStorageGetLocker,
&inScalar,
1,
NULL,
0,
&outScalar,
&one,
buffer,
&len);
}
int AppleEffaceableStorage__getBytes(uint8_t* buffer, size_t len)
{
const uint64_t offset = 0;
return IOKit_call("AppleEffaceableStorage",
kAppleEffaceableStorageGetBytes,
&offset,
1,
NULL,
0,
NULL,
NULL,
buffer,
&len);
}
int AppleEffaceableStorage__getLockerFromBytes(uint32_t tag, uint8_t* lockers, size_t lockers_len, uint8_t* buffer, size_t len)
{
struct EffaceableLocker* p = (struct EffaceableLocker*) lockers;
unsigned int i=0;
while (i < lockers_len)
{
//printf("p->magic=%x\n", p->magic);
if (p->magic != 0x4c6B) //'Lk'
break;
if (p->len == 0 || ((i+8+p->len) > lockers_len))
break;
//printf("p->tag=%x\n", p->tag);
if ((p->tag & ~0x80000000) == tag)
{
len = len < p->len ? len : p->len;
memcpy(buffer, p->data, len);
return 0;
}
i = i + 8 + p->len;
p = (struct EffaceableLocker*) (&lockers[i]);
}
return -1;
}