473,842 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to disassemble with objdump and recompile the program ?

Anyone have hints for me on how I can disassemble a binary file using
objdump, do some modifications and then recompile everything ?

thanks,
--Ben
Dec 6 '07 #1
11 20233
Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary file using
objdump, do some modifications and then recompile everything ?
No. This cannot be done. Disassembly gives you assembler code which a C
compiler cannot compile. Also often disassembly is very difficult to
figure out and modifications might lead to errors. If source is not
accessible and you must modify the binary then ask in a platform
specific group. For example if you are disassembling x86 machine code
ask in <news:comp.lang .asm.x86or <news:alt.lang. asm>.

Dec 6 '07 #2
On Dec 6, 9:51 pm, Benoit Lefebvre <benoit.lefeb.. .@gmail.comwrot e:
Anyone have hints for me on how I can disassemble a binary file using
objdump, do some modifications and then recompile everything ?
How about something like this? You could easily enhance it to report
any errors that occur.

#include <stdio.h>

int main(void)
{
FILE *fp, *fq;
int c;
if(fp=fopen("pr ogname", "rb")) {
if(fq=fopen("pr ogname-new", "wb")) {
while((c=fgetc( fp))!=EOF) {
c ^= 0x42; /* <--- supply the desired modification here */
if(fputc(c, fq)==EOF)
break;
}
fclose(fq);
}
fclose(fp);
}
return 0;
}
>
thanks,
You're welcome.
--Ben
Dec 6 '07 #3
On Dec 6, 4:55 pm, santosh <santosh....@gm ail.comwrote:
Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary file using
objdump, do some modifications and then recompile everything ?

No. This cannot be done. Disassembly gives you assembler code which a C
compiler cannot compile. Also often disassembly is very difficult to
figure out and modifications might lead to errors. If source is not
accessible and you must modify the binary then ask in a platform
specific group. For example if you are disassembling x86 machine code
ask in <news:comp.lang .asm.x86or <news:alt.lang. asm>.
And... can't an asm compiler recompile the code ?
Dec 7 '07 #4
Benoit Lefebvre wrote:
On Dec 6, 4:55 pm, santosh <santosh....@gm ail.comwrote:
>Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary file
using objdump, do some modifications and then recompile everything
?

No. This cannot be done. Disassembly gives you assembler code which a
C compiler cannot compile. Also often disassembly is very difficult
to figure out and modifications might lead to errors. If source is
not accessible and you must modify the binary then ask in a platform
specific group. For example if you are disassembling x86 machine code
ask in <news:comp.lang .asm.x86or <news:alt.lang. asm>.

And... can't an asm compiler recompile the code ?
It could, but that's off-topic here.

Dec 7 '07 #5
santosh wrote:
>
Benoit Lefebvre wrote:
On Dec 6, 4:55 pm, santosh <santosh....@gm ail.comwrote:
Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary file
using objdump, do some modifications and then recompile everything
?

No. This cannot be done. Disassembly gives you assembler code which a
C compiler cannot compile. Also often disassembly is very difficult
to figure out and modifications might lead to errors. If source is
not accessible and you must modify the binary then ask in a platform
specific group. For example if you are disassembling x86 machine code
ask in <news:comp.lang .asm.x86or <news:alt.lang. asm>.
And... can't an asm compiler recompile the code ?
Assuming the disassembler got everything correct, perhaps. But,
I doubt that it would generate code that could be modified and
then properly recompiled without considerable effort, in all but
the simplest of programs.

Consider a simple disassembly of:

push 0x1234

Is "0x1234" a constant, or the address of a variable?
It could, but that's off-topic here.
"What he said."

(And why has no one brought up the "cow from hamburger" analogy yet?)

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Dec 7 '07 #6
Kenneth Brody wrote:
santosh wrote:

Benoit Lefebvre wrote:
On Dec 6, 4:55 pm, santosh <santosh....@gm ail.comwrote:
>Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary file
using objdump, do some modifications and then recompile everything
?
>>
>No. This cannot be done. Disassembly gives you assembler code which a
>C compiler cannot compile. Also often disassembly is very difficult
>to figure out and modifications might lead to errors. If source is
>not accessible and you must modify the binary then ask in a platform
>specific group. For example if you are disassembling x86 machine code
>ask in <news:comp.lang .asm.x86or <news:alt.lang. asm>.
>
And... can't an asm compiler recompile the code ?

Assuming the disassembler got everything correct, perhaps. But,
I doubt that it would generate code that could be modified and
then properly recompiled without considerable effort, in all but
the simplest of programs.

Consider a simple disassembly of:

push 0x1234

Is "0x1234" a constant, or the address of a variable?
Correct me if I'm wrong; I've never used one - but wouldn't "push
0x1234" be the output from a disassember, rather than the input? I
thought a disassembler is something which takes machine code and
converts it to corresponding assembler code. As such it should be a
perfectly straightforward task to reassemble the results.

I think what you (and the OP) are thinking about is a decompiler:
something that takes assembly language and converts it into a high-
level language like C. That would run into precisely the problems you
mention.
Dec 7 '07 #7
Benoit Lefebvre wrote:
santosh <santosh....@gm ail.comwrote:
>Benoit Lefebvre wrote:
>>Anyone have hints for me on how I can disassemble a binary file
using objdump, do some modifications and then recompile everything ?

No. This cannot be done. Disassembly gives you assembler code
which a C compiler cannot compile. Also often disassembly is
very difficult to figure out and modifications might lead to
errors. If source is not accessible and you must modify the
binary then ask in a platform specific group. For example if
you are disassembling x86 machine code ask in
<news:comp.lan g.asm.x86or <news:alt.lang. asm>.

And... can't an asm compiler recompile the code ?
No such thing exists. Assemblers 'assemble' from assembly source
code, which code describes each individual machine instruction.
The assembly language is different for every type of CPU, and often
for various sub-types. Assembly language is not written to be
understandable to the reader, but to the computer. (Although good
assembly language programmers can make assembly code
understandable)

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home .att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 8 '07 #8
ja*********@ver izon.net wrote:
Kenneth Brody wrote:
>santosh wrote:
>
Benoit Lefebvre wrote:

On Dec 6, 4:55 pm, santosh <santosh....@gm ail.comwrote:
Benoit Lefebvre wrote:
Anyone have hints for me on how I can disassemble a binary
file using objdump, do some modifications and then recompile
everything ?

No. This cannot be done. Disassembly gives you assembler code
which a C compiler cannot compile. Also often disassembly is
very difficult to figure out and modifications might lead to
errors. If source is not accessible and you must modify the
binary then ask in a platform specific group. For example if you
are disassembling x86 machine code ask in
<news:comp.lan g.asm.x86or <news:alt.lang. asm>.

And... can't an asm compiler recompile the code ?

Assuming the disassembler got everything correct, perhaps. But,
I doubt that it would generate code that could be modified and
then properly recompiled without considerable effort, in all but
the simplest of programs.

Consider a simple disassembly of:

push 0x1234

Is "0x1234" a constant, or the address of a variable?

Correct me if I'm wrong; I've never used one - but wouldn't "push
0x1234" be the output from a disassember, rather than the input?
It is output. A disassembler often interprets the machine code literally
and thus can generate instructions that the original source did not
have. Additionally symbols and type information are likely to be lost.
The disassembly could even come out erroneously for a reasonably
complex program.

Just try to disassemble a hello world C++ program and assemble it back
to an executable in a suitable assembler (that understands the
disassembler's output syntax) and run it. Sometimes the reassembly will
fail, while often when it succeeds the program run erroneously.

The <news:alt.lang. asmand <news:comp.lang .asm.x86newsgro ups have had
a lot of detailed discussions on disassembly and related topics. For
anyone interested (specifically the OP) a Google search of those groups
will be useful.

As this is totally OT to this group, I'll stop here.

<snip>

Dec 8 '07 #9
[snips]

On Fri, 07 Dec 2007 11:45:18 -0800, jameskuyper wrote:
>Consider a simple disassembly of:

push 0x1234

Is "0x1234" a constant, or the address of a variable?

Correct me if I'm wrong; I've never used one - but wouldn't "push
0x1234" be the output from a disassember, rather than the input?
I think he might have skipped some context. Consider two possible
disassemblies of the equivalent of a "Hello, world" program:

; Listing one
txt db 'Hello, world'

..main
load reg, offset_of txt
push reg
call .printf

; Listing two
txt db 'Hello, world'

..main
push 0x1234 ; address of 'Hello, world'
call 0x3917 ; address of printf
Each is a perfectly reasonable disassembling; one of 'em ain't gonna work
on re-assembling, unless every single byte is in exactly the right spot,
which even in assembly is not necessarily gonna happen, particularly if
the reason for disassembling was to fix/add/alter the code somehow.
Dec 9 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3622
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html Newsgroup Readers: If you circulate copies of this report to groups of computer programmers at different universities etc. around the world then they might find the subject matter to be interesting.
1
1680
by: nospam | last post by:
Dear all, I have written a C++ program 1.cpp #include <stdioh> main() { } then I compile with g++ 1.cpp, it generated a ./a.out.
7
3436
by: Randy Yates | last post by:
Hi, I work in an embedded environment in which we often use a mix of C and assembly code. Thus a recurring requirement is to be able to take a C header file with structure definitions as input and create an assembly include file with the structure member offsets defined. The problem is that the structure offsets are a complicated function of other syntactic elements such as other structures (I could have a structure as a member of...
14
1680
by: noridotjabi | last post by:
Two questions. 1)Is there any way that I can read from an executable and then execute what I have read. EXAMPLE: text text this is more text
8
1521
by: Dave | last post by:
I want to create a program that can only be run by a user with administrator privileges (ie in the BUILTIN/Administrators group - I think. Correct me if I'm wrong, I'm a bit hazy on users and groups). I'm not sure where to start. Can someone point me in the right direction. I'm using VS2005 (just upgraded from 2003) -- Dave
8
3759
by: sunny | last post by:
Hi All, When objdump command is executed It has displayed so many sections(segments) in the output ..data , .bss , .sbss , .rodata, .romdata, .COMMON, .appreset I came to know that the following segments usage ..data - Intialised Global Data ..bss - UnIntialised Global Data
2
1581
by: pingu219 | last post by:
Hi I'm currently in the midst of building a C high-level refactoring program in Java but I was wondering if there are any good parsers (or some other alternative) which are able to read in C files at a function or global level and allow transformations to the code, in other words it will allow me to swap a function out of one file and into another using the api etc... ATM I'm using ANTLR to generate a C Lexer/parser from a C grammar file...
8
2138
by: Horacius ReX | last post by:
Hi, I am developing some code in C which first I compile on my linux machine and afterwards I test on another special hardware which has almost no debug capabilities at all. Usually I get a lot of errors in the latter, because I have memory size limitations. So, I wonder what are the best practices to know for a given program, once it is compiled and before its execution:
5
2458
by: Andrew D | last post by:
I am creating a program that will be sold as a subscription. I am trying to decide how to prevent users from passing the program to others without purchasing it. I was thinking that on the very first run, the program could pull the MAC address from the computer it is run on, and create a constant at run time. This constant is then hard wired into the program and is used for comparison every time the program is run thereafter. If the MAC...
0
10950
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10617
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10681
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9459
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7862
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7045
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5699
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5886
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4506
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.