473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 20175
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.comwrote:
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
Dec 6 '07 #3
On Dec 6, 4:55 pm, santosh <santosh....@gmail.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....@gmail.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....@gmail.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....@gmail.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....@gmail.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 ?
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*********@verizon.net wrote:
Kenneth Brody wrote:
>santosh wrote:
>
Benoit Lefebvre wrote:

On Dec 6, 4:55 pm, santosh <santosh....@gmail.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?
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.x86newsgroups 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
Kenneth Brody wrote:
Consider a simple disassembly of:

push 0x1234

Is "0x1234" a constant, or the address of a variable?
The concepts of "address" and "constant",
aren't mutually exclusive.

N869
6.6 Constant expressions

[#9] An address constant is a null pointer, a pointer to an
lvalue designating an object of static storage duration, or
to a function designator;

--
pete
Dec 9 '07 #11
pete wrote:
>
Kenneth Brody wrote:
Consider a simple disassembly of:

push 0x1234

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

The concepts of "address" and "constant",
aren't mutually exclusive.

N869
6.6 Constant expressions

[#9] An address constant is a null pointer, a pointer to an
lvalue designating an object of static storage duration, or
to a function designator;
However, in the OPs case of wanting to disassemble, modify,
reassemble, it makes a big difference. Consider:

foo(&x);
bar(0x1234);

If &x==0x1234, it is quite possible to see this as a disassembly:

push 0x1234
call foo
push 0x1234
call bar

--
+-------------------------+--------------------+-----------------------+
| 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 10 '07 #12

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

Similar topics

22
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 ...
1
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
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...
14
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
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...
8
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...
2
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...
8
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
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,...
0
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...

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.