三味猪屋


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签
三味猪屋

iOS逆向实践

发表于 2017-03-31 | 分类于 iOS

iOS设备越狱

工具:PP助手、TaiG、evasi0n (http://evasi0n.com)
设备:iPhone6,iOS8.3
由于我使用了PP助手对手机设备进行越狱操作的,没有什么技术性,这里就暂时略过,以后再研究下使用TaiG、evasi0n等工具进行越狱再补上。

查看越狱iOS设备APP文件夹

工具:PP助手、iTools、iFunBox
iOS8.3之后由于苹果加强了沙盒的安全性,导致工具无法直接查看到APP的沙盒文件夹结构,所以要查看iOS设备沙盒文件就需要进行越狱之后使用文件管理工具查看。
文件查看工具查看越狱后的iOS设备文件夹结构如下:

如果想要查看APP沙盒文件夹结构,需要将iPhone越狱后再安装AFC2。
步骤如下:
1、打开Cydia
2、打开“搜索”Tab项
3、输入“Apple File Conduit ‘2’”
4、安装“Apple File Conduit ‘2’”
此时可通过文件查看工具查看APP沙盒文件夹结构如下:

远程连接iOS设备

工具:Terminal.app
1、手机中打开Cydia,打开“搜索”Tab项,输入“OpenSSH’”,安装“OpenSSH”
2、确保手机已经连接了WIFI并且你的手机的WIFI
和你的电脑要在同一个局域网内,打开终端输入:
ssh root@xx.xx.xx.xx,(xx.xx.xx.xx)为你的手机的IP地址—>Enter
3、接着会提示你输入password:
这里的密码一般情况下是alpine,但是如果你更改过的话就用你更改的[这里的密码是手机openssh的密码,不是电脑密码也不是手机解锁密码]
4、然后来输入吧,通过cd可以进入到制定的文件夹目录
iPhone6:~ root# cd /usr/bin

APP砸壳

工具:Clutch、Terminal.app、iFunBox
Clutch源码:(https://github.com/KJCracks/Clutch/releases)

1、将Clutch拷贝到手机设备中:/usr/bin/
方式1:iFunBox直接拷贝

方式2:scp /path/to/Clutch root@:/usr/bin/

2、解决运行Clutch时报Permission denied的错误
运行Clutch时报错如下:

解决方法如下:
从上图可以看出错误的类型,Permission denied就指权限受限,只要赋予其权限即可。
1、打开Terminal.app
2、终端里输入chmod a+x Clutch,如下图所示:

3、Clutch使用方法

4、查看iOS设备中所有所安装的APP

5、通过Clutch命令砸壳,如图所示:

参考:
http://iphonedevwiki.net/index.php/Reverse_Engineering_Tools

三味猪屋

Android反编译总结

发表于 2017-03-29 | 分类于 Android

Apk反编译

Apk反编译使用到的工具:
1、apktool (https://bitbucket.org/iBotPeaches/apktool/downloads/)
2、enjarify (https://github.com/google/enjarify)
3、Java Decompiler (http://jd.benow.ca)

1、apktool

功能:用于拆解安装包、重新打包。
下载地址: (https://bitbucket.org/iBotPeaches/apktool/downloads/)
安装方法: (https://ibotpeaches.github.io/Apktool/install/)
使用方法: (https://ibotpeaches.github.io/Apktool/documentation/)
apktool安装时注意几点:
1、检查是否安装java环境,如果没有,请先安装java环境

2、将apktool脚本变成可执行文件
图1:

图2:

图1红框内的脚本当右键保存的如果是apktool.txt格式的文件,本人保存的时候就是txt格式,见图2。当我使用Sublime Text编辑器将其保存为apktool.sh时,无法通过’chmod +x’将其变为可执行文件。最终使用Atom编辑器将其保存为apktool,此时这可使用’chmod +x’将其变为可执行文件。
Sublime Text2编辑器


Atom编辑器


最终得到如下结果

其实apktool脚本并不是必须的,作用就是在执行apktool.jar时,不必每次都要不厌其烦的输入:java -jar apktool.jar
关于这一点网站上也Note出来了:
Note - Wrapper scripts are not needed, but helpful so you don’t have to type java -jar apktool.jar over and over.
未使用apktool.sh wrapper shell script时的格式
java -jar apktool.jar yourapp.apk -o yourapp
使用enjarify.sh wrapper shell script时的格式
apktool yourapp.apk -o yourapp

2、enjarify

功能:用于反编译dex文件,得到java源代码,与dex2jar类似。
下载地址:(https://github.com/google/enjarify)
这个工具是谷歌官方开源的用于反编译dex文件的。
enjarify安装注意几点:
1、检查是否安装python3
因为enjarify是一个纯的python3应用,所以必须确保已经安装了python3,如果没有,则需要安装。
此时又要祭出大杀器 Homebrew
安装Python 2.7的话,请输入:
$ brew install python
如果你选择使用Python3,只需要将python替换成python3即可。
$ brew install python3
想查看可以安装哪些Python版本的话,可以通过下面的命令在Homebrew上搜索。
$ brew search python
这个命令会列出可以安装的全部Python版本。

2、为了方便原则,方便使用enjarify.sh脚本窍门
在终端里执行以下语句
ln -s "$PWD/enjarify.sh" usr/local/bin/enjarify
$PWD指enjarify所在的物理位置,我的电脑位置如下:
/Users/yuntai01/Desktop/下载/enjarify-1.0.3
执行完,则可在对应的文件夹中找到:

未使用enjarify.sh wrapper shell script时的格式
python3 -O -m enjarify.main yourapp.apk -o yourapp.jar
使用enjarify.sh wrapper shell script时的格式
enjarify yourapp.apk -o yourapp.jar

3、Java Decompiler

功能:查看java源代码
下载地址:(http://jd.benow.ca)选择jd-gui即可。
用法:启动jd-gui,直接将enjarify反编译出来得到jar包拖进jd-gui中即可。

Apk重新打包

1、使用前文提到的apktool工具解开test.apk
$ apktool d testapp.apk -o testapp

2、查看解开的目录下的 META-INF/CERT.RSA,该文件存储有原应用的签名
$ keytool -printcert -file test/original/META-INF/CERT.RSA

3、重新打包应用为 new_testapp.apk
$ apktool b test -o new_testapp.apk

4、生成一个新的 keystore
$ keytool -genkey -v -keystore androidse.keystore -alias androidsekey -keyalg RSA -keysize 2048 -validity 365

5、用刚刚生成的 keystore 对重新打包生成的 new_testapp.apk 进行重新签名
$ jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore androidse.keystore new_testapp.apk androidsekey


6、验证签名是否正确打到应用上
$ jarsigner -verify -verbose -certs new_testapp.apk


7、对齐 apk,应用要想上 Google Play 必须进行对齐操作,对齐后生成新的应用 new_testapp_align.apk
$ ANDROID_HOME/build-tools/23.0.2/zipalign -v 4 new_testapp.apk new_testapp_align.apk
以上就完成了最简单的重新打包操作。

Mac上安装apk到Android设备

使用Google官方推荐的工具 Android File Transfer:
Android File Transfer:(https://www.android.com/filetransfer/)

三味猪屋

objc_msgSend 的正确使用姿势

发表于 2016-11-30 | 分类于 iOS

首先需要import objc_msgSend 所在的头文件

1
#import <objc/message.h>

‘objc_msgSend’ 同时在 和都有定义,需要进一步了解其异同。

在64位机器上运行‘objc_msgSend’,如果姿势不对,编译器不会提示警告,而是直接crash。

解决办法:

需要将objc_msgSend重新声明成自己想要的参数,如下所示:

1
2
//objc_msgSend(self,selector,@"test");
((void(*)(id, SEL, id))objc_msgSend)(self, selector, @"test");

详情请参照苹果官方文档

1
2
3
4
5
6
Listing 2-14 Using a cast to call the Objective-C message sending functions
- (int) doSomething:(int) x { ... }
- (void) doSomethingElse {
int (*action)(id, SEL, int) = (int (*)(id, SEL, int)) objc_msgSend;
action(self, @selector(doSomething:), 0);
}

三味猪屋

iOS7中UITextField切换中文时某些协议方法无响应

发表于 2016-11-30 | 分类于 iOS

UITextField切换中文输入,选中键盘中被mark的中文字符时,iOS7中UITextField不会调用如下协议方法:

1
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

解决方法:

1、利用通知中心监听UITextFieldTextDidChangeNotification。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(textFiledEditChanged:)
name:UITextFieldTextDidChangeNotification
object:self];
- (void)textFiledEditChanged:(NSNotification *)notification
{
if ([notification.object isKindOfClass:[EzvizTokenTextField class]]) {
EzvizTokenTextField *textField = notification.object;
UITextRange *selectedRange = [textField markedTextRange];
//获取高亮部分
UITextPosition *position = [textField positionFromPosition:selectedRange.start offset:0];
if (!position) {
self.ezvizTokenTextFieldTextLength = [textField.text length];
}
}
}

当键盘中有mark的中文字符时,则根据UITextField实例方法markedTextRange可以获取开始位置以及长度,此时,只要没有选中被mark的字符时,textFiled.text 的 length是不会改变的。只有当选中被mark的字符时,markedTextRange返回的开始位置以及长度为0,则UITextPosition则为nil,此时说明textField.text 的 length改变。

2、通过KVO监听textField.text 的length。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[self addObserver:self
forKeyPath:@"ezvizTokenTextFieldTextLength"
options:NSKeyValueObservingOptionNew
context:NULL];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (object == self && [keyPath isEqualToString:@"ezvizTokenTextFieldTextLength"]) {
//DDLogInfo(@"ezvizTokenTextFieldTextLength: %d", self.ezvizTokenTextFieldTextLength);
if (self.ezvizTokenTextFieldTextLength) {
if (delegate && [delegate respondsToSelector:@selector(textFieldDidEndChanged:)]) {
[delegate textFieldDidEndChanged:self];
}
}
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}

从而可以达到在iOS7下监听UITextField输入框内字符变化。

三味猪屋

GitHub博客搭建

发表于 2016-11-30

工具
markdown语法:(http://www.appinn.com/markdown/#header)
Atom:(https://atom.io)

1. 创建Github 域名和空间

1.1注册

注册Github账号。

#注意:博客域名将会为username.github.io,所以username会影响到博客的域名。

1.2 创建仓库

创建一个仓库(repository) 来存储博客的网站,点击首页任意位置出现的 New repository按钮创建仓库。

#注意:Respository name 中的 username 一定与前面的 Owner 一致。

2. 环境搭建

这里介绍使用 Hexo 搭建博客框架。下面需要安装的工具包括 brew,Git,nvm,Nodejs,Hexo。

2.1 安装 brew

1
$/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.2 安装 Git

1
$ brew install git

2.3 安装 nvm(nvm主要用于安装、管理node)

1
2
3
4
5
6
7
1. Homebrew 安装方式,此安装方式无需重启
a、安装nvm
$ brew install nvm
$ mkdir ~/.nvm
$ export NVM_DIR=~/.nvm
b、启动nvm
$ . $(brew --prefix nvm)/nvm.sh 或者 source $(brew --prefix nvm)/nvm.sh

1
2
2. curl安装方式
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh

2.4 安装 Nodejs

1
2
3
4
5
6
查看Nodejs版本
$ nvm ls-remote
安装指定版本
$ nvm install 7.1.0
安装最新版本
$ nvm install stable

2.5 安装 Hexo

1
$ sudo npm install hexo-cli -g

3. 编写博客

3.1 创建博客

1
$ hexo init username.github.io

3.2 配置主题

3.2.1 安装主题

1
2
$ cd username.github.io
$ git clone https://github.com/iissnan/hexo-theme-next themes/next

查看更多主题

3.2.2 基础配置
打开文件_config.yml修改几个键值对,下面把几个必须设置的列出来按需求修改。注意配置的键值之间一定要有空格。

1
2
3
4
5
6
7
title: dimsky 的 9 维空间 //你博客的名字
author: dimsky //你的名字
language: zh-Hans //语言 中文
theme: next //刚刚安装的主题名称
deploy:
type: git //使用Git 发布
repo: https://github.com/username/username.github.io.git //刚创建的Github仓库

查看更多设置

3.2.3 如何添加“tags”页面、“categorys”页面、“about”页面等。
新增“tags”页面

1
2
$ cd your-hexo-site
$ hexo new page tags

新增“categorys”页面

1
2
$ cd your-hexo-site
$ hexo new page categories

新增“about”页面

1
2
$ cd your-hexo-site
$ hexo new page about

修改_config.yml菜单配置为:

1
2
3
4
5
6
menu:
home: /archives
categories: /categories
about: /about
archives: /archives
tags: /tags

参考:http://theme-next.iissnan.com/theme-settings.html#tags-page

3.2.4 主题配置
主题配置文件在username.github.io/themes/next/_config.yml中修改。
更多配置

3.3 写文章
在username.github.io/source/_posts下创建你的博客,命名“搭建GitHub个人博客.md”。既然是搭建GitHub个人博客,那么就用GitHub的编辑器 Atom吧。
markdown语法:(http://www.appinn.com/markdown/#header)

3.4 本地预览

1
2
$ cd username.github.io
$ hexo s

测试服务启动,浏览器中输入https://localhost:4000 就可以预览了。

  1. 发布博客
    4.1 安装发布工具
    1
    $ npm install hexo-deployer-git --save

4.2 发布

1
$ hexo clean && hexo g && hexo d

5 更多有趣的插件

Hexo更多插件

123
花生-sniper

花生-sniper

25 日志
14 分类
21 标签
© 2017 花生-sniper
由 Hexo 强力驱动
主题 - NexT.Pisces