切换到宽版
爱科技/爱创意/爱折腾/爱极致;技术知识分享平台,点击进入新版数码之家网站
  • 1681阅读
  • 4回复

[群联]PS2251 Linux加锁解锁程序 [复制链接]

上一主题 下一主题
离线mengxp
 
发帖
101
M币
357
专家
3
粉丝
15
只看楼主 倒序阅读 我要置顶 楼主  发表于: 2016-02-23
昨天把加解锁的scsi io数据分析出来了
今天搞了个linux版本的加锁解锁程序~

很简单主要涉及几个自定义命令,有查询写保护、查询设备密码状态和加密状态、清除密码、设置密码、解锁等

有意思的是,其中一个命令是设置当前失败次数,所以6次格式化优盘这个限制,本质上是软件限制的,而不是硬件限制的。

有没有感兴趣的,等我做完放上来哈,先贴部分实验代码



void ScsiUnlockFlashDrive(int fd, char *pwd)
{
    struct sg_io_hdr * p = InitScsiIoHdr();
    unsigned char cdb[12];
    int ret;

    SetScsiDataBuffer(p, ScsiDataBuffer, 0x200);
    SetScsiSenseData(p, ScsiSenseBuffer, 24);
    memset(ScsiDataBuffer, 0, 0x200);
    strncpy(ScsiDataBuffer, pwd, 16);

    memset(cdb, 0 ,sizeof(cdb));
    cdb[0] = 0xe;
    p->dxfer_direction = SG_DXFER_TO_DEV;
    p->cmdp = cdb;
    p->cmd_len = sizeof(cdb);

    ret = ioctl(fd, SG_IO, p);
    if (!ret)
    {

    }
    else
    {
        printf("ScsiUnlockFlashDrive ioctl failed %d\n",errno);
    }

    DestroyScsiIoHdr(p);
}

void ScsiFlashDrivePwdErrorCnt(int fd, unsigned char count)
{
    struct sg_io_hdr * p = InitScsiIoHdr();
    unsigned char cdb[12];
    int ret;

    SetScsiDataBuffer(p, ScsiDataBuffer, 0x200);
    SetScsiSenseData(p, ScsiSenseBuffer, 24);
    memset(ScsiDataBuffer, 0, 0x200);
    ScsiDataBuffer[0] = count;

    memset(cdb, 0 ,sizeof(cdb));
    cdb[0] = 6;
    cdb[0] = 6;
    p->dxfer_direction = SG_DXFER_TO_DEV;
    p->cmdp = cdb;
    p->cmd_len = sizeof(cdb);

    ret = ioctl(fd, SG_IO, p);
    if (!ret)
    {

    }
    else
    {
        printf("ScsiFlashDrivePwdErrorCnt ioctl failed %d\n",errno);
    }

    DestroyScsiIoHdr(p);
}

void ScsiEraseFlashDrivePwd(int fd, char *pwd)
{
    struct sg_io_hdr * p = InitScsiIoHdr();
    unsigned char cdb[12];
    int ret;

    SetScsiDataBuffer(p, ScsiDataBuffer, 0x200);
    SetScsiSenseData(p, ScsiSenseBuffer, 24);
    memset(ScsiDataBuffer, 0, 0x200);
    strncpy(ScsiDataBuffer, pwd, 16);

    memset(cdb, 0 ,sizeof(cdb));
    cdb[0] = 0xe;
    cdb[2] = 1;
    cdb[3] = 0x55;
    cdb[4] = 0xaa;
    p->dxfer_direction = SG_DXFER_TO_DEV;
    p->cmdp = cdb;
    p->cmd_len = sizeof(cdb);

    ret = ioctl(fd, SG_IO, p);
    if (!ret)
    {

    }
    else
    {
        printf("ScsiEraseFlashDrivePwd ioctl failed %d\n",errno);
    }

    DestroyScsiIoHdr(p);
}

void ScsiSetFlashDrivePwd(int fd, char *pwd, char *newpwd, char *pwdtip)
{
    struct sg_io_hdr * p = InitScsiIoHdr();
    unsigned char cdb[12];
    int ret;

    SetScsiDataBuffer(p, ScsiDataBuffer, 0x200);
    SetScsiSenseData(p, ScsiSenseBuffer, 24);
    memset(ScsiDataBuffer, 0, 0x200);
    strncpy(ScsiDataBuffer, pwd, 16);
    strncpy(ScsiDataBuffer + 16, newpwd, 16);
    strncpy(ScsiDataBuffer + 32, pwdtip, 16);

    memset(cdb, 0 ,sizeof(cdb));
    cdb[0] = 0xe;
    cdb[2] = 1;
    p->dxfer_direction = SG_DXFER_TO_DEV;
    p->cmdp = cdb;
    p->cmd_len = sizeof(cdb);

    ret = ioctl(fd, SG_IO, p);
    if (!ret)
    {

    }
    else
    {
        printf("ScsiSetFlashDrivePwd ioctl failed %d\n",errno);
    }

    DestroyScsiIoHdr(p);
}
本帖最近打赏记录:共5条打赏M币+15
离线sujian42007

发帖
13764
M币
105
专家
12
粉丝
2800
只看该作者 1楼 发表于: 2016-02-23
请登录后查看
本帖最近打赏记录:共2条打赏M币+6
离线xiaowhite

发帖
1294
M币
234
专家
2
粉丝
33
只看该作者 2楼 发表于: 2016-02-23
请登录后查看
离线ewrwqtr342

发帖
4448
M币
12494
专家
5
粉丝
60
只看该作者 3楼 发表于: 2016-02-23
请登录后查看
离线y781638432

发帖
3067
M币
3064
专家
44
粉丝
531
只看该作者 4楼 发表于: 2016-02-23
请登录后查看
快速回复
限80 字节
温馨提示:欢迎交流讨论,请勿发布纯表情、纯引用等灌水帖子;以免被删除
 
上一个 下一个