2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 static const struct dcerpc_interface_table *find_pipe(const char *pipe_name)
26 for (i=0;dcerpc_pipes[i];i++) {
27 if (strcmp(dcerpc_pipes[i]->name, pipe_name) == 0) {
31 if (!dcerpc_pipes[i]) {
32 printf("pipe '%s' not in table\n", pipe_name);
35 return dcerpc_pipes[i];
38 static const struct dcerpc_interface_call *find_function(
39 const struct dcerpc_interface_table *p,
43 if (isdigit(function[0])) {
44 i = strtol(function, NULL, 0);
47 for (i=0;i<p->num_calls;i++) {
48 if (strcmp(p->calls[i].name, function) == 0) {
52 if (i == p->num_calls) {
53 printf("Function '%s' not found\n", function);
59 static void usage(void)
61 printf("Usage: ndrdump <pipe> <function> <inout> <filename>\n");
65 static void show_pipes(void)
69 printf("\nYou must specify a pipe\n");
70 printf("known pipes are:\n");
71 for (i=0;dcerpc_pipes[i];i++) {
72 if(dcerpc_pipes[i]->helpstring) {
73 printf("\t%s - %s\n", dcerpc_pipes[i]->name, dcerpc_pipes[i]->helpstring);
75 printf("\t%s\n", dcerpc_pipes[i]->name);
81 static void show_functions(const struct dcerpc_interface_table *p)
85 printf("\nYou must specify a function\n");
86 printf("known functions on '%s' are:\n", p->name);
87 for (i=0;i<p->num_calls;i++) {
88 printf("\t0x%02x (%2d) %s\n", i, i, p->calls[i].name);
93 int main(int argc, char *argv[])
95 const struct dcerpc_interface_table *p;
96 const struct dcerpc_interface_call *f;
97 const char *pipe_name, *function, *inout, *filename;
101 struct ndr_pull *ndr;
110 setup_logging("ndrdump", DEBUG_STDOUT);
119 p = find_pipe(pipe_name);
130 if (strcmp(inout, "in") == 0 ||
131 strcmp(inout, "request") == 0) {
133 } else if (strcmp(inout, "out") == 0 ||
134 strcmp(inout, "response") == 0) {
137 printf("Bad inout value '%s'\n", inout);
141 f = find_function(p, function);
143 data = file_load(filename, &size);
152 mem_ctx = talloc_init("ndrdump");
154 ndr = ndr_pull_init_blob(&blob, mem_ctx);
156 st = talloc_zero(mem_ctx, f->struct_size);
158 printf("Unable to allocate %d bytes\n", f->struct_size);
162 if (flags == NDR_OUT) {
163 ndr->flags |= LIBNDR_FLAG_REF_ALLOC;
166 status = f->ndr_pull(ndr, flags, st);
168 printf("pull returned %s\n", nt_errstr(status));
170 if (ndr->offset != ndr->data_size) {
171 printf("WARNING! %d unread bytes\n", ndr->data_size - ndr->offset);
172 dump_data(0, ndr->data+ndr->offset, ndr->data_size - ndr->offset);
175 pr.mem_ctx = mem_ctx;
176 pr.print = ndr_print_debug_helper;
178 f->ndr_print(&pr, function, flags, st);
180 if (!NT_STATUS_IS_OK(status) ||
181 ndr->offset != ndr->data_size) {
182 printf("dump FAILED\n");