• VC编译openssl 3.0.7

    ·

    发布于

    修改于

    1. 安装ActivePerl和NASM
    2. 执行perl Configure no-asm no-shared no-sse2 zlib VC-WIN64A –prefix=d:\openssl-3.0.7 –with-zlib-include=d:\zlib-1.2.13 –with-zlib-lib=d:\zlib-1.2.13\zlib.lib 生成makefile
    3. 执行nmake 进行编译(或者使用jom)
    4. 执行nmake install进行安装
    • VC-WIN64A 使用VC编译器编译WIN64位版本,A表示架构为X64(区别于IA64)
    • VC-WIN32 使用VC编译器编译WIN32位版本
    • no-shared 编译为静态库
    • shared 编译为动态库(默认选项)
    • zlib 使用zlib静态库
    • zlib-dynamic 只用zlib动态库
    • no-zlib 不使用zlib

    可以通过修改第二步生成的makefile文件改变具体的编译链接选项,默认选项为/GF /Gs0 /Gy /MD,在3.1.3版本中发现已经没有这个/MD了,代码生成选项已经移动到了下面。下面是一些选项的含义。

    • /O2(最大速度优化)
    • /GF(消除重复的字符串)
    • /Gs(控制堆栈检查调用)
    • /Gy(启用函数级链接)

    可以根据需要在CFLAGS中调整代码生成选项,我这里使用/MT选项,记得删除文件中其它代码生成选项。若想编译调试版本需要将/MT改为/MDd。

    如果想使用jom -j<线程数>进行多线程编译,则必须给CFLAGS指定/FS选项。

    修改CFLAGS选项
    删除其它代码生成选项

    另外还有一些编译链接选项是分开的,也就是静态库、动态库、可执行程序都有自己独特的编译选项,修改这些内容的时候要注意区分。


  • PE文件释放资源

    ·

    发布于

    修改于

    姑且算是有C和C++两个版本吧。

    //C
    BOOL GetResource(HMODULE mod, const char* rname, const char* rtype, unsigned char** rdata, int* rlen)
    {
    	HRSRC rhandle = FindResourceA(mod, rname, rtype);
    	if (rhandle == NULL)
    		return FALSE;
    	*rlen = SizeofResource(mod, rhandle);
    	HGLOBAL global_handle = LoadResource(mod, rhandle);
    	if (NULL == global_handle)
    		return FALSE;
    	*rdata = LockResource(global_handle);
    	if (*rdata)
    	{
    		DWORD flOldProtect;
    		VirtualProtect(*rdata, *rlen, PAGE_READWRITE, &flOldProtect);
    		return TRUE;
    	}
    	FreeResource(global_handle);
    	return FALSE;
    }
    //C++
    bool GetResource(HMODULE module, const char * rname, const char * rtype, byte* &rdata, int &rlen)
    {
      HRSRC rhandle = FindResourceA(module, rname, rtype);
      if (rhandle == NULL)
        return false;
      rlen = SizeofResource(module, rhandle);
      HGLOBAL global_handle = LoadResource(module, rhandle);
      if (NULL == global_handle)
        return false;
      rdata = reinterpret_cast<byte*>(LockResource(global_handle));
      if (rdata)
      {
        DWORD flOldProtect;
        VirtualProtect(rdata, rlen, PAGE_READWRITE, &flOldProtect);
        return true;
      }
      FreeResource(global_handle);
      return false;
    }

  • 编译安装Apache

    ·

    发布于

    修改于

    下载apr和apr-util到apache源码目录下的srlib目录中,并去掉目录名称中的版本号,如图所示。

    安装步骤:

    1. 安装编译过程中需要用到的工具和库
    2. sudo apt-get install autoconf automake libtool libexpat1-dev libpcre3-dev

      其中前三个是编译apr需要用到的工具,libexpat1-dev是编译apr-util用到的库,最后libpcre3-dev是编译apache本体用到的库。

    3. apr
    4. cd srclib/apr
      ./configure --prefix=/usr/local/apr            
      make && make install
    5. apr-util
    6. cd srclib/apr-util
      ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
      make && make install
    7. apache
    8. ./configure --prefix=/opt/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
      make && make install

  • Linux安装cisco anyconnect VPN client

    ·

    发布于

    修改于

    首先将安装包解压,然后会看到4个组件,我们这里只安装vpn组件。

      1. 安装编译环境(如果已经安装,则忽略此步骤)
    sudo apt-get install build-essential
      1. 执行anyconnect vpn安装脚本
    sudo ./vpn_install.sh

    这一步很简单,只需要同意软件的协议就可以了,anyconnect会被安装到/opt/cisco/anyconnect/目录

      1. 执行vpn 图形界面客户端
    cd /opt/cisco/anyconnect/bin
    ./vpnui

    提示缺少组件libgtk

      1. 安装缺少的组件libgtk
    sudo apt-get install libgtk2.0-0
      1. 再次尝试执行vpn客户端即可成功运行


  • 将整个文件夹权限设置为本用户完全控制(包括所有子文件夹中的文件)

    ·

    发布于

    修改于

    该操作常用于恢复OneDrive的备份文件夹的访问权限:重装系统前将OneDrive文件夹备份到别处,重装系统后,新系统里的用户对备份的文件夹无权访问。

    一共需要两步:

    1. 更改所有者为当前用户
      takeown /f J:\Synologydrive /r
    2. 修改权限(username用户完全控制)
      cacls J:\SynologyDrive\*.* /T /G username:F

  • VMware Workstation 15 注册码

    ·

    发布于

    修改于

    VMware Workstation 15 注册码 序列号 KEY
    AF792-07Y86-481AZ-Z5NE9-YQ280


  • Everyone完全控制权限SECURITY_ATTRIBUTES

    ·

    发布于

    修改于

    SECURITY_ATTRIBUTES SecAttr;
    SECURITY_DESCRIPTOR SecDesc;
    
    InitializeSecurityDescriptor(&SecDesc, SECURITY_DESCRIPTOR_REVISION);
    SetSecurityDescriptorDacl(&SecDesc, TRUE, NULL, FALSE);
    SecAttr.nLength = sizeof(SecAttr);
    SecAttr.bInheritHandle = TRUE;
    SecAttr.lpSecurityDescriptor = &SecDesc;
    CreateEventA(&SecAttr, FALSE, TRUE, "Global\\test");
    SECURITY_ATTRIBUTES SecAttr;
    
    SecAttr.nLength = sizeof(SecAttr);
    SecAttr.bInheritHandle = FALSE;
    ConvertStringSecurityDescriptorToSecurityDescriptorA(
    	"D:(A;; GA;;; WD)",
    	SDDL_REVISION_1,
    	&(SecAttr.lpSecurityDescriptor),
    	NULL);
    CreateEventA(&SecAttr, FALSE, TRUE, "Global\\test");

  • 用PowerShell创建自签名证书

    ·

    发布于

    修改于

    New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName host.doman.com -KeySpec KeyExchange -FriendlyName SQLCert 

  • Make Classes Great Again

    ·

    发布于

    修改于

    //
    // Copyright (c) 2017 Vinnie Falco (vinnie dot falco at gmail dot com)
    //
    // Distributed under the Boost Software License, Version 1.0. (See accompanying
    // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
    //
    // Official repository: https://github.com/vinniefalco/CppCon2017
    //
    
    #include <cstdio>
    #include <iostream>
    #include <list>
    #include <map>
    #include <memory>
    #include <string>
    #include <string_view>
    #include <type_traits>
    #include <vector>
    
    using namespace std;
    
    //------------------------------------------------------------------------------
    //
    // Message Container
    //
    //------------------------------------------------------------------------------
    
    /// Holds an HTTP message
    template<bool isRequest, class Body, class Fields>
    struct message;
    
    /// Holds an HTTP request
    template<class Body, class Fields>
    struct message<true, Body, Fields> : Fields,
        private Body::value_type
    {
    	int version;
    
        string_view method() const
        {
            return this->get_method();
        }
    
        void method(string_view s)
        {
            this->set_method(s);
        }
    
        string_view target() const
        {
            return this->get_target();
        }
    
        void target(string_view s)
        {
            this->set_target(s);
        }
    
    	typename Body::value_type const&
        body() const
        {
            return *this;
        }
    
        typename Body::value_type&
        body()
        {
            return *this;
        }
    };
    
    /// Holds an HTTP response
    template<class Body, class Fields>
    struct message<false, Body, Fields> : Fields,
        private Body::value_type
    {
    	int version;
    	int status;
    
        string_view reason() const
        {
            return this->get_reason();
        }
    
        void reason(string_view s)
        {
            this->set_reason(s);
        }
    
    	typename Body::value_type const&
        body() const
        {
            return *this;
        }
    
        typename Body::value_type&
        body()
        {
            return *this;
        }
    };
    
    //------------------------------------------------------------------------------
    //
    // Body
    //
    //------------------------------------------------------------------------------
    
    /// `true_type` if B meets the requirements of Body
    template<class B, class = void>
    struct is_body : false_type
    {
    };
    
    template<class B>
    struct is_body<B, void_t<
        typename B::value_type,
        decltype(
            B::write(
                declval<ostream&>(),
                declval<typename B::value_type const&>()),
            (void)0)
        >> : true_type
    {
    };
    
    /// A Body that uses a string container
    struct string_body
    {
    	using value_type = string;
    
    	static void write(
    		ostream& os, string const& body)
    	{
            os << body;
    	}
    };
    
    /// A Body that uses a vector container
    template<class T>
    struct vector_body
    {
    	using value_type = vector<T>;
    
    	static void write(
    		ostream& os, vector<T> const& body)
    	{
    		os.write(body.data(), body.size());
    	}
    };
    
    /// A Body that uses a list container
    template<class T>
    struct list_body
    {
    	using value_type = list<T>;
    
    	static void write(
    		ostream& os, list<T> const& body)
    	{
    		for(auto const& t : body)
    			os << t;
    	}
    };
    
    /// A Body using file contents
    struct file_body
    {
    	using value_type = string; // Path to file
    	
    	static void write(
    		ostream& os, string const& path)
    	{
    		size_t n;
    		char buf[4096];
    		FILE* f = fopen(path.c_str(), "rb");
    		while((n = fread(buf, 1, sizeof(buf), f)))
    			os.write(buf, n);
    		fclose(f);
    	}
    };
    
    /// An empty body
    struct empty_body
    {
        struct value_type {};
    
    	static void write(ostream&, value_type const&)
        {
            // Do nothing
        }
    };
    
    //------------------------------------------------------------------------------
    //
    // Fields Container
    //
    //------------------------------------------------------------------------------
    
    /// A container for HTTP fields
    template<class Allocator>
    struct basic_fields
    {
        void set(string_view, string_view);
        string_view operator[](string_view) const;
    
    protected:
        string_view get_method() const noexcept;
        void set_method(string_view);
        
        string_view get_target() const noexcept;
        void set_target(string_view);
    
        string_view get_reason() const noexcept;
        void set_reason(string_view);
    };
    
    //------------------------------------------------------------------------------
    //
    // Type Aliases
    //
    //------------------------------------------------------------------------------
    
    /// A container for HTTP fields using the default allocator
    using fields = basic_fields<std::allocator<char>>;
    
    /// Holds an HTTP request
    template<class Body, class Fields = fields>
    using request = message<true, Body, Fields>;
    
    /// Holds an HTTP response
    template<class Body, class Fields = fields>
    using response = message<false, Body, Fields>;
    
    //------------------------------------------------------------------------------
    //
    // Serialization
    //
    //------------------------------------------------------------------------------
    
    /// Serialize the HTTP header to an ostream
    template<bool isRequest, class Body, class Fields>
    void write_header(ostream&,
        message<isRequest, Body, Fields> const&)
    {
    }
    
    /// Serialize an HTTP Message
    template<bool isRequest, class Body, class Fields>
    void write(ostream& os,
        message<isRequest, Body, Fields> const& msg)
    {
        static_assert(is_body<Body>::value,
            "Body requirements not met");
        write_header(os, msg);
        Body::write(os, msg.body());
    }
    
    //------------------------------------------------------------------------------
    //
    // Tests
    //
    //------------------------------------------------------------------------------
    
    // Error: missing value_type
    struct invalid_body_1
    {
        using body_type = string;
    
        static void write(
    		ostream& os, body_type const& body)
    	{
    		os.write(body.data(), body.size());
    	}
    };
    
    // Error: wrong signature for write
    struct invalid_body_2
    {
        using value_type = string;
    
        static void write(ostream& os)
    	{
    		os << "void";
    	}
    };
    
    static_assert(is_body<string_body>::value, "");
    static_assert(is_body<vector_body<char>>::value, "");
    static_assert(is_body<list_body<string>>::value, "");
    static_assert(is_body<file_body>::value, "");
    static_assert(is_body<empty_body>::value, "");
    
    static_assert(! is_body<invalid_body_1>::value, "");
    static_assert(! is_body<invalid_body_2>::value, "");
    
    int
    main()
    {
        {
            request<string_body> req;
            write(cout, req);
        }
        {
            response<vector_body<char>> res;
            write(cout, res);
        }
        {
            response<list_body<string>> res;
            write(cout, res);
        }
        {
            response<empty_body> res;
            write(cout, res);
        }
    }
    

最新