git-svn-id: https://spexeah.com:8443/svn/Asuro@918 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
kieron
2020-07-09 21:06:52 +00:00
parent 6db9d71479
commit 5d26e199aa
28 changed files with 240 additions and 15 deletions

View File

@ -78,7 +78,7 @@ type
OSXSAVE : Boolean;
AVX : Boolean;
RESV3 : Boolean;
RESV4 : Boolean;
RDRAND : Boolean;
RESV5 : Boolean;
end;
TClockSpeed = record
@ -247,6 +247,7 @@ begin
if CPUID.Capabilities1^.XSAVE then writestringWND(', XSAVE', WND);
if CPUID.Capabilities1^.OSXSAVE then writestringWND(', OSXSAVE', WND);
if CPUID.Capabilities1^.AVX then writestringWND(', AVX', WND);
if CPUID.Capabilities1^.RDRAND then writestringWND(', RDRAND', WND);
writestringlnWND(' ', WND);
end;

View File

@ -166,13 +166,28 @@ type
UID : uint32;
end;
PUDPHeader = ^TUDPHeader;
TUDPHeader = record
TUDPHeader = packed record
SrcPort : uint16;
DstPort : uint16;
Length : uint16;
Checksum : uint16;
end;
TUDPSendContext = record
DstPort : uint16;
socket : PUDPBindContext;
context : PPacketContext;
end;
PUDPSendContext = ^TUDPSendContext;
TUDPPseudoHeader = packed record
Source_IP : uint32;
Destination_IP : uint32;
Protocol : uint16;
Length : uint16;
UDP_Source : uint16;
UDP_Destination : uint16;
UDP_Length : uint16;
end;
PUDPPseudoHeader = ^TUDPPseudoHeader;
{ Callback Types }
@ -187,12 +202,22 @@ const
NULL_MAC : Array[0..5] of uint8 = ($00, $00, $00, $00, $00, $00);
FORCE_MAC : Array[0..5] of uint8 = ($08, $00, $27, $E6, $3F, $81);
{ IPs }
BROADCAST_IP : Array[0..3] of uint8 = ($FF, $FF, $FF, $FF);
NULL_IP : Array[0..3] of uint8 = ($00, $00, $00, $00);
{ ICMP Data }
ICMP_DATA_GENERIC : Array[0..31] of uint8 = ( $61, $62, $63, $64, $65, $66, $67, $68,
$69, $6a, $6b, $6c, $6d, $6e, $6f, $70,
$71, $72, $73, $74, $75, $76, $77, $61,
$62, $63, $64, $65, $66, $67, $68, $69 );
{ UDP Test Data }
UDPT_S_IP : Array[0..3] of uint8 = ($C0, $A8, $00, $1F);
UDPT_D_IP : Array[0..3] of uint8 = ($C0, $A8, $00, $1E);
UDPT_DATA : Array[0..1] of uint8 = ($48, $69);
implementation
end.

View File

@ -19,15 +19,136 @@ var
procedure register();
function bind(bindContext : PUDPBindContext) : TUDPError;
function unbind(bindContext : PUDPBindContext) : TUDPError;
procedure send(p_data : void; p_len : uint16; udpContext : PUDPSendContext);
implementation
uses
console, terminal;
procedure send(p_data : void; p_len : uint16; p_context : PPacketContext; bindContext : PUDPBindContext);
begin
function CalculateChecksum(p_data : void; p_len : uint16; udpContext : PUDPSendContext) : uint16;
var
pseudoBuffer : void;
pseudoBuffer32 : puint32;
pseudoBuffer16 : puint16;
pseudoBuffer8 : puint8;
pseudoSize : uint16;
nullend : boolean;
pseudoHeader : PUDPPseudoHeader;
pseduoSrc : uint16;
i : uint16;
Checksum_u : uint32;
Checksum_c : uint16;
Checksum_f : uint16;
size : uint16;
begin
size:= p_len + sizeof(TUDPHeader);
//Checksum
if udpContext^.socket <> nil then begin
pseduoSrc:= udpContext^.socket^.Port;
end else begin
pseduoSrc:= 0;
end;
nullend:= false;
pseudoSize:= p_len;
if (pseudoSize mod 2) = 1 then begin
pseudoSize:= pseudoSize + 1;
nullend:= true;
end;
pseudoBuffer:= kalloc(sizeof(TUDPPseudoHeader) + pseudoSize);
pseudoBuffer8:= puint8(pseudoBuffer);
pseudoBuffer16:= puint16(pseudoBuffer);
pseudoBuffer32:= puint32(pseudoBuffer32);
pseudoHeader:= PUDPPseudoHeader(pseudoBuffer);
copyIPv4(puint8(@udpContext^.context^.IP.Source[0]), puint8(@pseudoBuffer8[0]));
copyIPv4(puint8(@udpContext^.context^.IP.Destination[0]), puint8(@pseudoBuffer8[4]));
pseudoHeader^.Protocol:= $11;
pseudoHeader^.Length:= pseudoSize + sizeof(TUDPHeader);
pseudoHeader^.UDP_Source:= pseduoSrc;
pseudoHeader^.UDP_Destination:= udpContext^.DstPort;
pseudoHeader^.UDP_Length:= size;
memcpy(uint32(p_data), uint32(pseudoBuffer) + SizeOf(TUDPPseudoHeader), p_len);
if nullend then pseudoBuffer8[pseudoSize-1]:= 0;
pseudoHeader^.Source_IP:= switchendian32(pseudoHeader^.Source_IP);
pseudoHeader^.Destination_IP:= switchendian32(pseudoHeader^.Destination_IP);
//writehexln(pseudoHeader^.Source_IP);
//writehexln(pseudoHeader^.Destination_IP);
//writehexln(pseudoHeader^.Protocol);
//writehexln(pseudoHeader^.Length);
//writehexln(pseudoHeader^.UDP_Source);
//writehexln(pseudoHeader^.UDP_Destination);
//writehexln(pseudoHeader^.UDP_Length);
Checksum_u:= 0;
for i:=0 to (SizeOf(TUDPPseudoHeader) div 2)-1 do begin
//writestring('+ ');
//writehexln(pseudoBuffer16[i]);
Checksum_u:= Checksum_u + pseudoBuffer16[i];
end;
for i:=(SizeOf(TUDPPseudoHeader) div 2) to ((pseudoSize + SizeOf(TUDPPseudoHeader)) div 2) - 1 do begin
//writestring('- ');
//ritehexln( switchendian16(pseudoBuffer16[i]));
Checksum_u:= Checksum_u + switchendian16(pseudoBuffer16[i]);
end;
Checksum_f:= Checksum_u AND $FFFF;
Checksum_c:= (Checksum_u AND $FFFF0000) SHR 16;
Checksum_f:= Checksum_f + Checksum_c;
Checksum_f:= not Checksum_f;
CalculateChecksum:= Checksum_f;
end;
procedure send(p_data : void; p_len : uint16; udpContext : PUDPSendContext);
var
buffer : void;
hdr : PUDPHeader;
size : uint16;
checksum : uint16;
i : uint16;
begin
if udpContext <> nil then begin
size:= p_len + sizeof(TUDPHeader);
buffer:= kalloc(size);
hdr:= PUDPHeader(kalloc(sizeof(TUDPHeader)));
if udpContext^.socket <> nil then begin
hdr^.SrcPort:= switchendian16(udpContext^.socket^.Port);
end else begin
hdr^.SrcPort:= 0;
end;
hdr^.DstPort:= switchendian16(udpContext^.DstPort);
checksum:= CalculateChecksum(p_data, p_len, udpContext);
hdr^.Checksum:= switchendian16(checksum);
hdr^.Length:= switchendian16(size);
memcpy(uint32(hdr), uint32(buffer), sizeof(TUDPHeader));
memcpy(uint32(p_data), uint32(buffer + sizeof(TUDPHeader)), p_len);
for i:=0 to p_len-1 do begin
writehexpair(puint8(p_data)[i]);
end;
writestringln(' ');
for i:=0 to p_len-1 do begin
writechar(pchar(p_data)[i]);
end;
writestringln(' ');
for i:=0 to size-1 do begin
writehexpair(puint8(buffer)[i]);
end;
writestringln(' ');
udpContext^.context^.Protocol.L4:= $11;
ipv4.send(buffer, size, udpContext^.context);
kfree(buffer);
kfree(void(hdr));
end;
end;
function bind(bindContext : PUDPBindContext) : TUDPError;
@ -120,9 +241,14 @@ end;
procedure register();
var
i : uint16;
i : uint16;
context : PUDPBindContext;
r : TUDPError;
SendContext : PUDPSendContext;
BindContext : PUDPBindContext;
PacketContext : PPacketContext;
Checksum : uint32;
begin
for i:=0 to 65535 do begin
@ -133,13 +259,28 @@ begin
//context^.Callback:= @TestRecv;
//context^.UID:= 4398724;
//r:= bind(context);
//writestring('[TestBind] ');
writestring('[TestBind] ');
//case r of
// tueOK:writestringln('22294 bind OK');
// tuePortInUse:writestringln('22294 port in use');
// tueGenericError:writestringln('22294 generic error');
// tuePortRestricted:writestringln('22294 restricted');
//end;
SendContext:= PUDPSendContext(kalloc(SizeOf(TUDPSendContext)));
BindContext:= PUDPBindContext(kalloc(SizeOf(TUDPBindContext)));
PacketContext:= PPacketContext(kalloc(SizeOf(TPacketContext)));
SendContext^.DstPort:= 10;
SendContext^.Socket:= BindContext;
SendContext^.Context:= PacketContext;
BindContext^.Port:= 20;
copyIPv4(puint8(@UDPT_S_IP[0]), puint8(@PacketContext^.IP.Source[0]));
copyIPv4(puint8(@UDPT_D_IP[0]), puint8(@PacketContext^.IP.Destination[0]));
Checksum:= CalculateChecksum(void(@UDPT_DATA[0]), 2, SendContext);
writehexln(Checksum);
//while true do begin end;
ipv4.registerProtocol($11, @ProcessPacket);
end;

36
src/include/rand.pas Normal file
View File

@ -0,0 +1,36 @@
unit rand;
interface
function rand32 : uint32;
function rand16 : uint16;
function rand8 : uint8;
procedure srand(seed : uint32);
implementation
var
next : uint32 = 1;
function rand32 : uint32;
begin
next:= next * 1103515245 + 12345;
rand32:= (next div 65536) mod 32768;
end;
function rand16 : uint16;
begin
rand16:= rand32 AND $FFFF;
end;
function rand8 : uint8;
begin
rand8:= rand32 AND $FF;
end;
procedure srand(seed : uint32);
begin
next:= seed;
end;
end.

View File

@ -38,14 +38,15 @@ uses
shell,
memview,
splash,
cpu,
themer,
netlog,
vmlog,
vm,
vmstate,
edit,
udpcat;
udpcat,
cpu,
rand;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -154,6 +155,7 @@ begin
isrmanager.init();
faults.init();
RTC.init();
rand.srand((getDateTime.Seconds SHR 24) OR (getDateTime.Minutes SHR 16) OR (getDateTime.Hours SHR 8) OR (getDateTime.Day));
pmemorymanager.init();
vmemorymanager.init();
lmemorymanager.init();

View File

@ -8,7 +8,7 @@ unit udpcat;
interface
uses
console, terminal, keyboard, util, strings, tracer, udp, nettypes, lmemorymanager;
console, terminal, keyboard, util, strings, tracer, udp, nettypes, netutils, lmemorymanager;
procedure init();
@ -32,6 +32,8 @@ procedure OnReceive(p_data : void; p_len : uint16; p_context : PUDPPacketContext
var
c : pchar;
i : uint16;
sendContext : PUDPSendContext;
Message : pchar;
begin
c:= pchar(p_data);
@ -39,6 +41,23 @@ begin
writecharWND(c[i], Handle);
end;
writestringlnWND(' ', Handle);
sendContext:= PUDPSendContext(kalloc(sizeof(TUDPSendContext)));
sendContext^.DstPort:= p_context^.SrcPort;
sendContext^.Socket:= context;
sendContext^.context:= p_context^.PacketContext;
sendContext^.context^.TTL:= 128;
contextMACSwitch(p_context^.PacketContext);
contextIPv4Switch(p_context^.PacketContext);
Message:= pchar(kalloc(6));
Message[0]:= 'A';
Message[1]:= 'S';
Message[2]:= 'U';
Message[3]:= 'R';
Message[4]:= 'O';
Message[5]:= '!';
udp.send(void(Message), 6, sendContext);
kfree(void(sendContext));
kfree(void(Message));
end;
procedure run(Params : PParamList);