Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2005, 14:56
metro
 
Posts: n/a
finding aspack routine

Hi, Im a newbie to this, but Im very interested and want to learn.

Im trying to make a patch for a program that is aspacked - that will jmp to my code from the end of the unpacking routine when the app is run.

I don't know where to start, and could only find some very outdated tutorials that don't outline this area (and the tutorials here - which I can't download yet!).


How do I go about finding the end of the unpacking routine?


(I have ollydbg, but im sure I can 'find' softIce somewhere if needed!)

I have messed around a little making one or two trainers for games, but this side of it is completely new to me.

Sorry if this post is a bit too newbie! (most questions here seem to be rather more.. precise/accurate? (not sure of the word) )
Reply With Quote
  #2  
Old 01-02-2005, 23:00
ne_viens
 
Posts: n/a
End of unpacking routine looks like this (popa is a good indicator):

Code:
;.....
                add     eax, [ebp+422h]
                pop     ecx
                or      ecx, ecx
                mov     [ebp+3A8h], eax ; fills the push 0 with
                                        ; OEP address below
                popa
                jnz     short goon
                mov     eax, 1
                retn    0Ch
goon:
                push    0
                retn
But.., why you don't want to unpack application entirely, add your code
and run?
Reply With Quote
  #3  
Old 01-03-2005, 05:45
taos's Avatar
taos taos is offline
The Art Of Silence
 
Join Date: Aug 2004
Location: In front of my screen
Posts: 580
Rept. Given: 65
Rept. Rcvd 54 Times in 19 Posts
Thanks Given: 69
Thanks Rcvd at 134 Times in 36 Posts
taos Reputation: 54
I suggest you that read info about "getting the OEP".
Try with packing a very simple ASM file and see the result in olly.
Make a "hello world", see how it runs in olly, pack this file, see how it runs in olly.
You will see how to get the OEP with this packer.
You must STUDY AND READ much before to understand.
And please, please, use GOOGLE to search tuts, there're a lot of.
Reply With Quote
  #4  
Old 01-03-2005, 06:22
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
An complementary way to learn how the unpacker routine works is to use some tool like AspackDie or Un-Aspack wich gives you a working dump (and the right OEP). Then, using the chart feature of IDA, it's easier to follow in Olly the rebuild of the original exe
Reply With Quote
  #5  
Old 01-03-2005, 06:46
JMI JMI is offline
Leader
 
Join Date: Jan 2002
Posts: 1,627
Rept. Given: 5
Rept. Rcvd 199 Times in 99 Posts
Thanks Given: 0
Thanks Rcvd at 96 Times in 94 Posts
JMI Reputation: 100-199 JMI Reputation: 100-199
I would also suggest that you need to understand just what the heck an "unpacking" process does and I mean on an assembly language level, since this is the form in which you are most likely going to see it in a debugger. First consider it conceptually. Something with a certain size, whether it is the entire program, exe, dll, whatever, has been "packed." So, in this process of analysis, we know that "size does matter."

Now, as a general concept, packed code (or, for that matter, crypted code)will not run. So, some part of the code has to run to "unpack" the "packed" parts. Now to be effective, it simply has to know "how much" to apply it's unpacking routine to, or it will start doing "something" with parts of the code which was not originally "packed" and that part will now not work.

So, again, conceptually, the "unpacking routine" is going to take a chunk of code of a certain size and work its magic on that chunk and now you have code that will run.

So this suggests that there has to be, somewhere, something which tells the "unpacking routine" how many times it is supposed to work its magic before it has to stop or wreck the rest of the program. So now there is something you have to find which has the "count" of how many times the routine needs to "cycle" through its steps before it is done.

This suggests that you are looking for a routine which takes a portion of the code located somewhere else in the program and "adds something to it" or does "some other mechanical" process to the "packed" code so that it has returned to its "original" form. Having worked its magic on a particular chunk of the packed code it needs to know whether it has "finished" its job. So you can assume that there has to be some form of a "compare" near the end of the routine, where it checks to see if it is "done" yet. This could take several forms, such as subtracting from a starting number and branching when "0" is reached, or maybe comparing to an "ending" address in the code where it knows it is done. The point being you will see that the code is going to "return" or "branch" or "jump" back to the "unpacking" part until it has reached whatever point that is and then it will go somewhere else, like maybe to the original OEP.

And just to keep things interesting, maybe before it jumps off to the OEP, it might actually "erase" the "unpacking code" so that if some evil cracker dumps the running program, the "unpacking code" isn't there to be seen.

Regards,
__________________
JMI
Reply With Quote
  #6  
Old 01-03-2005, 15:55
metro
 
Posts: n/a
Thank you very much for the explanations guys (it was a very good explanation bu JMI). I tried to reply earlier, but I think an anti-spam system prevented me (It said I couldn't post again for 24hours).

taos - thanks for the tip with "getting OEP", I was previously googling for "unpacking aspack" and didn't make any ground with the tutorials I found, but adding OEP led to a nice tutorial here here.

ne_viens, I dont want to just unpack the file - as then I have to give my friends the complete file, rather then just a little patch. Thank you for the example code!

I have now finished the patch and all is working well, so im very happy.
Reply With Quote
Reply

Thread Tools
Display Modes

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
Finding which packer has been used rcer General Discussion 16 11-03-2019 01:56
Finding Correct EP RaptorX General Discussion 2 02-17-2011 14:53
Finding API Address britedream General Discussion 5 10-05-2006 21:28
meaning of a p-code Registration routine wassim_ General Discussion 0 09-29-2006 22:49


All times are GMT +8. The time now is 07:00.


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