code snippets
viktor
这个作者很懒,什么都没留下…
展开
-
简单的字符设备-myscull
参考: Linux Device Drivers chapter 3: scullhttp://oss.org.cn/kernel-book/ldd3/ch03.html字符设备是linux设备模型中最基本的一种。main.c#include "mysc.h"MODULE_LICENSE("GPL");struct mysc_dev scull_device;st原创 2011-11-04 17:25:34 · 291 阅读 · 0 评论 -
用LibVMI读取虚拟机进程列表
note:0. 环境:Linux 3.1.0 / Xen 4.1.3-rc1-pre / PV DomU1. 我运行的时候 直接使用System.map里面的init_task地址[C086F4A0],读取的值都是0,不能得到初始进程信息。经过与DomU实际地址对照,发现init_task的实际地址比配置文件中的多了0x6000(不带xen直接启动Linux3.1内核,地址也多出0x6原创 2012-04-29 17:49:45 · 3498 阅读 · 8 评论 -
libpcap steps (2) 简单的抓包实现。
用libpcap抓包的简单流程:1. 获得设备名:pcap_findalldevs列出所有设备——选择列出的网络设备,在链表中找到。得到设备名以后把链表释放。或者直接存在字符串里2. pcap_open_live用设备名打开设备(另一个函数是pcap_open_dead,略猎奇)3. pcap_loop开始抓包。这里没有使用混杂模式。(第二个参数是0)4. 利用回调函数处理捕获原创 2012-03-15 23:18:09 · 1665 阅读 · 0 评论 -
assert:自作版
#define str_(x) x#define Debug(format, ...) fprintf(stderr, "%s:%d: " str_(format) "\n", __FILE__, __LINE__, ##__VA_ARGS__)#define assert_(expr_, extra_op) do { if (!(expr_)) { Debug("在函数 `%s'中: 断言原创 2012-04-09 15:10:34 · 776 阅读 · 0 评论 -
libpcap steps (1) 使用pcap_findalldevs列出设备
libpcap版本1.3.0-PRE-GIT#include #include #include #define __USE_BSD#include #include #define Debug(format, ...) fprintf(stderr, "%s:%d: "format "\n", __FILE__, __LINE__, ##__VA_ARGS__)原创 2012-03-15 13:08:17 · 3709 阅读 · 0 评论 -
XSHelper :: XenStore API c++ 渣疯装
我把xenstore的API简单的封装了一下,方便用户空间的C++使用。主要功能:1. 把char换成了string,让c++去处理那什么gc。xenstore源代码里面的各种"call free() after use!!!"注释看得我很无语。2. 提供一个共享的xs_handle对象,一般的读写操作不需要自己定义xs_handle和xs_transaction,方便使用。3. 简单原创 2011-12-20 10:46:12 · 864 阅读 · 0 评论 -
rstmod
#!/bin/bashlsmod |grep $1if [ $? -eq 0 ]then sudo rmmod $1fisudo dmesg -cread -n 1 -p '按键继续...'clear echo "installing ${1}"sudo insmod ${1}.kodmesg自动刷新内核模块的shell脚本。原创 2011-11-04 17:21:01 · 289 阅读 · 0 评论 -
最简单的linux内核模块 - hello - 及其Makefile
一个最简单的linux内核模块。当他加载和退出时各会打出一行信息。可以作为程序的框架,也可以测试加载模块。#include "linux/init.h"#include "linux/module.h"//MODULE_LICENSE("GPL"); --此处:编译进内核的代码一定要标识自己符合GPL协议等开源协议。模块可以不用static原创 2011-11-04 16:57:21 · 467 阅读 · 0 评论 -
根据窗口部分标题,查找窗口hwnd
输入窗口标题中含有的字符串,调用EnumWindows查找所有符合条件的窗口。#include "windows.h"#include "psapi.h"#include "iostream"#include "vector"#include "algorithm"#include "string"#include "cstring"using namespace std;原创 2011-11-04 17:46:49 · 818 阅读 · 0 评论 -
在WinAPI中使用Lambda函数(坑:如何把no capture的lambda函数转换成函数指针)
使用WinAPI的时候经常有只是执行很简单功能的CallBack函数,我不想把它单独写成一个函数,这样把一个功能标记成(global) static单独悬在所有的类外面,很不好维护。于是想用lambda来简化。但是 这些callback函数有一个共同点就是——都有一个属性叫做CALLBACK(也就是 __stdcall)。怎样才能让winAPI正确的调用lambda呢?以下是cod原创 2011-11-04 17:40:33 · 799 阅读 · 2 评论 -
WinAPI 设定全局热键
text#include "windows.h"#include "psapi.h"#include "assert.h"#include "cstdio"static int hk_run, hk_exit;HWND g_hwnd;void reg(){ hk_run=GlobalAddAtom("C-A-X"); hk_exit=GlobalAddAtom原创 2011-11-04 17:43:15 · 415 阅读 · 0 评论 -
短代码比赛
转自http://www.felix021.com/blog/read.php?2096p主表示窝其实也默默地凹了一个3行的,不过太丑就不发了……比赛的起因是这样的,@Tranch同学在SegmentFault.com提了个问题,求一个代码,可以列出字符串"qwerty"被 "." 分割的所有情况,比如 q.werty qwe.rty q.w.e.r.t.y 等等。转载 2012-10-30 18:45:48 · 886 阅读 · 0 评论