so动态库只导出指定函数

retain_sym.txt

1
2
func1
func2

ver_script.txt

1
2
3
4
5
6
7
LIBA_1.1 {
	global:
		foo1;
		foo2;
	local:
		*;
};
1
ld -shared --retain-symbols-file=retain_sym.txt --version-script=ver_script.txt tst.o -o tst.so

refer to:
https://blog.csdn.net/chdhust/article/details/79356717
http://blog.sina.com.cn/s/blog_493667730100csde.html
http://www.gnu.org/software/gnulib/manual/html_node/LD-Version-Scripts.html

linux命令备忘录

名词

1
2
3
4
5
pie: position-independent executable
pic: position-independent code
aslr: address space layout randomization
got: global offset table
vdso: virtual dynamic shared object

swap文件

1
2
3
4
dd if=/dev/zero of=./swap_file bs=1G count=1
mkswap ./swap_file
swapon ./swap_file
swapoff ./swap_file

objcopy

1
2
3
objcopy -I binary -O elf32-i386 -B i386 test.jpg test.o
objdump -s -b binary test.o
readelf -s test.o

静态链编stdc++

1
-Bstatic -lstdc++ -Bdynamic

工具

1
2
3
systemtap
inotify-tools
windres

refer to:
http://blog.chinaunix.net/uid-28461677-id-5766451.html
https://blog.csdn.net/weixin_33842304/article/details/91443399

转载: Optimizing the kernel for VMware

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
[*] 64-bit kernel (leave blank for x86)
 
General Setup --->
  [*] Optimize very unlikely/likely branches
 
Processor type and features --->
  Processor Family (usually Core2/Newer Xeon)
 
Bus Options --->
  < > PCCard (PCMCIA/Cardbus) support
 
Networking support --->
  [ ] Amateur Radio support
  [ ] Wireless (only if you plan on using nat EXCLUSIVELY)
 
Device Drivers --->
  Generic Driver Options
    [*] Maintain a devtmpfs filesystem to mount at /dev
 
  Misc Devices --->
    [*] VMware Balloon Driver (manages memory between VM and host)
    [*] VMware VMCI Driver (Virtual Machine Communication Interface - low-latency access to host memory bus)
 
  SCSI device support --->
    [*] SCSI low-level drivers --->
      <*> VMware PVSCSI driver support (high throughput storage adapter)
 
  [*] Fusion MPT device support --->
    <*> Fusion MPT ScsiHost drivers for SPI
 
  [*] Network device support --->
    [*] Ethernet driver support --->
      (disable every driver but this)
      [*] AMD Devices
        <*> AMD PCNet32 PCI support
    [ ] Wireless LAN (ONLY if you disabled Wireless networking support above)
    < > VMware VMXNET3 ethernet driver (PCNet32 is more than enough for most use cases - enable this only if you have spare cpu cycles to burn)
 
  Graphics support --->
    <*> Direct Rendering Manager
    < > Intel 8xx/9xx/G3x/G4x/HD Graphics
    <*> DRM driver for VMware Virtual GPU
      [*] Enable framebuffer console support under vmwgfx by default
    <*> Support for frame buffer devices
 
    Console display driver support --->
      <*> Framebuffer Console support
 
  Sound card support --->
    <*> Advanced Linux Sound Architecture --->
      [*] PCI sound devices
        <*> (Creative) Ensoniq AudioPCI 1371/1373
        < > Intel HD Audio
 
  File systems --->
    (enable only those you anticipate using)
    <*> Second extended fs support
    <*> The Extended 4 (ext4) filesystem
    <*> XFS filesystem support
    <*> Btrfs filesystem Unstable disk format
 
    Pseudo filesystems --->
      [*] Tmpfs virtual memory file system support (former shm fs)
        [*] Tmpfs POSIX Access Control Lists

refer to:
https://forums.gentoo.org/viewtopic-p-7332884.html#7332884

kprobe and uprobe

kprobe

1
2
3
4
5
6
7
8
cd /sys/kernel/debug/tracing
echo 'p:myprobe do_sys_open' > kprobe_events
echo 'r:myretprobe do_sys_open $retval' > kprobe_events
echo 'r:myprobe getname +0($retval):string' > kprobe_events
echo 1 > tracing_on
echo 1 > events/kprobes/myprobe/enable
echo '-:myprobe' > kprobe_events
cat trace

uprobe

1
2
3
4
5
cd /sys/kernel/debug/tracing
echo 'p:do_sth /home/kernel_test/loop_print:0x52d %ip %ax' > uprobe_events
echo 'r:do_sth_exit /home/kernel_test/loop_print:0x52d %ip %ax' >> uprobe_events
echo 1 > events/uprobes/enable
cat trace

refer to:
https://blog.csdn.net/melody157398/article/details/113764679
https://blog.csdn.net/daiq531/article/details/52749673

西方神话备忘录

Α	α	alpha
Β	β	beta
Γ	γ	gamma
Δ	δ	delta
Ε	ε	epsilon
Ζ	ζ	zeta		/'zi:tə/
Η	η	eta		/'i:tə/
Θ	θ	theta
Ι	ι	iota		/aɪ'əʊtə/
Κ	κ	kappa	/'kæpə/
Λ	λ	lambda
Μ	μ	mu		/mju:/

Ν	ν	nu		/nju:/
Ξ	ξ	xi		/ksi/,/ˈksaɪ/,/ˈzaɪ/
Ο	ο	omicron	/əuˈmaikrən/,/ˈɑmɪˌkrɑn/
Π	π	pi
Ρ	ρ	rho		/rəʊ/
Σ	σ/ς	sigma
Τ	τ	tau		/tɔ:/,/taʊ/
Υ	υ	upsilon	/ˈipsilon/,/ˈʌpsɨlɒn/
Φ	φ	phi		/faɪ/
Χ	χ	chi		/kaɪ/
Ψ	ψ	psi		/psaɪ/
Ω	ω	omega

希腊神话

Chronos/Χρόνος: 柯罗诺斯/时间之神

五大创世神
	Gaia/Γαία: 盖亚/Terra特鲁斯
	Tartarus/Τάρταρος: 塔耳塔洛斯/深渊
	Erebus/Ἔρεβος: 厄瑞玻斯/幽冥
		Aether/Αἰθήρ: 埃忒尔/天光
		Hemera/Ἡμέρα: 赫墨拉/白昼
		Charon/Χάρων: 卡戎/冥海渡神
	Nyx/Νύξ: 倪克斯/暗夜
		Morus/Μόρος: 摩洛斯/厄运,惨死
		Cer/Κῆρ: 卡尔/横死,毁灭
		Thanatus/Θάνατς: 塔那托斯/死亡
		Hypnus/Ὕπνος: 修普诺斯/睡眠
		Oneiroi/Ὄνειροι: 俄尼里伊/梦,梦境
		Momus/Μῶμος: 摩墨斯/挑剔,嘲讽
		Ceres/Κῆρες: 刻瑞斯/致死,亡灵
		Oizys/Ὀϊζύς: 俄匊斯/悲惨,哀伤
		Nemesis/Νέμεσις: 涅墨西斯/义愤,报复
		Apate/Ἀπάτη: 阿帕忒/欺骗
		Philotes/Φιλότης: 菲罗忒斯/性欲,情欲
		Geras/Γῆρας: 革剌斯/衰老,老年
		Eris/Ἔρις: 厄里斯/纷争,不和
	Eros/Ἔρως: 厄洛斯/爱欲

Uranos: 乌拉诺斯/Caelus凯路斯/天神
Aphrodite: 阿佛洛狄忒/Venus维纳斯
Pontus: 蓬托斯/海神
Ourea: 乌瑞亚/山神
Prometheus: 普罗米修斯

Oceanus: 俄刻阿诺斯/泰坦十二神老大

Hyperion/Ὑπερίων: 许珀里翁/泰坦十二神之一
Theia/Θεία: 忒亚/视力、光照/泰坦十二神之一
	Helios: 赫利俄斯/太阳
	Phaethon: 法厄同
	Eos: 厄俄斯/曙光
	Selene: 塞勒涅/月亮
	Clytie: 向日葵

Kronos/Cronos/Κρόνος: 克洛诺斯/Saturn萨图恩/泰坦十二神老幺/第二代神王/农神
Rhea: 瑞亚/Ops俄普斯/泰坦十二神之一/时光
	Zeus/Ζεύς/Δίας: 宙斯/Jupiter朱庇特/老幺/第三代神王/Titanomachy泰坦之战
	Hera: 赫拉/Juno朱诺/
	Themis: 忒弥斯/Justitia朱斯提提亚/泰坦十二神之一/法律正义
		Ares: 阿瑞斯/Mars马尔斯
		Hephaestus/Ἥφαιστος: 赫菲斯托斯/Vulcan伏尔甘/火神、工匠
		Hermes: 赫尔墨斯/Mercury墨丘利/信使
		Eris: 厄里斯/Discordia狄斯科耳狄亚/不和女神
	Poseidon: 波塞冬/Neptune尼普顿
	Hades: 哈迪斯/Pluto普路托/冥王星
	Demeter: 得墨忒耳/Ceres刻瑞斯/丰收/谷神星
	
Adelos: 德罗斯岛
Phoebus Apollo/Απόλλων: 福玻斯·阿波罗/文艺、保护神、光明神、预言、雄辩之神、医神以及消灾弥难之神
Daphne: 达芙妮/月桂女神
Artemis: 阿尔忒弥斯/狩猎、接生

Eros/Έρως: 厄洛斯/Cupid丘比特
Psyche: 普赛克

refer to:
https://baike.baidu.com/item/%E5%B8%8C%E8%85%8A%E5%AD%97%E6%AF%8D/4428067?fr=aladdin
https://baike.baidu.com/item/%E4%BA%94%E5%A4%A7%E5%88%9B%E4%B8%96%E7%A5%9E/10466429
https://baike.baidu.com/item/%E5%85%8B%E6%B4%9B%E8%AF%BA%E6%96%AF/3399553
https://zhidao.baidu.com/question/2272801280037695908.html
http://www.360doc.com/content/15/0318/21/4240596_456274573.shtml

asn.1中的方括号

asn.1编码以tag + length + value为基本单元,IMPLICIT模式是用context-specific tag替换后面通常是universal的tag;EXPLICIT模式是用context-specific tag的tlv包裏里层的universal tag的tlv。

ber编码时,会默认为EXPLICIT模式。

在bnf范式语法中

1
2
3
4
5
圆括号(): 相当于C语言算术表达式中圆括号()的作用。
尖括号<>: 内包含的为必选项。 
方括号[]: 内包含的为可选项。 
花括号{}: 内包含的为可重复0至无数次的项。 
|: 或or的意思;若要表示并and的意思,直接两个符号之间空白间隔。

而在asn.1语法中,方括号[Index]指示的是context-specific tag值,即0xA0 + Index;花括号{}用于SEQUENCE,SET或CHOICE的定义。如

1
2
Number2 ::= [7] IMPLICIT [1] INTEGER
AccountedClosed [2] EXPLICIT BOOLEAN

这里Number2的tag值为0xA7;而对于AccountedClosed,当其值为true时其ber编码为

1
0xA2 0x3 0x1 0x1 0xFF

refer to:
https://blog.csdn.net/sever2012/article/details/7767867
https://www.cnblogs.com/qook/p/5957436.html

数字证书备忘录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
ca: certification authority
pem: privacy enhanced mail, "begin"+base64+"end"
der: distinguished encoding rules, binary
crt: certificate
cer: certificate
csr: certificate signing request
pkcs: public key cryptography standard
ietf: internet engineering task force
pkcs#12/pfx/p12: file format encoding private keys, certificates and etc, rfc7292
pkcs#7: cryptographic message syntex standard
pkcs#10/p10: certification request syntax specification, rfc2986
x.509: public key certificates format standard
ber: basic encoding rules
per: packed encoding rules
crl: certificate revocation list

refer to:
http://www.360doc.com/content/15/0520/10/21412_471902987.shtml
https://baike.baidu.com/item/BER/19940289?fr=aladdin
https://blog.csdn.net/mao834099514/article/details/109074661
https://datatracker.ietf.org/doc/html/rfc7292

asn.1编码的转换

这个工具在

1
strongswan/src/libstrongswan/asn1

以下是使用示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <asn1/asn1.h>
#include <asn1/asn1_parser.h>
 
#define INTEGER_SIZE 32
 
static chunk_t chunk_to_asn1(chunk_t chunk)
{
	chunk_t x;
	chunk_t y;
	chunk_t hash;
	chunk_t content;
	chunk_t asn1;
 
	x.ptr = chunk.ptr;
	x.len = INTEGER_SIZE;
	y.ptr = chunk.ptr + INTEGER_SIZE;
	y.len = INTEGER_SIZE;
	content.ptr = y.ptr + INTEGER_SIZE;
	content.len = chunk.len - INTEGER_SIZE * 3;
	hash.ptr = content.ptr + content.len;
	hash.len = INTEGER_SIZE;
 
	asn1 = asn1_wrap(ASN1_SEQUENCE, "mmmm",
		asn1_integer("c", x),
		asn1_integer("c", y),
		asn1_simple_object(ASN1_OCTET_STRING, hash),
		asn1_simple_object(ASN1_OCTET_STRING, content));
 
	chunk_free(&chunk);
	return asn1;
}
 
static const asn1Object_t patterns[] = {
	{ 0, "seq",			ASN1_SEQUENCE,		ASN1_NONE }, /*  0 */
	{ 1,   "x",			ASN1_INTEGER,		ASN1_BODY }, /*  1 */
	{ 1,   "y",			ASN1_INTEGER,		ASN1_BODY }, /*  2 */
	{ 1,   "hash",			ASN1_OCTET_STRING,	ASN1_BODY }, /*  3 */
	{ 1,   "content",		ASN1_OCTET_STRING,	ASN1_BODY }, /*  4 */
	{ 0, "exit",			ASN1_EOC,		ASN1_EXIT }
};
#define PATTERN_KEY_X			1
#define PATTERN_KEY_Y			2
#define PATTERN_KEY_HASH		3
#define PATTERN_KEY_CONTENT		4
 
static chunk_t correct_integer(chunk_t chunk)
{
	if (chunk.len == INTEGER_SIZE + 1)
		return chunk_skip(chunk, 1);
	return chunk;
}
 
static bool parse_asn1(chunk_t asn1, chunk_t* x, chunk_t* y, chunk_t* hash, chunk_t* content)
{
	chunk_t object;
	asn1_parser_t *parser;
	bool success = FALSE;
	int object_id, oid, i;
 
	parser = asn1_parser_create(patterns, asn1);
 
	while (parser->iterate(parser, &object_id, &object))
	{
		switch (object_id)
		{
			case PATTERN_KEY_X:
				*x = correct_integer(object);
				break;
			case PATTERN_KEY_Y:
				*y = correct_integer(object);
				break;
			case PATTERN_KEY_HASH:
				*hash = object;
				break;
			case PATTERN_KEY_CONTENT:
				*content = object;
				break;
		}
	}
	success = parser->success(parser);
	parser->destroy(parser);
	return success;
}
 
static bool chunk_from_asn1(chunk_t* chunk, chunk_t asn1)
{
	chunk_t x;
	chunk_t y;
	chunk_t hash;
	chunk_t content;
 
	if (!parse_asn1(asn1, &x, &y, &hash, &content))
		return false;
 
	*chunk = chunk_cat("cccc", x, y, content, hash);
	return true;
}
 
static void random_data(chunk_t chunk)
{
	int fd = open("/dev/urandom", O_RDONLY);
	read(fd, chunk.ptr, chunk.len);
	close(fd);
}
 
int test()
{
	bool is_ok;
	chunk_t result;
	chunk_t asn1;
	chunk_t total = chunk_alloc(INTEGER_SIZE * 3 + 345);
 
	random_data(total);
 
	asn1 = chunk_to_asn1(total);
	is_ok = chunk_from_asn1(&result, asn1);
 
	chunk_free(&result);
	chunk_free(&asn1);
	chunk_free(&total);
	return is_ok;
}

因为asn1模块里对ASN1_INTEGER类型有个two's complement处理,如果这个数最高位为1,则在此数前加一个0值字节,所以correct_integer函数的目地在于更正输出。

转载: linux下的多国语言解决方案

hello.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <libintl.h> // gettext
#include <locale.h>
 
#define _(STRING) gettext(STRING)
#define PACKAGE "hello"
#define LOCALEDIR "/usr/share/locale/"
 
int main(int argv, char* argc[])
{
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	printf(_("Hello, World\n"));
	printf(_("This is a example.\n"));
	return 0;
}

提取字符串

1
xgettext --keyword=_ hello.c -o hello.pot

编辑hello.pot

1
2
3
4
5
6
...
msgid "Hello, World\n"
msgstr "你好,世界!\n"
msgid "This is a example.\n"
msgstr "This is a example.\n"
...

将hello.pot编译为字节码

1
2
msgmerge zh_CN.po hello.pot
msgfmt zh_CN.po -o hello.mo

refer to:
https://leedd.com/linux-c-i18n-l10n-xgettext-msgfmt-rpmbuild/