• About TV's server
  • New in version 3.20
  • New in version 3.10
  • About the source code
  • About protocols/plugins
  • TV's server API
  • Protocol Initialisation
  • Protocol binding
  • Protocol Listening and handling
  • Protocol data storage
  • Control panel
  • Multi column list
  • Time and date
  • Http protocol functions
  • Unimplemented and/or replaced functions
  • Source code

    index About source code
    TV's server is written in assembler and was last successfully compiled with Flat Assembler (Fasm) version 1.73.30. The source is written to be able to be compiled for intel x86 and amd64 (read macros for more information about how this is done). The source is written for windows, however, all the windows API calls are made in source files in directory 'windows' and since version 3.20 it is ported to Linxu.

    Macros
    The source is written for both intel x86 and AMD64 processors. This was possible because of some macros created for this project. These macros are defined in file "Use32.inc" (32-bit macros) and "Use64.inc" (64-bit macros), located in the "windows" and "linux" directory. The following macro's are located in these files:
    Macro, constant or function32-bit meaning64-bit meaning
    is64--Makes it possible to use "if used is64" macro to enter specific x64 code.
    is32Makes it possible to use "if used is32" macro to enter specific x86 code.--
    StartProc--Writes parameters passed through a function, called with the Windows/Linux calling convention x64, on stack.
    EndProc--Removes parameters set on stack by StartProc, only functional on Linux x64.
    MakeStack--Creates free space on stack and rounds stack up to 16 bytes to be able to call a function with the Windows calling convention x64.
    ppushSimply pushes a pointer on stack in Windows. On Linux it first writes the pointer to register EAX and then pushes it on stack. The register is restored after the operation.Simply pushes a pointer on stack in Windows. On Linux it first writes the pointer to register RAX and then pushes it on stack. The register is restored after the operation.
    pmovSimply moves a pointer to a memory location on Windows. On Linux it first writes the pointer to register EAX and then writes it to a memory location. The register is restored after the operation.Simply moves a pointer to a memory location on Windows. On Linux it first writes the pointer to register RAX and then writes it to a memory location. The register is restored after the operation.
    p2movSame as pmov, except that you can now chose the register to move the pointer to the memory location in Linux. This is necessary is the pointer is calculated using the value on EAX.Same as pmov, except that you can now chose the register to move the pointer to the memory location in Linux. This is necessary is the pointer is calculated using the value on RAX.
    argpushPushes parameters on stack to be able to call a function with the Windows/Linux calling convention x86.Writes a parameter to register or on stack to be able to call a function with the Windows/Linux calling convention x64.
    argpushsysSets arguments on registers for a Linux syscall. Only used in folder 'linux'.Sets arguments on registers for a Linux syscall. Only used in folder 'linux'.
    linuxCallSet Linux syscall number on EAX and calls int 0x80.Set Linux syscall number on RAX and calls syscall.
    denterThis is a function and is used to start an internal function, it saves the following registers on stack: ESP, EDI, ESI, EBX, EDX, ECX en EBP and moves esp to ebp after one push (first parameter on stack will be on EBP+0x8). This is an internal function and is used to start an function, it saves the following registers on stack: RSP, RDI, RSI, RBX, RDX, RCX, R12, R13, R14, R15 and RBP and moves rsp to rbp after one push (first parameter on stack will be on RBP+0x10).
    dleaveThis is a function and restores the registers pushed on stack by denter.This is a function and restores the registers pushed on stack by denter.
    lodsp, stosp, movsp, scasp and jpcxzWill be replaced with instructions: lodsd, stosd, movsd, scasd and jecxz.Will be replaced with instruction lodsq, stosq, movsq, scasq, jrcxz.
    peax, pecx, pebx, pedx, pedi, pesi, pesi, pebp and pespWill be replaced with registers: eax, ecx, ebx, edx, edi, esi, esi, ebp and esp.Will be replaced with registers: rax, rcx, rbx, rdx, rdi, rsi, rsi, rbp and rsp.
    ClearSpaceForAPI0The size used on stack by macro MakeStack, which is 8*16 bytes.
    UsedSizeBydEnterThe size used by function denter to place the registers on stack. This is 20 bytes.The size used by function denter to place the registers on stack. This is 72 bytes.
    FunctionReturnFactorThe size that need to be cleared from stack when returning a Windows/Linux calling convention x86 function. This is 4 bytes per parameter on Windows, 0 bytes on Linux.The size that need to be cleared from stack when returning a Windows/Linux calling convention x64 function. This is 0 bytes per parameter.
    psizeThe size of a pointer, 4 bytes.The size of a pointer, 8 bytes.
    pointerThe name in fasm to create a dword (4 bytes), 'dd'.The name in fasm to create a qword (8 bytes), 'dq'.
    pdwordThe name in fasm to identify a dword, 'dword'.The name in fasm to identify a qword, 'qword'.

    Calling conventions
    There are more than one calling convention in this project, however, there is one commonly used calling convention: This calling convention can be recognized by the following block of comments above a function.

    The first parameter that needs to be pushed on stack before calling this function is number 6 "error code" and the last parameter to push on stack is number 1 "ProtocolSession".

    The functions exported by __asm_exchange_tables (and the function itself) in parameter get_export_table are all using the system default calling convection. These are different between x64/x86 and Windows/Linux, this is done for C compaibility. The functions on parameter get_export_table_internal are using the calling convention explained here above.

    If another calling convention is used it is clearly explained how to call this function. The example below shows it needs input on register EAX and 1 parameter on stack. Output of this function will be on register EDX and EBX.


    Memory mangement
    TV's server has thee different memory mangement modes that can be set in file windows/modulefunctions.inc. Please recompile all the files in the project when switching to an other mode, it effects them all.
    ModeUsageMeaning
    VirtualVery quick, but memory consumingAll memory is requested by calling VirtualAlloc. The smallest amount of memory it returns is ~4K. This means that if you require 10 bytes, you get 4K.
    Virtual DividerSlower than Virtual, but AL LOT less memory consuming.This will allocate memory though VirtualAlloc and divides it over multple requests. The overhead for every peace of memory is 0x10 bytes and all memory is rounded up by 0x10.
    Virtual Thread DividerA litle bit more memory consuming than Virtual divider, but a lot quicker.It's basicly the same as Virtual Divider, with the difference that every thread divides there own peace of memory, instead of centralizing it. This means that different threads don't have to wait on each other, which is a hugh win in time. The pointer that holds the allocated memory is placed in the TEB.

    Path structure
    FolderContents
    .Contains assembly files from TV's server and it's plugin's, compiled files and an install and uninstall script.
    windowsContains source that calls and uses Windows API.
    linuxContains source that calls and uses Linux API.
    test protocolsPlug-ins that where build to test the functionality of TV's server. Run "register_x86.reg" or "register_x64.reg" to register these plug-ins (edit the correct path in these files before running).
    include_tvs_server_plugin_tcp_protocolAssembly files for the TCP/IP protocol, included by the tvs_server_plugin_tcp_protocol_x**.asm file.
    include_tvs_server_plugin_httpAssembly files for the HTTP protocol, included by the tvs_server_plugin_http_x**.asm file.
    include_tvs_server_plugin_control_panelAssembly files for Control panel protocol, included by the tvs_server_plugin_control_panel_x**.asm file.
    include_plugin_generalAssembly files included by all plug-ins.
    include_http_protocolAssembly files included by the http protocol DLL used by the control panel and HTTP plugin-protocol.
    includeAssembly files included mostly by the base and some files are also included by some protocols.
    controlpanelHtml pages that are used by the control panel plugin to build the user interface.