使用 inline 内联函数对抗逆向分析

C++游戏逆向实战:从内存操作到Hook技术的完整路径 游戏逆向工程是深入理解软件运行机制的重要领域,其核心在于分析已编译程序的内存结构、数据流和逻辑流程。从原理上看,程序在内存中的布局直接反映了源代码的数据结构设计,尤其是C++这类系统级语言编写的应用。掌握内存操作、指针运算和数据结构对齐等底层知识,能够帮助开发者准确解读程序运行时的状态。这项技术的工程价值在于,它不仅是安全研究和漏洞分析的基础,也是性能优化、兼容性调试和遗留系统维护的关键手段。在实际应用场景中,游戏逆向常被用于单机游戏模组开发、反作弊机制研究、以及软件行为分析等。本文聚焦于C++在游戏逆向中 阅读详情

在 ARM 汇编里函数调用是使用 bl 指令跳转到函数地址,攻击者逆向分析很容易找到调用过程,分析参数和返回值。

可以将一些敏感的函数,比如将加密函数写成 inline 内联,无论代码里调用了多少次函数,编译器会将整个函数代码拷贝到需要调用的地方,而不会使用 bl 指令跳转,不能明显的看出函数参数传递和返回值,大大增加了分析的难度。
以下是一个简单的异或加密函数:

char* xor_encrypt (char *inbuf, int len){
 
    char *outbuf = malloc(len);
    for (int i=0; i <= len; i++) {
        
        outbuf[i] = inbuf[i] ^ 0x33;
    }
    
    return outbuf;
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    char *str1 = xor_encrypt("123", 3);
    char *str2 = xor_encrypt("456", 3);
    char *str3 = xor_encrypt("789", 3);
       
}

反汇编的效果如下:

xor_encrypt 函数的反汇编代码如下:

inlineTest`xor_encrypt:
    0x7b3f0 <+0>:  push   {r7, lr}
    0x7b3f2 <+2>:  mov    r7, sp
    0x7b3f4 <+4>:  sub    sp, #0x10
    0x7b3f6 <+6>:  str    r0, [sp, #0xc]
    0x7b3f8 <+8>:  str    r1, [sp, #0x8]
->  0x7b3fa <+10>: ldr    r0, [sp, #0x8]
    0x7b3fc <+12>: blx    0x7efd8                   ; symbol stub for: malloc
    0x7b400 <+16>: movs   r1, #0x0
    0x7b402 <+18>: str    r0, [sp, #0x4]
    0x7b404 <+20>: str    r1, [sp]
    0x7b406 <+22>: ldr    r0, [sp]
    0x7b408 <+24>: ldr    r1, [sp, #0x8]
    0x7b40a <+26>: cmp    r0, r1
    0x7b40c <+28>: bgt    0x7b42c                   ; <+60> at ViewController.m:324
    0x7b40e <+30>: ldr    r0, [sp]
    0x7b410 <+32>: ldr    r1, [sp, #0xc]
    0x7b412 <+34>: add    r0, r1
    0x7b414 <+36>: 
深入剖析Android游戏反Frida机制:从libtprt.so检测到实战绕过 在移动安全与逆向工程领域,动态分析工具是理解应用逻辑的关键。其核心原理在于通过注入技术拦截和修改目标进程的运行时行为,从而实现对应用内部机制的探查。这项技术的核心价值在于能够动态调试、实时分析,广泛应用于安全评估、漏洞挖掘和游戏修改等场景。面对日益增强的安全防护,特别是游戏应用部署的综合性反调试策略,如何有效绕过检测成为技术焦点。本文聚焦于某游戏加载的libtprt.so库,它构建了一套针对Frida的多维度检测体系,涉及进程内存扫描、端口监控和ptrace系统调用检测等热词。我们将深入其检测原理,并系统阐 阅读详情

相关推荐

C语言混淆代码解析:从IOCCC风格到工程实践的底层原理

在C语言开发中,代码混淆技术通过滥用预处理宏、未定义行为和复杂指针运算等手段,故意降低代码可读性,同时保持其可执行性。这类技术虽然违背常规工程规范,却深刻揭示了编译器行为边界和语言底层机制。从原理上看,混淆代码利用了C语言的预处理阶段展开、类型系统漏洞和特定编译器扩展,其技术价值在于为安全研究、逆向工程和编译器开发提供了极限测试场景。通过分析典型的IOCCC风格代码,可以训练开发者识别隐藏模式、理解数据与控制流转换的能力,进而提升对软件底层逻辑的洞察。在实际应用中,这种分析能力有助于发现潜在安全漏洞、优化性

weixin_34326429的博客 418

EXE反编译C语言实战:从原理到工具与逆向工程实践

在软件开发和逆向工程领域,理解程序如何从高级语言转化为机器指令是核心基础。编译器将C/C++等源代码编译为可执行文件(EXE)的过程,会丢失变量名、注释和高级控制结构等语义信息。反编译技术则致力于逆向这一过程,通过数据流分析和控制流图重建,尝试从机器码中恢复出近似的高级语言逻辑,其技术价值在于软件分析、安全审计和遗留系统维护。面对经过编译器优化的代码,反编译工具需要应对指令重排和内联函数等挑战。在实际应用中,工程师常借助Ghidra、IDA Pro等工具进行静态分析,并结合动态调试来验证逻辑,最终将伪代码重

weixin_33782386的博客 304

网络安全学习第2篇-C++程序编写一个带有一定加密技术(对抗逆向分析)的CrackMe程序

请使用C++程序编写一个带有一定加密技术(对抗逆向分析)的CrackMe程序,并使用IDA等工具逆向分析其原理。 说明: 1、如果编写的CrackMe程序过于复杂,则不强制要求使用IDA分析。 2、提交时,请提交实验报告、源代码(.cpp)文件以及编译好的exe程序。 3、除界面不做要求以外,CrackMe程序编写规则请参考看雪CTF规则 https://bbs.pediy.com/thread-...

一清道长的个人博客 1560

[系统安全] 逆向工程进阶篇之对抗逆向分析

线性反汇编策略是遍历每一个代码段,根据二进制码进行反汇编,缺点是不会区分某个二进制码是数据还是指令,全部按照指令来反汇编。如果在一个函数开头加上这个字节码,则反汇编器会认为是一个call指令,这条call指令占用了函数开头的4个字节,从而破坏掉要这个完整的函数。通过使用windwos提供的api可以判断自己是否正在被调试,比如下面的一些函数,如果在分析的代码中看到这些函数,就说明这个代码样本在检测自身是否被调试。当恶意代码意识到自己被调试时,可以改变正常的执行路径或者修改自身程序导致崩溃而对抗调试。

H4ppyD0g的博客 2740

【信息科学与工程学】计算机科学与自动化——第三十九篇 编程语言模型

定义值格 L={⊥,c1​,c2​,...,⊤},其中 ⊥表示未知/未初始化,ci​为具体常数,⊤表示非常量/多重可能值。格序关系:⊥⊑ci​⊑⊤。

weixin_49199313的博客 430

【信息科学与工程学】计算机科学与自动化——第二十四篇 编译器04 LLVM编译器01

训推一体方案通过整合训练与推理流程,实现资源复用、效率提升和全链路自动化。以下从。

weixin_49199313的博客 1522

C++函数参数传递与内联函数详解

本文深入探讨了C++中的函数参数传递机制,包括按值传递和按引用传递的原理及使用场景,并介绍了内联函数的概念、优势和使用限制。通过实例代码,展示了如何在程序中实现这些机制,并解释了它们对程序性能和代码可读性的影响。

weixin_35705784的博客 476

delphi 超级hook inlinehook 类

delphi的超级hook类 纯原创,找了很久没找到 自己琢磨很久 注入yx。然后就可以愉快的hook了 处理方法暂不支持类方法 可以用了 有问题或建议可以联系我qq。

Delphi 7以来的新语法特性

内联函数(Inlining) D7中的inline关键字作为保留字并不会对编译器产生实际作用,在2009中此关键字起到内嵌到代码中起到实际作用。语法如下: function foo: Integer; inline; 内部函数/过程也可以使用,但在D2009测试版中,类方法的内部函数使用inline后不认Self指针;类的子过程/子函数,也可以使用inline关键字,但没有实际效果,且虚方法/继承方法(virtual/override)不能使用。 重载运算符(Operator Overloading) 可以重载部分运算符,如+、-、类型转换等,在D2006只支持到record,但从2007开始支持到Class,以下示例修改自官网: TMyClass = class // Addition of two operands of type TMyClass class operator Add(a, b: TMyClass): TMyClass; // Subtraction of type TMyClass class operator Subtract(a, b: TMyClass): TMyclass; // Implicit conversion of an Integer to type TMyClass class operator Implicit(a: Integer): TMyClass; // Implicit conversion of TMyClass to Integer class operator Implicit(a: TMyClass): Integer; // Explicit conversion of a Double to TMyClass class operator Explicit(a: Double): TMyClass; end; class operator TMyClass.Add(a, b: TMyClass): TMyClass; begin //... end; var x, y: TMyClass begin x := 12; // Implicit conversion from an Integer y := x + x; // Calls TMyClass.Add(a, b: TMyClass): TMyClass end; 类助手(Class Helpers) Helper是对原Class的扩展,是我们在不修改原类的基础上增加类方法,并加入原类的空间中。在Delphi中,对对象的调用实际上采用了两个步骤,首先是把对象地址放入eax寄存器中,然后call类方法,所以如果不使用继承类增加数据的话,用父类调用继承类的方法是没问题的,所以其实这样的方法在D7中也可以使用,但却很麻烦。所以Class Helper起到的就是这个作用,在Class Helper中可以增加的就是与实例无关的内容,所以任何需要增加实例Size的活VMT的功能不能声明,例如变量、虚方法等,但只占用类空间的没关系,如class var。在应用上我们可以通过这种方法方便的给VCL一类控件加上某个属性。 TFoo = class helper for TControl private function GetA: Integer; public class var X: Integer; procedure MSG(var Message: TMessage); message WM_MYMESSAGE; procedure ProcFoo; property A: Integer read GetA; end; // ... procedure TForm1.Foofoo; begin ProcFoo; // TControl -> TWinControl -> TScrollingWinControl-> TCustomForm -> TForm -> TFrom1: Call TFoo.ProcFoo end; strict关键字(Keyword “strict”) 众所周知,在Delphi中,类的private和protected域中的变量可以被同一单元中可以自由的被访问(Delphi的类没有“友元”的概念,但同一个unit中可以说自动友元化了),而并非是真正的私有或只能被继承类访问。而strict关键字的作用就是使该内容变成严格OO意义上的private/protected作用域,这点没有什么多说的。语法: strict private // Blah... strict protected // Blah... 结构方法(Records with Methods) 也没什么特别的,就是和class差不多,就一个不用创建和销毁、不能继承、没有作用域之类的类,很容易掌握,所以这里就不多介绍了。但是很有意思的是带参数的constructor可以通过编译,可能是为了初始化的方便吧。 抽象类和固实类(Abstract and Sealed Classes) 这两个概念在OO中也并不陌生,抽象类是不应该创建实例的(但D2006起的编译器就不给检查,连个Warning都没有,这还有啥用啊 -.- ),而固实类是不能被继承的。语法: TAnAbstractClass = class abstract // or (TParentClass) // Blah... end; TASealedClass = class sealed(TAnAbstractClass) // or empty // Blah... end; 类常量、类变量、类属性与静态类方法(Class const/var/property and Static Class Methods) 老的Delphi中只提供了类方法,而没有提供类变量、类常量和类属性,这真的是很不方便。这里先区分一下我所使用的类(Class)和对象(Object)即类的实例(Instance of Class)。当在Delphi中声明一个类的时候,这个类是有实际地址的,该地址记录了许多类的相关信息,比如实例的Size啊、虚方法信息啊一堆东西,而创建一个对象的时候则把类实例化,在堆(Heap)中分配一块地址,包括内部数据和VMT之类的东西。在调用实例的时候,首先要知道对象地址,然后才能访问内部变量和调用方法时使用Self指针即实例地址;而在调用类方法的时候,eax中的并不是实例的地址而是类的地址,然后再call方法,这时的Self指针并非实例地址而是类地址。所以对于每一个类和继承类来说,包括它和它的继承类的所有实例,类变量、常量都是同一个,这样就存在了一个唯一的可供使用的变量或常量,方便同步并且不需要使用较多的内存(可以参考C#中的类,不过C#中不允许从实例直接访问类变量、常量、方法)。而静态类方法则是在使用这个类方法的时候不传入class地址,也就是说没有Self指针,这样的类方法的访问开销要小于普通的类方法;这自然也就意味着,该类方法不能被继承(不能virtual/override)。另外,类属性的get/set方法必须使用静态类方法。 TFooClass = class private class procedure SetFoo(const Value: Integer); static; // A Static Class Method protected class var FX : Integer; // class var public const FC: Integer = 10; // class const class procedure VirtualProc; virtual; class property X: Integer read FX write FX; // class property class property Foo: Integer read FC write SetFoo; end; 类内部类型与嵌套类(Class Types and Nested Classes) 可以说现在的Class的域几乎相当于原来的整个unit,以前不能放里面的元素现在都可以放里面了,这个也没什么好多说的,试验一下就很容易明白了。 终方法(Final Methods) 这个也是建立在虚方法的基础上的,在override后使用final关键字,则表示该虚方法不能再被子类继承下去了。 TAClass = class public procedure Foo; virtual; end; TFinalMethodClass = class(TAClass) public procedure Test; override; final; // A Final Method end; For-in循环(For-in Loop) 这个应该是受.Net影响吧,支持遍历一个数组或提供了GetEnumerator函数的类。GetEnumerator要求返回一个类的实例,该类包含有Current属性和MoveNext方法。 procedure Foo(List: TStrings); i : Integer; lst : array[0..100]of Integer; s : string; begin for i in lst do ; for s in List do ; // Support of TStrings.GetEnumerator end;

数字电路复位信号设计(异步复位、同步释放)笔记详解

复位信号设计(异步复位、同步释放)笔记详解 1 时序设计 1.1 复位信号设计(异步复位、同步释放) 1.1.0 复位恢复时间和清除时间 首先解释一下恢复时间(recovery time)和清除时间(removal time):(以复位信号低电平有效为例) 复位恢复时间(recovery time):撤销复位时,复位信号无效到时钟有效沿来临之间需要维持的最小的时间,类似于同步时钟的建立时间setup time; 复位清除时间(removal time):复位时,在时钟有效沿来临之后复位信号还需要保持复位

weixin_42294124的博客 1万+

VirtualBox增强功能安装全指南:从下载到配置复制粘贴功能

本文详细介绍了VirtualBox增强功能的完整安装与配置流程,重点解决了虚拟机与主机间复制粘贴、文件拖放等核心协作难题。通过分步指南和故障排查,帮助用户在不同操作系统(如Windows、Linux)中实现无缝集成,提升虚拟化工作效率与体验。

weixin_29206669的博客 429

避坑指南:MTK平台Widevine L1密钥安装全流程详解(含SP META工具使用与Log分析)

本文详细解析了MTK平台实现Widevine L1认证的全流程,涵盖密钥申请、格式转换、安全烧录等关键步骤,特别针对Trustonic TEE环境下的SP META工具使用与日志分析提供实用指南。帮助开发者规避常见错误,确保DRM密钥安全部署,满足高端内容保护需求。

weixin_27219587的博客 485

告别Win11睡眠假死:深入解析Modern Standby S0与S3冲突及注册表修复方案

本文深入解析了Windows 11中Modern Standby(S0)与传统睡眠(S3)模式的冲突,该冲突是导致电脑睡眠后出现假死、断网等问题的根源。文章提供了通过修改注册表键值(PlatformAoAcOverride)强制启用稳定S3睡眠的终极修复方案,并附有详细诊断步骤与避坑指南,帮助用户彻底解决睡眠故障。

ol789012的博客 828

《惠普工作站设置BIOS从U盘装系统》

惠普工作站设置BIOS 惠普工作站在做服务器时应用广泛,本文介绍下其BIOS开机自启动设置,附上图片,以供学习参考。 惠普工作站设置BIOS 启动步骤如下: 第一步:根据需要对BIOS进行更改,并保存 1.重启工作站按F10进入BIOS设置(也可以按ESC键选择进入BIOS设置的选项)。 图1 惠普工作站B...

istrangeboy&begin zero的博客 2万+

组态王通过以太网与西门子S7-200 SMART PLC通讯案例详解

通过以上步骤,我们成功实现了组态王与西门子S7-200 SMART PLC的以太网通讯。这一技术不仅提高了工业自动化系统的灵活性和可靠性,还为初学者提供了一个实用的学习案例。希望本文能帮助您快速掌握组态王与西门子S7-200 SMART PLC的通讯技术。如有任何疑问,欢迎留言讨论!

2401_88785500的博客 2009

Android系统开发工程师面试指南与参考答案

本文整理了Android系统开发工程师面试常见问题与参考答案。核心内容涵盖:1)Framework层定制方法,如修改HAL和系统服务;2)ANR问题分析工具(systrace)与解决方案;3)性能优化实践,包括开机加速和功耗管理;4)四大组件工作机制与应用案例;5)Native崩溃调试技巧。文章强调通过AOSP源码研究、工具使用和项目案例准备来提升面试表现,重点考察应聘者的系统开发深度和实操能力。参考答案均基于实际开发经验,提供可量化的优化成果说明。

郑伟强dev的专栏 267

3D iToF深度分辨率测量

本文展示了RGB-D传感器在三维测量中的高精度表现。标靶深度图显示其具备清晰、低噪、无干扰的特性,点云数据完整度高且轮廓分明。该技术已成功应用于物流(体积测量误差<1%)、工业(高反光部件装配检测)和农业(果蔬成熟度分级)等领域,验证了其硬件和算法的可靠性,能够满足不同场景下的三维测量需求。

dream it possible 260

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Xcode 不用签名编译程序
下一篇: obfuscator-llvm Theos 集成配置
sysprogram
博客等级 码龄17年 299粉丝 442原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址