You are invited to Log in or Register a free Frihost Account!

Edit a C compiled binary from PHP

Hello everyone,
What I need to do is to offer download of a certain program developed by my team in a website. Each program must be configured before it is downloaded, the configuration is stored online and assigned to a unique ID
I need to modify the binary in order to enter the ID in the form of a variable inside it.

I guess I could just run a hex editor, search for the line and then raw edit it in php to enter the ID, but I want to know if anyone has a better solution

If I was to do that, I'm guessing I should just open the file(fread), convert the raw binary to hex, and maybe running str_replace with a placeholder ID. Im pretty much writing my thoughts so far, if anyone knows a better way of doing so please tell me

Thanks in advance,
What you'll probably need to do is make a program that can overwrite parts of a file. In order to do that it needs to know where exactly to change the file. It has to know the position in the program to fseek The position wouldn't change if the program never changed. If I had to do it I'd assume that the program would change over time when it's recompiled which would move things around.

1. Have the program define the ID as something that can be easily searched and rather unique in the binary, something a program can search for.
If the unique ID is a string it would have to be long enough for the max length ID, or else the program would overwrite into other program code or data
2. scan the file to get it's md5 hash and save the file position and the md5 hash
3. If the hash is new and unknown, scan the file for the string with might be binary with file_get_contents or byte by byte with fgetc and save the file position of the string
4. When writing to a new file or screen have it replace the constant with the unique ID at that position. If it's a string you'll probably need to end it with a null 0x00 letter.
Related topics
Php, mime_content_type() problem
[Official] Best PHP Editor
Programming links, info, and tutorials
To Moderators: Should C++ questions be in "scripting&am
Why you should not be using Ubuntu!
Encrypt with C#, Decrypt with PHP
Which html editor?
[php] Php Editor
I Learned Binary Today :D
Website Counter
A confusion with C# and VB.NET...
Best Programming Language to Use
How to Install GD in local apache server ? | hELP !!
PHP reading a line?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.