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
|
/*
* This file is part of libsamsung-ipc.
*
* Copyright (C) 2016 Paul Kocialkowsk <contact@paulk.fr>
*
* libsamsung-ipc is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* libsamsung-ipc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sysexits.h>
#include <sys/types.h>
#include <samsung-ipc.h>
void usage_print(void)
{
printf("Usage: nv_data-md5 [nv_data.bin]\n");
}
void log_callback(__attribute__((unused)) void *data,
const char *message)
{
char *buffer;
size_t length;
int i;
if (message == NULL)
return;
buffer = strdup(message);
length = strlen(message);
for (i = length; i > 0; i--) {
if (buffer[i] == '\n')
buffer[i] = '\0';
else if (buffer[i] != '\0')
break;
}
printf("[ipc] %s\n", buffer);
free(buffer);
}
int main(int argc, char *argv[])
{
struct ipc_client *client = NULL;
char *secret = NV_DATA_SECRET;
size_t size = NV_DATA_SIZE;
size_t chunk_size = NV_DATA_CHUNK_SIZE;
char *md5_string = NULL;
char *path;
int rc = 0;
if (argc < 2) {
usage_print();
return 1;
}
path = argv[1];
client = ipc_client_create(IPC_CLIENT_TYPE_DUMMY);
if (client == NULL) {
printf("Creating client failed\n");
goto error;
}
rc = ipc_client_log_callback_register(client, log_callback, NULL);
if (rc < 0) {
printf("Registering log callback failed: error %d\n", rc);
goto error;
}
md5_string = ipc_nv_data_md5_calculate(client, path, secret, size,
chunk_size);
if (md5_string == NULL) {
fprintf(stderr, "Calculating nv_data backup md5 failed\n");
return 1;
}
printf("%s\n", md5_string);
free(md5_string);
return 0;
error:
if (client != NULL)
ipc_client_destroy(client);
return EX_SOFTWARE;
}
|