在编译的C程序中添加/编辑字符串?

时间:2022-05-11 11:58:37

I have a strange question, I am wondering if there is a way to add/edit a string (or something that could be accessed via the C program (inside, ie not an external file)) after it has been compiled?

我有一个奇怪的问题,我想知道是否有一种方法可以在编译后添加/编辑一个字符串(或者可以通过C程序访问的内容(内部,即不是外部文件))?

The purpose is to change a URL on an Windows program via PHP on Linux (obviously I cannot just compile it).

目的是通过Linux上的PHP更改Windows程序的URL(显然我不能只编译它)。

6 个解决方案

#1


1  

Many posix platforms come with the program strings which will read through a binary file searching for strings. There is an option to print out the offset of the strings. For example:

许多posix平台都带有程序字符串,它将通过二进制文件读取字符串。可以选择打印字符串的偏移量。例如:

strings -td myexec

From there you can use a hex editor but the main problem is that you wouldn't be able to make a string bigger than it already is.

从那里你可以使用十六进制编辑器,但主要问题是你不能使字符串比现在更大。

#2


1  

A Hex Editor is probably your best bet.

十六进制编辑器可能是您最好的选择。

#3


1  

A hex editor will work, but you have to be careful not to alter the size of the executable. If the string happens to be in the .res file, you can use ResEdit.

十六进制编辑器可以工作,但您必须小心不要改变可执行文件的大小。如果字符串恰好位于.res文件中,则可以使用ResEdit。

#4


1  

There are specialized tools to modify existing executable files. A notable tool is Resource Tuner, which can be used to edit all sorts of resources in an executable.

有专门的工具来修改现有的可执行文件。一个值得注意的工具是Resource Tuner,它可用于编辑可执行文件中的各种资源。

Another option is to use a text editor, like Hex Workshop, to edit the characters in the strings of an executable. However, bear in mind that with this method, you can only edit existing strings in an executable, and the replaced strings must have an equal or smaller length than the original ones, otherwise you'll end up modifying executable code.

另一种选择是使用文本编辑器(如Hex Workshop)来编辑可执行文件的字符串中的字符。但是,请记住,使用此方法,您只能编辑可执行文件中的现有字符串,并且替换的字符串必须具有与原始字符串相同或更小的长度,否则您最终将修改可执行代码。

#5


1  

As others have suggested, you can use a binary file editor (hex editor) to change the string in the executable file. You will want to embed into the string a marker (unique sequence of bytes) so that you can find the string in your file. And you will want to ensure that you are reading/writing the file at correct offsets.

正如其他人所建议的那样,您可以使用二进制文件编辑器(十六进制编辑器)来更改可执行文件中的字符串。您需要在字符串中嵌入一个标记(唯一的字节序列),以便您可以在文件中找到该字符串。并且您需要确保以正确的偏移量读取/写入文件。

As OP stated plans to use PHP on linux to rewrite the file, you will need to use fseek to position the file pointer to the starting location of this URL string, ensure you stay within the size of the string as you replace bytes, and then use fseek/rewind and fwrite to change the file.

由于OP声明计划在linux上使用PHP来重写文件,你需要使用fseek将文件指针定位到这个URL字符串的起始位置,确保在替换字节时保持在字符串大小内,然后使用fseek / rewind和fwrite来更改文件。

This technique can be used to change a URL embedded in a binary file, and it can also be used to embed a license key into a binary, or to embed an application checksum value into a binary so that one can detect when the binary has changed.

此技术可用于更改嵌入在二进制文件中的URL,也可用于将许可证密钥嵌入二进制文件,或将应用程序校验和值嵌入二进制文件中,以便可以检测二进制文件何时更改。

As some posters have suggested, you may need to recompute a checksum or re-sign a binary file. A quick way to check for this behavior would be to compile two versions of your binary with different URL values. Then compare the files and see if there are differences other than in the URL values.

正如一些海报所建议的那样,您可能需要重新计算校验和或重新签名二进制文件。检查此行为的一种快速方法是使用不同的URL值编译二进制文件的两个版本。然后比较文件,看看除了URL值之外是否存在差异。

#6


0  

Not unless you want to poke around in the generated hex or assembly code.

除非你想在生成的十六进制或汇编代码中找到它。

#1


1  

Many posix platforms come with the program strings which will read through a binary file searching for strings. There is an option to print out the offset of the strings. For example:

许多posix平台都带有程序字符串,它将通过二进制文件读取字符串。可以选择打印字符串的偏移量。例如:

strings -td myexec

From there you can use a hex editor but the main problem is that you wouldn't be able to make a string bigger than it already is.

从那里你可以使用十六进制编辑器,但主要问题是你不能使字符串比现在更大。

#2


1  

A Hex Editor is probably your best bet.

十六进制编辑器可能是您最好的选择。

#3


1  

A hex editor will work, but you have to be careful not to alter the size of the executable. If the string happens to be in the .res file, you can use ResEdit.

十六进制编辑器可以工作,但您必须小心不要改变可执行文件的大小。如果字符串恰好位于.res文件中,则可以使用ResEdit。

#4


1  

There are specialized tools to modify existing executable files. A notable tool is Resource Tuner, which can be used to edit all sorts of resources in an executable.

有专门的工具来修改现有的可执行文件。一个值得注意的工具是Resource Tuner,它可用于编辑可执行文件中的各种资源。

Another option is to use a text editor, like Hex Workshop, to edit the characters in the strings of an executable. However, bear in mind that with this method, you can only edit existing strings in an executable, and the replaced strings must have an equal or smaller length than the original ones, otherwise you'll end up modifying executable code.

另一种选择是使用文本编辑器(如Hex Workshop)来编辑可执行文件的字符串中的字符。但是,请记住,使用此方法,您只能编辑可执行文件中的现有字符串,并且替换的字符串必须具有与原始字符串相同或更小的长度,否则您最终将修改可执行代码。

#5


1  

As others have suggested, you can use a binary file editor (hex editor) to change the string in the executable file. You will want to embed into the string a marker (unique sequence of bytes) so that you can find the string in your file. And you will want to ensure that you are reading/writing the file at correct offsets.

正如其他人所建议的那样,您可以使用二进制文件编辑器(十六进制编辑器)来更改可执行文件中的字符串。您需要在字符串中嵌入一个标记(唯一的字节序列),以便您可以在文件中找到该字符串。并且您需要确保以正确的偏移量读取/写入文件。

As OP stated plans to use PHP on linux to rewrite the file, you will need to use fseek to position the file pointer to the starting location of this URL string, ensure you stay within the size of the string as you replace bytes, and then use fseek/rewind and fwrite to change the file.

由于OP声明计划在linux上使用PHP来重写文件,你需要使用fseek将文件指针定位到这个URL字符串的起始位置,确保在替换字节时保持在字符串大小内,然后使用fseek / rewind和fwrite来更改文件。

This technique can be used to change a URL embedded in a binary file, and it can also be used to embed a license key into a binary, or to embed an application checksum value into a binary so that one can detect when the binary has changed.

此技术可用于更改嵌入在二进制文件中的URL,也可用于将许可证密钥嵌入二进制文件,或将应用程序校验和值嵌入二进制文件中,以便可以检测二进制文件何时更改。

As some posters have suggested, you may need to recompute a checksum or re-sign a binary file. A quick way to check for this behavior would be to compile two versions of your binary with different URL values. Then compare the files and see if there are differences other than in the URL values.

正如一些海报所建议的那样,您可能需要重新计算校验和或重新签名二进制文件。检查此行为的一种快速方法是使用不同的URL值编译二进制文件的两个版本。然后比较文件,看看除了URL值之外是否存在差异。

#6


0  

Not unless you want to poke around in the generated hex or assembly code.

除非你想在生成的十六进制或汇编代码中找到它。