1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

messing about.

(This used to be commit 9c6f2d75d8)
This commit is contained in:
Luke Leighton 2000-05-31 05:39:54 +00:00
parent 23d705672e
commit d500cbb206
25 changed files with 296 additions and 208 deletions

View File

@ -1,7 +1,7 @@
CFLAGS=-Wall -g CFLAGS=-Wall -g
CC=gcc CC=gcc
OBJ = vluke.o parser.o OBJ = vluke.o parser.o util.o
AWKPROGS=dump.awk harness.awk header.awk parsefn.awk main.awk parsetree.awk template.awk util.awk AWKPROGS=dump.awk harness.awk header.awk parsefn.awk main.awk parsetree.awk template.awk util.awk
all: test.h vluke all: test.h vluke

View File

@ -8,6 +8,6 @@ if ! igawk -f main.awk $file; then
fi fi
echo compiling vluke echo compiling vluke
gcc -Wall -o vluke parser.c vluke.c gcc -Wall -o vluke parser.c vluke.c util.c
echo done. echo done.

View File

@ -29,7 +29,7 @@ typedef struct {
typedef struct { typedef struct {
uint8 tag2; uint8 tag2;
string protocol; STRING protocol;
} BUF2; } BUF2;
typedef struct { typedef struct {
@ -65,7 +65,7 @@ typedef struct {
USHORT Reserved; /* MBZ */ USHORT Reserved; /* MBZ */
USHORT ByteCount; /* Count of data bytes */ USHORT ByteCount; /* Count of data bytes */
UCHAR Challenge[ChallengeLength]; /* The challenge */ UCHAR Challenge[ChallengeLength]; /* The challenge */
string PrimaryDomain; /* The server's primary domain */ STRING PrimaryDomain; /* The server's primary domain */
} R_NEGPROT_12; } R_NEGPROT_12;
@ -99,7 +99,7 @@ typedef struct {
/* security package if CAP_EXTENDED_SECURITY is */ /* security package if CAP_EXTENDED_SECURITY is */
/* on in the Capabilities field; else challenge */ /* on in the Capabilities field; else challenge */
/* for CIFS challenge/response authentication. */ /* for CIFS challenge/response authentication. */
string OemDomainName[+]; /*The name of the domain (in OEM chars); not */ STRING OemDomainName[+]; /*The name of the domain (in OEM chars); not */
/* present if CAP_EXTENDED_SECURITY is on in the */ /* present if CAP_EXTENDED_SECURITY is on in the */
/* Capabilities field */ /* Capabilities field */
} R_NEGPROT_17; } R_NEGPROT_17;
@ -163,9 +163,9 @@ typedef struct {
uint16 bcount; uint16 bcount;
uint8 password[pwlen]; uint8 password[pwlen];
string domain; STRING domain;
string os; STRING os;
string server; STRING server;
} Q_SESSION_SETUP_ANDX_10; } Q_SESSION_SETUP_ANDX_10;
@ -183,10 +183,10 @@ typedef struct {
uint16 bcount; uint16 bcount;
uint8 password[pwlen]; uint8 password[pwlen];
uint8 upassword[upwlen]; uint8 upassword[upwlen];
string user; STRING user;
string domain; STRING domain;
string os; STRING os;
string server; STRING server;
} Q_SESSION_SETUP_ANDX_13; } Q_SESSION_SETUP_ANDX_13;
@ -204,8 +204,8 @@ typedef struct {
uint16 passlen; uint16 passlen;
uint16 bcount; uint16 bcount;
uint8 password[passlen]; uint8 password[passlen];
string path; STRING path;
string device; STRING device;
} Q_TCON_ANDX_4; } Q_TCON_ANDX_4;
typedef struct _Q_TCON_ANDX { typedef struct _Q_TCON_ANDX {
@ -219,7 +219,7 @@ typedef struct {
ANDX_INFO andx; ANDX_INFO andx;
uint16 vwv2; uint16 vwv2;
uint16 bcount; uint16 bcount;
string share; STRING share;
} R_TCON_ANDX_3; } R_TCON_ANDX_3;
typedef struct _R_TCON_ANDX { typedef struct _R_TCON_ANDX {
@ -234,9 +234,9 @@ typedef struct {
uint16 action; uint16 action;
uint16 count; uint16 count;
string os; STRING os;
string server; STRING server;
string domain; STRING domain;
} R_SESSION_SETUP_ANDX_10; } R_SESSION_SETUP_ANDX_10;
typedef struct _R_SESSION_SETUP_ANDX { typedef struct _R_SESSION_SETUP_ANDX {
@ -694,7 +694,7 @@ typedef struct {
typedef struct { typedef struct {
USHORT InformationLevel; /* Level of information requested */ USHORT InformationLevel; /* Level of information requested */
ULONG Reserved; /* Must be zero */ ULONG Reserved; /* Must be zero */
string FileName; /* File or directory name */ STRING FileName; /* File or directory name */
} TRANS2_QUERY_PATH_INFO_STRUCT; } TRANS2_QUERY_PATH_INFO_STRUCT;
typedef struct { typedef struct {
@ -703,7 +703,7 @@ typedef struct {
USHORT Flags; USHORT Flags;
USHORT InformationLevel; USHORT InformationLevel;
ULONG SearchStorageType; ULONG SearchStorageType;
string FileName; STRING FileName;
} TRANS2_FIND_FIRST2_STRUCT; } TRANS2_FIND_FIRST2_STRUCT;
typedef struct _Q_TRANS2_15 { typedef struct _Q_TRANS2_15 {
@ -857,7 +857,7 @@ typedef struct _Q_TRANS_16 {
UCHAR Reserved3; /* Reserved (pad above to word) */ UCHAR Reserved3; /* Reserved (pad above to word) */
USHORT Setup[SetupCount]; /* Setup words (# = SetupWordCount) */ USHORT Setup[SetupCount]; /* Setup words (# = SetupWordCount) */
USHORT ByteCount; /* Count of data bytes */ USHORT ByteCount; /* Count of data bytes */
string Name; /* Must be NULL */ STRING Name; /* Must be NULL */
.align4 0; .align4 0;
UCHAR Parameters[ParameterCount];/* Parameter bytes (# = ParameterCount) */ UCHAR Parameters[ParameterCount];/* Parameter bytes (# = ParameterCount) */
.align4 0; .align4 0;

View File

@ -3,9 +3,16 @@
function header_elstring(elnum, function header_elstring(elnum,
LOCAL, elem) LOCAL, elem)
{ {
array_len = elements[elnum, "array_len"];
elem=elements[elnum, "elem"]; elem=elements[elnum, "elem"];
if (elements[elnum, "ptr"]=="1") elem="*"elem; if (elements[elnum, "ptr"]=="1") elem="*"elem;
if (elements[elnum, "array_len"]!="") elem="*"elem; if (array_len!="") {
if (match(array_len,"[0-9]") == 1) {
elem=elem"["array_len"]";
} else {
elem="*"elem;
}
}
return elem; return elem;
} }
@ -54,9 +61,12 @@ function produce_headers(f, NIL,
LOCAL, i) LOCAL, i)
{ {
xprintf(f,"/* auto-generated headers for %s */\n\n\n", module); xprintf(f,"/* auto-generated headers for %s */\n\n\n", module);
xprintf(f,"#ifndef _%s_\n", module);
xprintf(f,"#define _%s_\n", module);
for (i=0;i < num_structs;i++) { for (i=0;i < num_structs;i++) {
header_struct(f, i); header_struct(f, i);
} }
xprintf(f,"/* end auto-generated headers */\n\n"); xprintf(f,"/* end auto-generated headers */\n\n");
xprintf(f,"#endif /* _%s_ */\n", module);
} }

View File

@ -14,7 +14,7 @@ END {
printf("Producing headers...\n"); printf("Producing headers...\n");
produce_headers("prs_"module".h"); produce_headers("prs_"module".h");
printf("Producing parsers...\n"); printf("Producing parsers...\n");
produce_parsers("prs_"module".c"); produce_parsers("prs_"module".c", "mod_"module".c");
printf("Producing harness...\n"); printf("Producing harness...\n");
produce_harness("test.h"); produce_harness("test.h");
printf("Done.\n"); printf("Done.\n");

View File

@ -47,6 +47,9 @@ function parse_array(f, v, elnum, flags,
function parse_element(f, v, elnum, flags, function parse_element(f, v, elnum, flags,
LOCAL, type, elem) LOCAL, type, elem)
{ {
if (elements[elnum,"nowire"] != "") {
return;
}
type = elements[elnum, "type"]; type = elements[elnum, "type"];
if (substr(type,1,1) == ".") return; if (substr(type,1,1) == ".") return;
elem = elements[elnum, "elem"]; elem = elements[elnum, "elem"];
@ -130,6 +133,40 @@ function parse_pointer(f, v, elnum, flags,
print_template(f, "prs_pointer.tpl", v); print_template(f, "prs_pointer.tpl", v);
} }
function parse_scalar_fn(m, v, elnum,
LOCAL, elem, type)
{
elem = elements[elnum, "elem"];
type = elements[elnum, "type"]
xprintf(m, "%s %s", type, elem_name(v, elem));
if (type == "union") {
} else if (elements[elnum, "array_len"]!="") {
} else {
}
}
function parse_pointer_fn(f, v, elnum, flags,
LOCAL, elem)
{
elem = elements[elnum, "elem"];
v["ELEM"] = elem_name(v, elem);
v["FLAGS"] = flags;
xprintf(m, "%s\n", v["ELEM"]);
}
function parse_scalars_fn(m, v, elnum, flags)
{
if (elements[elnum, "type"] == ".align2") {
}
else if (elements[elnum, "type"] == ".align4") {
}
else if (elements[elnum, "ptr"] == "1") {
parse_pointer_fn(m, v, elnum, flags);
} else {
parse_scalar_fn(m, v, elnum, flags);
}
}
function parse_scalars(f, v, elnum, flags) function parse_scalars(f, v, elnum, flags)
{ {
if (elements[elnum, "type"] == ".align2") { if (elements[elnum, "type"] == ".align2") {
@ -163,15 +200,20 @@ function parse_buffers(f, v, elnum, flags,
} }
} }
function struct_parser(f, v, struct_num, function struct_parser(f, m, v, struct_num,
LOCAL, i, n1) LOCAL, i, n1, f1, num_elems)
{ {
f1 = -1;
num_elems = structs[struct_num, "num_elems"];
v["STRUCTNAME"] = structs[struct_num, "name"]; v["STRUCTNAME"] = structs[struct_num, "name"];
v["FUNCNAME"] = "io_" v["STRUCTNAME"]; v["FUNCNAME"] = "io_" v["STRUCTNAME"];
print_template(f, "fn_start.tpl", v); print_template(f, "fn_start.tpl", v);
for (n1=0;n1<structs[struct_num, "num_elems"];n1++) { for (n1=0;n1<num_elems;n1++) {
if (elements[structs[struct_num, n1], "type"] == ".trailer") break; if (elements[structs[struct_num, n1], "type"] == ".trailer") {
f1 = n1;
break;
}
} }
# first all the structure pointers, scalars and arrays # first all the structure pointers, scalars and arrays
@ -187,7 +229,7 @@ function struct_parser(f, v, struct_num,
} }
# and any trailers # and any trailers
for (i=n1;i<structs[struct_num, "num_elems"];i++) { for (i=n1;i<num_elems;i++) {
parse_scalars(f, v, structs[struct_num, i], "PARSE_SCALARS"); parse_scalars(f, v, structs[struct_num, i], "PARSE_SCALARS");
parse_buffers(f, v, structs[struct_num, i], "PARSE_BUFFERS"); parse_buffers(f, v, structs[struct_num, i], "PARSE_BUFFERS");
} }
@ -198,9 +240,23 @@ function struct_parser(f, v, struct_num,
else { else {
print_template(f, "fn_end0.tpl", v); print_template(f, "fn_end0.tpl", v);
} }
if (f1 == -1)
return;
xprintf(m, "void fn_%s(\n", v["STRUCTNAME"]);
for (i=f1+1;i<num_elems;i++) {
parse_scalars_fn(m, v, structs[struct_num, i]);
if (i != num_elems-1)
xprintf(m, ", \n");
}
xprintf(m, ")\n{\n}\n");
} }
function produce_parsers(f, function produce_parsers(f, m,
LOCAL, v, i) LOCAL, v, i)
{ {
v["MODULE"]=module; v["MODULE"]=module;
@ -208,7 +264,7 @@ function produce_parsers(f,
print_template(f, "module_start.tpl", v); print_template(f, "module_start.tpl", v);
for (i=0;i < num_structs;i++) { for (i=0;i < num_structs;i++) {
struct_parser(f, v, i); struct_parser(f, m, v, i);
} }
print_template(f, "module_end.tpl", v); print_template(f, "module_end.tpl", v);

View File

@ -1,47 +1,12 @@
#include <stdio.h> #include "includes.h"
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
#include "parser.h"
char *tab_depth(int depth)
{
static pstring spaces;
memset(spaces, ' ', depth * 4);
spaces[depth * 4] = 0;
return spaces;
}
/****************************************************************************
expand a pointer to be a particular size
****************************************************************************/
void *Realloc(void *p,size_t size)
{
void *ret=NULL;
if (size == 0) {
if (p) free(p);
DEBUG(5,("Realloc asked for 0 bytes\n"));
return NULL;
}
if (!p)
ret = (void *)malloc(size);
else
ret = (void *)realloc(p,size);
if (!ret)
DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
return(ret);
}
/******************************************************************* /*******************************************************************
Attempt, if needed, to grow a data buffer. Attempt, if needed, to grow a data buffer.
Also depends on the data stream mode (io). Also depends on the data stream mode (io).
********************************************************************/ ********************************************************************/
BOOL prs_grow(prs_struct *ps, uint32 extra_space) BOOL io_grow(io_struct *ps, uint32 extra_space)
{ {
uint32 new_size; uint32 new_size;
char *new_data; char *new_data;
@ -53,11 +18,11 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
/* /*
* We cannot grow the buffer if we're not reading * We cannot grow the buffer if we're not reading
* into the prs_struct, or if we don't own the memory. * into the io_struct, or if we don't own the memory.
*/ */
if(UNMARSHALLING(ps) || !ps->is_dynamic) { if(UNMARSHALLING(ps) || !ps->is_dynamic) {
DEBUG(0,("prs_grow: Buffer overflow - unable to expand buffer by %u bytes.\n", DEBUG(0,("io_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
(unsigned int)extra_space)); (unsigned int)extra_space));
return False; return False;
} }
@ -76,7 +41,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
new_size = MAX(MAX_PDU_FRAG_LEN,extra_space); new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
if((new_data = malloc(new_size)) == NULL) { if((new_data = malloc(new_size)) == NULL) {
DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size)); DEBUG(0,("io_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
return False; return False;
} }
memset(new_data, '\0', new_size ); memset(new_data, '\0', new_size );
@ -88,7 +53,7 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space); new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);
if ((new_data = Realloc(ps->data_p, new_size)) == NULL) { if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_grow: Realloc failure for size %u.\n", DEBUG(0,("io_grow: Realloc failure for size %u.\n",
(unsigned int)new_size)); (unsigned int)new_size));
return False; return False;
} }
@ -104,14 +69,14 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
Ensure we can read/write to a given offset. Ensure we can read/write to a given offset.
********************************************************************/ ********************************************************************/
char *prs_mem_get(prs_struct *ps, uint32 extra_size) char *io_mem_get(io_struct *ps, uint32 extra_size)
{ {
if(UNMARSHALLING(ps)) { if(UNMARSHALLING(ps)) {
/* /*
* If reading, ensure that we can read the requested size item. * If reading, ensure that we can read the requested size item.
*/ */
if (ps->data_offset + extra_size > ps->buffer_size) { if (ps->data_offset + extra_size > ps->buffer_size) {
DEBUG(0,("prs_mem_get: reading data of size %u would overrun buffer.\n", DEBUG(0,("io_mem_get: reading data of size %u would overrun buffer.\n",
(unsigned int)extra_size )); (unsigned int)extra_size ));
return NULL; return NULL;
} }
@ -119,7 +84,7 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
/* /*
* Writing - grow the buffer if needed. * Writing - grow the buffer if needed.
*/ */
if(!prs_grow(ps, extra_size)) if(!io_grow(ps, extra_size))
return False; return False;
} }
return &ps->data_p[ps->data_offset]; return &ps->data_p[ps->data_offset];
@ -129,7 +94,7 @@ char *prs_mem_get(prs_struct *ps, uint32 extra_size)
Initialise a parse structure - malloc the data if requested. Initialise a parse structure - malloc the data if requested.
********************************************************************/ ********************************************************************/
BOOL prs_init(prs_struct *ps, uint32 size, BOOL io) BOOL io_init(io_struct *ps, uint32 size, BOOL io)
{ {
ZERO_STRUCTP(ps); ZERO_STRUCTP(ps);
ps->io = io; ps->io = io;
@ -142,7 +107,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, BOOL io)
if (size != 0) { if (size != 0) {
ps->buffer_size = size; ps->buffer_size = size;
if((ps->data_p = (char *)malloc((size_t)size)) == NULL) { if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size)); DEBUG(0,("io_init: malloc fail for %u bytes.\n", (unsigned int)size));
return False; return False;
} }
ps->is_dynamic = True; /* We own this memory. */ ps->is_dynamic = True; /* We own this memory. */
@ -157,7 +122,7 @@ BOOL prs_init(prs_struct *ps, uint32 size, BOOL io)
XXXX side-effect of this function is to increase the debug depth XXXX XXXX side-effect of this function is to increase the debug depth XXXX
********************************************************************/ ********************************************************************/
void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name) void io_debug(io_struct *ps, int depth, char *desc, char *fn_name)
{ {
DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->data_offset, fn_name, desc)); DEBUG(5+depth, ("%s%06x %s %s\n", tab_depth(depth), ps->data_offset, fn_name, desc));
} }
@ -167,13 +132,13 @@ void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name)
zeros. zeros.
********************************************************************/ ********************************************************************/
BOOL io_align2(prs_struct *ps, int offset) BOOL io_align2(io_struct *ps, int offset)
{ {
uint32 mod = (ps->data_offset + offset) & (2-1); uint32 mod = (ps->data_offset + offset) & (2-1);
if (mod != 0) { if (mod != 0) {
uint32 extra_space = (2 - mod); uint32 extra_space = (2 - mod);
if(!prs_grow(ps, extra_space)) if(!io_grow(ps, extra_space))
return False; return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space); memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space; ps->data_offset += extra_space;
@ -182,13 +147,13 @@ BOOL io_align2(prs_struct *ps, int offset)
return True; return True;
} }
BOOL io_align4(prs_struct *ps, int offset) BOOL io_align4(io_struct *ps, int offset)
{ {
uint32 mod = (ps->data_offset + offset) & (4-1); uint32 mod = (ps->data_offset + offset) & (4-1);
if (mod != 0) { if (mod != 0) {
uint32 extra_space = (4 - mod); uint32 extra_space = (4 - mod);
if(!prs_grow(ps, extra_space)) if(!io_grow(ps, extra_space))
return False; return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space); memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space; ps->data_offset += extra_space;
@ -202,7 +167,7 @@ BOOL io_align4(prs_struct *ps, int offset)
zeros. zeros.
********************************************************************/ ********************************************************************/
BOOL prs_align(prs_struct *ps, int align) BOOL io_align(io_struct *ps, int align)
{ {
uint32 mod = ps->data_offset & (align-1); uint32 mod = ps->data_offset & (align-1);
@ -210,7 +175,7 @@ BOOL prs_align(prs_struct *ps, int align)
if (align != 0 && mod != 0) { if (align != 0 && mod != 0) {
uint32 extra_space = (align - mod); uint32 extra_space = (align - mod);
if(!prs_grow(ps, extra_space)) if(!io_grow(ps, extra_space))
return False; return False;
memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space); memset(&ps->data_p[ps->data_offset], '\0', (size_t)extra_space);
ps->data_offset += extra_space; ps->data_offset += extra_space;
@ -220,21 +185,14 @@ BOOL prs_align(prs_struct *ps, int align)
} }
void print_asc(int level, unsigned char *buf,int len)
{
int i;
for (i=0;i<len;i++)
DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.'));
}
/******************************************************************* /*******************************************************************
read from a socket into memory. read from a socket into memory.
********************************************************************/ ********************************************************************/
BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout) BOOL io_read(io_struct *ps, int fd, size_t len, int timeout)
{ {
BOOL ok; BOOL ok;
size_t prev_size = ps->buffer_size; size_t prev_size = ps->buffer_size;
if (!prs_grow(ps, len)) if (!io_grow(ps, len))
{ {
return False; return False;
} }
@ -250,52 +208,19 @@ BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout)
return ok; return ok;
} }
void dump_data(int level,char *buf1,int len)
{
unsigned char *buf = (unsigned char *)buf1;
int i=0;
if (len<=0) return;
DEBUG(level,("[%03X] ",i));
for (i=0;i<len;) {
DEBUG(level,("%02X ",(int)buf[i]));
i++;
if (i%8 == 0) DEBUG(level,(" "));
if (i%16 == 0) {
print_asc(level,&buf[i-16],8); DEBUG(level,(" "));
print_asc(level,&buf[i-8],8); DEBUG(level,("\n"));
if (i<len) DEBUG(level,("[%03X] ",i));
}
}
if (i%16) {
int n;
n = 16 - (i%16);
DEBUG(level,(" "));
if (n>8) DEBUG(level,(" "));
while (n--) DEBUG(level,(" "));
n = MIN(8,i%16);
print_asc(level,&buf[i-(i%16)],n); DEBUG(level,(" "));
n = (i%16) - n;
if (n>0) print_asc(level,&buf[i-n],n);
DEBUG(level,("\n"));
}
}
/******************************************************************* /*******************************************************************
do IO on a uint32. do IO on a uint32.
********************************************************************/ ********************************************************************/
BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags) BOOL io_uint32(char *name, io_struct *ps, int depth, uint32 *data32, unsigned flags)
{ {
char *q; char *q;
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
if (!prs_align(ps, 4)) return False; if (!io_align(ps, 4)) return False;
q = prs_mem_get(ps, sizeof(uint32)); q = io_mem_get(ps, sizeof(uint32));
if (q == NULL) return False; if (q == NULL) return False;
DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32) DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data32)
@ -307,18 +232,18 @@ BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned f
/******************************************************************* /*******************************************************************
do IO on a uint16. do IO on a uint16.
********************************************************************/ ********************************************************************/
BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags) BOOL io_uint16(char *name, io_struct *ps, int depth, uint16 *data16, unsigned flags)
{ {
char *q; char *q;
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
if (!prs_align(ps, 2)) return False; if (!io_align(ps, 2)) return False;
q = prs_mem_get(ps, sizeof(uint16)); q = io_mem_get(ps, sizeof(uint16));
if (q == NULL) return False; if (q == NULL) return False;
DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16) DBG_RW_SVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data16)
ps->data_offset += sizeof(uint16); ps->data_offset += sizeof(uint16);
return True; return True;
@ -327,13 +252,13 @@ BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned f
/******************************************************************* /*******************************************************************
do IO on a uint8. do IO on a uint8.
********************************************************************/ ********************************************************************/
BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags) BOOL io_uint8(char *name, io_struct *ps, int depth, uint8 *data8, unsigned flags)
{ {
char *q; char *q;
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
q = prs_mem_get(ps, sizeof(uint8)); q = io_mem_get(ps, sizeof(uint8));
if (q == NULL) return False; if (q == NULL) return False;
DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data8) DBG_RW_IVAL(name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, *data8)
@ -345,7 +270,7 @@ BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flag
/******************************************************************* /*******************************************************************
do IO on a pointer do IO on a pointer
********************************************************************/ ********************************************************************/
BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags) BOOL io_pointer(char *desc, io_struct *ps, int depth, void **p, unsigned flags)
{ {
uint32 v; uint32 v;
@ -360,7 +285,7 @@ BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags)
/******************************************************************* /*******************************************************************
Stream a null-terminated string. Stream a null-terminated string.
********************************************************************/ ********************************************************************/
BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags) BOOL io_SMBSTR(char *name, io_struct *ps, int depth, char **str, unsigned flags)
{ {
char *q; char *q;
uint8 *start; uint8 *start;
@ -371,7 +296,7 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
if (UNMARSHALLING(ps)) { if (UNMARSHALLING(ps)) {
*str = prs_mem_get(ps, 0); *str = io_mem_get(ps, 0);
if (*str == NULL) if (*str == NULL)
return False; return False;
len = strlen(*str); len = strlen(*str);
@ -379,25 +304,17 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
} }
else else
{ {
len = strlen(*str); len = strlen(*str)+1;
start = (uint8*)q; start = (uint8*)q;
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
q = prs_mem_get(ps, 1); q = io_mem_get(ps, 1);
if (q == NULL) if (q == NULL)
return False; return False;
RW_CVAL(ps->io, q, (*str)[i],0); RW_CVAL(ps->io, q, (*str)[i],0);
if ((*str)[i] == 0)
break;
ps->data_offset++; ps->data_offset++;
} }
/* The terminating null. */
(*str)[i] = '\0';
RW_CVAL(ps->io, q, (*str)[i], 0);
ps->data_offset++;
} }
DEBUG(5,("%s%04x %s: %s\n", tab_depth(depth), DEBUG(5,("%s%04x %s: %s\n", tab_depth(depth),
@ -408,16 +325,14 @@ BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags
/****************************************************************** /******************************************************************
do IO on a byte array do IO on a byte array
********************************************************************/ ********************************************************************/
BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, unsigned flags) BOOL io_uint8s(char *name, io_struct *ps, int depth, uint8 **data8s, int len, unsigned flags)
{ {
char *q; char *q;
size_t num_bytes = len * sizeof(uint8); size_t num_bytes = len * sizeof(uint8);
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
if (!prs_align(ps, 2)) return False; q = io_mem_get(ps, num_bytes);
q = prs_mem_get(ps, num_bytes);
if (q == NULL) return False; if (q == NULL) return False;
if (MARSHALLING(ps)) if (MARSHALLING(ps))
@ -427,26 +342,92 @@ BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, u
else else
{ {
*data8s = q; *data8s = q;
dump_data(depth+5, q, num_bytes); dump_data(depth+5, *data8s, num_bytes);
} }
ps->data_offset += num_bytes; ps->data_offset += num_bytes;
return True; return True;
} }
/******************************************************************
do IO on a fixed-size byte array
********************************************************************/
BOOL io_uint8s_fixed(char *name, io_struct *ps, int depth, uint8 *data8s, int len, unsigned flags)
{
char *q;
size_t num_bytes = len * sizeof(uint8);
if (!(flags & PARSE_SCALARS)) return True;
q = io_mem_get(ps, num_bytes);
if (q == NULL) return False;
DBG_RW_PCVAL(True, name, depth, ps->data_offset, ps->io, q, data8s, len)
ps->data_offset += num_bytes;
return True;
}
/******************************************************************
do IO on an io (eh?? :)
********************************************************************/
BOOL io_io_struct(char *name, io_struct *ps, int depth, io_struct *io, unsigned flags)
{
char *q;
uint16 len;
if (!(flags & PARSE_SCALARS)) return True;
q = io_mem_get(ps, sizeof(uint16));
if (q == NULL) return False;
/* length first */
if (MARSHALLING(ps))
{
len = io->data_offset;
}
if (!io_uint16("len", ps, depth+1, &len, flags))
{
return False;
}
if (UNMARSHALLING(ps))
{
if (!io_init(io, len, UNMARSHALL))
{
return False;
}
}
/* now data */
q = io_mem_get(ps, len * sizeof(uint8));
if (q == NULL) return False;
if (MARSHALLING(ps))
{
DBG_RW_PCVAL(False, name, depth+1, ps->data_offset, ps->io, q, io->data_p, len)
}
else
{
io->data_p = q;
dump_data(depth+5, q, len);
}
ps->data_offset += len;
return True;
}
/****************************************************************** /******************************************************************
do IO on a unicode array do IO on a unicode array
********************************************************************/ ********************************************************************/
BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags) BOOL io_wstring(char *name, io_struct *ps, int depth, uint16 *data16s, int len, unsigned flags)
{ {
char *q; char *q;
if (!(flags & PARSE_SCALARS)) return True; if (!(flags & PARSE_SCALARS)) return True;
if (!prs_align(ps, 2)) return False; if (!io_align(ps, 2)) return False;
q = prs_mem_get(ps, len * sizeof(uint16)); q = io_mem_get(ps, len * sizeof(uint16));
if (q == NULL) return False; if (q == NULL) return False;
DBG_RW_PSVAL(False, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data16s, len) DBG_RW_PSVAL(False, name, depth, ps->data_offset, ps->io, ps->bigendian_data, q, data16s, len)
@ -459,7 +440,19 @@ BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len,
/****************************************************************** /******************************************************************
allocate some memory for a parse structure allocate some memory for a parse structure
********************************************************************/ ********************************************************************/
BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size) void io_free(io_struct *ps)
{
if (ps->is_dynamic && ps->data_p)
{
free(ps->data_p);
ps->data_p = NULL;
}
}
/******************************************************************
allocate some memory for a parse structure
********************************************************************/
BOOL io_alloc(char *name, io_struct *ps, void **ptr, unsigned size)
{ {
(*ptr) = (void *)malloc(size); (*ptr) = (void *)malloc(size);
if (*ptr) return True; if (*ptr) return True;
@ -469,7 +462,7 @@ BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size)
/****************************************************************** /******************************************************************
realloc some memory for a parse structure realloc some memory for a parse structure
********************************************************************/ ********************************************************************/
BOOL io_realloc(char *name, prs_struct *ps, void **ptr, unsigned size) BOOL io_realloc(char *name, io_struct *ps, void **ptr, unsigned size)
{ {
(*ptr) = (void *)Realloc(*ptr, size); (*ptr) = (void *)Realloc(*ptr, size);
if (*ptr) return True; if (*ptr) return True;

View File

@ -27,7 +27,7 @@ typedef unsigned char uint8;
typedef unsigned short uint16; typedef unsigned short uint16;
typedef unsigned short wchar; typedef unsigned short wchar;
typedef unsigned uint32; typedef unsigned uint32;
typedef char *string; typedef char *SMBSTR;
#ifndef _PSTRING #ifndef _PSTRING
@ -50,7 +50,7 @@ typedef char fstring[FSTRING_LEN];
#define MAX_STRINGLEN 256 #define MAX_STRINGLEN 256
#define MAX_BUFFERLEN 512 #define MAX_BUFFERLEN 512
typedef struct _prs_struct typedef struct _io_struct
{ {
BOOL io; /* parsing in or out of data stream */ BOOL io; /* parsing in or out of data stream */
/* /*
@ -61,26 +61,32 @@ typedef struct _prs_struct
BOOL is_dynamic; /* Do we own this memory or not ? */ BOOL is_dynamic; /* Do we own this memory or not ? */
uint32 data_offset; /* Current working offset into data. */ uint32 data_offset; /* Current working offset into data. */
uint32 buffer_size; /* Current size of the buffer. */ uint32 buffer_size; /* Current size of the buffer. */
uint32 grow_size; /* size requested via prs_grow() calls */ uint32 grow_size; /* size requested via io_grow() calls */
char *data_p; /* The buffer itself. */ char *data_p; /* The buffer itself. */
} prs_struct; } io_struct;
char *prs_mem_get(prs_struct *ps, uint32 extra_size); char *io_mem_get(io_struct *ps, uint32 extra_size);
BOOL prs_init(prs_struct *ps, uint32 size, BOOL io); BOOL io_init(io_struct *ps, uint32 size, BOOL io);
void prs_debug(prs_struct *ps, int depth, char *desc, char *fn_name); void io_debug(io_struct *ps, int depth, char *desc, char *fn_name);
BOOL prs_align(prs_struct *ps, int align); BOOL io_align(io_struct *ps, int align);
BOOL io_align4(prs_struct *ps, int align); BOOL io_align4(io_struct *ps, int align);
BOOL io_align2(prs_struct *ps, int align); BOOL io_align2(io_struct *ps, int align);
void print_asc(int level, unsigned char *buf,int len); void print_asc(int level, unsigned char *buf,int len);
BOOL prs_read(prs_struct *ps, int fd, size_t len, int timeout); BOOL io_read(io_struct *ps, int fd, size_t len, int timeout);
void dump_data(int level,char *buf1,int len); void dump_data(int level,char *buf1,int len);
BOOL io_alloc(char *name, prs_struct *ps, void **ptr, unsigned size); BOOL io_alloc(char *name, io_struct *ps, void **ptr, unsigned size);
BOOL io_uint32(char *name, prs_struct *ps, int depth, uint32 *data32, unsigned flags); BOOL io_uint32(char *name, io_struct *ps, int depth, uint32 *data32, unsigned flags);
BOOL io_uint16(char *name, prs_struct *ps, int depth, uint16 *data16, unsigned flags); BOOL io_uint16(char *name, io_struct *ps, int depth, uint16 *data16, unsigned flags);
BOOL io_uint8(char *name, prs_struct *ps, int depth, uint8 *data8, unsigned flags); BOOL io_uint8(char *name, io_struct *ps, int depth, uint8 *data8, unsigned flags);
BOOL io_pointer(char *desc, prs_struct *ps, int depth, void **p, unsigned flags); BOOL io_pointer(char *desc, io_struct *ps, int depth, void **p, unsigned flags);
BOOL io_string(char *name, prs_struct *ps, int depth, char **str, unsigned flags); BOOL io_SMBSTR(char *name, io_struct *ps, int depth, char **str, unsigned flags);
BOOL io_wstring(char *name, prs_struct *ps, int depth, uint16 *data16s, int len, unsigned flags); BOOL io_io_struct(char *name, io_struct *ps, int depth, io_struct *io, unsigned flags);
BOOL io_uint8s(char *name, prs_struct *ps, int depth, uint8 **data8s, int len, unsigned flags); BOOL io_wstring(char *name, io_struct *ps, int depth, uint16 *data16s, int len, unsigned flags);
BOOL io_uint8s_fixed(char *name, io_struct *ps, int depth, uint8 *data8s, int len, unsigned flags);
BOOL io_uint8s(char *name, io_struct *ps, int depth, uint8 **data8s, int len, unsigned flags);
char *tab_depth(int depth);
void *Realloc(void *p,size_t size);
void print_asc(int level, unsigned char *buf,int len);
void dump_data(int level,char *buf1,int len);

View File

@ -51,6 +51,11 @@ function add_element(type, elem, case,
} }
elem_num=num_elements; elem_num=num_elements;
if (substr(elem, 1, 1) == ".") {
elem=substr(elem, 2);
elements[elem_num, "nowire"]=1;
}
if (substr(elem, 1, 1) == "*") { if (substr(elem, 1, 1) == "*") {
elem=substr(elem, 2); elem=substr(elem, 2);
elements[elem_num, "ptr"]=1; elements[elem_num, "ptr"]=1;
@ -185,7 +190,8 @@ function end_function(LOCAL, i)
i--; i--;
} }
} }
add_function_param("[out]", "STATUS", "status"); if (return_result!="void")
add_function_param("[out]", return_result, "status");
end_struct(); end_struct();
} }

View File

@ -4,7 +4,9 @@ end:
return True; return True;
fail: fail:
ZERO_STRUCTP(il); if (UNMARSHALLING(ps)) {
ZERO_STRUCTP(il);
}
return False; return False;
} /* @FUNCNAME@ */ } /* @FUNCNAME@ */

View File

@ -1,13 +1,17 @@
/******************************************************************* /*******************************************************************
parse a @STRUCTNAME@ structure parse a @STRUCTNAME@ structure
********************************************************************/ ********************************************************************/
BOOL @FUNCNAME@(char *desc, prs_struct *ps, int depth, BOOL @FUNCNAME@(char *desc, io_struct *ps, int depth,
@STRUCTNAME@ *il, unsigned flags) @STRUCTNAME@ *il, unsigned flags)
{ {
prs_debug(ps, depth, desc, "@FUNCNAME@"); io_debug(ps, depth, desc, "@FUNCNAME@");
depth++; depth++;
if (!(flags & PARSE_SCALARS)) goto buffers; if (!(flags & PARSE_SCALARS)) goto buffers;
ZERO_STRUCTP(il); #if 0
if (UNMARSHALLING(ps)) {
ZERO_STRUCTP(il);
}
#endif
/* parse the scalars */ /* parse the scalars */

View File

@ -1,5 +1,5 @@
if (strcmp(test,"@TEST@")==0) { if (strcmp(test,"@TEST@")==0) {
@TEST@ il; @TEST@ il;
ret = io_@TEST@("@TEST@", ps, 0, &il, PARSE_SCALARS|PARSE_BUFFERS); ret = io_@TEST@("@TEST@", ps, 0, &il, flags);
} }

View File

@ -1,8 +1,7 @@
#include "prs_@MODULE@.h"
#include "prs_@MODULE@.c" #include "prs_@MODULE@.c"
static BOOL run_test(char *test, prs_struct *ps) static BOOL run_test(char *test, io_struct *ps, int flags)
{ {
BOOL ret; BOOL ret;

View File

@ -1,5 +1,6 @@
/* auto-generated structure parsers for @MODULE@ /* auto-generated structure parsers for @MODULE@
generated by aparser generated by aparser
*/ */
#include "includes.h"
#include "prs_@MODULE@.h"

View File

@ -1 +1 @@
if(!prs_align(ps)) goto fail; if(!io_align(ps)) goto fail;

View File

@ -1,5 +1,5 @@
if ((@FLAGS@ & PARSE_SCALARS) && if ((@FLAGS@ & PARSE_SCALARS) &&
!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail; !io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
{ {
int i; int i;
for (i=0;i<il->@ARRAY_LEN@;i++) { for (i=0;i<il->@ARRAY_LEN@;i++) {

View File

@ -1,3 +1,4 @@
if (UNMARSHALLING(ps))
{ {
int i; int i;
for (i=0;ps->data_offset < ps->buffer_size;i++) { for (i=0;ps->data_offset < ps->buffer_size;i++) {
@ -5,3 +6,12 @@
if (!io_@TYPE@("@ELEM@...", ps, depth+1, &il->@ELEM@[i], @FLAGS@)) goto fail; if (!io_@TYPE@("@ELEM@...", ps, depth+1, &il->@ELEM@[i], @FLAGS@)) goto fail;
} }
} }
else
{
int i = -1;
/* HACK ALERT! */
do {
i++;
if (!io_@TYPE@("@ELEM@...", ps, depth+1, &il->@ELEM@[i], @FLAGS@)) goto fail;
} while (il->@ELEM@[i].tag2 != 0);
}

View File

@ -1 +1 @@
if (!prs_uint16("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail; if (!io_uint16("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;

View File

@ -1 +1 @@
if (!prs_uint32("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail; if (!io_uint32("@ELEM@", ps, depth+1, &il->@ELEM@)) goto fail;

View File

@ -1,2 +1,2 @@
if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail; if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
if (!io_uint8s("@ELEM@", ps, depth+1, &il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail; if (!io_uint8s("@ELEM@", ps, depth+1, &il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail;

View File

@ -1,2 +1 @@
if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*@ARRAY_LEN@)) goto fail; if (!io_uint8s_fixed("@ELEM@", ps, depth+1, il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;
if (!io_uint8s("@ELEM@", ps, depth+1, &il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;

View File

@ -1,2 +1,2 @@
if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*il->@ARRAY_LEN@)) goto fail; if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(il->@ARRAY_LEN@))) goto fail;
if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail; if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, il->@ARRAY_LEN@, @FLAGS@)) goto fail;

View File

@ -1,2 +1,2 @@
if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*@ARRAY_LEN@)) goto fail; if (!io_alloc("@ELEM@", ps, (void **)&il->@ELEM@, sizeof(*(il->@ELEM@))*(@ARRAY_LEN@))) goto fail;
if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail; if (!io_wstring("@ELEM@", ps, depth+1, il->@ELEM@, @ARRAY_LEN@, @FLAGS@)) goto fail;

View File

@ -53,10 +53,19 @@ function parse_error(msg) {
next; next;
} }
/^[ \t]*STATUS.*\(/ { /^[ \t]*void.*\(/ {
{if (current_struct!="") parse_error("you cannot have nested structures");} {if (current_struct!="") parse_error("you cannot have nested structures");}
split($0,a,"[ \t;()]*"); split($0,a,"[ \t;()]*");
start_function(a[2], a[3]); start_function(a[2], a[3]);
return_result="void";
next;
}
/^[ \t]*STATUS.*\(|^[ \t]*void.*\(/ {
{if (current_struct!="") parse_error("you cannot have nested structures");}
split($0,a,"[ \t;()]*");
start_function(a[2], a[3]);
return_result="STATUS";
next; next;
} }
@ -118,6 +127,7 @@ function parse_error(msg) {
/^[ \t]*\);/ { /^[ \t]*\);/ {
end_function(); end_function();
return_result="";
next; next;
} }

View File

@ -1,11 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include "parser.h"
#include "test.h" #include "test.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -14,7 +6,7 @@ int main(int argc, char *argv[])
char *fname, *test; char *fname, *test;
int fd; int fd;
struct stat st; struct stat st;
prs_struct ps; io_struct ps;
if (argc < 3) { if (argc < 3) {
printf("usage: vluke <structure> <file>\n"); printf("usage: vluke <structure> <file>\n");
@ -31,13 +23,13 @@ int main(int argc, char *argv[])
} }
fstat(fd, &st); fstat(fd, &st);
prs_init(&ps, 0, MARSHALL); io_init(&ps, 0, MARSHALL);
ps.is_dynamic=True; ps.is_dynamic=True;
prs_read(&ps, fd, st.st_size, 0); io_read(&ps, fd, st.st_size, 0);
ps.data_offset = 0; ps.data_offset = 0;
ps.buffer_size = ps.grow_size; ps.buffer_size = ps.grow_size;
ps.io = UNMARSHALL; ps.io = UNMARSHALL;
ret = run_test(test, &ps); ret = run_test(test, &ps, PARSE_SCALARS|PARSE_BUFFERS);
printf("\nret=%s\n", ret?"OK":"Bad"); printf("\nret=%s\n", ret?"OK":"Bad");
printf("Trailer is %d bytes\n\n", ps.grow_size - ps.data_offset); printf("Trailer is %d bytes\n\n", ps.grow_size - ps.data_offset);
if (ps.grow_size - ps.data_offset > 0) { if (ps.grow_size - ps.data_offset > 0) {