Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to disassemble with objdump and recompile the program ?

Reply
Thread Tools

How to disassemble with objdump and recompile the program ?

 
 
Benoit Lefebvre
Guest
Posts: n/a
 
      12-06-2007
Anyone have hints for me on how I can disassemble a binary file using
objdump, do some modifications and then recompile everything ?

thanks,
--Ben
 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-06-2007
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.x86> or <news:alt.lang.asm>.

 
Reply With Quote
 
 
 
 
Francine.Neary@googlemail.com
Guest
Posts: n/a
 
      12-06-2007
On Dec 6, 9:51 pm, Benoit Lefebvre <(E-Mail Removed)> wrote:
> 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("progname", "rb")) {
if(fq=fopen("progname-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

 
Reply With Quote
 
Benoit Lefebvre
Guest
Posts: n/a
 
      12-07-2007
On Dec 6, 4:55 pm, santosh <(E-Mail Removed)> wrote:
> 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.x86> or <news:alt.lang.asm>.


And... can't an asm compiler recompile the code ?
 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      12-07-2007
Benoit Lefebvre wrote:

> On Dec 6, 4:55 pm, santosh <(E-Mail Removed)> wrote:
>> 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.x86> or <news:alt.lang.asm>.

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


It could, but that's off-topic here.

 
Reply With Quote
 
Kenneth Brody
Guest
Posts: n/a
 
      12-07-2007
santosh wrote:
>
> Benoit Lefebvre wrote:
>
> > On Dec 6, 4:55 pm, santosh <(E-Mail Removed)> wrote:
> >> 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.x86> or <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: <(E-Mail Removed)>

 
Reply With Quote
 
jameskuyper@verizon.net
Guest
Posts: n/a
 
      12-07-2007
Kenneth Brody wrote:
> santosh wrote:
> >
> > Benoit Lefebvre wrote:
> >
> > > On Dec 6, 4:55 pm, santosh <(E-Mail Removed)> wrote:
> > >> 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.x86> or <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.
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-08-2007
Benoit Lefebvre wrote:
> santosh <(E-Mail Removed)> wrote:
>> 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.x86> or <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

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      12-08-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Kenneth Brody wrote:
>> santosh wrote:
>> >
>> > Benoit Lefebvre wrote:
>> >
>> > > On Dec 6, 4:55 pm, santosh <(E-Mail Removed)> wrote:
>> > >> 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.x86> or <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.asm> and <news:comp.lang.asm.x86> newsgroups 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>

 
Reply With Quote
 
Kelsey Bjarnason
Guest
Posts: n/a
 
      12-09-2007
[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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Need some information in output of objdump sunny C Programming 8 11-10-2006 06:25 PM
[ANN] YARV Compile and Disassemble CGI SASADA Koichi Ruby 1 10-04-2005 07:07 AM
Re: How to disassemble Canon S30 protective lens CH Digital Photography 0 09-08-2003 03:19 AM
disassemble an assembly into source code, how to thwart BH ASP .Net 0 07-10-2003 03:24 AM



Advertisments