GNOME Terminal Bold Font

Enable bold font for GNOME Terminal:


# Get profile id
dconf dump /org/gnome/terminal/legacy/
# Set bold font
dconf write /org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9/font "'Monospace Bold 14'"

Select “Show bold text in bright colors”

Catch exception thrown from memory references

By default an exception can only occur during a function call or a throw. If we needs to catch excpetions thrown from trapping instructions, using the `-fnon-call-exceptions`.



Generate code that allows trapping instructions to throw exceptions. Note that this requires platform-specific runtime support that does not exist everywhere. Moreover, it only allows trapping instructions to throw exceptions, i.e. memory references or floating point instructions. It does not allow exceptions to be thrown from arbitrary signal handlers such as SIGALRM. 


#include <iostream>
#include <signal.h>
using namespace std;
static void
sigsegv_handler (int signo)
    throw 0;
main (int argc, char *argv[])
    int *ptr = nullptr;
    int res;
    signal (SIGSEGV, sigsegv_handler);
    try {
        res = *ptr;
    } catch (...) {
        cout << "exception" << endl;
    return res;
g++ -fnon-call-exceptions -o sig sig.cpp


Load shared libraries with preferred base address

For performance, sometimes we need to adjust the address space layout. The following way allows the shared or executable object to be loaded with preferred base address.

When the dynamic link maps the shared object, the virtual address of segment(that in ELF program header) will be used as the mapping address hints.

Type 1
Link with text-segment starting address.

# Adjust base address to 0x10000 */
gcc -shared ... -Wl,-Ttext-segment=0x10000

Type 2
We can adjust the virtual address of loaded segment by linker scripts.

0x1 Get link script template

gcc -shared -Wl,--verbose > ld.script

Clear the contents before and after the ‘equal sign’.

0x2 Adjust the base address

    /* Adjust base address to 0x10000 */
    . = SEGMENT_START("text-segment", 0x10000) + SIZEOF_HEADERS;

0x3 Link with script

gcc -shared ... -Wl,-T ld.script


Nginx WebDAV Service

0x01 Installation

git clone --depth 1
cd nginx
git clone --depth 1
./auto/configure --prefix=/opt/nginx \
    --with-compat \
    --with-file-aio \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_dav_module \
    --with-http_degradation_module \
    --with-http_flv_module \
    --with-http_geoip_module \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_mp4_module \
    --with-http_realip_module \
    --with-http_secure_link_module \
    --with-http_slice_module \
    --with-http_ssl_module \
    --with-http_stub_status_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-pcre-jit \
    --with-threads \
sudo make install

0x02 Configuration
Main: /opt/nginx/conf/nginx.conf:

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/;
events {
    worker_connections  1024;
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    dav_ext_lock_zone zone=foo:10m;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            auth_basic Restricted;
            auth_basic_user_file htpasswd;
            dav_methods PUT DELETE MKCOL COPY MOVE;
            dav_ext_lock zone=foo;
            dav_access user:rw group:rw all:r;
            client_max_body_size 0;
            create_full_put_path on;
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht {
        #    deny  all;

Auth: /opt/nginx/conf/htpasswd:

htpasswd -b -c /opt/nginx/conf/htpasswd YOUR_USERNAME YOUR_PASSWORD

Start, Stop and Reload:

# Start
sudo /opt/nginx/sbin/nginx
# Stop
sudo /opt/nginx/sbin/nginx -s stop
# Reload
sudo /opt/nginx/sbin/nginx -s reload

0x03 Clients

Windows 10
Fix authentication and file size limits, open regedit and modify:

BasicAuthLevel = 2
FileSizeLimitInBytes = 0xffffffff