| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#define FORMAT hugo |
| 11 |
#define HOME_PAGE "http://www.generalcoffee.com" |
| 12 |
#define FORMAT_EXT ".hex" |
| 13 |
#define NO_METADATA |
| 14 |
#define NO_COVER |
| 15 |
|
| 16 |
#include "treaty_builder.h" |
| 17 |
#include <ctype.h> |
| 18 |
#include <stdio.h> |
| 19 |
|
| 20 |
static int number_of_hexadecimals_before_hyphen(char *s, size_t len) |
| 21 |
{ |
| 22 |
size_t offset = 0; |
| 23 |
|
| 24 |
while (offset < len && isxdigit(s[offset])) |
| 25 |
offset++; |
| 26 |
|
| 27 |
if (offset == len || (offset < len && s[offset] == '-')) |
| 28 |
return offset; |
| 29 |
|
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
static int isUUID(char *s) |
| 38 |
{ |
| 39 |
if (!(number_of_hexadecimals_before_hyphen(s, 9) == 8)) |
| 40 |
return 0; |
| 41 |
if (!(number_of_hexadecimals_before_hyphen(s+9, 5) == 4)) |
| 42 |
return 0; |
| 43 |
if (!(number_of_hexadecimals_before_hyphen(s+14, 5) == 4)) |
| 44 |
return 0; |
| 45 |
if (!(number_of_hexadecimals_before_hyphen(s+19, 5) == 4)) |
| 46 |
return 0; |
| 47 |
if (!(number_of_hexadecimals_before_hyphen(s+24, 12) == 12)) |
| 48 |
return 0; |
| 49 |
return 1; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
static char hugo_decode(char c) |
| 54 |
{ |
| 55 |
int decoded_char = c - 20; |
| 56 |
if (decoded_char < 0) |
| 57 |
decoded_char = decoded_char + 256; |
| 58 |
return (char)decoded_char; |
| 59 |
} |
| 60 |
|
| 61 |
static int32 get_story_file_IFID(void *s_file, int32 extent, char *output, int32 output_extent) |
| 62 |
{ |
| 63 |
|
| 64 |
size_t i,j; |
| 65 |
char ser[9]; |
| 66 |
char buffer[32]; |
| 67 |
char UUID_candidate[37]; |
| 68 |
char hyphen = '-'+20; |
| 69 |
|
| 70 |
char *story_file = (char *) s_file; |
| 71 |
|
| 72 |
if (extent<0x0B) return INVALID_STORY_FILE_RV; |
| 73 |
|
| 74 |
for(i=0;i<extent-28;i++) |
| 75 |
{ |
| 76 |
|
| 77 |
|
| 78 |
if (story_file[i] == hyphen && i >= 8 && extent-i >= 28 && |
| 79 |
story_file[i+5] == hyphen && |
| 80 |
story_file[i+10] == hyphen && |
| 81 |
story_file[i+15] == hyphen) |
| 82 |
{ |
| 83 |
for (j=0;j<36;j++) |
| 84 |
{ |
| 85 |
UUID_candidate[j] = hugo_decode(story_file[i+j-8]); |
| 86 |
} |
| 87 |
if (isUUID(UUID_candidate)) |
| 88 |
{ |
| 89 |
|
| 90 |
ASSERT_OUTPUT_SIZE((signed) 37); |
| 91 |
memcpy(output,UUID_candidate,36); |
| 92 |
output[36]='\0'; |
| 93 |
return 1; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
memcpy(ser, (char *) story_file+0x03, 8); |
| 101 |
ser[8]=0; |
| 102 |
|
| 103 |
for(j=0;j<8;j++) |
| 104 |
if (!isalnum(ser[j])) ser[j]='-'; |
| 105 |
|
| 106 |
sprintf(buffer,"HUGO-%d-%02X-%02X-%s",story_file[0],story_file[1], story_file[2],ser); |
| 107 |
|
| 108 |
ASSERT_OUTPUT_SIZE((signed) strlen(buffer)+1); |
| 109 |
strcpy((char *)output,buffer); |
| 110 |
return 1; |
| 111 |
} |
| 112 |
|
| 113 |
static uint32 read_hugo_addx(unsigned char *from) |
| 114 |
{ |
| 115 |
return ((uint32) from[0])| ((uint32)from[1] << 8); |
| 116 |
} |
| 117 |
|
| 118 |
static int32 claim_story_file(void *story_file, int32 exten) |
| 119 |
{ |
| 120 |
unsigned char *sf=(unsigned char *)story_file; |
| 121 |
int32 i; |
| 122 |
int32 scale; |
| 123 |
uint32 extent=(uint32) exten; |
| 124 |
|
| 125 |
if (!story_file || extent < 0x28) return INVALID_STORY_FILE_RV; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
if (sf[0] > 39) return INVALID_STORY_FILE_RV; |
| 131 |
|
| 132 |
if (sf[0]<34) scale=4; |
| 133 |
else scale=16; |
| 134 |
for(i=3;i<0x0B;i++) if (sf[i]<0x20 || sf[i]>0x7e) return INVALID_STORY_FILE_RV; |
| 135 |
for(i=0x0b;i<0x18;i+=2) |
| 136 |
if (read_hugo_addx(sf+i) * scale > extent) return INVALID_STORY_FILE_RV; |
| 137 |
|
| 138 |
return VALID_STORY_FILE_RV; |
| 139 |
} |