-
Notifications
You must be signed in to change notification settings - Fork 24
/
logging.cpp
150 lines (135 loc) · 3.8 KB
/
logging.cpp
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
/*
* ______________________.___
* \_ _____/\_ _____/| |
* | __)_ | __) | |
* | \ | \ | |
* /_______ / \___ / |___|
* \/ \/
* _________ .__ ____ __. .__ _____
* / _____/_ _ _|__| ______ _____ | |/ _| ____ |__|/ ____\____
* \_____ \\ \/ \/ / |/ ___// ___/ | < / \| \ __\/ __ \
* / \\ /| |\___ \ \___ \ | | \| | \ || | \ ___/
* /_______ / \/\_/ |__/____ >____ > |____|__ \___| /__||__| \___ >
* \/ \/ \/ \/ \/ \/
*
* EFI Swiss Knife
* An IDA plugin to improve (U)EFI reversing
*
* Copyright (C) 2016, 2017 Pedro Vilaça (fG!) - [email protected] - https://reverse.put.as
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* logging.c
*
*/
#include "logging.h"
#include <ida.hpp>
#include <idp.hpp>
#include <loader.hpp>
#include <bytes.hpp>
#include <kernwin.hpp>
#include <search.hpp>
#include <allins.hpp>
#include <segment.hpp>
#include <limits.h>
#include <auto.hpp>
#include <name.hpp>
#include <frame.hpp>
#include <struct.hpp>
#include <funcs.hpp>
#include <time.h>
#include "config.h"
static FILE *g_log_file;
int
open_log_file(void)
{
g_log_file = qfopen(LOG_FILE, "a+");
if (g_log_file == NULL)
{
ERROR_MSG("Can't open log file: %s %s.", LOG_FILE);
return 1;
}
/* time stamp start of log */
time_t start_time = time(NULL);
char logtime_string[32];
/* write date */
if (start_time != (time_t)-1)
{
char *c = ctime(&start_time);
if (c != NULL)
{
strlcpy(logtime_string, c, sizeof(logtime_string));
logtime_string[strlen(logtime_string)-1] = '\0'; // string from ctime includes return
}
}
qfprintf(g_log_file, "---[ Start @ %s ]---\n", logtime_string);
qfprintf(g_log_file, "---[ Target: %s ]---\n", command_line_file);
return 0;
}
int
close_log_file(void)
{
if (g_log_file != NULL)
{
time_t start_time = time(NULL);
char logtime_string[32];
/* write date */
if (start_time != (time_t)-1)
{
char *c = ctime(&start_time);
if (c != NULL)
{
strlcpy(logtime_string, c, sizeof(logtime_string));
logtime_string[strlen(logtime_string)-1] = '\0'; // string from ctime includes return
}
}
qfprintf(g_log_file, "---[ End @ %s ]---\n", logtime_string);
qfprintf(g_log_file, "---[ Target: %s ]---\n\n", command_line_file);
qfclose(g_log_file);
}
return 0;
}
void
log_error_msg(const char *format, ...)
{
va_list args;
va_start(args, format);
if (g_config.generate_log == 1)
{
qvfprintf(g_log_file, format, args);
}
else
{
vmsg(format, args);
}
va_end(args);
}
void
log_debug_msg(const char *format, ...)
{
if (g_config.debug_msgs == 1)
{
va_list args;
va_start(args, format);
if (g_config.generate_log == 1)
{
qvfprintf(g_log_file, format, args);
}
else
{
vmsg(format, args);
}
va_end(args);
}
}