C++嵌入Assembler(汇编)汇编内出错?

我在C++中插入了汇编代码,但汇编代码老报错,不知什么原因。求各位大神帮助!

代码:

#include <iostream>
using namespace std; 
int main(int argc,char *argv[]) {
 volatile int a[3] = {0,0,0};
 for (int i = 0;i < 3;i ++)
  cout << a[i] << ends;
 cout << endl;
 asm ("inc [esp + 2]");//Assembler:inc [esp + 2]   (++ a[1];)
 for (int i = 0;i < 3;i ++)
  cout << a[i] << ends;
 cout << endl;
 return 0;
}

报错信息:

(File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Assembler messages:
(Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Error: invalid char '[' beginning operand 1 `[esp+2]'

之后我想是不是这个汇编器不支持Intel,就把那一行汇编改成了AT&T格式的:

asm ("inc [esp + 2]");//Assembler:inc [esp + 2]   (++ a[1];)

| |

\/

asm ("inc 2(%esp)");//Assembler:inc 2(%esp)   (++ a[1];)

但还是报错了:

(File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Assembler messages:
(Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Error: no instruction mnemonic suffix given and no register operands; can't size instruction

本人对AT&T不熟悉,麻烦大家看看哪错了,致以感谢!

Varible
Varible 贵阳老马马善福专业维修游泳池堵漏防水工程: 已采纳、点赞。之前手机有点问题,不好采纳,今天换了电脑。请原谅!
4 个月之前 回复
Varible
Varible 回复贵阳老马马善福专业维修游泳池堵漏防水工程: 已采纳、点赞。之前手机有点问题,不好采纳,今天换了电脑。请原谅!
4 个月之前 回复
Varible
Varible 回复贵阳老马马善福专业维修游泳池堵漏防水工程: 已采纳、点赞。之前手机有点问题,不好采纳,今天换了电脑。请原谅!
4 个月之前 回复
caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 之前问题解决的话,请采纳,采纳后回答新问题
4 个月之前 回复

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C++嵌入Assembler(汇编)汇编内出错?

<style> .important { color:red; } </style> <!--blog--> <h4><b>我在C++中插入了汇编代码,但汇编代码老报错,不知什么原因。求各位大神帮助!</b></h4> 代码: ```C++ #include <iostream> using namespace std; int main(int argc,char *argv[]) { volatile int a[3] = {0,0,0}; for (int i = 0;i < 3;i ++) cout << a[i] << ends; cout << endl; asm ("inc [esp + 2]");//Assembler:inc [esp + 2] (++ a[1];) for (int i = 0;i < 3;i ++) cout << a[i] << ends; cout << endl; return 0; } ``` 报错信息: ```Message (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Assembler messages: (Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccR9LmJd.s)) Error: invalid char '[' beginning operand 1 `[esp+2]' ``` 之后我想是不是这个汇编器不支持<c class="important">Intel</c>,就把那一行汇编改成了<c class="important">AT&T</c>格式的: ``` asm ("inc [esp + 2]");//Assembler:inc [esp + 2] (++ a[1];) ``` | | \/ ``` asm ("inc 2(%esp)");//Assembler:inc 2(%esp) (++ a[1];) ``` 但还是报错了: ``` (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Assembler messages: (Line(42)) (File(C:\Users\ADMINI~1\AppData\Local\Temp\ccEzueAV.s)) Error: no instruction mnemonic suffix given and no register operands; can't size instruction ``` </h6><b><c style="color:green">本人对<cc class="important">AT&T</cc>不熟悉,麻烦大家看看哪错了,致以感谢!</c></b></h6>

求解,gcc内联汇编标号编译报错

``` unsigned long strcpy0(char* dst,const char* src) { __asm__ __volatile__ ( ".intel_syntax noprefix\n" "POS2:\n" "lodsb\n" "stosb\n" "test al,al\n" "jnz POS2\n" : : :"rax","bl" ); } ``` 上面代码使用gcc编译的时候报错,请问该怎么解决: gcc -masm=intel -O3 -c -o test.o test.c test.c: Assembler messages: test.c:7: Error: symbol `POS2' is already defined test.c:7: Error: symbol `POS2' is already defined test.c:7: Error: symbol `POS2' is already defined

汇编程序在CCS中运行时出现4个错,请问该如何修改?

``` ;---------------------------------------------------------------; ;输入参数: ; ;ar0 -->指向输入缓冲起始地址的指针,也就是待交织的数据的首地址 ; ;ar1 -->指向交织表起始地址的指针 ; ;ar2 -->指向输出缓冲起始地址的指针,也就是交织完的数据的地址 ; ;ar3 -->待交织数据的长度,以比特表示 ; ;---------------------------------------------------------------- ;uninter_word -->待交织的数据的长度,以字表示 ; ;inter_bit -->交织数据的比特位置 ; ;loc_bit -->待交织数据的比特位置 ; ;loc_word -->待交织数据的字的位置 ; ;---------------------------------------------------------------; .def inter_R inter_R: ldm ar3,a ;待交织数据的长度 sftl a,-4 ;长度/16 得到待交织数据所占的字数 stl a,uninter_word ;存储待交织数据的长度(字的个数) stm #15,BRC ;循环的次数为 16 outstart: st #0000h,inter_bit ;字内比特起始位置为 0 inerstart: rptb i_inner-1 ;循环开始 ld *ar1,-4,a ;由交织表的数据得到此输出比特在待交织数据中的 WORD 位置 stl a,loc_word ;将此 WORD 位置保存起来 ld #15,b ;由交织表的数据得到此输出比特在待交织数据 and *ar1+,b ;中的 BIT 位置 stl b,loc_bit ;将此 BIT 位置保存起来 ld #1,a rsbx c ;清 C rpt loc_bit rol a ;将 1<<loc_bit+1 ror a stlm a,ar4 ;保存 A 中的数据 ldm ar0,b ;保存 AR0 中的数据 ldm ar0,a ;在输入缓冲区中寻找要交织的 BIT 的字的位置 add loc_word,a ;ar0+loc_word stlm a,ar0 ldm ar4,a and *ar0,a ;a 中的第 loc_bit 个比特就是需要交织到此比特位置的数据 stlm b,ar0 rsbx c rpt loc_bit ror a ;数据右移到 A 的最低位中 rol a rsbx c rpt inter_bit rol a ;A<<inter_bit,inter_bit 是输出缓冲当前字中 ror a ;要处理的比特位置 ssbx c ;置 C ld #0ffffh,16,b or #0fffeh,b rpt inter_bit rol b ror b and *ar2,b ;清除输出缓冲此比特位置原有的数据 or a,b ;将 A 中的数据通过“或”操作写入输出 B 中 stl b,*ar2 ;将 B 中的数据写入输出缓冲区中 addm #0001h,inter_bit ;输出缓冲中待操作的比特位置加 1 nop i_inner mar *ar2+ ;输出缓冲中待操作的字位置加 1 ld uninter_word,a sub #1,a ;待交织数据的字的长度减 1 stl a,uninter_word and #0ffffh,a ;判断整字的待交织数据是否交织完 bc outstart,aneq ;没有交织完则继续交织,否则去判断剩下的数据够不够一个字 ldm ar3,a ;如果待交织数据长度除以 16 所得余不为 0 and #15,a ;的话,还要继续处理最后一个字的数据 bc endprog,aeq sub #1,a stlm a,brc stm #0000h,ar3 B inerstart endprog: ret ``` ![图片说明](https://img-ask.csdn.net/upload/201605/20/1463724097_621672.png) 不知道图片能否上传,再把错误陈列下: ``` "c:\ti\c5500\cgtools\bin\cl55" -g -q -fr"C:/ti/tutorial/jiaozhi2/Debug" -d"_DEBUG" -@"Debug.lkf" "jiaozhi.asm" "jiaozhi.asm", ERROR! at line 13: [E9999] Syntax Error .def inter_R ^ "jiaozhi.asm", ERROR! at line 13: [E9999] Invalid mnemonic specified .def inter_R ^ "jiaozhi.asm", REMARK at line 55: [R5571] This instruction may corrupt the carry bit if the M40 bit is set (see the C55x silicon exceptions errata; Advisory CPU_41) addm #0001h,inter_bit ;输出缓冲中待操作的比特位置加 1 "jiaozhi.asm", REMARK at line 57: [R5573] Any BKxx and BSAxx updates are not pipline protected against MAR operations within 5 cycles (see line 55) (see the C55x silicon exceptions errata; Advisory CPU_43) i_inner mar *ar2+ ;输出缓冲中待操作的字位置加 1 "jiaozhi.asm", ERROR! at EOF: [E0300] The following symbols are undefined: 3 Assembly Errors, No Assembly Warnings uninter_word loc_word loc_bit inter_bit Errors in Source - Assembler Aborted Compile Complete, 4 Errors, 0 Warnings, 2 Remarks. ```

如何在Golang中使用在汇编代码中定义的函数?

<div class="post-text" itemprop="text"> <p>In golangs AES crypto package <a href="https://golang.org/src/crypto/aes/cipher_amd64.go" rel="nofollow noreferrer">cipher_amd64.go</a> makes use of functions that are defined in assembler code (<a href="https://golang.org/src/crypto/aes/asm_amd64.s" rel="nofollow noreferrer">asm_amd64.s</a>). In the mentioned go file only the function headers are defined:</p> <pre><code>// defined in asm_amd64.s func encryptBlockAsm(nr int, xk *uint32, dst, src *byte) func decryptBlockAsm(nr int, xk *uint32, dst, src *byte) func expandKeyAsm(nr int, key *byte, enc *uint32, dec *uint32) </code></pre> <p>How can I use these functions in my own code? Just declaring the headers and importing "crypto/aes" as in the mentioned .go file does not work (<code>undefined: expandKeyAsm</code>).</p> <p>Thank you very much!</p> </div>

Bomb Lab问题,求分析代码,汇编看不懂。

Dump of assembler code for function phase_2: => 0x0000000000401107 <+0>: mov %rbx,-0x18(%rsp) 0x000000000040110c <+5>: mov %rbp,-0x10(%rsp) 0x0000000000401111 <+10>: mov %r12,-0x8(%rsp) 0x0000000000401116 <+15>: sub $0x38,%rsp 0x000000000040111a <+19>: mov %rsp,%rsi 0x000000000040111d <+22>: callq 0x401294 <read_six_numbers> 0x0000000000401122 <+27>: mov %rsp,%rbx 0x0000000000401125 <+30>: lea 0xc(%rsp),%r12 0x000000000040112a <+35>: mov $0x0,%ebp 0x000000000040112f <+40>: mov (%rbx),%eax 0x0000000000401131 <+42>: cmp 0xc(%rbx),%eax 0x0000000000401134 <+45>: je 0x40113b <phase_2+52> 0x0000000000401136 <+47>: callq 0x401272 <explode_bomb> 0x000000000040113b <+52>: add (%rbx),%ebp 0x000000000040113d <+54>: add $0x4,%rbx 0x0000000000401141 <+58>: cmp %r12,%rbx 0x0000000000401144 <+61>: jne 0x40112f <phase_2+40> 0x0000000000401146 <+63>: test %ebp,%ebp 0x0000000000401148 <+65>: jne 0x40114f <phase_2+72> 0x000000000040114a <+67>: callq 0x401272 <explode_bomb> 0x000000000040114f <+72>: mov 0x20(%rsp),%rbx 0x0000000000401154 <+77>: mov 0x28(%rsp),%rbp ---Type <return> to continue, or q <return> to quit---return 0x0000000000401159 <+82>: mov 0x30(%rsp),%r12 0x000000000040115e <+87>: add $0x38,%rsp 0x0000000000401162 <+91>: retq

使用内联汇编程序用C调用golang函数时,对于'mov'的内存引用过多

<div class="post-text" itemprop="text"> <p>I'm trying to call a golang function from my C code. Golang does not use the standard x86_64 calling convention, so I have to resort to implementing the transition myself. As gcc does not want to mix cdecl with the x86_64 convention, I'm trying to call the function using inline assembly:</p> <pre><code>void go_func(struct go_String filename, void* key, int error){ void* f_address = (void*)SAVEECDSA; asm volatile(" sub rsp, 0xe0; \t \ mov [rsp+0xe0], rbp; \t \ mov [rsp], %0; \t \ mov [rsp+0x8], %1; \t \ mov [rsp+0x18], %2; \t \ call %3; \t \ mov rbp, [rsp+0xe0]; \t \ add rsp, 0xe0;" : : "g"(filename.str), "g"(filename.len), "g"(key), "g"(f_address) : ); return; } </code></pre> <p>Sadly the compiler always throws an error at me that I dont understand:</p> <pre><code>./code.c:241: Error: too many memory references for `mov' </code></pre> <p>This corresponds to this line: <code>mov [rsp+0x18], %2; \t \</code> If I delete it, the compilation works. I don't understand what my mistake is...</p> <p>I'm compiling with the -masm=intel flag so I use Intel syntax. Can someone please help me?</p> </div>

使用cgo和不使用cgo进行编译时,golang使用的汇编程序

<div class="post-text" itemprop="text"> <p>Let's say I have a golang package, which contains some assembly code:</p> <pre><code> demopkg/ source1.go source2.go asm_amd64.s </code></pre> <p>If I try to build it using <code>go build</code>, toolchain will use <code>go tool asm</code> to assemble the *.s files.</p> <p>But if I add Cgo to the mixture, by putting a single <code>import "C"</code> into any of the sources, go will switch to gcc assembler.</p> <p>I can see it by executing <code>go build -n</code>. Calls to the <code>/usr/local/go/pkg/tool/linux_amd64/asm</code> from the first case get replaced by calls to <code>gcc</code>. Besides that, it starts complaining about broken syntax.</p> <p>Is this behaviour documented, so I can rely on it for the maintaining of my package? Can I force <code>go build</code> to use one exact assembler?</p> </div>

Go的汇编程序的条件跳转指令是什么?

<div class="post-text" itemprop="text"> <p>Go's 6a assembler has conditional jump instructions:</p> <pre><code>JCC JCS JCXZL JEQ JGE JGT JHI JLE JLS JLT JMI JNE JOC JOS JPC JPL JPS </code></pre> <p>But how do they map to x86 conditional jumps?</p> </div>

什么时候装配比 c 快?

<div class="post-text" itemprop="text"> <p>One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular. However, I've also heard it stated many times that although that's not entirely false, the cases where assembler can <strong>actually</strong> be used to generate more performant code are both extremely rare and require expert knowledge of and experience with assembly. </p> <p>This question doesn't even get into the fact that assembler instructions will be machine-specific and non-portable, or any of the other aspects of assembler. There are plenty of good reasons for knowing assembly besides this one, of course, but this is meant to be a specific question soliciting examples and data, not an extended discourse on assembler versus higher-level languages.</p> <p>Can anyone provide some <strong>specific examples</strong> of cases where assembly will be faster than well-written C code using a modern compiler, and can you support that claim with profiling evidence? I am pretty confident these cases exist, but I really want to know exactly how esoteric these cases are, since it seems to be a point of some contention.</p> </div> <p>转载于:https://stackoverflow.com/questions/577554/when-is-assembly-faster-than-c</p>

将Go汇编程序翻译为NASM

<div class="post-text" itemprop="text"> <p>I came across the following Go code:</p> <pre><code>type Element [12]uint64 //go:noescape func CSwap(x, y *Element, choice uint8) //go:noescape func Add(z, x, y *Element) </code></pre> <p>where the <code>CSwap</code> and <code>Add</code> functions are basically coming from an assembly, and look like the following:</p> <pre><code>TEXT ·CSwap(SB), NOSPLIT, $0-17 MOVQ x+0(FP), REG_P1 MOVQ y+8(FP), REG_P2 MOVB choice+16(FP), AL // AL = 0 or 1 MOVBLZX AL, AX // AX = 0 or 1 NEGQ AX // RAX = 0x00..00 or 0xff..ff MOVQ (0*8)(REG_P1), BX MOVQ (0*8)(REG_P2), CX // Rest removed for brevity TEXT ·Add(SB), NOSPLIT, $0-24 MOVQ z+0(FP), REG_P3 MOVQ x+8(FP), REG_P1 MOVQ y+16(FP), REG_P2 MOVQ (REG_P1), R8 MOVQ (8)(REG_P1), R9 MOVQ (16)(REG_P1), R10 MOVQ (24)(REG_P1), R11 // Rest removed for brevity </code></pre> <p>What I try to do is that translate the assembly to a syntax that is more familiar to me (I think mine is more like NASM), while the above syntax is Go assembler. Regarding the <code>Add</code> method I didn't have much problem, and translated it correctly (according to test results). It looks like this in my case:</p> <pre><code>.text .global add_asm add_asm: push r12 push r13 push r14 push r15 mov r8, [reg_p1] mov r9, [reg_p1+8] mov r10, [reg_p1+16] mov r11, [reg_p1+24] // Rest removed for brevity </code></pre> <p>But, I have a problem when translating the <code>CSwap</code> function, I have something like this:</p> <pre><code>.text .global cswap_asm cswap_asm: push r12 push r13 push r14 mov al, 16 mov rax, al neg rax mov rbx, [reg_p1+(0*8)] mov rcx, [reg_p2+(0*8)] </code></pre> <p>But this doesn't seem to be quite correct, as I get error when compiling it. Any ideas how to translate the above <code>CSwap</code> assembly part to something like NASM?</p> <p><strong>EDIT (SOLUTION):</strong></p> <p>Okay, after the two answers below, and some testing and digging, I found out that the code uses the following three registers for parameter passing:</p> <pre><code>#define reg_p1 rdi #define reg_p2 rsi #define reg_p3 rdx </code></pre> <p>Accordingly, <code>rdx</code> has the value of the <code>choice</code> parameter. So, all that I had to do was use this:</p> <pre><code>movzx rax, dl // Get the lower 8 bits of rdx (reg_p3) neg rax </code></pre> <p>Using <code>byte [rdx]</code> or <code>byte [reg_3]</code> was giving an error, but using <code>dl</code> seems to work fine for me.</p> </div>

Link Go与任意目标文件(汇编)?

<div class="post-text" itemprop="text"> <p>I would like to make functions written in assembly available to my Go code. I have seen <a href="https://stackoverflow.com/questions/25460967/go-isnt-linking-my-assembly-undefined-external-function">methods for linking functions written in Go assembler's syntax</a> or <a href="https://stackoverflow.com/questions/2951028/is-it-possible-to-include-inline-assembly-in-google-go-code">linking object files using the gccgo toolchain</a>.</p> <p>However, ideally, I would like to be able to use NASM and the "gc" toolchain. I have been messing around with cgo/6g/6l, but had no luck so far.</p> </div>

什么时候组装速度比 c 快?

<div class="post-text" itemprop="text"> <p>One of the stated reasons for knowing assembler is that, on occasion, it can be employed to write code that will be more performant than writing that code in a higher-level language, C in particular. However, I've also heard it stated many times that although that's not entirely false, the cases where assembler can <strong>actually</strong> be used to generate more performant code are both extremely rare and require expert knowledge of and experience with assembly. </p> <p>This question doesn't even get into the fact that assembler instructions will be machine-specific and non-portable, or any of the other aspects of assembler. There are plenty of good reasons for knowing assembly besides this one, of course, but this is meant to be a specific question soliciting examples and data, not an extended discourse on assembler versus higher-level languages.</p> <p>Can anyone provide some <strong>specific examples</strong> of cases where assembly will be faster than well-written C code using a modern compiler, and can you support that claim with profiling evidence? I am pretty confident these cases exist, but I really want to know exactly how esoteric these cases are, since it seems to be a point of some contention.</p> </div> <p>转载于:https://stackoverflow.com/questions/577554/when-is-assembly-faster-than-c</p>

keil5打开keil4工程后编译出现问题怎么办?

keil5打开keil4工程出现这样的情况,编译后出现"no source": Error: #5: cannot open source input file "..\source\crc32.c": No such file or directory的问题?

在CentOS6.5装redis时候报错,是不是gcc问题,的错误困扰我好久啦?

make[2]: Leaving directory `/usr/local/redis-3.2.3/deps' CC adlist.o CC quicklist.o CC ae.o In file included from ae.c:53: ae_epoll.c: 在函数‘aeApiAddEvent’中: ae_epoll.c:75: 警告:缺少初始值设定 ae_epoll.c:75: 警告:(在‘ee.data’的初始化附近) ae_epoll.c: 在函数‘aeApiDelEvent’中: ae_epoll.c:92: 警告:缺少初始值设定 ae_epoll.c:92: 警告:(在‘ee.data’的初始化附近) CC anet.o anet.c: 在函数‘anetSockName’中: anet.c:640: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:638: 附注:initialized from here anet.c:644: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:642: 附注:initialized from here anet.c: 在函数‘anetPeerToString’中: anet.c:584: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:582: 附注:initialized from here anet.c:588: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:586: 附注:initialized from here anet.c: 在函数‘anetTcpAccept’中: anet.c:555: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:553: 附注:initialized from here anet.c:559: 警告:dereferencing pointer ‘s’ does break strict-aliasing rules anet.c:557: 附注:initialized from here /tmp/ccMyxAR8.s: Assembler messages: /tmp/ccMyxAR8.s:3732: Error: symbol `fstatat64' is already defined /tmp/ccMyxAR8.s:3755: Error: symbol `fstat64' is already defined /tmp/ccMyxAR8.s:3774: Error: symbol `lstat64' is already defined /tmp/ccMyxAR8.s:3793: Error: symbol `stat64' is already defined make[1]: *** [anet.o] 错误 1

CentOS安装gcc-c++出现错误

在Centos中安装gcc gcc-c++总是出现Connot find a valid baseurl for repo : base的错误,怎样解决?

Benny's Compiler

These days Benny has designed a new compiler for C programming language. His compilation system provides a compiler driver that invokes the language preprocessor, compiler, assembler and linker. C source file (with .C suffix) is translated to relocatable object module first, and then all modules are linked together to generate an executable object file. The translator (preprocessor, compiler and assembler) works perfectly and can generate well optimized assembler code from C source file. But the linker has a serious bug -- it cannot resolve global symbols when there are circular references. To be more specific, if file 1 references variables defined in file 2, file 2 references variables defined in file 3, ... file n-1 references variables defined in file n and file n references variables defined in file 1, then Benny's linker walks out because it doesn't know which file should be processed first. Your job is to determine whether a source file can be compiled successfully by Benny's compiler. Input There are multiple test cases! In each test case, the first line contains one integer N, and then N lines follow. In each of these lines there are two integers Ai and Bi, meaning that file Ai references variables defined in file Bi (1 <= i <= N). The last line of the case contains one integer E, which is the file we want to compile. A negative N denotes the end of input. Else you can assume 0 < N, Ai, Bi, E <= 100. Output There is just one line of output for each test case. If file E can be compiled successfully output "Yes", else output "No". Sample Input 4 1 2 2 3 3 1 3 4 1 4 1 2 2 3 3 1 3 4 4 -1 Sample Output No Yes

cs app缓冲区溢出攻击

Level 0: Candle (10 pts) The function getbuf is called within BUFBOMB by a function test having the following C code: 1 void test() 2 { 3 int val; 4 volatile int local = 0xdeadbeef; 5 entry_check(3); /* Make sure entered this function properly */ 6 val = getbuf(); 7 /* Check for corrupted stack */ 8 if (local != 0xdeadbeef) { 9 printf("Sabotaged!: the stack has been corrupted\n"); 10 } 11 else if (val == cookie) { 12 printf("Boom!: getbuf returned 0x%x\n", val); 13 validate(3); 14 } 15 else { 16 printf("Dud: getbuf returned 0x%x\n", val); 17 } 18 } When getbuf executes its return statement (line 5 of getbuf), the program ordinarily resumes execution within function test (at line 8 of this function). Within the file bufbomb, there is a function smoke having the following C code: void smoke() { entry_check(0); /* Make sure entered this function properly */ printf("Smoke!: You called smoke()\n"); validate(0); exit(0); } Your task is to get BUFBOMB to execute the code for smoke when getbuf executes its return statement, rather than returning to test. You can do this by supplying an exploit string that overwrites the stored return pointer in the stack frame for getbuf with the address of the first instruction in smoke. Note that your exploit string may also corrupt other parts of the stack state, but this will not cause a problem, since smoke causes the program to exit directly. Some Advice: All the information you need to devise your exploit string for this level can be determined by examining a diassembled version of BUFBOMB. Be careful about byte ordering. You might want to use GDB to step the program through the last few instructions of getbuf to make sure it is doing the right thing. The placement of buf within the stack frame for getbuf depends on which version of GCC was used to compile bufbomb. You will need to pad the beginning of your exploit string with the proper number of bytes to overwrite the return pointer. The values of these bytes can be arbitrary. 可以看到:Your task is to get BUFBOMB to execute the code for smoke when getbuf executes its return statement, rather than returning to test. 任务是把getbuf函数返回的地址改为smoke的地址。 getbuf函数的反汇编代码: [cpp] view plain copy 0x08048ad0 <+0>: push %ebp 0x08048ad1 <+1>: mov %esp,%ebp 0x08048ad3 <+3>: sub $0x28,%esp 0x08048ad6 <+6>: lea -0x18(%ebp),%eax 0x08048ad9 <+9>: mov %eax,(%esp) 0x08048adc <+12>: call 0x80489c0 <Gets> 0x08048ae1 <+17>: leave 0x08048ae2 <+18>: mov $0x1,%eax 0x08048ae7 <+23>: ret 可以看到buff存放在返回地址的4+0x18=0x1c处,其十进制是28则要在输入填充28个数,后接smoke的地址 smoke反汇编: Dump of assembler code for function smoke: 0x08048eb0 <+0>: push %ebp 0x08048eb1 <+1>: mov %esp,%ebp 0x08048eb3 <+3>: sub $0x8,%esp 0x08048eb6 <+6>: movl $0x80495f7,(%esp) 0x08048ebd <+13>: call 0x8048758 <puts@plt> 0x08048ec2 <+18>: movl $0x0,(%esp) 0x08048ec9 <+25>: call 0x8048af0 <validate> 0x08048ece <+30>: movl $0x0,(%esp) 0x08048ed5 <+37>: call 0x80487e8 <exit@plt> smoke地址08048eb0,因为是小端机器 所以填入 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 b0 8e 04 08 然而怎么都不对,输出 run -t wu<text.txt Starting program: /home/zawdcxs/Desktop/bufbomb -t wu<text.txt Team: wu Cookie: 0x706f2ba4 Program received signal SIGSEGV, Segmentation fault. 0x30302030 in ?? () 我试验,输入12个字符,就是刚超出buf长度也提示上面这个。按理论上面先pad28个字符是没毛病啊

判断一个整数是否介于两个整数(含已知值)之间的最快方法

<div class="post-text" itemprop="text"> <p>Is there a faster way than <code>x &gt;= start &amp;&amp; x &lt;= end</code> in C or C++ to test if an integer is between two integers?</p> <p><em>UPDATE</em>: My specific platform is iOS. This is part of a box blur function that restricts pixels to a circle in a given square.</p> <p><em>UPDATE</em>: After trying the <a href="https://stackoverflow.com/a/17095534/1165522">accepted answer</a>, I got an order of magnitude speedup on the one line of code over doing it the normal <code>x &gt;= start &amp;&amp; x &lt;= end</code> way.</p> <p><em>UPDATE</em>: Here is the after and before code with assembler from XCode:</p> <p><strong>NEW WAY</strong></p> <pre><code>// diff = (end - start) + 1 #define POINT_IN_RANGE_AND_INCREMENT(p, range) ((p++ - range.start) &lt; range.diff) Ltmp1313: ldr r0, [sp, #176] @ 4-byte Reload ldr r1, [sp, #164] @ 4-byte Reload ldr r0, [r0] ldr r1, [r1] sub.w r0, r9, r0 cmp r0, r1 blo LBB44_30 </code></pre> <p><strong>OLD WAY</strong></p> <pre><code>#define POINT_IN_RANGE_AND_INCREMENT(p, range) (p &lt;= range.end &amp;&amp; p++ &gt;= range.start) Ltmp1301: ldr r1, [sp, #172] @ 4-byte Reload ldr r1, [r1] cmp r0, r1 bls LBB44_32 mov r6, r0 b LBB44_33 LBB44_32: ldr r1, [sp, #188] @ 4-byte Reload adds r6, r0, #1 Ltmp1302: ldr r1, [r1] cmp r0, r1 bhs LBB44_36 </code></pre> <p>Pretty amazing how reducing or eliminating branching can provide such a dramatic speed up.</p> </div> <p>转载于:https://stackoverflow.com/questions/17095324/fastest-way-to-determine-if-an-integer-is-between-two-integers-inclusive-with</p>

如何对类型检查的ast运行优化?

<div class="post-text" itemprop="text"> <p>There are packages to scan/parse/typecheck Go code, but what about optimizations? </p> <p>Suppose we have a program that translates Go to the other target language. If we do it only based on the AST, we will miss all optimizations (unless we apply them by hand). Target environment can have really bad or no optimizer at all, and of course even if it has one, it could not be able to optimize transcompiled code well. </p> <p>Simply put: <em>what are our options?</em></p> <p>Maybe there is some way to compile Go to its assembler with optimizations and then (either of 2): <strong>a)</strong> translate assembler back to Go and traverse AST as usual? <br> <strong>b)</strong> read assembler into some kind of IR structure and use that to emit code?</p> <p>Thanks in advance.</p> </div>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

大胆预测下未来5年的Web开发

在2019年的ReactiveConf 上,《Elm in Action》的作者Richard Feldman对未来5年Web开发的发展做了预测,很有意思,分享给大家。如果你有机会从头...

大牛都会用的IDEA调试技巧!!!

导读 前天面试了一个985高校的实习生,问了他平时用什么开发工具,他想也没想的说IDEA,于是我抛砖引玉的问了一下IDEA的调试用过吧,你说说怎么设置断点...

立即提问
相关内容推荐