summaryrefslogtreecommitdiffhomepage
path: root/include/pemagine/bits/nt32/pe_inline_asm__common.h
blob: 10473b4e7fb7a8b28b9632a16720c8489fc29413 (plain)
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
static __inline__ void * pe_get_teb_address(void)
{
	void * ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x18, %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}


static __inline__ void * pe_get_peb_address(void)
{
	void * ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x18, %0\n\t"
		"mov %%ds:0x30(%0), %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}


static __inline__ void * pe_get_peb_address_alt(void)
{
	void * ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x30, %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}


static __inline__ void * pe_get_peb_ldr_data_address(void)
{
	void * ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x18, %0\n\t"
		"mov %%ds:0x30(%0), %0\n\t"
		"mov %%ds:0x0C(%0), %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}


static __inline__ void * pe_get_peb_ldr_data_address_alt(void)
{
	void * ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x30, %0\n\t"
		"mov %%ds:0x0C(%0), %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}

static __inline__ uint32_t pe_get_current_process_id(void)
{
	uint32_t ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x20, %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}

static __inline__ uint32_t pe_get_current_thread_id(void)
{
	uint32_t ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x24, %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}

static __inline__ uint32_t pe_get_current_session_id(void)
{
	uint32_t ptrRet;
	__asm__ __volatile__ (
		"mov %%fs:0x18, %0\n\t"
		"mov %%ds:0x30(%0), %0\n\t"
		"mov %%ds:0x1d4(%0), %0\n\t"
		: "=r" (ptrRet) : :
		);
	return ptrRet;
}