understanding find

understanding find (by hanlray(at)gmail.com)

一个典型的查找请求描述如下:

查找foo目录树下名字为bar的文件,不查找mount上的子目录,然后把查找到的文件名打印出来

这里包含几个要素:
  • 查找的目录树,这里是foo
  • 匹配条件,这里是名字为bar的文件
  • 查找选项,这里是不查找mount上的子目录
  • 对匹配的文件执行的动作,这里是把它们的文件名打印出来

find是如何表达由这几个要素构成的查找请求呢?

find [-H][-L][-P][path...][expression]

path指定查找的目录树,其他要素都由expression来表达。

expression由谓词表达式options、tests和actions组成,它们之间由operator连接,可以表达复杂的查找逻辑:

  • options指定查找选项,针对整个查找操作,永远返回true
  • tests指定匹配条件,测试文件是否满足匹配条件
  • actions指定对匹配文件执行的动作
  • operator包括否、与、或等,根据其优先级对expression进行求值,在求值的过程中完成查找。

     

options、tests和actions的写法,除了极个别的几个,用的都是Linux/Unix command中通用的short option的形式:短横杠后跟option name,如果有参数的话隔一个空格跟在后面。

常用tests:

-name <pattern>
基于文件名的匹配
-iname <pattern>
和-name一样,忽略大小写
-type <c>
测试文件类型,<c>的值为:
  • d directory
  • f regular file

常用actions:

-print
打印匹配的文件名,如果没有指定action则是缺省action
-delete
删除文件,如果删除成功则返回true
-exec command;
执行某个命令,如果返回状态为0则返回true,可以在命令中用'{}'代表当前文件

常用options:

-mount
不查找mount的目录

常用operators:

expr1 expr2
表示与,如果expr1为false则不对expr2求值

examples

find .
这里没有写expression,-print为缺省action,因此将打印当前目录下(包括当前目录)的所有文件,包括子目录及子目录下的文件。
find . -type f
查找当前目录树下所有的普通文件并打印出来
Frida-Gum is a powerful instrumentation framework for dynamic binary analysis and reverse engineering. It provides a high-level API for writing custom code to interact with native code running on different platforms. To use Gum to find a C++ class method function using C++ code, you can start by loading your target binary into memory using the `gum_process_attach()` function. Once attached, you can use `gum_module_find_export_by_name()` function to find the address of the C++ class method function inside the target binary. Here is an example code snippet that demonstrates how to use Gum to find a C++ class method function: ```c++ #include <gum/gum.h> class MyClass { public: void myMethod(int arg1, int arg2) { // implementation of myMethod } }; int main() { gum_init_embedded(); GumAddress myMethodAddress = 0; GumAddress targetAddress = gum_module_find_base_address("mybinary"); if (targetAddress != 0) { GumExportDetails exportDetails; if (gum_module_find_export_by_name("mybinary", "_ZN7MyClass8myMethodEii", &exportDetails)) { myMethodAddress = exportDetails.address; } } // myMethodAddress now contains the address of MyClass::myMethod() gum_deinit_embedded(); return 0; } ``` In this example, we defined a simple C++ class `MyClass` with a method `myMethod()`. We then attached to the target binary using `gum_process_attach()`, and used `gum_module_find_export_by_name()` to find the address of the `MyClass::myMethod()` function inside the target binary. The function signature `_ZN7MyClass8myMethodEii` corresponds to the mangled name of the `MyClass::myMethod()` function in C++. Note that this is just a basic example, and you will need to adapt the code to your specific use case. Also, keep in mind that using Gum to interact with native code requires a good understanding of the target binary and its environment.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值