在获取root shell的一些漏洞中,我经常看到这样一个指针:
int i;
unsigned *p = *(unsigned**)(((unsigned long)&i) & ~8191);
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释一下这个指针吗?我认为8191是内核堆栈的大小.p指向内核堆栈的底部?以下是指针p的使用方法:
int i;
unsigned *p = *(unsigned**)(((unsigned long)&i) & ~8191);
for (i = 0; i < 1024-13; i++) {
if (p[0] == uid && p[1] == uid &&
p[2] == uid && p[3] == uid &&
p[4] == gid && p[5] == gid &&
p[6] == gid && p[7] == gid) {
p[0] = p[1] = p[2] = p[3] = 0;
p[4] = …Run Code Online (Sandbox Code Playgroud) 我有一个简单的程序:
int main(void) {
int fd;
const char *text = "This is a test";
fd = open("/tmp/msyncTest", (O_CREAT | O_TRUNC | O_RDWR), (S_IRWXU | S_IRWXG | S_IRWXO) );
if ( fd < 0 ) {
perror("open() error");
return fd;
}
/* mmap the file. */
void *address;
off_t my_offset = 0;
address = mmap(NULL, 4096, PROT_WRITE, MAP_SHARED, fd, my_offset);
if ( address == MAP_FAILED ) {
perror("mmap error. " );
return -1;
}
/* Move some data into the file …Run Code Online (Sandbox Code Playgroud) 根据我的理解,ltrace实用程序用于跟踪库调用.我跟踪一个printf只调用的简单程序,但库函数显示的是puts代替printf.我好奇为什么它没有显示printf但是puts?
我编写了一个简单的程序来使用 RDTSC 指令测量代码执行时间。但是我不知道我的结果是否正确以及我的代码是否有问题......我不知道如何验证它。
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#define N (1024*4)
unsigned cycles_low, cycles_high, cycles_low1, cycles_high1;
static __inline__ unsigned long long rdtsc(void)
{
__asm__ __volatile__ ("RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high), "=r" (cycles_low)::
"%rax", "rbx", "rcx", "rdx");
}
static __inline__ unsigned long long rdtsc1(void)
{
__asm__ __volatile__ ("RDTSC\n\t"
"mov %%edx, %0\n\t"
"mov %%eax, %1\n\t": "=r" (cycles_high1), "=r" (cycles_low1)::
"%rax", "rbx", "rcx", "rdx");
}
int main(int argc, char* argv[])
{
uint64_t start, end;
rdtsc();
malloc(N); …Run Code Online (Sandbox Code Playgroud) 文件 'hello' 的内容是hello.
$ od -tx1 -tc hello
0000000 68 65 6c 6c 6f 0a
h e l l o \n
0000006
Run Code Online (Sandbox Code Playgroud)
下面是我对文件“hello”进行一些更改的代码。
static void *task();
int main(void)
{
int *p;
pthread_t Thread;
int fd = open("hello", O_RDWR);
if (fd < 0) {
perror("open hello");
exit(1);
}
p = mmap(NULL, 6, PROT_WRITE, MAP_PRIVATE, fd, 0);
if (p == MAP_FAILED) {
perror("mmap");
exit(1);
}
close(fd);
pthread_create(&Thread, NULL, &task, p)
printf("Help");
pthread_join(Thread, 0);
munmap(p, 6);
return 0;
}
static void …Run Code Online (Sandbox Code Playgroud) 很抱歉提出这个问题,我试图在stackoverflow上找到解决方案,但没有令人满意的结果.我的代码如下,感谢您的耐心等待.
#include <inttypes.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <string.h>
typedef uint32_t req_id_t;
typedef uint32_t view_id_t;
typedef uint64_t db_key_type;
typedef struct view_stamp_t {
view_id_t view_id;
req_id_t req_id;
}view_stamp;
typedef struct consensus_component_t {
view_stamp* highest_committed_vs;
}consensus_component;
uint64_t vstol(view_stamp* vs) {
uint64_t result = ((uint64_t)vs->req_id)&0xFFFFFFFFl;
uint64_t temp = (uint64_t)vs->view_id&0xFFFFFFFFl;
result += temp<<32;
return result;
}
int main() {
consensus_component* comp = (consensus_component*)malloc(sizeof(consensus_component));
memset(comp, 0, sizeof(consensus_component));
if(NULL != comp) {
comp->highest_committed_vs->view_id = 1;
comp->highest_committed_vs->req_id = 0;
db_key_type start = vstol(comp->highest_committed_vs)+1;
printf("%" PRIu64 …Run Code Online (Sandbox Code Playgroud) 任何人都可以帮助解释val以下示例中的含义吗?我完全不知道它的价值是什么val.
#define SPLAT(p) (*(p) * (~0UL / 255))
uint8_t *page;
unsigned long val = SPLAT(page);
Run Code Online (Sandbox Code Playgroud)