从头再来

#

asio服务器



原来使用boost::asio 库时,基本上只用了一个io_serve   这种情况下,其实并不能把多线程的好处利用起来。 当异步任务多的时候,集中到一个线程上去了。

这边有网友贴了一个完整的asio 多线程服务器。

http://blog.sina.com.cn/s/blog_48d4cf2d0100nvei.html

粗看了一下, 服务器里面的session封装不给力,没有用到shared_ptr 。 多次出现delete .  

这个其实用智能指针,可以很方便的管理生命周期。

posted @ 2014-06-16 15:25 易宝@byhh 阅读(157) | 评论 (0)编辑 收藏

Android 逆向

APKTool反编译后再打包出错(Error retrieving parent for item: No resource found that matches the given name '@*android:style/Theme.Light')  


 看出错情形,是styles.xml出错了,因为是自己写的,所以打开原始的XML与反编译后的XML一对比,发现反编译后的XML里<resources>/<style>parent属性出错了,由原本的android:Theme.xxx变成了@*android:style/Theme.xxx,前面多出来@*,中间多出来style/,原因找到就好办了,将这些XML改正确,再打包,成了!

http://dreamisx.blog.163.com/blog/static/1150048392012112024649308/


另外还有一些@*的不能改。 

如果报lib png 的错。直接打开画图程序一个个重新覆盖一下就行了。 这个是体力活。

posted @ 2014-04-06 22:08 易宝@byhh 阅读(158) | 评论 (0)编辑 收藏

Linux 服务器配置证书登陆


一、背景
项目需要,研究了使用ossec ,其中有一个ossec agentless的功能,可以实现远程的文件完整性校验 。为方便使用, 决定采用证书模式来处理登陆。


二、配置过程

以下直接抄了  http://praetorianprefect.com/archives/2009/11/ossec-agentless-to-save-the-day/

obsd46# sudo -u ossec ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/var/ossec/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /var/ossec/.ssh/id_rsa. Your public key has been saved in /var/ossec/.ssh/id_rsa.pub. The key fingerprint is: b8:c3:47:9a:33:09:5c:eb:54:a0:82:39:a6:06:63:08 ossec@obsd45.ptnsecurity.com   The key's randomart image is: +--[ RSA 2048]----+ |E     .          | |oo   . .         | |Bo. . . .        | |=o o . +         | |..  o + S        | |.    = *         | |      @ .        | |       =         | |                 | +-----------------+ 

Now that the SSH keys are present, we can add the host without a password. The special command line argument used with register_host.sh is NOPASS in all capitals, which will tell OSSEC supplied scripts to make use of SSH keys.

obsd46# /var/ossec/agentless/register_host.sh add root@172.17.20.20   NOPASS 

Enabling SSH key on the host to be monitored.

You will now need to securely get the contents of /var/ossec/.ssh/id_rsa.pub to 172.17.20.20.

Using SSH and the password for a single time will make this simple. This will create the /root/.ssh if it is not already created, but might throw an error as it does if the directory is already present. This is not a problem and can be ignored.

obsd46# cat /var/ossec/.ssh/id_rsa.pub | ssh root@172.17.20.20   "( mkdir /root/.ssh/;  cat - >> /root/.ssh/authorized_keys )" root@172.17.20.20  's password: mkdir: cannot create directory `/root/.ssh/': File exists obsd46# ssh root@172.17.20.20   "cat  /root/.ssh/authorized_keys " root@172.17.20.20  's password: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAzyTBo7CqkI0TISR9S+KPS/gYY60nkD7Qe8wTTXrAEFvPNFJ NJJpVVKsij6zw86lvTZ6hx9ib1M+MXvt+70uF/z1hYwnYrczR2TR03Z5nwOUA9OK61nBWXVwCi9GsQs6Oeo mY9vkBDoKzB52+TKKSk9ZoC+HYPiT5SaiHZvMOV7kWuwF67lnYwlG5FdkRdOiXp7DcRjje4/Hixg7RLLl7o dEXpIakzGfalt3yQDmwvSUZhyg3OuoKimTeNiKU/jlHlmEPuDZpiQe6QhFH38EeEIZTdHsYITodl8sY+n9I eNMalGIHPs+bph+qcK+6cOb1RGaeGqJBFjaqPUyismz0bw== ossec@obsd45.ptnsecurity.com   

We can also verify that it worked with the following command.

obsd46# sudo -u ossec ssh root@172.17.20.20   The authenticity of host '172.17.20.20 (172.17.20.20)' can't be established. RSA key fingerprint is 14:cd:f2:e9:c3:5b:07:28:68:75:a7:b5:88:c2:6b:77. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.17.20.20' (RSA) to the list of known hosts. Last login: Tue Oct  6 12:40:05 2009 from 172.17.20.154 [linux26.ptnsecurity.com ~]# exit 

三、问题
在以上各种折腾完成后,使用root账号已经可以正常登陆使用了
但在使用普通账号的mytest时却一直失败。 经网上搜索有以下版本的信息

http://www.2cto.com/os/201206/137286.html
http://serverfault.com/questions/230771/ssh-configuration-publickeys-permission-denied-publickey-password-error 
另外还有一个网址一时忘记了。

中途试着将密码鉴权关闭,直接报错:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).  

最终查看 /var/log/secure Authentication refused: bad ownership or modes for directory /home/mytest/.ssh

想起来我忘记的那个网址上有一句话: .ssh 目录需要是 755 不能是775 。。。然后修改就搞定了!!!!完成收工。

posted @ 2014-04-01 14:20 易宝@byhh 阅读(488) | 评论 (0)编辑 收藏

将系统线程与设备驱动程序相关联


当设备驱动 程序创建一个 系统线程运行时,线程运行在system process中,任务管理器在计算cpu占用时,以进程为单位,无法确定CPU实际消耗在哪个驱动上。


以下为一个使用的例子

1、打开cmd窗口。
2、执行dir \\computername\c$ /s 遍历列出c盘文件,这个list会很大,所以一直会运行。
3、运行process explorer ,打开system process 属性页面
4、切换到线程标签页
5、按Cswith data 排序 ,在start address处将可以看到srv2.sys 设备驱动。此处即表示线程对应的驱动程序。点击module按钮可以浏览驱动文件的属性。

posted @ 2013-08-24 23:18 易宝@byhh 阅读(200) | 评论 (0)编辑 收藏

Failed to create snapshot. Error -3941


早上收到邮件。VDR又故障了,这次的错是  Failed to create snapshot. Error -3941

google了一下, VDR的知识文章还是略少了。 各种都不相关啊。

最后在官方的KB中 找到一篇看上去有点像的文章  http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1028924

结果
也是大失所望。居然说是磁盘超过备份限制。。。官方的文章果然各种二。


最后各种折腾,发现是虚拟机上直联了一块PCI设备。导致无法创建快照。

posted @ 2013-07-03 09:17 易宝@byhh 阅读(1208) | 评论 (0)编辑 收藏

vSphere Data Protection 备份失败

E100007: Miscellaneous error 
到VDP 控制台去查看日志后 有以下结果。
avvcbimage error  12041   disk size in backup  is different than target and changed block processing was requested, restore of disk   at    failed please collect administrator log and submit a support request


原因应当是我修改硬盘属性导致。

posted @ 2013-01-09 10:48 易宝@byhh 阅读(496) | 评论 (0)编辑 收藏

windows 进程 可打开的最大句柄数

以下文字摘自"Windows Internals Fifth Edition "


An object handle is an index into a process-specific handle table, pointed to by the executive
process (EPROCESS) block (described in Chapter 5). The first handle index is 4, the second
8, and so on. A process’s handle table contains pointers to all the objects that the process
has opened a handle to. Handle tables are implemented as a three-level scheme, similar
to the way that the x86 memory management unit implements virtual-to-physical address
152 Windows Internals, Fifth Edition
translation, giving a maximum of more than 16,000,000 handles per process


The test program Testlimit from Sysinternals has an option to open handles to an object
until it cannot open any more handles. You can use this to see how many handles can
be created in a single process on your system. Because handle tables are allocated from
paged pool, you might run out of paged pool before you hit the maximum number of
handles that can be created in a single process. To see how many handles you can create
on your system, follow these steps:
1. Download the Testlimit .zip file from www.microsoft.com/technet/ sysinternals, and
unzip it into a directory.
Run Process Explorer, and then click View and then System Information. Notice
the current and maximum size of paged pool. (To display the maximum pool size
values, Process Explorer must be configured properly to access the symbols for
the kernel image, Ntoskrnl.exe.) Leave this system information display running so
that you can see pool utilization when you run the Testlimit program.
3. Open a command prompt.
4. Run the Testlimit program with the -h switch (do this by typing testlimit –h).
When Testlimit fails to open a new handle, it will display the total number of
handles it was able to create. If the number is less than approximately 16 million,
you are probably running out of paged pool before hitting the theoretical perprocess
handle limit.
5. Close the Command Prompt window; doing this will kill the Testlimit process, thus
closing all the open handles.

posted @ 2012-11-07 17:26 易宝@byhh 阅读(2531) | 评论 (0)编辑 收藏

Linux 内存寻址 - 常规分页

从80386开始,Intel 处理器处理 4KB的页。


32位线性地址分为 10 10 12 三部分。 directory table offset

cr3控制寄存器中存放正使用的页目录的物理地址。


一个页目录项与页表项结构相同。 其中有20位Field 包含页框的物理地址。

当从cr3 中获取到页目录地址时,取线性地址的高10位取页目录(4KB,每一个32位占4字节,共1024个页表)中指向的页表项地址(20位的Field)

使用取出来的物理地址得到页表地址,线性地址的中间10位,取页表内偏移量,取含有数据的页的物理地址。

最终使用线性地址的12位取页内数据偏移量。


页目录项指向的页表中有4096的物理地址,也就是对应1024个页表项,刚好与线性地址的10位相符。

而页表项指向的项含有4096的物理地址,偏移量需要线性地址的12来取offset



cr4寄存器,PSE标记,可使得扩展分页与常规分页共存。

cr0 的PG = 0时,线性地址被解析为物理地址。

posted @ 2012-04-30 20:10 易宝@byhh 阅读(352) | 评论 (1)编辑 收藏

webkit 随笔

How to: Set a Thread Name in Native Code

dddd

最近在分析webkit 项目 。

分享其中几个tips!

一、WTF库
WTF的详细含义未找到出处,在webkit上找了找,大致是webkit 项目 继承使用的之前的一个封装库。其中包涵了数值转换,字符串,智能指针,线程管理,线程间同步等函数库。
从源代码的命名来看,有多种移植版本,如以下注释 

// For portability, we do not use thread-safe statics natively supported by some compilers (e.g. gcc).
#define AtomicallyInitializedStatic(T, name) \
    WTF::lockAtomicallyInitializedStaticMutex(); \
    static T name; \
    WTF::unlockAtomicallyInitializedStaticMutex();

二、

How to: Set a Thread Name in Native Code

   MSDN的释义是To set a thread name in your program, use the SetThreadName function

原文见:http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.90).aspx

 
 1
//
 2 // Usage: SetThreadName (-1, "MainThread");
 3 //
 4 #include <windows.h>
 5 const DWORD MS_VC_EXCEPTION=0x406D1388;
 6 
 7 #pragma pack(push,8)
 8 typedef struct tagTHREADNAME_INFO
 9 {
10    DWORD dwType; // Must be 0x1000.
11    LPCSTR szName; // Pointer to name (in user addr space).
12    DWORD dwThreadID; // Thread ID (-1=caller thread).
13    DWORD dwFlags; // Reserved for future use, must be zero.
14 } THREADNAME_INFO;
15 #pragma pack(pop)
16 
17 void SetThreadName( DWORD dwThreadID, char* threadName)
18 {
19    THREADNAME_INFO info;
20    info.dwType = 0x1000;
21    info.szName = threadName;
22    info.dwThreadID = dwThreadID;
23    info.dwFlags = 0;
24 
25    __try
26    {
27       RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
28    }
29    __except(EXCEPTION_EXECUTE_HANDLER)
30    {
31    }
32 }


posted @ 2012-04-28 22:32 易宝@byhh 阅读(451) | 评论 (0)编辑 收藏

chrome 编译

一、准备编译
   此步参照网络上的文章,中文翻译或者直接查看官网,推荐 官网,翻译后的文章可能会少掉一些步骤。

二、编译中注意事项

下载与安装 DirectX SDK 这一步是必须的,否则会提示少了d3d9.h 文件以及一系列的lib文件。

i18n.cc 文件中可能有一个错误

typedef BOOL( WINAPI* GetPreferredUILanguages_Fn)(DWORD, PULONG, PWZZSTR, PULONG);
这一行报错。 __stdcall 前缺少) ,经查看,此函数声明对应一个指针数组中的函数。

第三个参数应当为PWSTR .修改后。base.lib 项目编译通过

-- update 此处是windows SDK 7 中的函数声明。需要更新SDK包后就编译OK啦。

三、编译最好选在休息时间。

夜间编译其实也不错,但若出问题,可能反而浪费了时间。

posted @ 2012-04-01 21:05 易宝@byhh 阅读(738) | 评论 (0)编辑 收藏

仅列出标题
共3页: 1 2 3