Skip to content

Commit

Permalink
SunnyNetV4
Browse files Browse the repository at this point in the history
  • Loading branch information
qtgolang committed Dec 29, 2024
1 parent 0b5dc82 commit 4894290
Show file tree
Hide file tree
Showing 13,731 changed files with 3,229 additions and 2,669,801 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
24 changes: 18 additions & 6 deletions Api/SunnyNet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1363,24 +1363,36 @@ func SetIeProxy(SunnyContext int, Off bool) bool {
return w.SetIeProxy(Off)
}

// StartProcess 开始进程代理 只允许一个 SunnyNet 使用
func StartProcess(SunnyContext int) bool {
// OpenDrive 开始进程代理/打开驱动 只允许一个 SunnyNet 使用 [会自动安装所需驱动文件]
// IsNfapi 如果为true表示使用NFAPI驱动 如果为false 表示使用Proxifier
func OpenDrive(SunnyContext int, IsNf bool) bool {
SunnyNet.SunnyStorageLock.Lock()
w := SunnyNet.SunnyStorage[SunnyContext]
SunnyNet.SunnyStorageLock.Unlock()
if w != nil {
return w.StartProcess()
return w.OpenDrive(IsNf)
}
return false
}

// ProcessALLName 设置是否全部进程通过 所有 SunnyNet 通用
func ProcessALLName(SunnyContext int, open bool) {
// UnDrive 卸载驱动,仅Windows 有效【需要管理权限】执行成功后会立即重启系统,若函数执行后没有重启系统表示没有管理员权限
func UnDrive(SunnyContext int) {
SunnyNet.SunnyStorageLock.Lock()
w := SunnyNet.SunnyStorage[SunnyContext]
SunnyNet.SunnyStorageLock.Unlock()
if w != nil {
w.ProcessALLName(open)
w.UnDrive()
}
return
}

// ProcessALLName 设置是否全部进程通过
func ProcessALLName(SunnyContext int, open, StopNetwork bool) {
SunnyNet.SunnyStorageLock.Lock()
w := SunnyNet.SunnyStorage[SunnyContext]
SunnyNet.SunnyStorageLock.Unlock()
if w != nil {
w.ProcessALLName(open, StopNetwork)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Api/UDP.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Api

import (
NFapi "github.com/qtgolang/SunnyNet/src/nfapi"
"github.com/qtgolang/SunnyNet/src/ProcessDrv/nfapi"
"github.com/qtgolang/SunnyNet/src/public"
)

Expand Down
11 changes: 0 additions & 11 deletions BuildLibrary/BuildCertificateDocument.bat

This file was deleted.

10 changes: 0 additions & 10 deletions BuildLibrary/BuildExe.bat

This file was deleted.

11 changes: 0 additions & 11 deletions BuildLibrary/BuildGoScriptCode.bat

This file was deleted.

Binary file removed BuildLibrary/DLLCopy.exe
Binary file not shown.
Binary file modified BuildLibrary/Library/windows/x32/Sunny.dll
Binary file not shown.
11 changes: 8 additions & 3 deletions BuildLibrary/Library/windows/x32/Sunny.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,14 @@ WebpToPng Webp图片转Png图片 根据文件名
extern __declspec(dllexport) GoUint8 WebpToPng(char* webpPath, char* savePath);

/*
StartProcess 开启进程代理 加载 nf api 驱动
OpenDrive 开启进程代理/打开驱动
*/
extern __declspec(dllexport) GoUint8 StartProcess(GoInt SunnyContext);
extern __declspec(dllexport) GoUint8 OpenDrive(GoInt SunnyContext, GoUint8 isNf);

/*
UnDrive 卸载驱动,仅Windows 有效【需要管理权限】执行成功后会立即重启系统,若函数执行后没有重启系统表示没有管理员权限
*/
extern __declspec(dllexport) void UnDrive(GoInt SunnyContext);

/*
ProcessAddName 进程代理 添加进程名
Expand Down Expand Up @@ -542,7 +547,7 @@ extern __declspec(dllexport) void ProcessCancelAll(GoInt SunnyContext);
/*
ProcessALLName 进程代理 设置是否全部进程通过
*/
extern __declspec(dllexport) void ProcessALLName(GoInt SunnyContext, GoUint8 open);
extern __declspec(dllexport) void ProcessALLName(GoInt SunnyContext, GoUint8 open, GoUint8 StopNetwork);

/*
GetCommonName 证书管理器 获取证书 CommonName 字段
Expand Down
Binary file removed DrDLL
Binary file not shown.
23 changes: 19 additions & 4 deletions SunnyNet/Callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (s *proxyRequest) CallbackTCPRequest(callType int, msg *public.TcpMsg, Remo

// CallbackBeforeRequest HTTP发起请求处理回调
func (s *proxyRequest) CallbackBeforeRequest() {

if s.noCallback() {
return
}
if s.Response.Response != nil {
if s.Response.Body != nil {
_ = s.Response.Body.Close()
Expand Down Expand Up @@ -160,7 +162,9 @@ func (s *proxyRequest) CallbackBeforeRequest() {

// CallbackBeforeResponse HTTP请求完成处理回调
func (s *proxyRequest) CallbackBeforeResponse() {

if s.noCallback() {
return
}
pid, _ := strconv.Atoi(s.Pid)

MessageId := NewMessageId()
Expand Down Expand Up @@ -210,9 +214,21 @@ func (s *proxyRequest) CallbackBeforeResponse() {
Call.Call(s.HttpCall, s.Global.SunnyContext, s.Theology, MessageId, int(public.HttpResponseOK), Method, Url, err, pid)
}

// 不要进入回调的一些请求
func (s *proxyRequest) noCallback() bool {
if (s.Target.Host == "127.0.0.1" || s.Target.Host == "::1") && s.Target.Port == 9229 {
//疑似Chrome 开发人员工具正在使用专用的DevTools 即使所有选项卡都关闭,除了空白的新选项卡,它仍可能继续发送
//https://superuser.com/questions/1419223/google-chrome-developer-tools-start-knocking-to-127-0-0-1-and-1-ip-on-9229-por
return true
}
return false
}

// CallbackError HTTP请求失败处理回调
func (s *proxyRequest) CallbackError(err string) {

if s.noCallback() {
return
}
pid, _ := strconv.Atoi(s.Pid)
MessageId := NewMessageId()
messageIdLock.Lock()
Expand Down Expand Up @@ -260,7 +276,6 @@ func (s *proxyRequest) CallbackError(err string) {

// CallbackWssRequest HTTP->Websocket请求处理回调
func (s *proxyRequest) CallbackWssRequest(State int, Method, Url string, msg *public.WebsocketMsg, MessageId int) {

if s._Display == false {
return
}
Expand Down
2 changes: 1 addition & 1 deletion SunnyNet/ConnUDP.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package SunnyNet
import (
"github.com/qtgolang/SunnyNet/src/CrossCompiled"
"github.com/qtgolang/SunnyNet/src/Interface"
NFapi "github.com/qtgolang/SunnyNet/src/nfapi"
"github.com/qtgolang/SunnyNet/src/ProcessDrv/nfapi"
)

type ConnUDP Interface.ConnUDPScriptCall
Expand Down
132 changes: 81 additions & 51 deletions SunnyNet/SunnyNet.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/qtgolang/SunnyNet/src/GoScriptCode"
"github.com/qtgolang/SunnyNet/src/HttpCertificate"
"github.com/qtgolang/SunnyNet/src/Interface"
"github.com/qtgolang/SunnyNet/src/ProcessDrv/Info"
"github.com/qtgolang/SunnyNet/src/ReadWriteObject"
"github.com/qtgolang/SunnyNet/src/Resource"
"github.com/qtgolang/SunnyNet/src/SunnyProxy"
Expand Down Expand Up @@ -1211,18 +1212,7 @@ func (s *proxyRequest) https() {
tlsConfig.InsecureSkipVerify = true
//继续握手
err = tlsConn.ServerHandshake(HelloMsg)
if err == nil {
_ = tlsConn.SetDeadline(time.Now().Add(3 * time.Second))
peek = tlsConn.Peek(1)
if len(peek) < 1 {
s.Target.Parse(serverName, "")
s.Request = new(http.Request)
s.Request.URL, _ = url.Parse(public.HttpsRequestPrefix + strings.ReplaceAll(s.Target.Host, public.Space, public.NULL))
s.Request.Host = strings.ReplaceAll(s.Target.Host, public.Space, public.NULL)
s.Error(clientCertificateVerifyFail, true)
return
}
} else {
if err != nil {
s.Target.Parse(serverName, "")
s.Request = new(http.Request)
s.Request.URL, _ = url.Parse(public.HttpsRequestPrefix + strings.ReplaceAll(s.Target.Host, public.Space, public.NULL))
Expand All @@ -1232,7 +1222,7 @@ func (s *proxyRequest) https() {
strings.Index(ess, "An existing connection was forcibly closed by the remote host") != -1 ||
strings.Index(ess, "An established connection was aborted by the software in your host machine") != -1 ||
strings.Index(ess, "client offered only unsupported versions") != -1 {
s.Error(clientHandshakeFail, true)
s.Error(err, true)
return
}
s.Error(clientHandshakeFail, true)
Expand Down Expand Up @@ -1290,7 +1280,6 @@ func (s *proxyRequest) https() {
}

var clientHandshakeFail = errors.New("与客户端握手失败")
var clientCertificateVerifyFail = errors.New("客户端验证证书失败")
var noHttps = errors.New("No HTTPS ")

func (s *proxyRequest) handleWss() bool {
Expand Down Expand Up @@ -2353,30 +2342,62 @@ func (s *Sunny) SetGoCallback(httpCall func(ConnHTTP), tcpCall func(ConnTCP), ws
return s
}

// StartProcess 开始进程代理
func (s *Sunny) StartProcess() bool {
if CrossCompiled.NFapi_IsInit() {
if CrossCompiled.NFapi_ProcessPortInt() != 0 && CrossCompiled.NFapi_SunnyPointer() != uintptr(unsafe.Pointer(s)) {
CrossCompiled.NFapi_MessageBox("启动失败:", "已在其他 SunnyNet 对象启动\r\n\r\n同一进程不能多次加载驱动", 0x00000010)
return false
// UnDrive 卸载驱动,仅Windows 有效【需要管理权限】执行成功后会立即重启系统,若函数执行后没有重启系统表示没有管理员权限
func (s *Sunny) UnDrive() {
CrossCompiled.Drive_UnInstall()
}

// OpenDrive 开始进程代理 会自动安装所需驱动文件
// IsNfapi 如果为true表示使用NFAPI驱动 如果为false 表示使用Proxifier
func (s *Sunny) OpenDrive(IsNfapi bool) bool {
if (CrossCompiled.DrvInitState == CrossCompiled.DrvUndefined && IsNfapi) || (CrossCompiled.DrvInitState == CrossCompiled.DrvNF && IsNfapi) {
if CrossCompiled.NFapi_IsInit() {
if CrossCompiled.NFapi_ProcessPortInt() != 0 && CrossCompiled.NFapi_SunnyPointer() != uintptr(unsafe.Pointer(s)) {
CrossCompiled.NFapi_MessageBox("启动失败:", "已在其他 SunnyNet 对象启动\r\n\r\n同一进程不能多次加载驱动", 0x00000010)
CrossCompiled.DrvInitState = CrossCompiled.DrvNF
return false
}
CrossCompiled.NFapi_SunnyPointer(uintptr(unsafe.Pointer(s)))
CrossCompiled.DrvInitState = CrossCompiled.DrvNF
return true
}
CrossCompiled.NFapi_SunnyPointer(uintptr(unsafe.Pointer(s)))
return true
CrossCompiled.NFapi_ProcessPortInt(uint16(s.Port()))
CrossCompiled.NFapi_IsInit(CrossCompiled.NFapi_ApiInit())
CrossCompiled.NFapi_UdpSendReceiveFunc(s.udpNFSendReceive)
ok := CrossCompiled.NFapi_IsInit()
if ok {
CrossCompiled.DrvInitState = CrossCompiled.DrvNF
} else {
CrossCompiled.DrvInitState = CrossCompiled.DrvUndefined
}
return ok
}
if (CrossCompiled.DrvInitState == CrossCompiled.DrvUndefined && !IsNfapi) || (CrossCompiled.DrvInitState == CrossCompiled.DrvPr && !IsNfapi) {
if !CrossCompiled.Pr_Install() {
return false
}
ok := CrossCompiled.Pr_IsInit()
if !ok {
if CrossCompiled.Pr_SetHandle(s.handleClientConn) {
CrossCompiled.DrvInitState = CrossCompiled.DrvPr
return true
}
}
//已经启动或已经在其他SunnyNet启动
return false
}
CrossCompiled.NFapi_SunnyPointer(uintptr(unsafe.Pointer(s)))
CrossCompiled.NFapi_ProcessPortInt(uint16(s.Port()))
CrossCompiled.NFapi_IsInit(CrossCompiled.NFapi_ApiInit())
CrossCompiled.NFapi_UdpSendReceiveFunc(s.udpNFSendReceive)
return CrossCompiled.NFapi_IsInit()
fmt.Println("你已选择另一个模式,不可切换")
return false
}

// ProcessALLName 是否允许所有进程通过 所有 SunnyNet 通用,
// 请注意GoLang调试时候,请不要使用此命令,因为不管开启或关闭,都会将当前所有TCP链接断开一次
// StopNetwork 是否对所有进程执行一次断网操作
// 请注意GoLang调试时候,StopNetwork请不要设置true
// 因为如果不断开的一次的话,已经建立的TCP链接无法抓包。
// Go程序调试,是通过TCP连接的,若使用此命令将无法调试。
func (s *Sunny) ProcessALLName(open bool) *Sunny {
CrossCompiled.NFapi_SetHookProcess(open)
//CrossCompiled.NFapi_ClosePidTCP(-1)
func (s *Sunny) ProcessALLName(open, StopNetwork bool) *Sunny {
CrossCompiled.NFapi_HookAllProcess(open, StopNetwork)
return s
}

Expand Down Expand Up @@ -2524,8 +2545,13 @@ func (s *Sunny) Close() *Sunny {
_ = conn.Close()
delete(s.connList, k)
}
if CrossCompiled.NFapi_SunnyPointer() == uintptr(unsafe.Pointer(s)) {
CrossCompiled.NFapi_ProcessPortInt(0)
if CrossCompiled.DrvInitState == CrossCompiled.DrvNF {
if CrossCompiled.NFapi_SunnyPointer() == uintptr(unsafe.Pointer(s)) {
CrossCompiled.NFapi_ProcessPortInt(0)
}
}
if CrossCompiled.DrvInitState == CrossCompiled.DrvPr {
CrossCompiled.Pr_SetHandle(nil)
}
s.lock.Unlock()
return s
Expand Down Expand Up @@ -2602,6 +2628,18 @@ func (s *proxyRequest) free() {
s.Request = nil
s.Target = nil
}
func (s *proxyRequest) isDriveConn() (Info.ProxyProcessInfo, uint16) {
if s == nil {
return nil, 0
}
addr, ok := s.Conn.RemoteAddr().(*net.TCPAddr)
if ok {
u := uint16(addr.Port)
info := CrossCompiled.NFapi_GetTcpConnectInfo(u)
return info, u
}
return nil, 0
}
func (s *Sunny) handleClientConn(conn net.Conn) {
Theoni := atomic.AddInt64(&public.Theology, 1)
//存入会话列表 方便停止时,将所以连接断开
Expand All @@ -2626,24 +2664,16 @@ func (s *Sunny) handleClientConn(conn net.Conn) {
req.RwObj = ReadWriteObject.NewReadWriteObject(conn) //构造客户端读写对象
req.Theology = int(Theoni) //当前请求唯一ID
req.Response = response{}
addr, ok := conn.RemoteAddr().(*net.TCPAddr)
if ok {
u := uint16(addr.Port)
//这里是判断 是否是通过 NFapi 驱动进来的数据
if runtime.GOOS == "windows" {
info := CrossCompiled.NFapi_GetTcpConnectInfo(u)
if info != nil {
//如果是 通过 NFapi 驱动进来的数据 对连接信息进行赋值
req.Pid = info.Pid
req.Target.Parse(info.RemoteAddress, info.RemoteProt, info.V6)
req.Target.Parse(req.Target.String(), 0)
//然后进行数据处理,按照HTTPS数据进行处理
req.https()
CrossCompiled.NFapi_DelTcpConnectInfo(u)
CrossCompiled.NFapi_API_NfTcpClose(info.Id)
return
}
}
info, DrivePort := req.isDriveConn()
if info != nil {
//如果是 通过 NFapi 驱动进来的数据 对连接信息进行赋值
req.Pid = info.GetPid()
req.Target.Parse(info.GetRemoteAddress(), info.GetRemotePort(), info.IsV6())
//然后进行数据处理,按照HTTPS数据进行处理
req.https()
info.Close()
CrossCompiled.NFapi_DelTcpConnectInfo(DrivePort)
return
}
req.Pid = CrossCompiled.GetTcpInfoPID(conn.RemoteAddr().String(), s.port)
//若不是 通过 NFapi 驱动进来的数据 那么就是通过代理传递过来的数据
Expand Down Expand Up @@ -2683,6 +2713,6 @@ func (s *Sunny) handleClientConn(conn net.Conn) {
req.httpProcessing(nil, public.TagTcpAgreement)
}
}
func SetDnsServer(server string) {
func (s *Sunny) SetDnsServer(server string) {
dns.SetDnsServer(server)
}
5 changes: 5 additions & 0 deletions SunnyNet/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (s *proxyRequest) httpCall(rw http.ResponseWriter, req *http.Request) {
res.URL.Host = host
res.Host = host
}
ip := net.ParseIP(res.Host)
if ip4 := ip.To4(); ip4 == nil && len(ip) == net.IPv6len {
res.URL.Host = "[" + res.Host + "]"
res.Host = "[" + res.URL.Host + "]"
}
}

}
Expand Down
Loading

0 comments on commit 4894290

Please sign in to comment.