• R/O
  • SSH
  • HTTPS

ttssh2: Commit


Commit MetaInfo

Revision8679 (tree)
Time2020-04-09 01:01:33
Authorzmatsuo

Log Message

OutputDebugHexDump() 追加

- ttxsshから持ってきた

Change Summary

Incremental Difference

--- trunk/teraterm/common/ttlib.h (revision 8678)
+++ trunk/teraterm/common/ttlib.h (revision 8679)
@@ -85,6 +85,7 @@
8585 DllExport BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg);
8686 DllExport void OutputDebugPrintf(const char *fmt, ...);
8787 void OutputDebugPrintfW(const wchar_t *fmt, ...);
88+void OutputDebugHexDump(const void *data, size_t len);
8889 DllExport DWORD get_OPENFILENAME_SIZEA();
8990 DllExport DWORD get_OPENFILENAME_SIZEW();
9091 DllExport BOOL IsWindows95();
--- trunk/teraterm/common/ttlib_static_cpp.cpp (revision 8678)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp (revision 8679)
@@ -1,5 +1,33 @@
1+/*
2+ * Copyright (C) 2020 TeraTerm Project
3+ * All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions
7+ * are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ * 2. Redistributions in binary form must reproduce the above copyright
12+ * notice, this list of conditions and the following disclaimer in the
13+ * documentation and/or other materials provided with the distribution.
14+ * 3. The name of the author may not be used to endorse or promote products
15+ * derived from this software without specific prior written permission.
16+ *
17+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
18+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
128
229 #include <windows.h>
30+#include <stdio.h>
331 #include <string.h>
432 #if !defined(_CRTDBG_MAP_ALLOC)
533 #define _CRTDBG_MAP_ALLOC
@@ -74,3 +102,86 @@
74102
75103 return r;
76104 }
105+
106+
107+// from ttxssh
108+static void format_line_hexdump(char *buf, int buflen, int addr, int *bytes, int byte_cnt)
109+{
110+ int i, c;
111+ char tmp[128];
112+
113+ buf[0] = 0;
114+
115+ /* 先頭のアドレス表示 */
116+ _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%08X : ", addr);
117+ strncat_s(buf, buflen, tmp, _TRUNCATE);
118+
119+ /* バイナリ表示(4バイトごとに空白を挿入)*/
120+ for (i = 0; i < byte_cnt; i++) {
121+ if (i > 0 && i % 4 == 0) {
122+ strncat_s(buf, buflen, " ", _TRUNCATE);
123+ }
124+
125+ _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%02X", bytes[i]);
126+ strncat_s(buf, buflen, tmp, _TRUNCATE);
127+ }
128+
129+ /* ASCII表示部分までの空白を補う */
130+ _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, " %*s%*s", (16 - byte_cnt) * 2 + 1, " ", (16 - byte_cnt + 3) / 4, " ");
131+ strncat_s(buf, buflen, tmp, _TRUNCATE);
132+
133+ /* ASCII表示 */
134+ for (i = 0; i < byte_cnt; i++) {
135+ c = bytes[i];
136+ if (isprint(c)) {
137+ _snprintf_s(tmp, sizeof(tmp), _TRUNCATE, "%c", c);
138+ strncat_s(buf, buflen, tmp, _TRUNCATE);
139+ }
140+ else {
141+ strncat_s(buf, buflen, ".", _TRUNCATE);
142+ }
143+ }
144+}
145+
146+void DebugHexDump(void (*f)(const char *s), const void *data_, size_t len)
147+{
148+ const char *data = (char *)data_;
149+ char buff[4096];
150+ int c, addr;
151+ int bytes[16], *ptr;
152+ int byte_cnt;
153+ int i;
154+
155+ addr = 0;
156+ byte_cnt = 0;
157+ ptr = bytes;
158+ for (i = 0; i < len; i++) {
159+ c = data[i];
160+ *ptr++ = c & 0xff;
161+ byte_cnt++;
162+
163+ if (byte_cnt == 16) {
164+ format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
165+ f(buff);
166+
167+ addr += 16;
168+ byte_cnt = 0;
169+ ptr = bytes;
170+ }
171+ }
172+
173+ if (byte_cnt > 0) {
174+ format_line_hexdump(buff, sizeof(buff), addr, bytes, byte_cnt);
175+ f(buff);
176+ }
177+}
178+
179+static void OutputDebugHexDumpSub(const char *s)
180+{
181+ OutputDebugPrintf("%s\n", s);
182+}
183+
184+void OutputDebugHexDump(const void *data, size_t len)
185+{
186+ DebugHexDump(OutputDebugHexDumpSub, data, len);
187+}
Show on old repository browser