Skip to content
yuanihoPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Simple SOCKS5 Protocol Parsing Library

This is a simple SOCKS5 protocol parsing library that implements basic SOCKS5 protocol parsing. It does not include server or client components and requires network connection operations such as socket or Netty.

Description:

The codec package contains the codec (implementation of MessageCodec<T>), responsible for converting SOCKS5 protocol byte sequences to and from message objects and performing protocol field validity checks (such as VER/RSV/ATYP/CMD/STATUS, etc.).

The io package contains the underlying read/write abstractions and adapters (Reader/Writer and their implementations), used to shield the differences between different transport media such as byte[], ByteBuffer, InputStream/OutputStream, etc., and provide unified readable/writable length checks and Underflow/Overflow exception semantics.

The protocol package stores protocol-level constants and field definitions (such as ProtocolConstants and ProtocolField), used for centralized management of enumerations/constants such as version numbers, method codes, command codes, address types, and response codes, preventing magic values ​​from being scattered throughout the encoding and decoding logic.

The recorders package stores protocol messages and data models (Java records/interfaces), used to express structured data such as handshakes, authentication, command requests/responses, and target addresses, serving as the input and output carriers for the codec.

The exception package stores the exception hierarchy and error code definitions, distinguishing between protocol invalidities (such as Socks5ProtocolException) and boundary issues (such as Socks5UnderflowException / Socks5OverflowException), and providing recoverability indicators and field-level error location information.

Usage: (Using Socket as an example)

// Create a Socket connection

Socket socket = new socket();

socket.connect(new InetSocketAddress(ip, port));

// Use Writer/Reader

OutputStream os = socket.getOutputStream();

InputStream is = socket.getInputStream();

OutputStreamWriter out = new OutputStreamWriter(os);

InputStreamReader in = new InputStreamReader(is);

// Create a handshake packet

byte[] methods = new byte[]{0x00, 0x02};

HandShakeRequest request = new HandShakeRequest(methods);

ByteArrayWriter requestBytes = new ByteArrayWriter();

Socks5Codecs.HAND_SHAKE_REQ.encode(request, requestBytes);

// Send data

out.write(requestBytes.toByteArray());

out.flush();

// Parse the response

HandShakeReply hs = Socks5Codecs.HAND_SHAKE_REP.decode(in);

Finally:

At the time, I was developing SOCKS5-related tools using Java. I found implementing SOCKS5 protocol parsing and related packet construction quite cumbersome. I searched for relevant repositories on GitHub but couldn't find a suitable library, so I created this one. I only spent three days on this library, and as an amateur Java developer, the code will have many flaws and shortcomings. If you have better ideas or implementations, please submit an issue. Finally, I hope this library can help you.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages