detect the compressed stuff, actually returns bad data, but at least it doesnt crash, add the python code of the guide too so ik what i need to do

This commit is contained in:
Mylloon 2023-06-14 18:52:17 +02:00
parent 4951920f67
commit 121e93e0a0
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -25,6 +25,10 @@ and decode_name_simple reader =
let length = int_of_char (Bytes.get reader.data (reader.pointer + pos)) in let length = int_of_char (Bytes.get reader.data (reader.pointer + pos)) in
if length = 0 if length = 0
then 1, parts then 1, parts
else if length land 0b1100_0000 <> 0
then (
let decoded_name = decode_compressed_name reader length in
length + 1, decoded_name :: parts)
else ( else (
let part = Bytes.sub_string reader.data (reader.pointer + pos + 1) length in let part = Bytes.sub_string reader.data (reader.pointer + pos + 1) length in
let last_length, parts' = read_parts (parts @ [ part ]) (pos + 1 + length) in let last_length, parts' = read_parts (parts @ [ part ]) (pos + 1 + length) in
@ -32,10 +36,40 @@ and decode_name_simple reader =
in in
let offset, parts = read_parts [] 0 in let offset, parts = read_parts [] 0 in
String.to_bytes (String.concat "." parts), offset String.to_bytes (String.concat "." parts), offset
(*
---
def decode_compressed_name(length, reader):
pointer_bytes = bytes([length & 0b0011_1111]) + reader.read(1)
pointer = struct.unpack("!H", pointer_bytes)[0]
current_pos = reader.tell()
reader.seek(pointer)
result = decode_name(reader)
reader.seek(current_pos)
return result
---
*)
and decode_compressed_name _reader _length =
(* TODO *)
String.empty
;; ;;
let parse_record _reader = (*
let name, _offset_name = Bytes.empty, 0 (* decode_name_simple reader *) in ---
def parse_record(reader):
name = decode_name_simple(reader)
# the the type, class, TTL, and data length together are 10 bytes (2 + 2 + 4 + 2 = 10)
# so we read 10 bytes
data = reader.read(10)
# HHIH means 2-byte int, 2-byte-int, 4-byte int, 2-byte int
type_, class_, ttl, data_len = struct.unpack("!HHIH", data)
data = reader.read(data_len)
return DNSRecord(name, type_, class_, ttl, data)
---
*)
let parse_record reader =
let name, _offset_name = decode_name_simple reader in
(* TODO *)
let type_, class_, ttl, data = 0, 0, 0, Bytes.empty in let type_, class_, ttl, data = 0, 0, 0, Bytes.empty in
{ name; type_; class_; ttl; data } { name; type_; class_; ttl; data }
;; ;;