/usr/lib/radare/bin/spcc is in radare-common 1:1.5.2-4.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #!/usr/bin/env perl
#
#
#
if ($ARGV[0] eq "" || $ARGV[0] eq "-h") {
print "spcc - structure parser c compiler\n";
print "Usage: spcc [-ht] [file.spc] ([gcc-flags])\n";
exit 0
}
if ( $ARGV[0] eq "-t" ) {
print <<EOF
/*-- test.spcc --*/
struct foo {
int id;
void *next;
void *prev;
};
void parse(struct spcc *spcc, uchar *buffer) {
struct foo tmp;
memcpy(&tmp, buffer, sizeof(struct foo));
printf(\"id: %d\\nnext: %p\\nprev: %p\\n\",
tmp.id, tmp.next, tmp.prev);
}
EOF
;
exit 0;
}
my $file = $ARGV[0];
shift @ARGV;
my $cflags=$ENV{"CFLAGS"}." ".$ENV{"LDFLAGS"}." ".join(' ',@ARGV);
open FD, ">/tmp/spcc.c" or die "Cannot open /tmp/spcc.c";
print FD <<EOF
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#define uchar unsigned char
#define ull unsigned long long
#define OFF_FMTx "%llx"
#define OFF_FMTd "%lld"
struct spcc {
char *filename;
ull offset;
};
ull get_offset (char *arg)
{
int i;
unsigned long long ret = 0;
for(i=0;arg[i]==' ';i++);
for(;arg[i]=='\\\\';i++); i++;
if (arg[i] == 'x')
sscanf(arg, OFF_FMTx, &ret);
else
sscanf(arg, OFF_FMTd, &ret);
return ret;
}
EOF
;
print FD qx(cat $file);
print FD <<EOF
int main(int argc, char **argv)
{
struct spcc spcc;
char *buffer;
size_t len;
int fd;
if (argc < 2 || !strcmp(argv[1], "-h")) {
printf("Usage: %s [file] [[offset]]\\n", argv[0]);
return 1;
}
spcc.filename = argv[1];
if (argc>2) spcc.offset = get_offset(argv[2]);
else spcc.offset = 0;
fd = open(spcc.filename, O_RDONLY);
if (fd == -1) {
printf("Cannot open '%s'\\n", spcc.filename);
return 1;
}
len = lseek (fd, 0, SEEK_END);
if (spcc.offset > len)
len = 0;
buffer = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0);
if (((int)buffer) == -1) {
printf("Cannot mmap file.\\n");
close(fd);
return 1;
}
parse(&spcc, buffer+spcc.offset);
close(fd);
return 0;
}
EOF
;
close FD;
$ENV{"CC"}="gcc" if ($ENV{"CC"} eq "");
system($ENV{"CC"}." $cflags /tmp/spcc.c");
|