source: svn/trunk/newcon3bcm2_21bu/dta/tools/wordswap32.c @ 5

Last change on this file since 5 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 1.6 KB
Line 
1/*
2   wordswap32.c is a tool to word swap RSA signatures for the BSP. BSP
3   requres signatures to be placed in to the binaries with least
4   significant word first. Keys and signatures must follow this format.
5   For the LE binaries the signatures must also be endian swapped which
6   can be achieved by using sswap32.c tool in a pipe with this tool.
7 */
8
9#include <stdio.h>
10#include <fcntl.h>
11
12#define BLOCK_SIZE 0x100
13
14unsigned char data[BLOCK_SIZE];
15unsigned char out_data[BLOCK_SIZE];
16
17int main(int argc, char * argv[])
18{
19    FILE * input;
20    FILE * output;
21    size_t read_count;
22    size_t write_count;
23    unsigned long * walker;
24    unsigned long * out_walker;
25    /* uncomment this if compiling on cygwin */
26#if 0
27    if(-1 == setmode(fileno(stdin), O_BINARY)){
28        perror("Cannot set stdin to binary mode");
29        return -1;
30    }
31    if(-1 == setmode(fileno(stdout), O_BINARY)){
32        perror("Cannot set stdout to binary mode");
33        return -1;
34    }
35#endif
36    if((read_count != 0x80) && (0x100 != read_count)){
37        fprintf(stderr, "Input size must be 128 or 256 bytes! %d\n", read_count);
38        return -1;
39    }
40    if(read_count != 0){
41        walker = (unsigned long*)data + (read_count / 4) - 1;
42        out_walker = (unsigned long*)out_data;
43        while(walker >= (unsigned long*)data) {
44            *out_walker = *walker;
45            out_walker++; walker--;
46        }
47
48        write_count = fwrite(out_data, 1, read_count, stdout);
49        if(read_count != write_count){
50            perror("Unable to write data");
51            return -1;
52        }
53    }
54
55    return 0;
56}
Note: See TracBrowser for help on using the repository browser.