|
|
发表于 2025-6-17 23:14:27
|
显示全部楼层
本帖最后由 Five66 于 2025-6-18 23:06 编辑
回复 25# 娃娃
弄了个c#的 ,将下面的保存为ansi编码的bat运行
没有cs_ed2k_hash.exe的话自动尝试编译 ,有cs_ed2k_hash.exe的话直接运行
运行后没问题的话会计算当前目录下所有文件的ed2k (不包括子目录)
原本的有问题 ,已修改
- /* 2>nul&cls&@echo off
- set "exename=cs_ed2k_hash.exe"&setlocal
- if not exist "%exename%" echo 未找到%exename%&call :bianyi
- if not exist "%exename%" echo 需要%exename%,将退出&echo,&pause&exit /b
- echo,&endlocal
- set _self=%%~nx0
- for %%a in (*) do (
- set "_name=%%~nxa"
- set "_size=%%~za"
- if "%%~nxa" neq "%_self%" (
- if "%%~nxa" neq "%exename%" (
- for /f "delims=" %%b in ('%exename% "%%a"') do set _md4=%%b
- setlocal enabledelayedexpansion
- if "!_size!" neq "0" (
- set _name=!_name:%%=%%25!
- set _name=!_name: =%%20!
- set _md4=!_md4: =!
- echo ed2k://^|file^|!_name!^|!_size!^|!_md4!^|/
- echo,&endlocal
- ))))
- echo done&pause&exit /b 0
- :bianyi
- echo 开始尝试编译
- for /f "delims=" %%a in ('dir /b /ad /o-n "%systemroot%\Microsoft.NET"') do (
- for /f "delims=" %%b in ('dir /b /ad /o-n "%systemroot%\Microsoft.NET\%%a"') do (
- for /f "delims=" %%r in ('dir /b /a-d "%systemroot%\Microsoft.NET\%%a\%%b\csc.exe"') do (
- if "%%r"=="csc.exe" (
- set "csc=%systemroot%\Microsoft.NET\%%a\%%b\csc.exe"
- echo,已找到C#编译器,开始编译&echo,&goto :aaa)
- )))
- echo 找不到C#编译器csc.exe&exit/b
- :aaa
- "%csc%" /target:exe /out:"%exename%" "%~f0"
- echo,&timeout /t 1 1>nul
- if exist "%exename%" (echo,编译成功,将运行) else (echo,编译失败)
- exit/b
- */
- using System;
- using System.Text;
- namespace zxcvbnm{class Program{static void Main(string[] args){
- if(0==args.Length||!System.IO.File.Exists(args[0]))return;
- System.IO.FileStream f=System.IO.File.OpenRead(args[0]);
- if(0==f.Length){f.Close();return;}
- int md4_block=9500*1024;
- byte[] md4_nil=new byte[]{49,214,207,224,209,106,233,49,183,60,89,215,224,192,137,192};
- byte[] bf1=new byte[md4_block],bf2,bf3;
- Blood.COM.Security.MD4 md4=new Blood.COM.Security.MD4();
- System.IO.MemoryStream m=new System.IO.MemoryStream();
- int aaa=0,i=0;
- if((f.Length>0)&&(f.Length<md4_block)){
- bf3=new byte[f.Length];f.Read(bf3,0,bf3.Length);
- System.Console.WriteLine(md4.GetHexHashFromBytes(bf3));
- }else{
- while(true){
- aaa=f.Read(bf1,0,md4_block);
- if(0==aaa){if(0==(f.Length%md4_block))m.Write(md4_nil,0,16);
- break;
- }
- if(md4_block==aaa){
- bf2=md4.GetByteHashFromBytes(bf1);
- }else{
- bf3=new byte[aaa];
- for(;i<aaa;i++)bf3[i]=bf1[i];
- bf2=md4.GetByteHashFromBytes(bf3);
- }
- m.Write(bf2,0,bf2.Length);
- }
- m.Capacity=(int)m.Length;//.Capacity return int ,.Length return long ,WTF
- System.Console.WriteLine(md4.GetHexHashFromBytes(m.GetBuffer()));
- }
- f.Close();m.Close();}}}
- /*
- Copyright 2002 Blood (eaststarbuy@sina.com)
- This code is ported from Norbert Hranitzky's
- (norbert.hranitzky@mchp.siemens.de)
- Java version.
- */
- //reference Namespace
- namespace Blood.COM.Security{
- public class MD4{
- // MD4 specific object variables
- private const int BLOCK_LENGTH = 64; // = 512 / 8
- private uint[] context = new uint[4];
- private long count;
- private byte[] buffer = new byte[BLOCK_LENGTH];
- private uint[] X = new uint[16];
- // Constructors
- public MD4(){
- engineReset();
- }
- private MD4(MD4 md): this(){
- //this();
- context = (uint[])md.context.Clone();
- buffer = (byte[])md.buffer.Clone();
- count = md.count;
- }
- // Clonable method implementation
- public object Clone(){
- return new MD4(this);
- }
- // JCE methods
- private void engineReset(){
- // initial values of MD4 i.e. A, B, C, D
- // as per rfc-1320; they are low-order byte first
- context[0] = 0x67452301;
- context[1] = 0xEFCDAB89;
- context[2] = 0x98BADCFE;
- context[3] = 0x10325476;
- count = 0L;
- for(int i = 0; i < BLOCK_LENGTH; i++){
- buffer[i] = 0;
- }
- }
- private void engineUpdate(byte b){
- // compute number of bytes still unhashed; ie. present in buffer
- int i = (int)(count % BLOCK_LENGTH);
- count++; // update number of bytes
- buffer[i] = b;
- if(i == BLOCK_LENGTH - 1)
- transform(ref buffer, 0);
- }
- private void engineUpdate(byte[] input, int offset, int len){
- // make sure we don't exceed input's allocated size/length
- if(offset < 0 || len < 0 || (long)offset + len > input.Length){
- throw new ArgumentOutOfRangeException();
- }
- // compute number of bytes still unhashed; ie. present in buffer
- int bufferNdx = (int)(count % BLOCK_LENGTH);
- count += len; // update number of bytes
- int partLen = BLOCK_LENGTH - bufferNdx;
- int i = 0;
- if(len >= partLen){
- Array.Copy(input, offset + i, buffer, bufferNdx, partLen);
- transform(ref buffer, 0);
- for(i = partLen; i + BLOCK_LENGTH - 1 < len; i+= BLOCK_LENGTH){
- transform(ref input, offset + i);
- }
- bufferNdx = 0;
- }
- // buffer remaining input
- if(i < len){
- Array.Copy(input, offset + i, buffer, bufferNdx, len - i);
- }
- }
- private byte[] engineDigest(){
- // pad output to 56 mod 64; as RFC1320 puts it: congruent to 448 mod 512
- int bufferNdx = (int)(count % BLOCK_LENGTH);
- int padLen = (bufferNdx < 56) ? (56 - bufferNdx) : (120 - bufferNdx);
- // padding is always binary 1 followed by binary 0's
- byte[] tail = new byte[padLen + 8];
- tail[0] = (byte)0x80;
- // append length before final transform
- // save number of bits, casting the long to an array of 8 bytes
- // save low-order byte first.
- for(int i = 0; i < 8 ; i++){
- tail[padLen + i] = (byte)((count * 8) >> (8 * i));
- }
- engineUpdate(tail, 0, tail.Length);
- byte[] result = new byte[16];
- // cast this MD4's context (array of 4 uints) into an array of 16 bytes.
- for(int i = 0;i < 4; i++){
- for(int j = 0; j < 4; j++){
- result[i * 4 + j] = (byte)(context[i] >> (8 * j));
- }}
- // reset the engine
- engineReset();
- return result;
- }
- public byte[] GetByteHashFromBytes(byte[] b){
- MD4 md4 = new MD4();
- md4.engineUpdate(b, 0, b.Length);
- return md4.engineDigest();
- }
- public string GetHexHashFromBytes(byte[] b){
- byte[] e = GetByteHashFromBytes(b);
- return bytesToHex(e, e.Length);
- }
- private static string bytesToHex(byte[] a, int len){
- string temp = BitConverter.ToString(a);
- // We need to remove the dashes that come from the BitConverter
- StringBuilder sb = new StringBuilder((len - 2) / 2); // This should be the final size
- for(int i = 0; i < temp.Length ; i++){
- if(temp[i] != '-'){
- sb.Append(temp[i]);
- }}
- return sb.ToString();
- }
- // own methods
- private void transform(ref byte[] block, int offset){
- // decodes 64 bytes from input block into an array of 16 32-bit
- // entities. Use A as a temp var.
- for (int i = 0; i < 16; i++){
- X[i] = ((uint)block[offset++] & 0xFF) |
- (((uint)block[offset++] & 0xFF) << 8) |
- (((uint)block[offset++] & 0xFF) << 16) |
- (((uint)block[offset++] & 0xFF) << 24);
- }
- uint A = context[0];
- uint B = context[1];
- uint C = context[2];
- uint D = context[3];
- A = FF(A, B, C, D, X[ 0], 3);
- D = FF(D, A, B, C, X[ 1], 7);
- C = FF(C, D, A, B, X[ 2], 11);
- B = FF(B, C, D, A, X[ 3], 19);
- A = FF(A, B, C, D, X[ 4], 3);
- D = FF(D, A, B, C, X[ 5], 7);
- C = FF(C, D, A, B, X[ 6], 11);
- B = FF(B, C, D, A, X[ 7], 19);
- A = FF(A, B, C, D, X[ 8], 3);
- D = FF(D, A, B, C, X[ 9], 7);
- C = FF(C, D, A, B, X[10], 11);
- B = FF(B, C, D, A, X[11], 19);
- A = FF(A, B, C, D, X[12], 3);
- D = FF(D, A, B, C, X[13], 7);
- C = FF(C, D, A, B, X[14], 11);
- B = FF(B, C, D, A, X[15], 19);
- A = GG(A, B, C, D, X[ 0], 3);
- D = GG(D, A, B, C, X[ 4], 5);
- C = GG(C, D, A, B, X[ 8], 9);
- B = GG(B, C, D, A, X[12], 13);
- A = GG(A, B, C, D, X[ 1], 3);
- D = GG(D, A, B, C, X[ 5], 5);
- C = GG(C, D, A, B, X[ 9], 9);
- B = GG(B, C, D, A, X[13], 13);
- A = GG(A, B, C, D, X[ 2], 3);
- D = GG(D, A, B, C, X[ 6], 5);
- C = GG(C, D, A, B, X[10], 9);
- B = GG(B, C, D, A, X[14], 13);
- A = GG(A, B, C, D, X[ 3], 3);
- D = GG(D, A, B, C, X[ 7], 5);
- C = GG(C, D, A, B, X[11], 9);
- B = GG(B, C, D, A, X[15], 13);
- A = HH(A, B, C, D, X[ 0], 3);
- D = HH(D, A, B, C, X[ 8], 9);
- C = HH(C, D, A, B, X[ 4], 11);
- B = HH(B, C, D, A, X[12], 15);
- A = HH(A, B, C, D, X[ 2], 3);
- D = HH(D, A, B, C, X[10], 9);
- C = HH(C, D, A, B, X[ 6], 11);
- B = HH(B, C, D, A, X[14], 15);
- A = HH(A, B, C, D, X[ 1], 3);
- D = HH(D, A, B, C, X[ 9], 9);
- C = HH(C, D, A, B, X[ 5], 11);
- B = HH(B, C, D, A, X[13], 15);
- A = HH(A, B, C, D, X[ 3], 3);
- D = HH(D, A, B, C, X[11], 9);
- C = HH(C, D, A, B, X[ 7], 11);
- B = HH(B, C, D, A, X[15], 15);
- context[0] += A;
- context[1] += B;
- context[2] += C;
- context[3] += D;
- }
- // The basic MD4 atomic functions.
- private uint FF(uint a, uint b, uint c, uint d, uint x, int s){
- uint t = a + ((b & c) | (~b & d)) + x;
- return t << s | t >> (32 - s);
- }
- private uint GG(uint a, uint b, uint c, uint d, uint x, int s){
- uint t = a + ((b & (c | d)) | (c & d)) + x + 0x5A827999;
- return t << s | t >> (32 - s);
- }
- private uint HH(uint a, uint b, uint c, uint d, uint x, int s){
- uint t = a + (b ^ c ^ d) + x + 0x6ED9EBA1;
- return t << s | t >> (32 - s);
- }
- } // class MD4
- } // namespace Blood.COM.Security
复制代码 |
评分
-
查看全部评分
|