JEFFREY

feiworks.com

USB HID usage table

This usage table lets usbhidctl decode the HID data correctly for the APC RS/XS1000's.

This work was obtained from riccardo@torrini.org.

Note that the default /usr/share/misc/usb_hid_usages already contains entries for these a Power Device (132 or 0x84) and a Battery System (133 or 0x85).  It is interesting that usbhidctl shows the APC as using 0xff84 and 0xff84 for their values.  The HID Power Devices specification indicates 0x84 and 0x85.  There is at least one macro in /usr/include/dev/usb/usbhid.h which removes the high order bits.  Perhaps we need to do that when using the values.  Perhaps this macro:

#define HID_USAGE2(p,u) (((p) << 16) | u)

Linux/i386 system calls

List of Linux/i386 system calls

Copyright (C) 1999-2000 by Konstantin Boldyshev

This list is NOT READY and is under heavy construction, a lot of entries are missing, and some may be incorrect. This is more a template than a real document. Meanwhile, I suggest you to examinethis listby H-Peter Recktenwald.


Dalvik opcodes

Dalvik opcodes

Author:Gabor Paller


Vx values in the table denote a Dalvik register. Depending on the instruction, 16, 256 or 64k registers can be accessed. Operations on long and double values use two registers, e.g. a double value addressed in the V0 register occupies the V0 and V1 registers.

Boolean values are stored as 1 for true and 0 for false. Operations on booleans are translated into integer operations.

All the examples are in hig-endian format, e.g. 0F00 0A00 is coded as
0F, 00, 0A, 00 sequence.

Note there are no explanation/example at some instructions. This means that I have not seen that instruction "in the wild" and its presence/name is only known from Android opcode constant list.

Android smali代码注入

1.增加log信息

变量为string类型
const-string v3,"message"
invoke-static {v3,v0}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I
变量为int类型
const-string v3, "message"
invoke-static {v1}, Ljava/lang/Integer;->toString(I)Ljava/lang/String;
move-result-object v4
invoke-static {v3, v4}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I
变量为bool类型
const-string v3, "message"
invoke-static {v1}, Ljava/lang/Boolean;->toString(Z)Ljava/lang/String;
move-result-object v4
invoke-static {v3, v4}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I


2.弹出消息框

new AlertDialog.Builder(self)
.setTitle("普通对话框")
.setMessage("你好,Android!")
.show();
new-instance v1,Landroid/app/AlertDialog$Builder;
invoke-direct {v1,p0}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V
.local v1,builder:Landroid/app/AlertDialog$Builder;

const-string v2,"\u666e\u901a\u5bf9\u8bdd\u6846"
invoke-virtual {v1,v2}, Landroid/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

const-string v2,"\u4f60\u597d\uff0cAndroid!"
invoke-virtual {v1,v2},Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

invoke-virtual {v1},Landroid/app/AlertDialog$Builder;->create()Landroid/app/AlertDialog;
move-result-object v2
invoke-virtual {v2},Landroid/app/AlertDialog;->show()V

 

解决mysql使用autocommit导致挂起的bug

torndb使用MySQLdb连接远程mysql,会挂起超时,提示Lost connection to MySQL server during query。

跟踪后发现在autocommit后hang住,解决办法hook这个方法,直接返回。

使用下面的代码,之后再连接数据就不会挂起了。

from MySQLdb.connections import Connection
def func(self,t):
	return None
Connection.autocommit=func

Linux screen

new session: screen -S 
restore session: screen -r 
list session: screen -ls 

In session:
detach session: Ctrl+a,d
create window: Ctrl+a,c
next/prev window: Ctrl+a,n/p
lock/unlock: Ctrl+a,s/q
show status in title: Ctrl+a,w
split window: Ctrl+a,S
change window: Ctrl+a,Tab
kill window: Ctrl+a,K
start/stop log: Ctrl+a,H

php在pdo方式下对mysql导入导出

<?php 
header("Content-Type:text/html;charset=utf-8"); 
/* 
* 数据库导出调用 
*/ 
$host = '';//主机名 
$dbname = '';//数据库名 
$us

android ramdisk编辑

mkdir /etc/mm
mount -o rw -t ext4 /dev/block/sda3 /etc/mm
cp /etc/mm/ramdisk /data/local/tmp/ramdisk.img.gz
cd /data/local/tmp/
gunzip ramdisk.img.gz
mkdir ramdisk
cd ramdisk
cpio -i -F ../ramdisk.img
cpio -i -t -F ../ramdisk.img > list

cat list|cpio -o -H newc|gzip > ramdisk.img.gz
cp ramdisk.img.gz /etc/mm/ramdisk
umount /etc/mm

tornado缓存

class CacheBaseHandler(tornado.web.RequestHandler):
  
    def prepare(self):
        # 这里判断一下是否是GET请求,是否是非登陆用户,才做以下处理
        cached = self.application.db.cache.find_one({"slug": self.request.path})
        if cached is not None:
            self.write(cached["content"])
            self.finish()
  
    def render_string(self, template_name, **kwargs):
        html_generated = \
            super(CacheBaseHandler, self).render_string(template_name, **kwargs)
        self.application.db.cache.update({"slug": self.request.path},
            {"$set": {"content": html_generated}},
            upsert=True)
 
        return html_generated
 
    def on_finish(self):
        """ 重写结束请求前的方法函数 """
        if self.request.method == "POST":
            # 如果遇到POST提交则清空缓存
            self.application.db.cache.remove({"slug": self.request.path})

url计数

CREATE TABLE `ps_url2` (
  `text` varchar(300) DEFAULT NULL,
  `url` varchar(500) DEFAULT NULL,
  `url_crc` int(11) unsigned NOT NULL DEFAULT '0',
  `count` int(11) DEFAULT '0',
  PRIMARY KEY (`url_crc`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TRIGGER IF EXISTS `pseudohash_crc_ins`;
DELIMITER ;;
CREATE TRIGGER `pseudohash_crc_ins` BEFORE INSERT ON `ps_url2` FOR EACH ROW begin set NEW.url_crc=crc32(NEW.url);end
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `pseudohash_crc_upd`;
DELIMITER ;;
CREATE TRIGGER `pseudohash_crc_upd` BEFORE UPDATE ON `ps_url2` FOR EACH ROW begin set NEW.url_crc=crc32(NEW.url);end
;;
DELIMITER ;

记录text和url,采用crc32作为主键,插入与更新的时候用触发器更新url的crc32,采用crc32可以加快查询速度。

mysql的哈希索引只能在memory引擎的表中使用,mysql重启后表数据会丢失。

插入数据一条语句搞定:

insert into ps_url2(text,url) values(%s,%s) on duplicate key update count=count+1

on duplicate key确保插入时有重复数据自动更新原数据count数。

Powered By Z-BlogPHP 1.5 Zero

Copyright @ 2014-2019 All Rights Reserved.
feiworks.com