Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2004, 00:08
netxman
 
Posts: n/a
Red face How to add a section In an EXE

I don't know how to explain it detailedly ,just like this:

0001: PUSH EAX
0002: DEC EDI
0003: INC EBP
.
.
I want this:

0001: PUSH EAX
0002: JMP 0008
0003: INC EBP
.
.
.
0008: NOP
0009: DEC EDI
0010: JMP 0003

============================

Begin 0008 is the added section, use PEeditor can add a section, someone told me it needs change the ImageSize at the same time,PEeditor also can do this. But I failed.When I use OllyDbg open it , I was told it's not a valid EXE file.

Thank you very much for guidance.

Last edited by netxman; 12-13-2004 at 00:11.
Reply With Quote
  #2  
Old 12-13-2004, 05:12
LOUZEW's Avatar
LOUZEW LOUZEW is offline
Friend
 
Join Date: Feb 2002
Location: Britanny
Posts: 101
Rept. Given: 1
Rept. Rcvd 2 Times in 1 Post
Thanks Given: 6
Thanks Rcvd at 7 Times in 7 Posts
LOUZEW Reputation: 2
Adding Section

You can use Code Snippet Creator for that (you can find it on programmer's tools site)
Reply With Quote
  #3  
Old 12-13-2004, 15:37
zaratustra
 
Posts: n/a
adding a section is a very simple task with lordpe.
when you add a new section in a exe you should control the following things:
1) section do not overlap
2) the virtual size of each section must fill entirely the range between one
section and the other.
Lordpe is a very useful tool as it can do it automatically.
In particular it can be forced to do the step 2) with the option recontruct pe.
you can post the new section header table so i can show you where the problem is (grab the section header with lordpe or some other tool).
Reply With Quote
  #4  
Old 12-13-2004, 22:41
netxman
 
Posts: n/a
Thanks LOUZEW , Code Snippet Creator is a good tool but it's a little difficulty for me, it needs MASM environment first.

Thanks zaratustra , I may need your further help.

What I want in my attached file , this is the first step. Maybe I understand how to do this then I can go to next step...

Big thanks.
Attached Images
File Type: jpg exe.jpg (87.7 KB, 26 views)
Reply With Quote
  #5  
Old 12-14-2004, 00:36
Michel Michel is offline
Friend
 
Join Date: Sep 2004
Location: France
Posts: 66
Rept. Given: 2
Rept. Rcvd 6 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
Michel Reputation: 6
Q1 : VirtualSize is the size which is occupied by the section when this is loaded in RAM.

Q2 : RawSize is the size which is occupied by the section on the HD.

Q3 : When you attribue some value at the VirtualSize of a section, SizeOfImage, which is the VirtualSize of the whole exe when loaded in RAM, will be automatically update.

I hope this can help you...

Last edited by Michel; 12-14-2004 at 00:39.
Reply With Quote
  #6  
Old 12-14-2004, 01:08
zaratustra
 
Posts: n/a
Thanks Michel that would be my answer too.
Only a note :
if you add a new section, to obtain a valid pe (which olly can see)
you have to adjust the size of the previous section.
In the image you have posted you should also set the vsize of the .rsrc section to
10000 - a000

cheers
z.
Reply With Quote
  #7  
Old 12-14-2004, 01:25
Michel Michel is offline
Friend
 
Join Date: Sep 2004
Location: France
Posts: 66
Rept. Given: 2
Rept. Rcvd 6 Times in 1 Post
Thanks Given: 0
Thanks Rcvd at 1 Time in 1 Post
Michel Reputation: 6
Quote:
you should also set the vsize of the .rsrc section to 10000 - a000
Do you think it's really necessary ?
Look that 65CA != 8000 - 1000 (sec .text)
Reply With Quote
  #8  
Old 12-14-2004, 10:54
netxman
 
Posts: n/a
Thank you Michel and zaratustra.I know the theory more than before.

But I was puzzled about what size and where I should fill in.

See the attached file.

I change the value twice for each place. But the Notepad.exe both could not run.


Maybe I'm thickheaded So could you please use Interkodex Screen Recorder to make avi for a simple sample if convenience ? Not necessary if inconvenience.
Attached Images
File Type: jpg exe2.jpg (31.5 KB, 18 views)
Reply With Quote
  #9  
Old 12-14-2004, 15:56
zaratustra
 
Posts: n/a
Quote:
Originally Posted by Michel
Do you think it's really necessary ?
Look that 65CA != 8000 - 1000 (sec .text)



Notepad has an 'irregular' PE Header format. I will explain it later.
Please have a look at another exe, you should note that my assertion
about the virtual size is correct. ( You can obtain the same result
with the option rebuild pe in lordpe applied to notepad).
YOU WILL OBTAIN AN ERROR IF THE VSIZE OF YOUR ADDED SECTION IS 0.
Also when you add a new section you should specify the Raw offset in the file
where your data reside. In your case, you should also add some datas at the end of file. You can do it with winhex or some other program. Or with lordpe
for example loading the section directly from disk. It is the way I prefer.
Save your datas to disk and load a new section from disk with lordpe.
Fix the vsize of the previous last section to fit the new allotted section and try...
Please try also with a program different from notepad, or post the
data of your new section I can try it on my own.
Cheers.
Z.

Last edited by zaratustra; 12-14-2004 at 16:09.
Reply With Quote
  #10  
Old 12-18-2004, 11:22
netxman
 
Posts: n/a
Thanks all.

Someone told me a simple way to do that.

Just change the Vsize Rsize and Image size with the same size.

The exe ran normally. But I am not very satisfy with this way because I learnt little from it.Maybe I'm insatiable..Oh..~~~
Reply With Quote
Reply


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chinese Section Utshiha General Discussion 6 02-02-2015 21:32


All times are GMT +8. The time now is 04:52.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )