Defining Bytes in GCC Inline Assembly in Dev-C++(.

6 down vote favorite
2

The code below is just showing a Message Box on the screen.
The addresses are hardcoded to facilitate:

int main (){    asm("xorl %eax, %eax        \n"        "xorl %ebx, %ebx        \n"        "xorl %ecx, %ecx        \n"        "xorl %edx, %edx        \n"        "pushl %ecx             \n" //$0x0        "pushl $0x20206c6c      \n" //"  ll"        "pushl $0x642e3233      \n" //"d.23"        "pushl $0x72657375      \n" //"resu"        "movl %esp, %ecx        \n" //store "user32.dll" address in %ecx        "movl $0x7c801d7b, %ebx \n" //store address of LoadLibraryA in %ebx        "pushl %ecx             \n"        "call *%ebx             \n"        "movl $0xef30675e, %ecx \n"        "addl $0x11111111, %ecx \n"        "pushl %ecx             \n"        "pushl $0x42656761      \n"        "pushl $0x7373654d      \n"        "movl %esp, %ecx        \n"        "pushl %ecx             \n"        "pushl %eax             \n"        "movl $0x7c80ae40, %ebx \n"        "call *%ebx             \n"        "movl %esp, %ecx        \n"        "xorl %edx, %edx        \n"        "pushl %edx             \n"        "pushl %ecx             \n"        "pushl %ecx             \n"        "pushl %edx             \n"        "call *%eax             \n"        "xorl %eax, %eax        \n"        "pushl %eax             \n"        "movl $0x7c81cb12, %eax \n"        "call *%eax             \n"    );}

(I didn't comment all the code because my question is not really about the code)

My question is: Is there a way to write the string "user32.dll" in assembly inline without pushing manually to the stack? I mean like this in NASM: db 'Hello'

I know that in AT&T syntax I could do .ascii 'Hello' or .string 'Hello' but how about in gcc inline?

Please note that I'm using Dev-C++ on Windows XP SP3

Thanks!

share | improve this question
add comment

1 Answer

up vote 7 down vote accepted

Yes, by making use of assembler directives inside your inline assembler.  The trick is in putting the string in the right place (the data section), which you can do by switching using .section .data, and then switching back again with .section .text.

You must give the data a label so that you can refer to it; I would recommend using the local label syntax here (where the label is a number, e.g. 1:, and you reference it as either 1b for the first 1: label backwards, or 1f for the first 1: label forwards - see the GNU assembler documentation for more details).

Like this:

int main(void){  asm(".section .data      \n"      "1: .asciz \"Hello\" \n"      ".section .text      \n"      "pushl $1b           \n"      "call _puts          \n"      "add $4, %esp        \n"     );  return 0;}

I don't have a Windows system handy to test this on, but it compiles OK and looks like it should be doing the right thing using a MinGW cross-compiler on Linux (I believe Dev-C++ is based on MinGW).

Note: this technique is generally applicable when using a GNU toolchain.  If you're building ELF binaries (e.g. native Linux), there is a neater way to switch back to the text section, which is to use .previous, which means "whatever the section before the previous .section was".  (The above example works on Linux if you change _puts to puts to account for different symbol prefixing conventions.)

share | improve this answer
Cool! Does "1:" means it's a label to the address of the string? Is the instruction "pushl $1b" pushing the address of "Hello"? What ".previous" do? Thanks!–                     jyzuz Sep 15 '10 at 11:00
": Does ".previous" works on Windows? I'm not able to.. I'm using Dev-Cpp Portable–                     jyzuz Sep 15 '10 at 13:47
1
@jyzuz: no, it seems not; sorry about that.  I've updated my answer with a way round that.  1: is indeed a label, and 1b refers to it (see the assembler documentation I linked to in my updated answer); so yes, pushl $1b pushes the value of the label - which is the address of the string - as a constant onto the stack.–                     Matthew Slattery Sep 15 '10 at 19:20

转载于:https://my.oschina.net/zhuzihasablog/blog/266505

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当你在Spring项目中使用@Autowired注解注入某个模块A中定义的bean时,如果出现"Consider defining a bean of type 'xxx' in your configuration"的问题,这通常是因为Spring容器无法找到对应的bean定义。这可能是由于以下几个原因导致的: 1. 没有在Spring配置文件或使用@Configuration注解的配置类中定义该bean。你需要确保你的bean已经被正确地定义和配置。 2. 如果你使用的是自动扫描的方式配置bean,你需要确保被注入的bean所在的包被正确地扫描到。你可以检查一下包扫描的配置,确保被注入的bean所在的包被包含在扫描范围内。 3. 如果你使用的是@ComponentScan注解进行自动扫描配置,你需要确保被注入的bean有@Component或其他相关注解进行标注。 4. 如果你使用的是XML配置文件,你需要确保正确地配置了bean的定义,并且确保注入的bean的ID和名称与配置文件中的一致。 总结来说,当出现"Consider defining a bean of type 'xxx' in your configuration"问题时,需要检查你的配置文件或代码中是否正确地定义了对应的bean,并确保注入的bean能够被Spring容器正确地识别和加载。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Spring Boot Consider defining a bean of type `xxx` in your configuration 错误6种情况解决(Spring、...](https://blog.csdn.net/weixin_44917365/article/details/129999944)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [SpringBoot 出现 Consider defining a bean of type ‘xxx‘ in your configuration 问题解决方案](https://blog.csdn.net/tancj_/article/details/125149342)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值