Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while unpacking given PECompact samples #54

Closed
SigmaStar opened this issue Feb 28, 2024 · 5 comments · Fixed by #56
Closed

Error while unpacking given PECompact samples #54

SigmaStar opened this issue Feb 28, 2024 · 5 comments · Fixed by #56

Comments

@SigmaStar
Copy link

I have installed unipacker but it cannot unpack PECompact samples:

It gives following errors:
`Next up: Sample: [PECompact] lbop20_PECompact.exe
Traceback (most recent call last):
File "/home/wnm/anaconda3/envs/sunflower/bin/unipacker", line 33, in
sys.exit(load_entry_point('unipacker==1.0.7', 'console_scripts', 'unipacker')())
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/shell.py", line 786, in main
Shell()
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/shell.py", line 86, in init
IOHandler(samples, args.dest, args.partition_by_packer)
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/io_handler.py", line 17, in init
self.handle_sample(sample, dest_dir, partition_by_packer)
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/io_handler.py", line 30, in handle_sample
engine = UnpackerEngine(sample, dest_file)
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/core.py", line 159, in init
self.init_uc()
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unipacker-1.0.7-py3.8.egg/unipacker/core.py", line 446, in init_uc
self.uc.mem_write(self.sample.BASE_ADDR, self.sample.loaded_image)
File "/home/wnm/anaconda3/envs/sunflower/lib/python3.8/site-packages/unicorn_unipacker-1.0.3b7-py3.8-linux-x86_64.egg/unicorn/unicorn.py", line 441, in mem_write
status = _uc.uc_mem_write(self._uch, address, data, len(data))
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type

  • still running -`
@SigmaStar
Copy link
Author

I found the reason, it's pefile, pefile.get_memory_mapped_image sometime return bytearray

@SigmaStar
Copy link
Author

But, after I fix that error, unipacker still cannot finish unpacking:

Next up: Sample: [PECompact] lbop20_PECompact.exe
Emulation starting at 0x401252
Invalid memory access UC_MEM_READ_UNMAPPED, addr: 0x8024a8

Emulation of lbop20_PECompact.exe finished.
--- Saved to ./unpacked_lbop20_PECompact.exe ---

@attilamester
Copy link

But, after I fix that error, unipacker still cannot finish unpacking:

Next up: Sample: [PECompact] lbop20_PECompact.exe
Emulation starting at 0x401252
Invalid memory access UC_MEM_READ_UNMAPPED, addr: 0x8024a8

Emulation of lbop20_PECompact.exe finished.
--- Saved to ./unpacked_lbop20_PECompact.exe ---

receiving the same error on various other samples from BODMAS dataset

@MrROBUST
Copy link
Contributor

I found the reason, it's pefile, pefile.get_memory_mapped_image sometime return bytearray

Hello @SigmaStar, is it possible to simply convert the result of get_memory_mapped_image to bytes? I ran into the same problem and adding this simple conversion allowed unipacker to do the job perfectly.

@SigmaStar
Copy link
Author

SigmaStar commented May 17, 2024 via email

MrROBUST added a commit to MrROBUST/unipacker that referenced this issue May 18, 2024
`uc_mem_write` not working with 'bytearray'
fix unipacker#54
Masrepus pushed a commit that referenced this issue May 19, 2024
`uc_mem_write` not working with 'bytearray'
fix #54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants