1 #include <File.h> 2 #include <Message.h> 3 4 #include <stdio.h> 5 #include <string.h> 6 #include <stdlib.h> 7 8 9 namespace BPrivate { 10 status_t unflatten_dano_message(uint32 magic, BDataIO& stream, BMessage& message); 11 size_t dano_message_size(const char* buffer); 12 } 13 14 15 extern const char* __progname; 16 17 static const uint32 kMessageFormat = 'FOB2'; 18 static const uint32 kMessageFormatSwapped = '2BOF'; 19 20 21 int 22 main(int argc, char** argv) 23 { 24 if (argc < 2) { 25 fprintf(stderr, "usage: %s <flattened dano message>\n", __progname); 26 return -1; 27 } 28 29 for (int32 i = 1; i < argc; i++) { 30 BFile file(argv[i], B_READ_ONLY); 31 if (file.InitCheck() != B_OK) { 32 fprintf(stderr, "Could not open message \"%s\": %s\n", argv[i], strerror(file.InitCheck())); 33 continue; 34 } 35 36 off_t size; 37 if (file.GetSize(&size) != B_OK) 38 continue; 39 40 uint32 magic; 41 if (file.Read(&magic, sizeof(uint32)) != sizeof(uint32)) 42 continue; 43 44 if (magic != kMessageFormat && magic != kMessageFormatSwapped) { 45 fprintf(stderr, "Not a dano message \"%s\"\n", argv[i]); 46 continue; 47 } 48 49 BMessage message; 50 status_t status = BPrivate::unflatten_dano_message(magic, file, message); 51 if (status == B_OK) 52 message.PrintToStream(); 53 else 54 fprintf(stderr, "Could not unflatten message: %s\n", strerror(status)); 55 } 56 57 return 0; 58 } 59 60