2015/10/29

How to format C and C++ code in Sublime Text

没有评论:
How to format C and C++ code in Sublime Text

I am writing some C code on my mac using Sublime Text and I needed a quick way to format the code for better readability.

I found this package for Sublime Text named SublimeAStyleFormatter:

https://packagecontrol.io/packages/SublimeAStyleFormatter

I’ve installed it with git by going on the packages folder and cloning the git repo:

cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
git clone git://github.com/timonwong/SublimeAStyleFormatter.git


And that was it! I can format my C code by pressing Ctrl + Alt + F.

2015/10/26

Cross-compiling a C application using the Android NDK

没有评论:
1 download ndk
export NDK=~/Downloads/android-ndk-r10e

2 Set cross-compiler for x86 (emulator)
mac:
export NDK_TOOLCHAIN=${NDK}/toolchains/x86-4.8/prebuilt/darwin-x86_64/bin/i686-linux-android-
export NDK_SYSROOT=${NDK}/platforms/android-19/arch-x86

Set cros-compiler for arm (device)
export NDK_TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-
export NDK_SYSROOT=${NDK}/platforms/android-19/arch-arm

3 compile
// hello-world.c
#include <stdio.h>
int main(void)
{
printf("Hello world cross compiled on Android!\n");
 return 0;
}

make CC=${NDK_TOOLCHAIN}gcc CFLAGS=--sysroot=${NDK_SYSROOT} hello-world

4 push to test
$ adb push hello-world /data/

$ adb shell

# /data/hello-world

Hello world cross compiled on Android!

reference:
https://yaapb.wordpress.com/2012/09/27/cross-compiling-a-c-application-using-the-android-ndk/

2015/10/21

Linux ELF 文件操作的一些工具

没有评论:
Linux ELF 文件操作的一些工具

1 file yourlib.so 识别文件格式

2  nm -g yourlib.so 列举目标文件中的符号,
默认输出这个文件中声明的任何函数和全局变量的名称
nm -g yourlib.so   列出所有 extern & exported symbols
nm -gC  yourlib.so    #for C++
nm -t d -l -S -v ./a.out
nm -Ca lib.so     显示所有symbols and function names
nm -D lib.so      # list symbols in the dynamic symbol table, which you can find its address by dlsym.

3 ldd yourlib.so 解析动态链接二进制文件所依赖的库文件
在OS X上,使用 otool -L yourlib.dylib 可实现类似的功能

4  objdump
Linux 自带, Mac OS 上类似为otool.
objdump -D   lib.so    #display assembler contents for all sections
objdump -tT /lib/i386-linux-gnu/libc.so.6 | grep fopen
objdump -Dslx  lib.so
objdump -x lib.so
objdump -TC lib.so

5 readelf
readelf -Ws libc.so 显示所有symbol tables
readelf -s lib.so 显示所有symbol tables
readelf -h  lib.so     # elf header
readelf -S lib.so      #sections

6 strings yourfile 用于提取文件中的字符串
strings —readix=x  yourfile     显示字符串在文件中位置
-a    扫描整个文件  
-e   也扫描Unicode字符

7   size
size /usr/sbin/httpd
Sample outputs:
   text       data        bss        dec        hex    filename
 314213      12376      13304     339893      52fb5    /usr/sbin/httpd
Where,
text - Actual machine instructions that your CPU going to execute. Linux allows to share this data.
data - All initialized variables (declarations) declared in a program (e.g., float salary=123.45;).
bss - The BSS consists of uninitialized data such as arrays that you have not set any values to or null pointers.

8 elfedit
Linux 自带, 可修改machine type, file type, osabi信息

9 hexdump -C  /bin/ls | more
linux command, 查看二进制信息

refer to:
http://www.tenouk.com/Module000linuxnm3.html

2015/07/29

T-OTP for Google Authenticator

没有评论:
Google Authenticator采用的算法是T-OTP(Time-Based One-Time Password),需要知道以下三点信息:
   * Key: 共享密钥
   * Current Time: 当前时间输入
   * HMAC-SHA1函数

共享密钥
共享密码用于在手机端上建立账户。密码内容可以是通过手机拍照二维码或者手工输入,并会被进行base32加密。

手工密码的输入格式如下:

    xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx

包含该令牌的二维码的内容是一个URL:

    otpauth://totp/Google%3Ayourname@gmail.com?secret=xxxx&issuer=Google

时间输入(当前时间)

输入的时间值来自于手机,一旦注册获得密钥后,就无需与服务器再进行通信,所以要确保手机上的时间准确,因为往后的步骤服务器可能会验证多个收到的OTP token,但时间值服务器只会取当前时间: 服务器会比对所有提交的token以确认是否有正确输入。

Hash函数

验证所用的方法是HMAC-SHA1,以一个密钥和一个消息为输入,生成一个20字节消息摘要作为输出。其算法可以简单表示为:

    hmac = SHA1(secret + SHA1(secret + input))

T-OTP与H-OTP的区别是T-OTP以当前时间作为输入,而H-OTP以自增counter(based on a seed)作为输入,该计数器使用时需要两边同步。

算法

首先,要进行密钥的base32加密。虽然谷歌上的密钥格式是带空格的,不过base32拒绝空格输入,并只允许大写。所以要作如下处理:

    original_secret = xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 
    secret = BASE32_DECODE(TO_UPPERCASE(REMOVE_SPACES(original_secret)))

第二步要获取当前时间值,这里使用的是UNIX time函数,或者可以用纪元秒。

    input = CURRENT_UNIX_TIME()

在Google Authenticator中,input值拥有一个有效期。因为如果直接根据时间进行计算,结果将时刻发生改变,那么将很难进行复用。Google Authenticator默认使用30秒作为有效期(时间片),最后input的取值为从Unix epoch(1970年1月1日 00:00:00)来经历的30秒的个数。

    input = CURRENT_UNIX_TIME() / 30

最后一步是进行HMAC-SHA1运算

    1.original_secret = xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 

    2.secret = BASE32_DECODE(TO_UPPERCASE(REMOVE_SPACES(original_secret))) 

    3.input = CURRENT_UNIX_TIME() / 30 

    4.hmac = SHA1(secret + SHA1(secret + input))

HMAC运算后的结果会是20字节即40位16进制数,我们需要的是常规6位数字密码. 首先要对20字节的SHA1进行瘦身。我们把SHA1的最后4个比特数(每个数的取值是0~15)用来做索引号,然后使用从索引号开始的4个字节计算OTP。因此,索引号的操作范围是15+4=19,加上是以零开始,所以能完整表示20字节的信息。4字节的获取方法是:

    1.然后将它转化为标准的32bit无符号整数(4 bytes = 32 bit):

    2.large_integer = INT(four_bytes)

最后再进行7位数(1百万)取整,就可得到6位数字了:

    1.large_integer = INT(four_bytes) 

    2.small_integer = large_integer % 1,000,000

这也是我们最后要的目标结果,整个过程总结如下:

    1.original_secret = xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx 

    2.secret = BASE32_DECODE(TO_UPPERCASE(REMOVE_SPACES(original_secret))) 

    3.input = CURRENT_UNIX_TIME() / 30 

    4.hmac = SHA1(secret + SHA1(secret + input)) 

    5.four_bytes = hmac[LAST_BYTE(hmac):LAST_BYTE(hmac) + 4] 

    6.large_integer = INT(four_bytes) 

    7.small_integer = large_integer % 1,000,000

一个完整可执行的GO语言程序,可以这里进行查看:
http://garbagecollected.org/2014/09/14/how-google-authenticator-works/

2015/06/11

Linux 32-bit和64-bit编译

没有评论:
Environment:
Ubuntu 14.04 64-bit desktop, as guest virtual machine in virtual box
Host: MacBook Pro

在64位机器上缺省编译或运行时查找的是64位程序,但如果编译32位程序通常会遇到一些问题,这里做一个说明。

Build  32-bit C/C++ program on 64-bit Linux


sudo apt-get install g++    #to build C++ source files
sudo apt-get install g++-multilib   #to build 32-bit executable on 64-bit Linux
g++ -m32 -g -o a.out file1.cpp file2.cpp   #specify 32-bit binary

Run 32-bit executable on 64-bit Linux
要运行32位legacy程序,则需要安装相应的32位库文件(ia32-libs)。
首先添加 i386 architecture,然后安装必要的32位库。
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo ./file-name

以下步骤可能也需要:
sudo apt-get update
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0


特别的,比如需要libgc library,则需指定i386类型下载:
sudo apt-get install libgc1c2            (for 32-bit linux)
sudo apt-get install libgc1c2:i386 
  (for 64-bit linux)

可以用命令 “file file_name”查看执行文件类型:
file-name: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped

2015/06/10

Shrink Virtualbox VM VDI File Size

没有评论:
Virtualbox  的VM image size (.vdi file)有时候会变得很大, 如何缩减文件大小呢? 
这里我的host = MacBook Pro, guest = Win7. 虚拟机创建的时候设置的是 “Dynamically Expanding Storage” , 但以后随着增删文件操作而磁盘只会增加不会减少。
  1. Run defrag in the guest (Windows only)
  2. Nullify free space:
    With a Linux Guest run this:
    sudo dd if=/dev/zero of=/bigemptyfile bs=4096k
    sudo rm -rf /bigemptyfile
    
    With a Windows Guest, download SDelete from Sysinternals and run this:
    sdelete –z c:
    
  3. Shutdown the guest VM
  4. Now run VBoxManage's modifyhd command with the --compact option:
    With a Linux Host run this:
    vboxmanage modifyhd /path/to/thedisk.vdi --compact
    
    With a Windows Host run this:
    VBoxManage.exe modifyhd c:\path\to\thedisk.vdi --compact
    
    With a Mac Host run this:
    VBoxManage modifyhd /path/to/thedisk.vdi --compact
    
This reduces the vdi size.

2015/01/13

一些用来加固应用的.so库

没有评论:

libsecexe.so 梆梆加固

libAPKProtect.so APKProtect加固,

libprotectClass.so 360加固,

libNSaferOnly.so 通付盾加固,

libnqshield.so 网秦加固,

libshell.so 腾讯加固,

ijiami.dat 爱加密加固,

libddog.so 娜迦加固,

libmobisec.so 阿里加固,

libbaiduprotect.so 百度加固

2015/01/08

Virtualization on Android OS

没有评论:


Virtualisation on Android OS:
  1. OKL4 Microvisor from Open Kernel Labs.  VMM runs on highest privilege, virtualising: processor(instructions,registers), memory, I/O. The other applications run on light-weight lower level.
  2. VLX from VirtualLogix.
  3. Mobile visor platform (MVP) from VMware, offering a hypervisor on smart mobile phones

Linux Container.

major difference between hypervisor and V-OS:
  hypervisor lies between OS and hardware, while V-OS lies above OS level. so the security of V-OS actually heavily depends on protection/obfuscation on application code.


major difference btw. security method of V-OS and app-wrapping:


Problems: the purpose of security is not very clear. what does V-OS want to protect?
algorithm/implementation or sensitive data. code obfuscation can only improve the difficulty of reverse engineering (sometimes it is sufficient). if it is sensitive data, no absolute secure solution without hardware isolation support. the best effort may be to provide multiple layer securities.

2015/01/06

轻量级C Compiler比较

没有评论:
要求,纯C写就,轻量级。

TCC, LCC, PCC
结论: lcc比较适合用来写新的architecture, 即retargetable compiler. lcc规模较小,各个模块边界清晰,而且宏少,使用经验多,还有教程。 依赖少, 较易移植。缺点是不支持ARM处理器。

LCC - little C compiler
arch: x86, mips, alpha, sparc, microsoft cil
implement: ANSI C
license: LCC license
written in C
last release: sept. 2002
Retargeting能力比较强。

TCC - tiny C compiler, 
arch: X86 + ARM processor,
license: LGPL licence
implement all ANSI C(C89/C90), much of C99, many GNU C extensions including inline assembly
written in C and assembly
last release: feb. 2013
tcc有自己的汇编器与连接器

PCC: portable c compiler
arch: x86, x64
implement: C99
license: BSD
written in: C


retarget 一般放在backend做 code generation产生 machine code.

TCC的retarget支持不强。
比如一个例子: 将tinycc编译retarget to a virtual processor I designed.
则必须要实现一个code generator backend for this architecture, 类似于目录下的
i386-gen.c, arm-gen.c, and c67-gen.c 文件实现。

注意:there are apparently some issues with byte ordering, such
that the compile and target hosts must have the same endianness if you
want the output to be sensible. But I don't know if that's due to the
the *-gen implementation itself or part of the core compiler code.

另外针对 assembler, tcc does not normally generate any intermediate assembly; it goes
directly from C code to object code.


LCC
lcc code generator is based on the lburg. Some retarget examples:

retargetable C compiler for network processor
http://www.iro.umontreal.ca/~aboulham/pdfs_sources/SCI02.pdf

A PDP-11 target for lcc
http://telegraphics.com.au/sw/info/lcc-pdp11.html

Retargeting lcc for Magic-1
http://www.homebrewcpu.com/retargeting_lcc.htm

vcode or tick cc
vcode: a retargetable, extensible, very fast dynamic code generation system,
This paper appeared in PLDI '96. Slides are available here .
vcode is a portable system to generate executable code at runtime. It generates code in approximately 10 instructions per generated instruction, and is easily extendible by clients. A tutorial describing it can be obtained by clicking here. A beta version of the system is also available. To get on the vcode mailing list, please email engler@lcs.mit.edu. Click here for a bit more information. 

`C and tcc: A Language and Compiler for Dynamic Code Generation,


Quake 3

id Software's id Tech 3 engine relies on a modified version of LCC to compile the source code of each game module or third-party mod into bytecode targeting its virtual machine.[6] This means that modules are oblivious to the system beyond the system calls and limited file system scope offered by the engine, which is intended to reduce the threat posed by malicious mod authors. Another consideration is that games and mods written for the engine are portable without recompilation; only the virtual machine needs to be ported to new platforms in order to execute the modules.

id Tech 3 uses a virtual machine to control object behavior on the server, effects and prediction on the client and the user interface. This presents many advantages as mod authors do not need to worry about crashing the entire game with bad code, clients could show more advanced effects and game menus than was possible in Quake II and the user interface for mods was entirely customizable.

Virtual machine files are developed in ANSI C, using LCC to compile them to a 32-bit RISC pseudo-assembly format. A tool called q3asm then converts them to QVM files, which are multi-segmented files consisting of static data and instructions based on a reduced set of the input opcodes. Unless operations which require a specific endianness are used, a QVM file will run the same on any platform supported by Quake 3.

The virtual machine also contained bytecode compilers for the x86 and PowerPC architectures, executing QVM instructions via an interpreter.

https://github.com/id-Software/Quake-III-Arena/tree/master/q3asm
http://fabiensanglard.net/quake3/qvm.php
http://gamedev.stackexchange.com/questions/15107/how-can-i-edit-qvm-quake-virtual-machine-files
http://www.icculus.org/~phaethon/q3mc/q3vm_specs.html

Object-C Code Obfuscators

没有评论:
iOS application protection


Object-C是有反射(reflect)机制的,可以被用来做混淆,在一定程度上提高代码的安全性。
关键代码把核心逻辑尽量放在c层, 这样还有一个好处是iOS和android可以公用.

数据加密,服务器解析
一般对各个参数进行签名验证,对核心参数进行加密,而且防止别人进行重放攻击,一般都会将时间戳做为一个参数

Protection Techniques:
  1. Control flow obfuscation e.g. ARM instruction flows are mangled with redundant instructions to try to hide the original purpose of the code,
  2. Class and Method renaming - renames your methods and classes to meaningless names although you have to be careful where this is used as you can easily break your app because the Objective-C runtime is expecting to find certain names,
  3. String encryption - all static strings in the app are encrypted and code is inserted to decrypt the strings just before use in order to make static analysis harder
  4. Anti-debug - code is inserted to break the usual debuggers (not always successfully),
  5. Anti-tamper - usually builds a network of checksums that protect the binary code from modification,
  6. Objective-C runtime protection - usually checks obj-c registered method implementations to make sure that they are in the app and haven't been 'swizzled'. 
  7. encrypt constant, strings, decrypt in real-time
  8. encrypt local stored files

Detection Techniques:
  • detect debug status
  • detect jail-break status
  • integrity check of data or piece of code

Object-C code obfuscators:
  • EnsureIT for Apple iOS
  • Contaxiom Code Protection
  • Arxan,
  • Metaforic,
  • Cryptanium
  • iOS class-guard to rename class /method names

RE tools:
  • class-dump
  • gdb
  • IDA pro/hopper disassembler

2015/01/05

关于ARM的built-in security

没有评论:
iOS和Android smartphone 的ARM芯片都内置实现了TrustZone技术,提供TEE安全运行环境(包含TrustedOS和硬件支持), 与Android OS隔离,因此理论上可以彻底阻止软件层面上来的攻击。 这里TrustedOS可以看作一个Hypervisor,监视上层的”TrustedAPP”.

因为TrustedOS属于定制build和安装,它是不能从app store上下载的,所以应用提供者还必须将智能手机定制为TrustedOS firmware才可以使用. 看起来移植性不太好哈,不过还是可以做一个支持通用接口的TEE kernel用来安装其他认证应用。Trustonic和三星就在做。

当然ARM也不落后,针对64-bit ARMv8 系列芯片,它给出了一个开源的项目(BSD license) the source code is available on Github.

其他开源的TrustOS:
OVOS : http://www.openvirtualization.org/  也是隔离了secure world and normal world.


reference:
http://www.androidauthority.com/arms-built-security-might-just-get-rid-password-397924/

2015/01/02

为反编译Android应用设置Linux环境

没有评论:
Linux environment setup

ubuntu 14.04 64-bit virtual machine on virtual box
1. shared folder:   in virtual box setting, create two shared folder “Documents”, “Downloads” on mac os, set full r/w rights and permanent. then in unbuntu’s mnt directory you will see “sf_Downloads” and “sf_Documents” ( with AdditionIn package installed ).
2. however, you may need to run “sudo adduser fanghui vboxsf” to add yourself to vboxsf group, and restart ubuntu guest.


android apktool
http://ibotpeaches.github.io/Apktool/install/
1. Check java 1.7 installed or not
       $java -version
       $sudo apt-get install default-jre  (or openjdk-7-jre)


2. Download Linux wrapper script (https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool,  Right click, Save Link As apktool)

3. Download apktool-2 (https://bitbucket.org/iBotPeaches/apktool/downloads, find newest here)

4. Make sure you have the 32bit libraries (ia32-libs) downloaded and installed by your linux package manager, if you are on a 64bit unix system.
(This helps provide support for the 32bit native binary aapt, which is required by apktool)

5. Rename downloaded jar to apktool.jar

6. Move both files (apktool.jar & apktool) to /usr/local/bin (root needed)
Make sure both files are executable (chmod +x)

7. Try running apktool via cli
   example:   $apktool d flappy-bird.apk
  will unzip the file structure
  find “Fake Flappy birds on Android” on http://androidmalwaredump.blogspot.sg/


dex2jar
   download dex2jar from http://sourceforge.net/projects/dex2jar/files/
   extract to a folder
        $unzip -x dex2jar-2.0.zip  -d /home/your_folder
   convert apk to jar file  ( you might need chmod +x d2j* )
        $sh /home/your_folder/dex2jar-2.0/d2j-dex2jar.sh  flappy_bird.apk


jd-gui
    download from jd.benow.ca
  it is a jar file “jd-gui-1.1.0.jar", so run with
     $java -jar jd-gui-1.1.0.jar
 a gui will pop up.

jad
jad is a decompiler tool similar to jd-gui, except command line.
download from http://varaneckas.com/jad/
somehow i cannot run jad 1.5.8e for linux on intel, so i choose jad 1.5.8e for linux (statically linked) instead.


boomerang (not mature)
download boomerang-linux-alpha-0.3 from http://boomerang.sourceforge.net/download.php
it requires libgc. when I try to run the program, I get this error:
./boomerang: error while loading shared libraries: libgc.so.1: cannot open shared object file: No such file or directory

You need to install libgc, something like

sudo apt-get install libgc1c2
sudo apt-get install libgc1c2:i386 
  (for 64-bit linux)

boomerang also requires libexpat1
sudo apt-get install libexpat1:i386

ok.

====
Note: run 32-bit executable on 64-bit linux

use “file file_name” to view exe type.

file-name: ELF 32-bit LSB  executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, not stripped


firstly install ia32-libs.
sudo apt-get install ia32-libs
or
sudo apt-get update
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0

or
To run 32bit executable file in a 64 bit multi-arch Ubuntu system, you have to add i386 architecture and also you have to install libc6:i386,libncurses5:i386,libstdc++6:i386 these three library packages.
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
sudo ./file-name

2014/12/01

Linux compiler warnings

没有评论:
When compiling C++ programs, gcc reports -Wwrite-strings warning.
xxx.cpp:344:5: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
Solution 1 (推荐):
     cast constant string from char * s = "constant string" to const char *s= "constant string".

Solution 2:
 you can also pass -Wno-write-strings to gcc which then suppresses this warning.

Solution 3:
#pragma GCC diagnostic ignored "-Wwrite-strings"    忽略警报
...
#pragma GCC diagnostic pop       重新打开警报


gcc reports -Wmultichar warning:
xxx.cpp:332:7: warning: multi-character character constant [-Wmultichar]
 #if (('1234' >> 24) == '1')     // little endian ?
       ^
这个是用宏判断机器是否little-endian/big-endian,一般主机都是little-endian.
Solution 1 (推荐):
Check endian-ness at run time:
 int IS_LITTLE_ENDIAN() {
  static const int NL_AT_END = 0x000A;
  return ((char*)(void*)&NL_AT_END)[0] == '\n';
 }

Solution 2:
pass -Wno-multichar  to gcc for suppressing this warning.

Further reading: http://zipcon.net/~swhite/docs/computers/languages/c_multi-char_const.html
 

2014/06/18

ODBC driver problem

没有评论:
2009年写的一个船舶碰撞模拟器最近要求再产生一些数据,于是重新拾掇了程序。发现连接的mdb文件数据库在windows 7 64-bit上有问题:

Microsoft ODBC Administrator: The setup routines for the Microsoft Access Driver (*.mdb, *.accdb) ODBC driver could not be found. Please reinstall the driver.

找出原因如下:

We have an excel sheet that runs a report and get it's data from a database. The database that it gets the data from was recently moved to a different shared instance. I am now having issues setting up a new connection to the shared instance that the database now resides on. When I try to go in to try to add an ODBC I only have an option to setup a SQL server connection (No option to setup an Excel Files ODBC). If I try to configure the existing Excel Files ODBC I get the error

"The setup routines for the Microsoft Excel Driver ODBC driver could not be found. Please re-install the driver."

Once I click "OK" on that error another one pops up saying "Errors found: The specified DSN contains an architecture mismatch between the driver an application."

The system is running Windows 7 Enterprise (x64), has 6GB of RAM, an Intel Xeon E5620 (2.4GHz) and the version of office is Office 2010 Pro.


解决办法:
在64位机器上直接使用odbc 32-bit程序。
Use odbcad32.exe under %WINDIR%\SYSWOW64, you will find all the 32bit drivers enumerated.  MS Access 32-bit ODBC driver is already shipped.

32-Bit Excel needs 32-Bit ODBC-Adminstrator odbcad32.exe which lives in C:\Windows\SysWOW64

64-Bit Excel needs 64-Bit ODBC-Adminstrator odbcad32.exe which lives in C:\Windows\System32



2014/04/09

OpenSSL HeartBleed 漏洞来势凶猛

没有评论:
最近透露出来的OpenSSL HeartBleed (心脏滴血)漏洞很厉害,yahoo.com 都被用来作为POC攻击的示范站点。不过发此文时yahoo似乎已修复, 但查询top 1000...网站确实还有不少中招。ssltest python script 轻易就可以搜到,就不放在此了,注意它们只是显示是否vulnerable,并没有显示message content,当然这也很简单。此时攻防双方应该是在分秒必争,我觉得一些搞bitcoin的一些网站真是应该小心了。。。

INSECURE - bitcurex.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - localbitcoins.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - vip.btcchina.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - www.bitfinex.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - www.bitgo.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - www.bitstamp.net:443 has the heartbeat extension enabled and is vulnerable
INSECURE - www.cryptsy.com:443 has the heartbeat extension enabled and is vulnerable
INSECURE - www.virwox.com:443 has the heartbeat extension enabled and is vulnerable



OpenSSL HeartBleed bug
http://heartbleed.com/

Online heartbleed test
http://possible.lv/tools/hb/
http://filippo.io/Heartbleed/
https://www.ssllabs.com/ssltest/



2014/04/08

Skype Silk 与Opus的关系

没有评论:
Skype自2009年1月以来一直采用自己的SILK音频编码解码器,但是从2012年起过渡到新的Opus标准。Opus标准已经获互联网工程任务组(IETF)批准,标准格式为RFC 6716。它 是一个有损声音编码的格式,适用于网络上的实时声音传输。Opus支持6kbps到510kbps的可变比特率。由于是一个开放格式,Opus在使用上没有任何专利限制。

Opus合并了Xiph.org的CELT低延时音频编解码器和Skype的SILK语音编解码器,专为互联网音频设计,可用于替代现有的私有音频编解码器,由 Xiph.Org、Mozilla、微软、Broadcom、Octasic和Google联合开发。


目前软件包版本是Opus v1.1
Skype Opus Codec

2010/04/29

VC2005 --> 2008

没有评论:
Vs2008兼容vs2005 的项目;但vs2008的项目却不能放在vs2005中.

将vs2008 项目 转换成到2005 下的解决方法:
l. 修改解决方案文件:解决方案.sln
Microsoft Visual Studio Solution File, Format Version 10.00 [9.00]
# Visual Studio 2008 [2005]

2. 修改项目文件:项目.vcproj
delete ToolsVersion="3.5"
change MSBuildTools to MSBuildbin
通过以上步骤就可以用Vs2005打开vs2008下的项目.

另:vs2008下使用的类库跟vs2005的类库是有区别的:
1 删除 using System.Linq;
2 移除包含!号的引用


手动卸载 Visual Studio 2005/2008
refer to http://support.microsoft.com/kb/907965

or 卸载 Visual Studio 2008 组件时,必须按照以下顺序进行。 (VS2005类同)

打开“添加或删除程序”(Windows Server 2003 和 Windows XP)或“程序和功能”(Windows Vista 和 Windows Server 2008)。

1. 删除“Microsoft SQL 发布向导”。

2. 删除“Crystal Reports Basic for Visual Studio 2008”。

3. 删除“Crystal Reports Basic for Visual Studio 2008 64 位运行库(x64)”。 只有当 Visual Studio 安装在 64 位计算机时,才需要此步骤。

4. 删除“Microsoft Windows SDK for Visual Studio 2008 SDK 引用程序集和 IntelliSense”。

5. 删除“Microsoft Windows SDK for Visual Studio 2008 .NET Framework Tools”。

6. 删除“Microsoft Windows SDK for Visual Studio 2008 Win32 Tools”。

7. 删除“Microsoft Windows SDK for Visual Studio 2008 标头和库”。

8. 删除“Microsoft Windows SDK for Visual Studio 2008 Tools”。

9. 删除“Microsoft Visual Studio 2008 远程调试器”。 只有当 Visual Studio 安装在 64 位计算机时,才需要此步骤。

10. 删除“Microsoft SQL Server 2005 Express Edition”。

11. 删除“Microsoft SQL Server Native Client”。

12. 删除“Microsoft Device Emulator 3.0 版”。

13. 删除“Windows Mobile 5.0 SDK R2 for Smartphone”。

14. 删除“Windows Mobile 5.0 SDK R2 for Pocket PC”。

15. 删除“Microsoft SQL Server Compact 3.5 for Devices”。

16. 删除“Microsoft SQL Server Compact 3.5 设计工具”。

17. 删除“Microsoft SQL Server Compact 3.5”。

18. 删除“Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System Runtime”。

19. 删除“Microsoft Visual Studio Tools for the Microsoft Office system (3.0 版运行库)”。

20. 删除“Microsoft .NET Compact Framework 3.5”。

21. 删除“Microsoft .NET Compact Framework 2.0 SP2”。

22. 删除“Microsoft Visual Studio”。

23. 删除“Microsoft Visual Studio Web 创作组件”。

24. 删除“Microsoft Document Explorer 2008”。

25. 删除“Microsoft Visual Studio 2008 64 位系统必备”。 只有当 Visual Studio 安装在 64 位计算机时,才需要此步骤。

26. 删除“Microsoft .NET Framework 3.5”。

2010/03/01

Update vbox guest additions

没有评论:
New VirtualBox 3.1.4
How to update VBox Guest(Ubuntu) Additions?

1. use Vbox install option in GUI to download file "VBoxGuestAdditions_3.1.4.iso". The file was put into "C:\Documents and Settings\Administrator\.VirtualBox", and hint to mount. It will be mount to "/media/cdrom"

2. go to this directory and run
sudo ./VBoxLinuxAdditions-x86.run
Before do this, you might want to run
sudo apt-get install build-essential linux-headers-generic

3. restart guest OS (virtual linux)

Note: If you already download a *.iso file, you can mount it manually in vbox media manager.

P.S.: vbox 3.1.4 still has an annoying problem "could not switch the monitor configuration... CRTC56"!

2009/12/15

PyGTK下编写多线程程序

没有评论:
虽然在PyGTK中Python有关多线程的库(thread,threading)可以使用,但其行为常现异常,所以一定要按照PyGTK的要求编写多线程应用程序。

How threads works in pygtk using the threading module?

Threads are a way for a program to split itself into two or more simultaneously running tasks. The way that we create threads in python is writing subclasses of the threading.Thread class, the method run, should be overloaded so we include there the code that we want to be rant on each thread.

In order to create a new thread, we should create a new Thread object and then, call the start method which creates the new thread, and executes the run method in its context.

The problem with PyGTK is that the gtk.main() loop won't refresh the screen each time that the fraction is set, we need to use the gtk thread engine. We need to call the gtk.thread_init() function to start the thread engine, this call should be made on the same thread that the gtk.main() function is called. In fact, calling it right afer importing the gtk module is a good practice.

Thus, we should use gtk.threads_enter() before any access to gtk object, and, once we end up doing transformations, we should call gtk.threads_leave().

We should call to the stop method in the exit callback so when the window is closed the application ends the thread and the script doesn't hangs.

只允許主線程修改圖形界面

這是較常用的一種方式,但編寫時略顯複雜。首先,在程序初始化時調用(一定在gtk.main()之前運行):
gobject.threads_init()
多線程的實現方式與純Python相同:
t=threading.Thread(target=新线程的函数)
t.start()
要修改界面的代碼則使用gobject.idle_add加到GTK的主循環中。
gobject.idle_add(新线程函数, 参数)
注意如果新線程函數返回True,則該函數仍在GTK的主循環中,如果返回False,則退出主循環。下面的例子是PyGTK.org上給出的:
import threading
import time
import gobject
import gtk

gobject.threads_init()

class MyThread(threading.Thread):
 def __init__(self, label):
     super(MyThread, self).__init__()
     self.label = label
     self.quit = False

 def update_label(self, counter):
     self.label.set_text("Counter: %i" % counter)
     return False

 def run(self):
     counter = 0
     while not self.quit:
         counter += 1
         gobject.idle_add(self.update_label, counter)
         time.sleep(0.1)

w = gtk.Window()
l = gtk.Label()
w.add(l)
w.show_all()
w.connect("destroy", lambda _: gtk.main_quit())
t = MyThread(l)
t.start()

gtk.main()
t.quit = True

允許所有線程修改圖形界面

這種方法要簡單很多。與前面類似,在程序初始化時調用:
gtk.gdk.threads_init()
不過要把gtk.main()用下面兩個函數括起來:
gtk.threads_enter()
gtk.main()
gtk.threads_leave()
其它線程也是如此,在修改界面內容的代碼前後加上
gtk.threads_enter()
...
gtk.threads_leave()

The following example shows how to do it using a random fraction for the progress bar:

import threading
import random, time
import gtk
#Initializing the gtk's thread engine
gtk.threads_init()


class FractionSetter(threading.Thread):
 """This class sets the fraction of the progressbar"""

#Thread event, stops the thread if it is set.
stopthread = threading.Event()

def run(self):
  """Run method, this is the code that runs while thread is alive."""

 #Importing the progressbar widget from the global scope
 global progressbar

 #While the stopthread event isn't setted, the thread keeps going on
 while not self.stopthread.isSet() :
  # Acquiring the gtk global mutex
  gtk.threads_enter()
  #Setting a random value for the fraction
  progressbar.set_fraction(random.random())
  # Releasing the gtk global mutex
  gtk.threads_leave()
 
  #Delaying 100ms until the next iteration
  time.sleep(0.1)
 
def stop(self):
  """Stop method, sets the event to terminate the thread's main loop"""
 self.stopthread.set()

def main_quit(obj):
 """main_quit function, it stops the thread and the gtk's main loop"""
#Importing the fs object from the global scope
global fs
#Stopping the thread and the gtk's main loop
fs.stop()
gtk.main_quit()

#Gui bootstrap: window and progressbar
window = gtk.Window()
progressbar = gtk.ProgressBar()
window.add(progressbar)
window.show_all()
#Connecting the 'destroy' event to the main_quit function
window.connect('destroy', main_quit)

#Creating and starting the thread
fs = FractionSetter()
fs.start()

gtk.main()

Refer to:
http://aruiz.typepad.com/siliconisland/2006/04/threads_on_pygt.html
http://docs.python.org/library/threading.html

2009/11/29

Ubuntu下的PDF编辑工具

没有评论:
Pdftk是由Sid Steward写的一个PDF增强软件,也就是所谓的PDF Hacks。它可以合并/分割PDF文档、解开必要的输入密码、输出加密、给PDF文档加水印、从PDF文档中解出附件、将PDF文档变成一页等等,能够做到操作PDF文档的所有事情。

安装:
sudo apt-get install pdftk


其合并文档的具体用法为:

按照顺序合并多个文档成一个文档:
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

使用参数:
pdftk A=1.pdf B=2.pdf cat A B output 12.pdf

使用通配符:
pdftk *.pdf cat output combined.pdf

从几个文档中分割内容合并成一个文档:
pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf

或者 (使用通配符):
pdftk *.pdf cat output combined.pdf

把多个PDF的不同页面组合成一个新的PDF文档
pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf

旋转PDF第一页90度
pdftk in.pdf cat 1E 2-end output out.pdf

选择所有PDF页面180度:
pdftk in.pdf cat 1-endS output out.pdf

使用128强度加密PDF
pdftk mydoc.pdf output mydoc.128.pdf owner_pw foopass

同上,同时给PDF加上访问密码
pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz

同上,但是运行打印:
pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz allow printing

解密PDF文档:
pdftk secured.pdf input_pw foopass output unsecured.pdf

合并两个PDF文档,其中一个是加密的,但最终文档不加密:
pdftk A=secured.pdf mydoc.pdf input_pw A=foopass cat output combined.pdf

解压PDF流,以便文本编辑:
pdftk mydoc.pdf output mydoc.clear.pdf uncompress

修复PDF文档
pdftk broken.pdf output fixed.pdf

分解成单页
pdftk mydoc.pdf burst

报告PDF信息,输出到文本
pdftk mydoc.pdf dump_data output report.txt


Pdfedit

PDFedit可以让你整个的编辑PDF文档。你可以改变PDF的任意部分。功能可以使用脚本添加。
脚本可以使用其他外部编辑器,并且可以定制自己的脚本。

安装
sudo apt-get install pdfedit


GIMP

首先安装krita:
sudo apt-get install krita

打开GIMP,然后打开PDF文件。对于多页文件,编辑也非常容易,它会自动打开多个编辑窗口。编辑完成以后,存为XCF格式。用krita打开XCF文件,选择“File"->"Printe",选择打印成PDF文件,并且选择目标文件的保持位置。


pdfjam
pdf合并和分拆工具.
下载:http://umn.dl.sourceforge.net/sourceforge/pdfsam/pdfsam-0.7sr1-out.zip(使用basic版,加强版收费)