From eb6bae9923b46b088d9cf01101620fca620308f9 Mon Sep 17 00:00:00 2001 From: eparisot Date: Wed, 20 Jan 2021 22:22:14 +0100 Subject: [PATCH 1/7] added an ASCII representation at end of line, non printable chars are replaced by dots abstract class HexRecordFormatter renamed in abstract class AbsRecordFormatter for sake of clarity --- .gitignore | 7 +++--- hex.iml | 15 +++++++++++++ lib/src/hexview.dart | 51 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 hex.iml diff --git a/.gitignore b/.gitignore index 9085be2..d3b5ece 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,7 @@ pubspec.lock # Directory created by dartdoc doc/api/ - -.dart_tool - .idea -*.iml \ No newline at end of file +hexview.iml + +.dart_tool \ No newline at end of file diff --git a/hex.iml b/hex.iml new file mode 100644 index 0000000..0854fb6 --- /dev/null +++ b/hex.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/src/hexview.dart b/lib/src/hexview.dart index b5af21e..d247fc4 100644 --- a/lib/src/hexview.dart +++ b/lib/src/hexview.dart @@ -67,13 +67,14 @@ class Record { } } -abstract class HexRecordFormatter { +// Experimental : print ASCII repr +abstract class AbsRecordFormatter { int get recordLength; String format(Record record, {int fullDataEndAddress}); } -class DefaultRecordFormatter implements HexRecordFormatter { +class DefaultRecordFormatter implements AbsRecordFormatter { const DefaultRecordFormatter({this.recordLength = 16}); @override @@ -85,7 +86,7 @@ class DefaultRecordFormatter implements HexRecordFormatter { } final sb = StringBuffer(); - sb.write('0x' + Hex.hex32(record.startAddress)); + sb.write('0x' + Hex.hex16(record.startAddress)); sb.write('\t'); for (int datum in record.data) { if (datum != null) { @@ -99,8 +100,38 @@ class DefaultRecordFormatter implements HexRecordFormatter { } } +// Experimental : print ASCII repr +class AsciiRecordFormatter implements AbsRecordFormatter { + const AsciiRecordFormatter({this.recordLength = 16}); + + @override + final int recordLength; + + String format(Record record, {int fullDataEndAddress}) { + if (record.length != recordLength) { + throw Exception('Record should be of length $recordLength'); + } + + final sb = StringBuffer(); + sb.write('\t\t'); + for (int datum in record.data) { + if (datum == null) { + sb.write(' '); + } else if (datum > 32 && datum < 127) { + sb.write(String.fromCharCode(datum)); + } else { + sb.write('.'); + } + sb.write(' '); + } + return sb.toString(); + } +} + String hexView(int startAddress, Iterable data, - {HexRecordFormatter formatter = const DefaultRecordFormatter(), + {AbsRecordFormatter formatter = const DefaultRecordFormatter(), + bool printAscii = false, + AbsRecordFormatter asciiFormatter = const AsciiRecordFormatter(), String recordSeparator = '\n'}) { final recordLength = formatter.recordLength; final sb = StringBuffer(); @@ -113,6 +144,10 @@ String hexView(int startAddress, Iterable data, data = data.skip(firstTake); final record = Record.prefix(startAddress, first, recordLength); sb.write(formatter.format(record)); + // Experimental : print ASCII repr + if (printAscii) { + sb.write(asciiFormatter.format(record)); + } address = record.startAddress + recordLength; } @@ -121,6 +156,10 @@ String hexView(int startAddress, Iterable data, final record = Record(address, recordData.toList()); sb.write(recordSeparator); sb.write(formatter.format(record)); + // Experimental : print ASCII repr + if (printAscii) { + sb.write(asciiFormatter.format(record)); + } address = record.startAddress + recordLength; data = data.skip(recordLength); } @@ -129,6 +168,10 @@ String hexView(int startAddress, Iterable data, final record = Record.suffix(address, data, recordLength); sb.write(recordSeparator); sb.write(formatter.format(record)); + // Experimental : print ASCII repr + if (printAscii) { + sb.write(asciiFormatter.format(record)); + } } return sb.toString(); From e02484f1f3079cce3cd31d0490548dac99fb6145 Mon Sep 17 00:00:00 2001 From: eparisot Date: Wed, 20 Jan 2021 22:50:25 +0100 Subject: [PATCH 2/7] Fixed a bug if startAddress is ZERO The suffix and prefix methods returned a List if the input effectivelly needed padding but returned an Iterable if not... So just adding data.toList() in an else case is enough... Signed-off-by: eparisot --- lib/src/hexview.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/hexview.dart b/lib/src/hexview.dart index d247fc4..dfad8f4 100644 --- a/lib/src/hexview.dart +++ b/lib/src/hexview.dart @@ -18,6 +18,8 @@ class Record { data = [...List(size - data.length), ...data]; startAddress -= data.length - size; + } else { + data = data.toList(); } return Record(startAddress, data); @@ -28,6 +30,8 @@ class Record { data = [...data, ...List(size - data.length)]; startAddress -= data.length - size; + } else { + data = data.toList(); } return Record(startAddress, data); From 1e3d4edff18a2ef68db9ddad41bef64992221e93 Mon Sep 17 00:00:00 2001 From: Eric Parisot Date: Wed, 20 Jan 2021 22:54:32 +0100 Subject: [PATCH 3/7] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71683ad..12fd8cf 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ void main() { ```dart void main() { - print(hexView(5, List.generate(125, (i) => i + 5))); + print(hexView(5, List.generate(125, (i) => i + 5), {printAscii: true})); } ``` @@ -35,4 +35,4 @@ void main() { final hexString = '00:B2:0C:EC:EA:F3:76:B2:F7:87:56:B6:97:57:4C:DD:A1:5C:A1:59:41:D6:35:0D:31:9E:11:D3:3E:18:ED:E6:08:07:99:2B:EB:53:1B:D4:A5:77:CA:58:23:FD:81:9A:39:F5:0E:DD:C7:4C:9D:8E:A0:6C:76:8A:17:0A:89:95:3F:89:06:0E:3B:A5:BC:E1:D6:82:F7:15:9B:04:EC:2F:46:C0:32:A9:AC:0B:2C:89:28:CE:89:5A:A8:BC:13:E0:8F:4C:EA:4C:05:67:5A:A5:4C:6F:C1:A4:A6:A2:9F:20:7A:24:ED:9D:7D:1A:57:8C:C6:5F:0B:33:DA:6C:1D:A2:06:E8:BA:74:23:30:1F:C4:C3:BB:EF:F1:7B:6A:C1:74:A9:9D:1E:E4:33:91:CF:7C:CE:F0:6F:D1:7C:32:39:51:BA:76:BA:36:DD:95:EE:2D:28:52:BF:84:12:DE:9F:21:81:15:64:58:87:4D:25:33:0C:B6:B3:D9:E0:A5:25:E0:8D:76:FC:AA:69:E1:82:0A:AB:3E:2E:E9:CC:AB:79:19:8C:EF:5A:86:D4:B6:FB:5A:99:C5:F0:73:69:CF:F4:29:74:58:9C:B6:B4:90:64:07:65:BC:34:79:C8:1D:64:2F:58:A6:AA:8C:79:37:92:9C:93:CF:5F:8F:D3:42:DE:78:A9:52:D0:5C:CD:FE:87:CC:6F:C2:DD:E5:22:D7:09:3D:94:74:BF:ED:32:41:EE:50:13:03:CB:E1:CE:54:17:CD:63:7C:6A:D8:7C:4C:E6:1A:D8:7A:29:12:26:44:C7:45:2C:5F:7E:17:BA:33:02:01:AA:08:B4:2D:DD:E5:76:60:C5:C8:05:87:D9:4B:D2:FF:94:EF:D0:DE:6E:0C:18:04:59:5D:41:37:8E:59:1C:7C:59:5C:6E:70:34:BB:03:01:4A:37:4D:52:CC:38:CC:78:D5:C2:4E:9A:1B:90:B0:60:56:15:1C:6F:67:E6:FE:2A:0B:12:95:10:D4:62:9F:38:06:46:7C:24:37:20:03:79:CB:DB:71:0D:F4:FD:43:AE:85:4E:58:06:77:C5:49:8A:EB:86:AF:DF:C8:26:E9:9D:EB:B1:93:61:28:B8:BD:E9:93:F1:80:EE:61:B3:AA:18:CF:63:36:9A:34:65:59:F2:7F:98:CA:CD:24:C6:E3:FD:5C:33:94:10:39:23:5E:96:BF:4B:37:99:12:4F:45:5C:C9:4B:73:B5:B2:76:3F:FB:11:2E:2B:E9:26:02:B3:82:8C:AF:EA:7B:0A:31:60:FD:AE:C8:75:EA:4B:43:7B:71:AD:97:9C:AC:1C:68:1B:99:81:0D:88:02:24:27:CB:06:ED'; print(bigIntFromHex(hexString)); } -``` \ No newline at end of file +``` From 382bb679a7360b1a315edb5d1669c53400b3fb4a Mon Sep 17 00:00:00 2001 From: Eric Parisot Date: Wed, 20 Jan 2021 22:54:49 +0100 Subject: [PATCH 4/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12fd8cf..f7c44d4 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ void main() { ```dart void main() { - print(hexView(5, List.generate(125, (i) => i + 5), {printAscii: true})); + print(hexView(5, List.generate(125, (i) => i + 5), printAscii: true)); } ``` From a38aa67fd2b7c48e79fd9fe0abb2ad18d0f8c089 Mon Sep 17 00:00:00 2001 From: eparisot Date: Thu, 21 Jan 2021 14:47:37 +0100 Subject: [PATCH 5/7] clean and update hexView example Signed-off-by: eparisot --- .gitignore | 7 ++++--- example/hexview_example.dart | 2 +- hex.iml | 15 --------------- 3 files changed, 5 insertions(+), 19 deletions(-) delete mode 100644 hex.iml diff --git a/.gitignore b/.gitignore index d3b5ece..9085be2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ pubspec.lock # Directory created by dartdoc doc/api/ -.idea -hexview.iml -.dart_tool \ No newline at end of file +.dart_tool + +.idea +*.iml \ No newline at end of file diff --git a/example/hexview_example.dart b/example/hexview_example.dart index 25ece6e..0b5af37 100644 --- a/example/hexview_example.dart +++ b/example/hexview_example.dart @@ -1,5 +1,5 @@ import 'package:ninja_hex/ninja_hex.dart'; void main() { - print(hexView(5, List.generate(125, (i) => i + 5))); + print(hexView(5, List.generate(125, (i) => i + 5), printAscii: true)); } diff --git a/hex.iml b/hex.iml deleted file mode 100644 index 0854fb6..0000000 --- a/hex.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file From 60a635d15880813a20d5b29fcb24c2d0e5e47a0e Mon Sep 17 00:00:00 2001 From: eparisot Date: Thu, 21 Jan 2021 14:50:17 +0100 Subject: [PATCH 6/7] reset default address size --- lib/src/hexview.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/hexview.dart b/lib/src/hexview.dart index dfad8f4..e88c458 100644 --- a/lib/src/hexview.dart +++ b/lib/src/hexview.dart @@ -90,7 +90,7 @@ class DefaultRecordFormatter implements AbsRecordFormatter { } final sb = StringBuffer(); - sb.write('0x' + Hex.hex16(record.startAddress)); + sb.write('0x' + Hex.hex32(record.startAddress)); sb.write('\t'); for (int datum in record.data) { if (datum != null) { From 2c22d175f333536b313e45a37596122ed042f907 Mon Sep 17 00:00:00 2001 From: eparisot Date: Tue, 13 Sep 2022 17:05:46 +0200 Subject: [PATCH 7/7] null --- lib/src/hexview.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/hexview.dart b/lib/src/hexview.dart index 33310e5..75e2273 100644 --- a/lib/src/hexview.dart +++ b/lib/src/hexview.dart @@ -111,14 +111,14 @@ class AsciiRecordFormatter implements AbsRecordFormatter { @override final int recordLength; - String format(Record record, {int fullDataEndAddress}) { + String format(Record record, {int? fullDataEndAddress}) { if (record.length != recordLength) { throw Exception('Record should be of length $recordLength'); } final sb = StringBuffer(); sb.write('\t\t'); - for (int datum in record.data) { + for (int? datum in record.data) { if (datum == null) { sb.write(' '); } else if (datum > 32 && datum < 127) {