吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4661|回复: 8
收起左侧

[Python 原创] 【python】原创利用Python3 解码exe格式flash文件,还原swf文件

  [复制链接]
sitiger 发表于 2019-2-17 12:32
本帖最后由 wushaominkk 于 2019-2-18 14:18 编辑

手里有一批exe格式的flash文件,由于相对来说exe格式的文件比较大,且exe文件给人印象不安全,于是想把它解码出swf原始文件。

首先,了解一些数据结构原理:
    exe格式的flash文件是一个Flash播放器程序,加上一个swf原始文件,合成一个文件,再加上最后8个字符,就生成了最终的exe文件。最后8个字节前四个是文件标识符“563412FA”(exe格式flash独有?还有exe格式flash不是,这事怎么回事?),后四个是swf原始文件的长度。

基础:

字节(Byte):字节是通过网络传输信息(或在硬盘或内存中存储信息)的单位。字节是计算机信息技术用于计量存储容量和传输容量的一种计量单位,1个字节等于8位二进制,它是一个8位的二进制数,是一个很具体的存储空间。
字符:人们使用的记号,抽象意义上的一个符号。 '1', '中', 'a', '$', '¥', ……
位(bit):一个二进制位

通过二进制读取文件后,切片出最后8个字节,比对一下前四个是否是文件标识符“563412FA”,如果是,就可以转换。再取后四位,是十六进制显示的bytes,如b'\x1c\x97\x01\x00',可以使用struct模块,unpack方法换算成一个长整数。Byte Order, Size, and Alignment
By default, C types are represented in the machine’s native format and byteorder, and properly aligned by skipping pad bytes if necessary (according to therules used by the C compiler).Alternatively, the first character of the format string can be used to indicatethe byte order, size and alignment of the packed data, according to thefollowing table:[td]
CharacterByte orderSizeAlignment
@nativenativenative
=nativestandardnone
<little-endianstandardnone
>big-endianstandardnone
!network (= big-endian)standardnone


Format Characters
Format characters have the following meaning; the conversion between C andPython values should be obvious given their types.  The ‘Standard size’ columnrefers to the size of the packed value in bytes when using standard size; thatis, when the format string starts with one of '<', '>', '!' or'='.  When using native size, the size of the packed value isplatform-dependent.[td]
FormatC TypePython typeStandard sizeNotes
xpad byteno value
ccharbytes of length 11
bsigned charinteger1(1),(3)
Bunsigned charinteger1(3)
?_Boolbool1(1)
hshortinteger2(3)
Hunsigned shortinteger2(3)
iintinteger4(3)
Iunsigned intinteger4(3)
llonginteger4(3)
Lunsigned longinteger4(3)
qlong longinteger8(2), (3)
Qunsigned longlonginteger8(2), (3)
nssize_tinteger (4)
Nsize_tinteger (4)
e(7)float2(5)
ffloatfloat4(5)
ddoublefloat8(5)
schar[]bytes
pchar[]bytes
Pvoid *integer (6)



以上是python官方document的内容。注意平台和数据类型。其实知道数据结构原理后,也可以通过hex()手工解出这个长度数值。

然后就是读写了。源码如下:

[Python] 纯文本查看 复制代码
#!/usr/bin/env python
# coding: utf-8
import re,os,struct
def exe2swf(path_list):
    notexeflash=[]
    exe2swf_done=[]
    for path in path_list:
        with open(path,'rb') as f1:
            f1.seek(-8,2)
            if re.match(b'V4\x12\xfa',f1.read(4)):
                swf_l=struct.unpack('<I', f1.read(4))[0
                f1.seek(-8-swf_l,2)
                with open(path+'.swf','wb') as f2:
                    f2.write(f1.read(swf_l))
                exe2swf_done.append(path)
            else:
                notexeflash.append(path)
    print('转换完成,返回值为不能转换的列表和已转换的列表的两个元素的元组')
    return notexeflash,exe2swf_done
def list_all(path):
    l=[]
    def recursion(path):
        if os.path.isfile(path):
            if path.endswith('exe'):
                l.append(path)
        elif os.path.isdir(path):
            tmp=[path+os.sep+x for x in
            for i in tmp:
                recursion(i)
        return l
    return recursion(path)

if __name__ == "__main__":
    path=os.path.split(os.path.realpath(__file__))
    lexe=list_all(path)
    nots,dones=exe2swf(lexe)
    if input('需要删除已完成转换的exe文件吗?输入“yes”即可删除')=='yes':
       for i in dones:
            os.remove(i)







免费评分

参与人数 1吾爱币 +3 热心值 +1 收起 理由
wushaominkk + 3 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| sitiger 发表于 2019-2-17 12:35
read the fuck manualurl: https://docs.python.org/3/library/struct.html#format-characters
抱歉,第一次发源码,格式不太会调
hillman323 发表于 2019-2-17 12:45
伯牙 发表于 2019-2-17 18:01
收藏了,直接读取内存提取也行嘛,就是需要运行。
snakehack 发表于 2019-2-18 18:46
多谢楼主分享
 楼主| sitiger 发表于 2019-2-19 08:50
伯牙 发表于 2019-2-17 18:01
收藏了,直接读取内存提取也行嘛,就是需要运行。

感谢回复,请分享你的思路和原理,我看能不能用python实现
v888 发表于 2019-2-21 11:05
感谢发布原创作品
 楼主| sitiger 发表于 2019-2-25 19:28
还有不少exe格式的是avi等等格式转的,数据封装原理还不清楚,貌似是什么类似狂牛视频加密等等软件转换的,涉及密码,机器码等问题,
ming_2794 发表于 2020-11-9 22:06
感谢分享,学习学习。!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 09:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表