-
Notifications
You must be signed in to change notification settings - Fork 3
/
misc.c
94 lines (76 loc) · 2 KB
/
misc.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
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
/*
This file is part of macSSH
Copyright 2016 Daniel Machon
SSH 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/>.
*/
#include "includes.h"
#include "misc.h"
#include "ssh-options.h"
void macssh_exit(const char *msg, int err)
{
}
void macssh_err(const char *msg, int err)
{
}
void macssh_debug(const char *msg)
{
fprintf(stderr, "%s\n", msg);
}
void macssh_print(const char *msg)
{
printf("%s\n", msg);
}
void macssh_print_file(FILE *file, const char *msg)
{
fprintf(file, "%s\n", msg);
}
void macssh_print_array(void *data, int len)
{
char *ptr = (char *) data;
int x;
for(x = 0; x < len; x++) {
fprintf(stderr, "[%u]=%u ", x, *(ptr + x));
if(x % 15 == 0)
fprintf(stderr, "\n");
}
}
/* Attempt to print any embedded string in byte array */
void macssh_print_embedded_string(void *data, int len)
{
unsigned char *ptr = (unsigned char * )data;
int x;
int start = 0;
int end = 0;
for(x = 0; x < len; x++) {
if(ptr[x] >= ' ') {
/* Printable. Mark start. */
if(!start)
start = x;
}
else {
/* Zero termination. Mark end if previous byte
* was a printable */
if(start && ptr[x] == '\0')
end = x;
/* Non-printable and not zero.
* This is definitely not a string */
else
start = 0;
}
/* Check if we have something to print */
if(start && end) {
fprintf(stderr, "This looks stringy: %s\n",
ptr + start, end - start);
start = end = 0;
}
}
}