简体   繁体   English

查找和替换十六进制字符串

[英]Find and Replace HEX Strings

OK, I'm stuck at this point... I want to compare two files and copy over(replace) the strings from one file to another. 好的,这时我很棘手...我想比较两个文件并将字符串从一个文件复制(替换)到另一个文件。

Example File 1: 示例文件1:

01cd74a8h: 65 00 00 00 54 45 53 54 00 00 00 00 00 00 00 00 ; e...TEST........
01cd74b8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd74c8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd74d8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd74e8h: 00 00 00 00 00 00 20 C5 00 00 00 00 00 00 20 C5 ; ...... ?..... ?
01cd74f8h: 00 00 20 45 00 00 00 00 00 00 20 45 01 00 00 00 ; .. E...... E....
01cd7508h: 00 00 00 00 00 00 00 00 C9 00 00 00 54 61 6D 20 ; ........?..Tam 
01cd7518h: 54 61 20 51 75 61 6E 00 00 00 00 00 00 00 00 00 ; Ta Quan.........
01cd7528h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd7538h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd7548h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 45 ; .............. E
01cd7558h: 00 00 00 00 00 00 20 C5 00 00 F0 45 00 00 00 00 ; ...... ?.餎....
01cd7568h: 00 00 20 45 01 00 00 00 00 00 00 00 00 00 00 00 ; .. E............
01cd7578h: 2D 01 00 00 4C 69 65 75 20 43 68 69 6E 68 20 51 ; -...Lieu Chinh Q
01cd7588h: 75 61 6E 00 00 00 00 00 00 00 00 00 00 00 00 00 ; uan.............
01cd7598h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd75a8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd75b8h: 00 00 00 00 00 00 F0 C5 00 00 00 00 00 00 20 C5 ; ......鹋...... ?
01cd75c8h: 00 00 20 C5 00 00 00 00 00 00 20 45 01 00 00 00 ; .. ?..... E....
01cd75d8h: 00 00 00 00 00 00 00 00 91 01 00 00 56 6F 20 54 ; ........?..Vo T
01cd75e8h: 68 69 65 6E 20 43 61 63 20 31 00 00 00 00 00 00 ; hien Cac 1......
01cd75f8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd7608h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01cd7618h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 C4 ; ..............H?
01cd7628h: 00 00 00 00 00 00 48 C4 00 00 48 44 00 00 00 00 ; ......H?.HD....
01cd7638h: 00 00 48 44 00 00 00 00 10 CA 9A 3B 00 00 00 00 ; ..HD.....蕷;....

Example File 2: 示例文件2:

01b954a8h: 65 00 00 00 43 65 6E 74 72 61 6C 20 56 61 6C 6C ; e...Central Vall
01b954b8h: 65 79 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ey..............
01b954c8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b954d8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b954e8h: 00 00 00 00 00 00 20 C5 00 00 00 00 00 00 20 C5 ; ...... ?..... ?
01b954f8h: 00 00 20 45 00 00 00 00 00 00 20 45 01 00 00 00 ; .. E...... E....
01b95508h: 00 00 00 00 00 00 00 00 C9 00 00 00 48 69 6C 6C ; ........?..Hill
01b95518h: 20 56 61 6C 6C 65 79 00 00 00 00 00 00 00 00 00 ;  Valley.........
01b95528h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b95538h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b95548h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 45 ; .............. E
01b95558h: 00 00 00 00 00 00 20 C5 00 00 F0 45 00 00 00 00 ; ...... ?.餎....
01b95568h: 00 00 20 45 01 00 00 00 00 00 00 00 00 00 00 00 ; .. E............
01b95578h: 2D 01 00 00 52 69 76 65 72 73 69 64 65 20 50 6C ; -...Riverside Pl
01b95588h: 61 69 6E 73 00 00 00 00 00 00 00 00 00 00 00 00 ; ains............
01b95598h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b955a8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b955b8h: 00 00 00 00 00 00 F0 C5 00 00 00 00 00 00 20 C5 ; ......鹋...... ?
01b955c8h: 00 00 20 C5 00 00 00 00 00 00 20 45 01 00 00 00 ; .. ?..... E....
01b955d8h: 00 00 00 00 00 00 00 00 91 01 00 00 46 6F 72 62 ; ........?..Forb
01b955e8h: 69 64 64 65 6E 20 54 6F 77 65 72 20 31 46 00 00 ; idden Tower 1F..
01b955f8h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b95608h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ................
01b95618h: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 C4 ; ..............H?
01b95628h: 00 00 00 00 00 00 48 C4 00 00 48 44 00 00 00 00 ; ......H?.HD....
01b95638h: 00 00 48 44 00 00 00 00 10 CA 9A 3B 00 00 00 00 ; ..HD.....蕷;....

What I want to do is compare File1 to File2, to see if there are any matches in the Item ID's, and copy over File2's information to File1, ONLY if the item exists. 我要做的是将File1与File2进行比较,以查看项目ID中是否有任何匹配项,然后将File2的信息复制到File1(仅在项目存在的情况下)。

The Item ID starts 4 bytes behind the Item name. 物料ID在物料名称后4个字节开始。

  01b954a8h: 65 00 00 00 43 65 6E 74 72 61 6C 20 56 61 6C 6C ; e...Central Vall
  01b954b8h: 65 79 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; ey..............

  01b95508h: 00 00 00 00 00 00 00 00 C9 00 00 00 48 69 6C 6C ; ........?..Hill
  01b95518h: 20 56 61 6C 6C 65 79 00 00 00 00 00 00 00 00 00 ;  Valley.........

Here you can see that "65 00" and "C9 00" are the ID for Central Valley and Hill Valley correspondingly. 在这里,您可以看到“ 65 00”和“ C9 00”分别是中央谷和希尔谷的ID。

To me it's not clear why you want to do this in Hex. 对我来说,不清楚为什么要用十六进制执行此操作。 It seems like you can just deal with it as text. 似乎您可以将其作为文本来处理。

My thought is that you should look toward using a Regular Expression to find whitespace delimited words and back up a couple of characters to get the ID characters (which can then be converted to hex if you so need). 我的想法是,您应该考虑使用正则表达式查找空格分隔的单词,并备份几个字符以获取ID字符(如果需要,可以将其转换为十六进制)。

而不是将项目加载到列表框中,而是将项目加载到两个Dictionary对象中(其中整数是项目的ID,字符串是项目的描述。每个文件加载一个词典。然后比较词典中的项目,进行任何操作您需要对一个词典进行修改,然后将其保存回文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM