diff --git a/donut.c b/donut.c index d93e7001..2b8ac990 100644 --- a/donut.c +++ b/donut.c @@ -2085,6 +2085,9 @@ static int validate_format(opt_arg *arg, void *args) { } else if(!strcasecmp("hex", str)) { arg->u32 = DONUT_FORMAT_HEX; + } else + if(!strcasecmp("uuid", str)) { + arg->u32 = DONUT_FORMAT_UUID; } } // validate @@ -2097,6 +2100,7 @@ static int validate_format(opt_arg *arg, void *args) { case DONUT_FORMAT_POWERSHELL: case DONUT_FORMAT_CSHARP: case DONUT_FORMAT_HEX: + case DONUT_FORMAT_UUID: break; default: { printf("WARNING: Invalid format specified: %"PRId32" -- setting to binary.\n", arg->u32); @@ -2150,7 +2154,7 @@ static void usage (void) { printf(" -PIC/SHELLCODE OPTIONS-\n\n"); printf(" -a,--arch: ,--cpu: Target architecture : 1=x86, 2=amd64, 3=x86+amd64(default).\n"); printf(" -o,--output: Output file to save loader. Default is \"loader.bin\"\n"); - printf(" -f,--format: Output format. 1=Binary (default), 2=Base64, 3=C, 4=Ruby, 5=Python, 6=Powershell, 7=C#, 8=Hex\n"); + printf(" -f,--format: Output format. 1=Binary (default), 2=Base64, 3=C, 4=Ruby, 5=Python, 6=Powershell, 7=C#, 8=Hex, 9=UUID\n"); printf(" -y,--fork: Create a new thread for the loader and continue execution at relative to the host process's executable.\n"); printf(" -x,--exit: Exit behaviour. 1=Exit thread (default), 2=Exit process, 3=Do not exit or cleanup and block indefinitely\n\n"); diff --git a/format.c b/format.c index 9cb0882f..b2a315da 100644 --- a/format.c +++ b/format.c @@ -243,25 +243,27 @@ int hex_template(void * pic, uint32_t pic_len, FILE* fd){ return DONUT_ERROR_OK; } -static int uuid_null[16] = { 0 }; - int uuid_template(void * pic, uint32_t pic_len, FILE* fd){ uint32_t rem; uint32_t j; uint32_t base; uint8_t *p = (uint8_t*)pic; uint32_t len = pic_len; + uint32_t chunks = (len + 15) / 16; + uint8_t last_chunk[16]; - //Ensure there are enough bytes - rem = len % 16; - if(rem != 0){ - pic = realloc(pic, len+rem); - memcpy(p + len, uuid_null, rem); - len+=rem; - } - - for(j=0; j < len/16; j++){ + for(j=0; j < chunks; j++){ base = j*16; + + // last chunk have less than 16bytes + if (base+16 >= pic_len) { + rem = len % 16; + memcpy(last_chunk, p+base, rem); + memset(last_chunk+rem, 0xcc, 16-rem); + p = last_chunk; + base = 0; + } + fprintf(fd, "%02x%02x%02x%02x-", p[base+3], p[base+2], p[base+1], p[base]); fprintf(fd, "%02x%02x-", p[base+5], p[base+4]); fprintf(fd, "%02x%02x-", p[base+7], p[base+6]);