How to integrate SocksCap64 into your software?

This is mainly for some developer that hope to integrate SocksCap64 into their own software.

This integration is limited to free or learning to use, Please contact the author for business needs. At the same time, please be sure to respect the local laws and regulations, if the resulting legal issues have nothing to do with the software.

1: Command line£º
From version SocksCap64 2.6 began to support the command line mode startup parameters, the relevant instructions are as follows (parameters are case sensitive):

-i specify the proxy IP, such as: -i192.168.1.1 (Note: -i behind the proxy parameters without spaces)

-p Specifies the proxy port, for example: -p1080

-t Specifies the proxy type, such as: -t5
type: 
3: http
4: socks 4/4a
5: socks 5
6: shadwosocks

-r Specifies the full path for the program file to run with quotes
such as: -r¡±C:\Program Files (x86)\Google\Chrome\Application\chrome.exe¡±

-d Specifies the working directory of the program file to be run. If it is not specified, it will take the directory where the program file needs to be run. 
such as: -d¡±C:\Program Files (x86)\Google\Chrome\Application\¡±

-a Specifies that the parameter to be passed to the program.
such as: -ahttp://www.sockscap64.com/

-n Specifies how the domain name resolves, if not specified by default is DNS_REMOTE (2)
such as: -n2
local: 0
local then remote: 1
remote: 2

-w Specifies the window display mode hide / show. -whide hidden window start, -wshow display window to start. If the parameters specified in a program file (-r parameter), but did not specify the window display mode, the default is hidden window (-whide)
such as: -whide

-e -esilent Whether to start silently, quiet way to start, will not pop up some tips, such as: prompt to import the browser, etc. For example: -esilent in a quiet way to start.

--quit out before the start of the process. 

--hideicon hide tray icon

2: through SOCKET interaction, this requires you have a certain programming skills

SC64 provides a local NS parsing service that can handle some control behavior that typically listens on port 29810, but in some cases also changes (for example, the port is already in advance). 

So I suggest you find the installation directory of SC64 config\ns.ini, which records the current SC64 NS service is working on the port, as follows:

[basic]
ip=127.0.0.1
port=29810
searchport=1

'Port' is the current working port.

Okay, lets do it.

1, Open registry HKEY_CURRENT_USER\Software\Sockscap64
    Install_Dir: Specifies the working directory of sockscap64.

2, Read file Install_Dir\config\ns.ini. Get the port at which SC64 is currently working on the NS.

3, Create a Socket to send control commands to it. 
    Communication packet format (ns reply information is the same format): cmd (1 bytes) + length of packet body(4 bytes) + packet body
    length of packet body: length of 'packet body'
    packet body: Using "\ r \ n" segment of the multi-line text, using Utf8 encoding, end with 0x00 (send instructions must be sent to the end of 0x00).
    NS reply command only has two lines, separated by "\ r \ n", the first line is the error code, 0 means success, 1 for general error, other values for the specific error code.

    a) Show / hide main window
       cmd: 9
       line 1: on: show main window. off: hide main window

    b) Change currently proxy
       cmd: 10
       Line 1	proxy address£¬such as 1.2.3.4
       Line 2	proxy port£¬such as 1080
       Line 3	proxy account£¬empty means anonymous
       Line 4	proxy password, empty means anonymous
       Line 5	proxy type 3 for http,4 for socks4/4a,5 for socks5£¬6 for Shadowsocks
       Line 6	encryption, used only shadowsocks, The optional value is: aes-256-cfb, aes-192-cfb,aes-128-cfb,rc4-md5,rc4,salsa20,chacha20,chacha20-ietf

     c) Enable / Disable proxy ( That is: temporary disable SC64)
       cmd: 11
       line 1: on£ºenable£»off£ºdisable

     d) run program
       cmd: 12
       Line 1	full path name of program
       Line 2	wordking directory
       Line 3	parameters

     e)	Activity detection
       cmd: 13
       have not packet body, so length of packet body is 0

     f)	set proxy rules
	cmd:14
	   Each command consists of four lines (clear command only one line)
       Line 1	the sub-command of set proxy fule
	   The option value is:
       set:  set proxy fules
       clear: clear all proxy fules ( only one line )

       Line 2	target hosts
       A IP address, such as: 127.0.0.1
       A IP range, such as: 192.168.1.1-192.168.1.100
       If it is an asterisk, it means matching all.
       Can be multiple IP or multiple IP segments, separated by (semicolon). For example:
       192.168.1.1;10.0.0.1;139.12.10.1-139.12.10.100

       Line 3	target ports
       A port,such as: 1080
       A port range, such as: 8000-8010
       If it is an asterisk, it means matching all.

       Line 4	action
       proxy:  proxy
       direct: direct
       block: block
	   
	   Note: ip and port are AND relationship. For example: also specify the IP: 192.168.1.1 port: 80 that match to 192.168.1.1:80

       Note: You must set the rules first, and then start the target program. After the target program is started, the change rule does not take effect.

       Therefore, if you need to set only to allow some IP through the proxy, other IP are not through the proxy, you can send instructions as follows (in the example only allowed 133.155.1.10-133.155.1.15 through the proxy request network, all other requests are directly connected ):
       clear
       set\r\n*\r\n*\r\ndirect
       set\r\n133.155.1.10-133.155.1.15\r\n*\r\nproxy
	 g) exit program
	   no packet body. no replies.

