作者归档:softsim

ATSAM3S4B

ARM Cortex-M3 主频可至64MHz
256 Kbytes 内置 Flash
48 Kbytes 静态 SRAM

The SRAM is accessible over System Cortex-M3 bus at address 0x2000 0000

16 Kbytes ROM( UART, USB驱动和在线应用升级IAP)

调试器开发支持:
1. Serial Wire/JTAG Debug Port(SWJ-DP)
Serial Wire Debug Port (SW-DP) and Serial Wire JTAG Debug Port (SWJ-DP) debug access.

  1. 访问所有的内存和系统的寄存器
    当内核处于 运行,挂起,或者 reset暂停 状态时,寄存器都可以访问
  2. Flash Patch and Breakpoint (FPB) unit for implementing breakpoints and code patches.
  3. Data Watchpoint and Trace (DWT) unit for implementing watchpoints, data tracing, and system profiling.
  4. Instrumentation Trace Macrocell (ITM) for support of printf style debugging.
  5. IEEE1149.1 JTAG Boundary-scan on all digital pins.

在SRAM中执行代码

  1. 实现升级程序时, 此时Flash被擦除或者写入,不能执行代码
  2. 调试功能是,代码下载到SRAM中更快,且不会频繁写FLASH,造成Flash过快损耗。

https://community.arm.com/developer/tools-software/tools/f/armds-forum/992/cortex-m3-execution-code-from-ram-during-flash-programming/2971

https://community.arm.com/developer/tools-software/tools/f/keil-forum/30830/executing-code-from-sram

https://community.arm.com/developer/tools-software/tools/f/keil-forum/31659/no-jlink-algorithm-for-cortex-sram

使用keil的LOAD命令
http://www.keil.com/support/man/docs/uv4/uv4_cm_load.htm

https://stackoverflow.com/questions/42612329/executing-code-from-ram-in-stm32


https://studio.segger.com/index.htm?https://studio.segger.com/ide_section_placement.htm

These are the steps needed to get the whole application placed in RAM, and to get it to run as expected in RAM.

Get data (read/write and constant) and code linked to be placed in RAM.
Place the Vector Table in RAM (with at least the alignment forced by the Cortex-M design.)
During C-start-up, set VTOR to the address of the Vector Table.

两种方法

Place CODE and DATA in RAM.

Use the “edit”-button (or change directory in your .icf file) at Project > Options > Linker > Config to open the window “Linker configuration file editor”
配置链接器

Go to the tab “memory regions” – copy the value in RAM/start and paste that value in ROM/start – then copy the value in RAM/end and paste it as ROM/end.
修改内存, 把RAM 当成 ROM用

simtrace2使用步骤

0.
apt install libsctp1

  1. 从 https://download.opensuse.org/repositories/network:/osmocom:/latest/Debian_Testing/amd64/ 安装

simtrace2-utils_0.5.2_amd64.deb
libosmo-simtrace2-0_0.52_amd64.deb
libosmosim0_1.3.1_amd64.deb
libosmocore12_1.3.1_amd64.deb
libosmogsm13_1.3.1_amd64.deb

也可以将 lib 解压缩指定的目录

export LD_LIBRARY_PATH=/dev/shm/y/cc/usr/lib

3.运行
./simtrace2-list
USB matches: 2
1d50:60e3 Addr=22, Path=1-3.4, Cfg=1, Intf=0, Alt=0: 255/1/0 (SIMtrace Sniffer)
1d50:60e3 Addr=22, Path=1-3.4, Cfg=2, Intf=0, Alt=0: 255/255/0 (0.5.1.37-ede8)

JTAG管脚定义

Test Clock Input (TCK) 为TAP的操作提供一个独立的时钟信号
Test Mode Select(TMS) 测试模式选择, 在TCK的上升沿有效,用来控制TAP状态机的转换
Test Data Input (TDI) 是数据输入的接口。所有输入到特定寄存器的数据,都是通过TDI接口,一位一位串行输入的.
Test Data Output (TDO) 数据输出的接口。 所有要求从特定寄存器读出的数据,都是通过TDO接口串行输出的。

VTREF 接口参考电平,一般直接接在VSupply上。

Test Reset Input 测试复位输入。 TRST用来对TAP控制器复位。但是TMS也可以对TAP复位,所以这个管脚可以不要。

Return Test Clock (RTCK) 目标端反馈给emulator的时钟信号,用来通过TCK 信号的产生,不用时 接地。

System Reset (nSRST), 对目标系统复位。

==================
因为JTAG经常用排线连接,为了更好的抗干扰,就在每条线间,加了地线。

sim卡芯片供应商

紫光同芯微电子有限公司(原 北京同方微电子有限公司)
THC80F08BD
THC80F09AD
THC80F09BC

2001年 成立
2008年,SIM卡芯片市场占有率达到中国第一
http://www.tsinghuaic.com/

同方 thc8000, 中科讯联…

THC80F09BC
Flash 548KB
RAM 18KB
接口: ISO/IEC 7816 Slave/Master, SWP, SPI, GPIO

THC80F10AC
Flash 768KB
RAM 68KB
接口: ISO/IEC 7816 Slave/Master, SWP, IC-USB, SDC, SPI, GPIO


国民技术股份有限公司

深圳中兴集成电路设计有限责任公司(简称中兴IC)于2009年完成股份制改造,正式变更为“国民技术股份有限公司”。

中兴IC成立于2000年3月,由中兴通讯(ZTE)和国家开发投资公司(SDIC)共同投资组建,是国家“909”专项工程集成电路设计公司之一。

https://www.nationstech.com/


上海华虹集成电路有限责任公司(简称华虹设计), 中国电子信息产业集团有限公司(CEC)下属子公司。成立于1998年12月, 2015年被华大电子并购

http://shhic.com/about.aspx


北京中电华大电子设计有限责任公司 (简称 华大电子 )成立于2002年6月,是世界500强中国电子信息产业集团有限公司 (简称 中国电子 ) 下属集成电路业务板块华大半导体有限公司(简称 华大半导体 )旗下子公司
http://www.hed.com.cn/CN/WebPage_49.aspx

前身为 1986年成立的 电子工业部北京集成电路设计中心
2015年 并购 上海华虹设计后, 智能卡芯片市场占有率全球排名第四

CIU98M25

32bit CPU
1148KB FLASH
40KB RAM
算法硬件加速支持: DES/3DES/RSA/AES/ECC/SM1/SM2/SM3/SM4
接口: SWP/ISO7816/SPI/GPIO


大唐微电子技术有限公司(简称大唐微电子)是大唐电信科技股份有限公司(简称“大唐电信”沪市股票代码600198)的控股子公司。

1998年 邮电部电信科学技术研究院集成电路设计中心转制为大唐电信科技股份有限公司微电子分公司

http://www.dmt.com.cn/about/gsjj/1.html


复旦微电子

1998年7月,由复旦大学“专用集成电路与系统国家重点实验室”、上海商业投资公司和一批梦想创建中国最好的集成电路设计公司(芯片设计)的创业者联合发起创建了复旦微电子。公司成立以来,已成功地确立了在国内集成电路设计行业中举足轻重的地位。公司于2000年8月4日在香港上市(股票编号:1385),成为国内集成电路设计行业第一家上市企业。

http://www.fmsh.com/

英飞凌 SLE97 (SLE97CNFX1M00PE)
CPU: ARM SC300 52MHz
Flash: 1MB
RAM: 32KB
接口: ISO7816, SWP, UART, SPI, IIC, USB
算法: SHA1/256, RSA, ECC, DES/TDES, AES,
封装: 2FF/3FF/4FF, MFF2, QFN32

CIU98M25
CPU: ARM SC000 40MHz
Flash: 1.25MB
RAM: 40KB
接口: ISO7816, SWP, SPI, GPIO
算法: SHA1/256/513, RSA, AES, DES/TDES, SM1, SM2, SM3, SM4, SSF33
封装: 2FF/3FF/4FF, QFN16

ST33F1M

ST33G1M2

android关闭签名校验

以 Android 10为例

PackageManagerServiceUtils

/system/framework/services.jar

   public static int compareSignatures(Signature[] s1, Signature[] s2) {
        if(s1 == null) {
            return s2 == null ? 1 : -1;  // PackageManager.SIGNATURE_NEITHER_SIGNED  或者 PackageManager.SIGNATURE_FIRST_NOT_SIGNED
        }

        if(s2 == null) {
            return -2;  // PackageManager.SIGNATURE_SECOND_NOT_SIGNED
        }

        if(s1.length != s2.length) {
            return -3;  // PackageManager.SIGNATURE_NO_MATCH
        }

        if(s1.length == 1) {  // 因为签名集的大小是2,所以可以直接比较,不需要用到HashSets.
            String second_signature = s2[0].toCharsString();  // PackageManager.SIGNATURE_MATCH 0
                                                              // PackageManager.SIGNATURE_NO_MATCH  -3
            return ("031e8c8957468659".equals(second_signature.substring(second_signature.length() - 16))) || (s1[0].equals(s2[0])) ? 0 : -3;
        }

        ArraySet set1 = new ArraySet();
        int i;
        for(i = 0; i < s1.length; ++i) {
            set1.add(s1[i]);
        }

        ArraySet set2 = new ArraySet();
        int j;
        for(j = 0; j < s2.length; ++j) {
            set2.add(s2[j]);
        }

        return set1.equals(set2) ? 0 : -3;
    }

结论: 修改方法 PackageManagerServiceUtils 中的  compareSignatures

Androiid 8.1 则是在 PackageManagerService.java

android 10 dex

dex2oat --instruction-set=arm64   --dex-file=uimremoteclient.apk --oat-file=uim.odex
dex2oat --instruction-set=arm64   --dex-file=uimremoteclient.apk --oat-file=uim.vdex

还有
–runtime-arg
–boot-image=
–instruction-set-variant=
–instruction-set-features=

–include-patch-information –runtime-arg -Xnorelocate –no-generate-debug-info

 /apex/com.android.runtime/bin/dex2oat 
    --input-vdex-fd=-1 
    --output-vdex-fd=11 
    --resolve-startup-const-strings=true 
    --max-image-block-size=524288 
    --compiler-filter=verify 
    --classpath-dir=/system/product/app/uimremoteclient 
    --class-loader-context=PCL[]{PCL[/system/framework/android.hidl.manager-V1.0-java.jar]{PCL[/system/framework/android.hidl.base-V1.0-java.jar]}#PCL[/system/framework/android.hidl.base-V1.0-java.jar]#PCL[/product/framework/uimremoteclientlibrary.jar]#PCL[/product/framework/qti-telephony-hidl-wrapper.jar]} 
     --generate-mini-debug-info 
     --compact-dex-level=none 
     --compilation-reason=boot 
     --inline-max-code-units=0

参考资料

python生成随机字符串

#!/bin/env python3

import random
import string

def ranstr(num):
    return ''.join(random.sample(string.ascii_letters + string.digits, num))

salt = ranstr(32)
print(salt)

微信支付的Key就可以这么生成

android 10设备信息泄露

  1. MAC地址和IP地址
    用magiskpolicy解决
  2. 属性中 imei和 iccid泄露

vendor.oem.device.imeicache1
vendor.oem.device.imeicache2
persist.radio.bksim.iccid
persist.radio.ddssim.iccid

以上是一加

gsm.meid

以上是联想

persist.radio.imei
persist.radio.imei1
persist.radio.imei2
ro.ril.miui.imei0
ro.ril.miui.imei1
ro.ril.oem.imei
ro.ril.oem.imei1
ro.ril.oem.imei2
以上 小米,
但是已经被 selinux policy屏蔽

checkReadDeviceIdentifiers和reportAccessDeniedToReadIdentifiers

https://android.googlesource.com/platform/frameworks/base/+/refs/tags/android-10.0.0_r25/telephony/java/com/android/internal/telephony/TelephonyPermissions.java

setImmediate(function() { //prevent timeout
    Java.perform(function(){

        var TelephonyPermissions = Java.use("com.android.internal.telephony.TelephonyPermissions");
        console.log("TelephonyPermissions Found.");    


        TelephonyPermissions.reportAccessDeniedToReadIdentifiers.implementation = function(context, subId, pid, uid, callingPackage, message) {
            console.log("reportAccessDeniedToReadIdentifiers : " + callingPackage + " -> " + message);
            return this.reportAccessDeniedToReadIdentifiers(context, subId, pid, uid, callingPackage, message);
        }   

        console.log("...Hook OK...");
    });
});

代码运行在 “com.android.phone” 进程中

用Magisk为Android 增强Selinux限制

/data/adb/service.d/se
内容为

magiskpolicy --live "deny untrusted_app sysfs_thermal  file * "
magiskpolicy --live "deny untrusted_app sysfs_thermal  lnk_file * " 
magiskpolicy --live "deny untrusted_app sysfs_thermal  dir * "

magiskpolicy --live "deny untrusted_app_27 sysfs_thermal  file * "
magiskpolicy --live "deny untrusted_app_27 sysfs_thermal  lnk_file * " 
magiskpolicy --live "deny untrusted_app_27 sysfs_thermal  dir * "

magiskpolicy --live "deny untrusted_app_25 sysfs_thermal  file * "
magiskpolicy --live "deny untrusted_app_25 sysfs_thermal  lnk_file * " 
magiskpolicy --live "deny untrusted_app_25 sysfs_thermal  dir * "

magiskpolicy --live "deny untrusted_app untrusted_app  netlink_route_socket * "
magiskpolicy --live "deny untrusted_app_27 untrusted_app_27 netlink_route_socket * "
magiskpolicy --live "deny untrusted_app_25 untrusted_app_25 netlink_route_socket * "

magiskpolicy --live "deny untrusted_app untrusted_app udp_socket ioctl"
magiskpolicy --live "deny untrusted_app untrusted_app tcp_socket ioctl"
magiskpolicy --live "deny untrusted_app_27 untrusted_app_27 udp_socket ioctl"
magiskpolicy --live "deny untrusted_app_27 untrusted_app_27 tcp_socket ioctl"
magiskpolicy --live "deny untrusted_app_25 untrusted_app_25 udp_socket ioctl"
magiskpolicy --live "deny untrusted_app_25 untrusted_app_25 tcp_socket ioctl"

/data/adb/post-fs-data.d/hiden

resetprop gsm.version.baseband MPSS.Gen5.2020
resetprop gsm.imei1 unkown
resetprop gsm.imei2 unkown
resetprop gsm.meid   unkown

搜索规则

./sesearch --all   --target sysfs_thermal  --source   untrusted_app

Found 3 semantic av rules:
   allow untrusted_app sysfs_thermal : file { ioctl read getattr lock map open } ; 
   allow untrusted_app sysfs_thermal : dir { ioctl read getattr lock search open } ; 
   allow untrusted_app sysfs_thermal : lnk_file { ioctl read getattr lock map open } ; 




./sesearch --all  --class  netlink_route_socket  --target untrusted_app
allow untrusted_app untrusted_app : netlink_route_socket { read write create getattr setattr lock append bind connect getopt setopt shutdown nlmsg_read } ;




./sesearch --all  --class  udp_socket  --target untrusted_app                                                                                                                                                                                         
   allow untrusted_app untrusted_app : udp_socket { ioctl read write create getattr setattr lock append map bind connect getopt setopt shutdown } ;