1 19 20 package jcifs.dcerpc; 21 22 import java.io.IOException ; 23 import jcifs.dcerpc.ndr.*; 24 25 public abstract class DcerpcMessage extends NdrObject implements DcerpcConstants { 26 27 protected int ptype = -1; 28 protected int flags = 0; 29 protected int length = 0; 30 protected int call_id = 0; 31 protected int alloc_hint = 0; 32 protected int result = 0; 33 34 public boolean isFlagSet(int flag) { 35 return (flags & flag) == flag; 36 } 37 public void unsetFlag(int flag) { 38 flags |= flag; 39 } 40 public void setFlag(int flag) { 41 flags |= flag; 42 } 43 public DcerpcException getResult() { 44 if (result != 0) 45 return new DcerpcException(result); 46 return null; 47 } 48 49 void encode_header(NdrBuffer buf) { 50 buf.enc_ndr_small(5); 51 buf.enc_ndr_small(0); 52 buf.enc_ndr_small(ptype); 53 buf.enc_ndr_small(flags); 54 buf.enc_ndr_long(0x00000010); 55 buf.enc_ndr_short(length); 56 buf.enc_ndr_short(0); 57 buf.enc_ndr_long(call_id); 58 } 59 void decode_header(NdrBuffer buf) throws NdrException { 60 buf.dec_ndr_small(); 61 buf.dec_ndr_small(); 62 ptype = buf.dec_ndr_small(); 63 flags = buf.dec_ndr_small(); 64 if (buf.dec_ndr_long() != 0x00000010) 65 throw new NdrException("Data representation not supported"); 66 length = buf.dec_ndr_short(); 67 if (buf.dec_ndr_short() != 0) 68 throw new NdrException("DCERPC authentication not supported"); 69 call_id = buf.dec_ndr_long(); 70 } 71 public void encode(NdrBuffer buf) throws NdrException { 72 int start = buf.getIndex(); 73 int alloc_hint_index = 0; 74 75 buf.advance(16); 76 if (ptype == 0) { 77 alloc_hint_index = buf.getIndex(); 78 buf.enc_ndr_long(0); 79 buf.enc_ndr_short(0); 80 buf.enc_ndr_short(getOpnum()); 81 } 82 83 encode_in(buf); 84 length = buf.getIndex() - start; 85 86 if (ptype == 0) { 87 buf.setIndex(alloc_hint_index); 88 alloc_hint = length - alloc_hint_index; 89 buf.enc_ndr_long(alloc_hint); 90 } 91 92 buf.setIndex(start); 93 encode_header(buf); 94 buf.setIndex(start + length); 95 } 96 public void decode(NdrBuffer buf) throws NdrException { 97 decode_header(buf); 98 99 if (ptype != 12 && ptype != 2 && ptype != 3) 100 throw new NdrException("Unexpected ptype: " + ptype); 101 102 if (ptype == 2 || ptype == 3) { 103 alloc_hint = buf.dec_ndr_long(); 104 buf.dec_ndr_short(); 105 buf.dec_ndr_short(); 106 } 107 if (ptype == 3) { 108 result = buf.dec_ndr_long(); 109 } else { 110 decode_out(buf); 111 } 112 } 113 114 public abstract int getOpnum(); 115 public abstract void encode_in(NdrBuffer buf) throws NdrException; 116 public abstract void decode_out(NdrBuffer buf) throws NdrException; 117 } 118 | Popular Tags |