查找子装配 [英] Finding substring in assembly
问题描述
我想知道如果有一个更有效的方法,以找到在组件中的子凭什么我目前打算这样做。
I'm wondering if there is a more efficient method to finding a substring in assembly then what I am currently planning to do.
我知道这个字符串命令scansb / scasw /鲹可以在EAX的值进行比较,以通过EDI解决的一个值。不过,据我了解,我只能在同一时间使用这种方法搜索一个字符。
I know the string instruction "scansb/scasw/scads" can compare a value in EAX to a value addressed by EDI. However, as far as I understand, I can only search for one character at a time using this methodology.
所以,如果我想找到的帮助字符串pleasehelpme的位置,我可以用scansb找到的小时偏移,然后跳到另一个,我比较其余功能。如果余数是不正确的,我的previous抵消关口后跳回scansb并尝试再次搜索,这个时候。
So, if I want to find the location of "help" in string "pleasehelpme", I could use scansb to find the offset of the h, then jump to another function where I compare the remainder. If the remainder isn't correct, I jump back to scansb and try searching again, this time after the previous offset mark.
不过,我不想这样做,然后发现有一个更有效的方法。任何建议?在此先感谢
However, I would hate to do this and then discover there is a more efficient method. Any advice? Thanks in advance
推荐答案
有确实更有效的方式,这两种指令明智和算法。
There are indeed more efficient ways, both instruction-wise and algorithmically.
如果您有硬件,你可以使用SSE 4.2比较字符串函数,这是非常快的。见概述<一href="http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/intref_cls/common/intref_sse42_comp.htm" rel="nofollow">http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/intref_cls/common/intref_sse42_comp.htm和使用C instrinsics一个例子<一href="http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/" rel="nofollow">http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/
If you have the hardware you can use the sse 4.2 compare string functions, which are very fast. See an overview http://software.intel.com/sites/products/documentation/studio/composer/en-us/2009/compiler_c/intref_cls/common/intref_sse42_comp.htm and an example using the C instrinsics http://software.intel.com/en-us/articles/xml-parsing-accelerator-with-intel-streaming-simd-extensions-4-intel-sse4/
如果你有长串或多个搜索模式,在博耶 - 穆尔一>,克努特 - 莫里斯 - 普拉特并拉宾-卡普的算法可以是更有效的。
If you have long substrings or multiple search patterns, the Boyer-Moore, Knuth-Morris-Pratt and Rabin-Karp algorithms may be more efficient.
这篇关于查找子装配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!