Skip to content

Commit

Permalink
libfreerdp-utils: added hexdump utils
Browse files Browse the repository at this point in the history
  • Loading branch information
awakecoding committed Jun 28, 2011
1 parent 46c1d75 commit 7c3facc
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 71 deletions.
39 changes: 3 additions & 36 deletions channels/drdynvc/drdynvc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <freerdp/utils/stream.h>
#include <freerdp/utils/chan_plugin.h>
#include <freerdp/utils/wait_obj.h>
#include <freerdp/utils/hexdump.h>

#include "drdynvc_main.h"

Expand Down Expand Up @@ -72,43 +73,9 @@ struct drdynvc_plugin
};

#if LOG_LEVEL > 10
void
hexdump(char* p, int len)
{
unsigned char* line;
int i;
int thisline;
int offset;

line = (unsigned char*)p;
offset = 0;
while (offset < len)
{
printf("%04x ", offset);
thisline = len - offset;
if (thisline > 16)
{
thisline = 16;
}
for (i = 0; i < thisline; i++)
{
printf("%02x ", line[i]);
}
for (; i < 16; i++)
{
printf(" ");
}
for (i = 0; i < thisline; i++)
{
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
}
printf("\n");
offset += thisline;
line += thisline;
}
}
#define hexdump(data,length) freerdp_hexdump(data,length)
#else
#define hexdump(p,len)
#define hexdump(data,length) do { } while (0)
#endif

static int
Expand Down
3 changes: 2 additions & 1 deletion include/freerdp/utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ include_HEADERS = \
stopwatch.h \
stream.h \
unicode.h \
wait_obj.h
wait_obj.h \
hexdump.h
27 changes: 27 additions & 0 deletions include/freerdp/utils/hexdump.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
FreeRDP: A Remote Desktop Protocol client.
Hex Dump Utils
Copyright 2011 Marc-Andre Moreau <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef __UTILS_HEXDUMP_H
#define __UTILS_HEXDUMP_H

#define FREERDP_HEXDUMP_LINE_LENGTH 16

void freerdp_hexdump(uint8* data, int length);

#endif /* __UTILS_HEXDUMP_H */
2 changes: 0 additions & 2 deletions libfreerdp-core/frdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ void
ui_warning(rdpInst * inst, char * format, ...);
void
ui_unimpl(rdpInst * inst, char * format, ...);
void
hexdump(unsigned char * p, int len);
int
load_license(unsigned char ** data);
RD_BOOL
Expand Down
29 changes: 1 addition & 28 deletions libfreerdp-core/freerdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ext.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/hexdump.h>

#define RDP_FROM_INST(_inst) ((rdpRdp *) (_inst->rdp))

Expand Down Expand Up @@ -90,34 +91,6 @@ ui_unimpl(rdpInst * inst, char * format, ...)
xfree(text2);
}

void
hexdump(unsigned char * p, int len)
{
unsigned char *line = p;
int i, thisline, offset = 0;

while (offset < len)
{
printf("%04x ", offset);
thisline = len - offset;
if (thisline > 16)
thisline = 16;

for (i = 0; i < thisline; i++)
printf("%02x ", line[i]);

for (; i < 16; i++)
printf(" ");

for (i = 0; i < thisline; i++)
printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');

printf("\n");
offset += thisline;
line += thisline;
}
}

int
load_license(unsigned char ** data)
{
Expand Down
5 changes: 3 additions & 2 deletions libfreerdp-core/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "ext.h"
#include "surface.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>

#include "rdp.h"

Expand Down Expand Up @@ -1410,7 +1411,7 @@ process_redirect_pdu(rdpRdp * rdp, STREAM s)
rdp->redirect_routingtoken = xmalloc_in_len32_data(rdp, s,
&rdp->redirect_routingtoken_len);
printf("redirect_cookie_len: %d\n", rdp->redirect_routingtoken_len);
hexdump((void*)rdp->redirect_routingtoken, rdp->redirect_routingtoken_len);
freerdp_hexdump((uint8*)rdp->redirect_routingtoken, rdp->redirect_routingtoken_len);
}
if (redirFlags & LB_USERNAME)
{
Expand Down Expand Up @@ -1444,7 +1445,7 @@ process_redirect_pdu(rdpRdp * rdp, STREAM s)
rdp->redirect_target_net_addresses = xmalloc_in_len32_data(rdp, s,
&rdp->redirect_target_net_addresses_len);
printf("redirect_target_net_addresses_len: %d\n", rdp->redirect_target_net_addresses_len);
hexdump((void*)rdp->redirect_target_net_addresses, rdp->redirect_target_net_addresses_len);
freerdp_hexdump((uint8*)rdp->redirect_target_net_addresses, rdp->redirect_target_net_addresses_len);
}
if (redirFlags & LB_NOREDIRECT)
{
Expand Down
3 changes: 2 additions & 1 deletion libfreerdp-core/surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "rdp.h"
#include "stream.h"
#include <freerdp/freerdp.h>
#include <freerdp/utils/hexdump.h>

#include "surface.h"

Expand Down Expand Up @@ -83,7 +84,7 @@ surface_codec_cap(rdpRdp * rdp, uint8 * codec_guid, int codec_id,
else
{
//printf("unknown guid\n");
hexdump(codec_guid, 16);
freerdp_hexdump(codec_guid, 16);
}
return s;
}
Expand Down
3 changes: 2 additions & 1 deletion libfreerdp-utils/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ libfreerdp_utils_la_SOURCES = \
wait_obj.c \
chan_plugin.c \
stopwatch.c \
profiler.c
profiler.c \
hexdump.c

libfreerdp_utils_la_CFLAGS = \
-I$(top_srcdir) \
Expand Down
56 changes: 56 additions & 0 deletions libfreerdp-utils/hexdump.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
FreeRDP: A Remote Desktop Protocol client.
Hex Dump Utils
Copyright 2011 Marc-Andre Moreau <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <stdio.h>
#include <string.h>

#include <freerdp/types/base.h>

#include <freerdp/utils/hexdump.h>

void freerdp_hexdump(uint8* data, int length)
{
uint8* p = data;
int i, line, offset = 0;

while (offset < length)
{
printf("%04x ", offset);

line = length - offset;

if (line > FREERDP_HEXDUMP_LINE_LENGTH)
line = FREERDP_HEXDUMP_LINE_LENGTH;

for (i = 0; i < line; i++)
printf("%02x ", p[i]);

for (; i < FREERDP_HEXDUMP_LINE_LENGTH; i++)
printf(" ");

for (i = 0; i < line; i++)
printf("%c", (p[i] >= 0x20 && p[i] < 0x7F) ? p[i] : '.');

printf("\n");

offset += line;
p += line;
}
}

0 comments on commit 7c3facc

Please sign in to comment.