From a02b520d25c946d272ef9ec757edd5418172fe38 Mon Sep 17 00:00:00 2001
From: Phil <phil@secdev.org>
Date: Thu, 22 Oct 2009 15:43:33 +0200
Subject: [PATCH] Added RawVal object that ca be assigned to any packet field
 and will inserted as-is in the packet string

ex:
>>> a=IP(len=RawVal("####"))
>>> str(a)
'F\x00####\x00\x01\x00\x005\xb5\x00\x00\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x00'
---
 scapy/packet.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/scapy/packet.py b/scapy/packet.py
index 656645c9..86315760 100644
--- a/scapy/packet.py
+++ b/scapy/packet.py
@@ -17,6 +17,13 @@ except ImportError:
     pass
 
 
+class RawVal:
+    def __init__(self, val):
+        self.val = val
+    def __str__(self):
+        return self.val
+
+
 class Packet(BasePacket):
     __metaclass__ = Packet_metaclass
     name=None
@@ -275,7 +282,11 @@ class Packet(BasePacket):
     def do_build(self):
         p=""
         for f in self.fields_desc:
-            p = f.addfield(self, p, self.getfieldval(f.name))
+            val = self.getfieldval(f.name)
+            if isinstance(val, RawVal):
+                p += str(val)
+            else:
+                p = f.addfield(self, p, val)
         return p
     
     def post_build(self, pkt, pay):
-- 
GitLab