无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 2509|回复: 8
打印 上一主题 下一主题

内置函数的调用?

[复制链接]
跳转到指定楼层
#
发表于 2013-5-25 14:43:59 | 只看该作者 |只看大图 回帖奖励 |正序浏览 |阅读模式
我在这儿:http://code.google.com/p/grub4do ... wse/wiki/grub4dos.h找到了grub4dos.h,不知道是不是和chenall提到的相同?
看了看,基本上看不懂;
不过我有以下猜测:
define strstr ((char *(*)(const char *, const char *))((*(int **)0x8300)[11])) 结尾的11是不是就是call Fn.11这样调用?

((char *(*)(const char *, const char *))((*(int **)0x8300) 这个是函数之间传递的参数?但是这些参数怎么样理解,我还不知道。但是据chenall说与c语言有相似之处?我查询了部分函数,可以查询到函数功能,但是参数怎么样设置就是搞不清楚!

诚挚的恳请chenall解释一两个函数的参数?比如上面strstr相关的参数怎么样理解?

以下我把整个内容复制粘贴过来:
/*

* The C code for a grub4dos executable may have defines as follows:

* 用于编写外部命令的函数定义。

*/

#define sprintf ((int (*)(char *, const char *, ...))((*(int **)0x8300)[0]))

#define printf(...) sprintf(NULL, __VA_ARGS__)

#define putstr ((void (*)(const char *))((*(int **)0x8300)[1]))

#define putchar ((void (*)(int))((*(int **)0x8300)[2]))

#define get_cmdline ((int (*)(char *))((*(int **)0x8300)[3]))

#define getxy ((int (*)(void))((*(int **)0x8300)[4]))

#define gotoxy ((void (*)(int, int))((*(int **)0x8300)[5]))

#define cls ((void (*)(void))((*(int **)0x8300)[6]))

#define setcursor ((int (*)(int))((*(int **)0x8300)[7]))

#define nul_terminate ((int (*)(char *))((*(int **)0x8300)[8]))

#define safe_parse_maxint ((int (*)(char **, unsigned long long *))((*(int **)0x8300)[9]))

#define substring ((int (*)(const char *, const char *, int))((*(int **)0x8300)[10]))

#define strstr ((char *(*)(const char *, const char *))((*(int **)0x8300)[11]))

#define strlen ((int (*)(const char *))((*(int **)0x8300)[12]))

#define strtok ((char *(*)(char *, const char *))((*(int **)0x8300)[13]))

#define strncat ((int (*)(char *, const char *, int))((*(int **)0x8300)[14]))

#define strcmp ((int (*)(const char *, const char *))((*(int **)0x8300)[15]))

#define strcpy ((char *(*)(char *, const char *))((*(int **)0x8300)[16]))

#define tolower ((int (*)(int))((*(int **)0x8300)[17]))

#define isspace ((int (*)(int))((*(int **)0x8300)[18]))

#define getkey ((int (*)(void))((*(int **)0x8300)[19]))

#define checkkey ((int (*)(void))((*(int **)0x8300)[20]))

#define sleep ((unsigned int (*)(unsigned int))((*(int **)0x8300)[21]))

#define memcmp ((int (*)(const char *, const char *, int))((*(int **)0x8300)[22]))

#define memmove ((void *(*)(void *, const void *, int))((*(int **)0x8300)[23]))

#define memset ((void *(*)(void *, int, int))((*(int **)0x8300)[24]))

#define mem64 ((int (*)(int, unsigned long long, unsigned long long, unsigned long long))((*(int **)0x8300)[25]))

#define open ((int (*)(char *))((*(int **)0x8300)[26]))

#define read ((unsigned long (*)(unsigned long long, unsigned long long, unsigned long))((*(int **)0x8300)[27]))

#define close ((void (*)(void))((*(int **)0x8300)[28]))

#define unicode_to_utf8 ((void (*)(unsigned short *, unsigned char *, unsigned long))((*(int **)0x8300)[29]))

#define rawread ((int (*)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long long, unsigned long))((*(int **)0x8300)[30]))

#define rawwrite ((int (*)(unsigned long, unsigned long, char *))((*(int **)0x8300)[31]))

#define devread ((int (*)(unsigned long, unsigned long, unsigned long, unsigned long long, unsigned long))((*(int **)0x8300)[32]))

#define devwrite ((int (*)(unsigned long, unsigned long, char *))((*(int **)0x8300)[33]))

#define next_partition ((int (*)(void))((*(int **)0x8300)[34]))

#define open_device ((int (*)(void))((*(int **)0x8300)[35]))

#define real_open_partition ((int (*)(int))((*(int **)0x8300)[36]))

#define set_device ((char *(*)(char *))((*(int **)0x8300)[37]))

#define dir ((int (*)(char *))((*(int **)0x8300)[38]))

#define print_a_completion ((void (*)(char *))((*(int **)0x8300)[39]))

#define print_completions ((int (*)(int, int))((*(int **)0x8300)[40]))

#define parse_string ((int (*)(char *))((*(int **)0x8300)[41]))

#define hexdump ((void (*)(unsigned long, char *, int))((*(int **)0x8300)[42]))

#define saved_drive (*(unsigned long *)0x82A0)

#define saved_partition (*(unsigned long *)0x829C)

8#
 楼主| 发表于 2013-5-26 23:07:57 | 只看该作者
chenall 发表于 2013-5-26 22:04
忘了这个strncat和c标准里面的是不一样的。。

我上面的是C语言的。。

我又试了试,把结果贴出来:


和你说的一样,截取0xa000000处字符串的时候要算0x8000000处字符的个数加上要截取字符的个数才是最后一个参数值!
当然也别忘记\0这个结束标示!再次感谢chenall
回复

使用道具 举报

7#
 楼主| 发表于 2013-5-26 22:45:30 | 只看该作者
chenall 发表于 2013-5-26 22:04
忘了这个strncat和c标准里面的是不一样的。。

我上面的是C语言的。。

哦,谢谢chenall
回复

使用道具 举报

6#
发表于 2013-5-26 22:04:41 | 只看该作者
zbkh 发表于 2013-5-26 21:11
我又试了试,但是就只显示a了哦:


忘了这个strncat和c标准里面的是不一样的。。

我上面的是C语言的。。

GRUB4DOS里面的n值,会连前面的也一起算进去。

所以,2的时候就只有a了,因为a\0刚好两个字符。

具体的自己多测试一下就知道了。
回复

使用道具 举报

5#
 楼主| 发表于 2013-5-26 21:11:00 | 只看该作者
chenall 发表于 2013-5-26 08:15
strncat 最后一个参数是int不是指针。直接用数字。你这里用2就行了。

我又试了试,但是就只显示a了哦:
回复

使用道具 举报

4#
发表于 2013-5-26 08:15:26 来自手机 | 只看该作者
strncat 最后一个参数是int不是指针。直接用数字。你这里用2就行了。
回复

使用道具 举报

3#
 楼主| 发表于 2013-5-26 01:06:15 | 只看该作者
chenall 发表于 2013-5-25 15:24
我不知你是如何查找的....
用Google 搜grub4dos.h ,第一个就是了.还找半天,可能是用的百度的原因..
用百度 ...

我依葫芦画瓢的也测试了一个函数:

我是想把1234当中的12 粘贴到abcd后面,怎么都过去了?请chenall指正!
真是不太好意思,又麻烦你!
回复

使用道具 举报

2#
 楼主| 发表于 2013-5-25 21:44:41 | 只看该作者
chenall 发表于 2013-5-25 15:24
我不知你是如何查找的....
用Google 搜grub4dos.h ,第一个就是了.还找半天,可能是用的百度的原因..
用百度 ...

谢谢chenall!百度习惯了,的确常用百度!呵呵!不过看样子,谷歌更能帮上大忙!谢谢!
回复

使用道具 举报

1#
发表于 2013-5-25 15:24:49 | 只看该作者
我不知你是如何查找的....
用Google 搜grub4dos.h ,第一个就是了.还找半天,可能是用的百度的原因..
用百度很多技术资料都找不到的,建议还是放弃吧.

这些定义可以不用去管的,使用方法和C语言的函数一样.

像strstr函数用法参考
http://www.kuqin.com/clib/string/strstr.html

这些定义我以前也不懂的,后面对C语言比较了解一些之后才明白些,需要理解C语言的指针.
再看定义
#define strstr ((char *(*)(const char *, const char *))((*(int **)0x8300)[11]))
1.char *(*)(const char *, const char *)
(*) 说明这个是个指向函数的指针.
char *是返回值,返回指向字符串的指针.
(const char *, const char *)对应的参数.
后面的(*(int **)0x8300)[11])是该函数对应的地址.
0x8300这个地址上的值是一个指针,指向GRUB4DOS提供的函数指针列表开始处,列表中又是一系列的指针指向真实的函数.


不过像STRSTR之类的函数,如果是用来编写外部命令可以使用,若是在命令行下就不好使了,除非你同样用指针地址.
命令行使用的例子
::在0x60000地址处写入字符串abcd**1234供测试
write (md)0x300+1 abcd**1234\0
::调用strstr函数查找"**"
call Fn.11 0x60000 "**"
set /A ret=%@retval%
得到ret的值应该是0x60004.

命令行调用函数时字符串可以直接提供也可以用一个数值(代表指针地址)

::显示0x60000处的字符串内容
call Fn.0 0 0x60000
直接提供字符串
call Fn.0 0 "atesta"
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-9-22 20:34

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表