forked from chago/ADVMP
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
3,966 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="buwai.android.shell.advmptest" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="8" | ||
android:targetSdkVersion="10" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ic_launcher" | ||
android:label="@string/app_name" > | ||
<activity | ||
android:name=".MainActivity" | ||
android:label="@string/app_name" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(call all-subdir-makefiles) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
DEVFLAG := _static | ||
|
||
LOCAL_MODULE := advmpc | ||
|
||
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../minizip | ||
|
||
LOCAL_SRC_FILES := ioapi.c \ | ||
unzip.c \ | ||
Globals.cpp \ | ||
avmp.cpp \ | ||
BitConvert.cpp \ | ||
InterpC.cpp \ | ||
io.cpp \ | ||
Utils.cpp \ | ||
YcFile.cpp \ | ||
|
||
LOCAL_LDLIBS := -llog -lz | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "stdafx.h" | ||
#include "BitConvert.h" | ||
|
||
// 将字节数组转换为字符串。 | ||
char* ToString(unsigned char bytes[], size_t size) { | ||
char* str = (char*) calloc (size + 1, sizeof(char)); | ||
if (NULL == str) { | ||
return NULL; | ||
} | ||
for (int i = 0; i < size; i++) { | ||
str[i] = (char)(bytes[i]); | ||
} | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
/** | ||
* 将字节数组转换为字符串。 | ||
* @return 成功:返回字符串。失败:返回NULL。 | ||
* @note 返回指针值需要调用者释放。 | ||
*/ | ||
char* ToString(unsigned char bytes[], size_t size); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "Globals.h" | ||
|
||
ADVMPGlobals gAdvmp; | ||
|
||
#ifdef _AVMP_DEBUG_ | ||
|
||
const char* gYcFileName = "classes.yc"; | ||
|
||
#else | ||
|
||
//+${gYcFileName} | ||
|
||
#endif // _DEBUG_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <jni.h> | ||
#include "YcFile.h" | ||
|
||
// TODO 这里是调试标志。 | ||
#define _AVMP_DEBUG_ | ||
|
||
extern const char* gYcFileName; | ||
|
||
typedef struct _ADVMPGlobals { | ||
YcFile* ycFile; | ||
char* ycFilePath; | ||
} ADVMPGlobals; | ||
|
||
extern ADVMPGlobals gAdvmp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "InterpC.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include <jni.h> | ||
|
||
jvalue BWdvmInterpretPortable(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include "stdafx.h" | ||
#include "Utils.h" | ||
|
||
char* GetAppPath(JNIEnv* env) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
/** | ||
* 获得APP文件路径。 | ||
* @param[in] env JNI环境。 | ||
* @return 返回APP文件路径。这个路径使用完后需要通过free函数释放内存。 | ||
*/ | ||
char* GetAppPath(JNIEnv* env); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
#include "stdafx.h" | ||
#include "BitConvert.h" | ||
#include "io.h" | ||
#include "Globals.h" | ||
#include "unzip.h" | ||
#include "YcFile.h" | ||
|
||
YcFile::YcFile(const char* filePath) | ||
: mFilePath(NULL) | ||
{ | ||
mFilePath = strdup(filePath); | ||
} | ||
|
||
YcFile::~YcFile() { | ||
if (NULL != mFilePath) { | ||
free(mFilePath); | ||
} | ||
} | ||
|
||
// 解析Yc文件。 | ||
bool YcFile::parse() { | ||
FileReader fileReader; | ||
|
||
if (!fileReader.Open(mFilePath)) { | ||
MY_LOG_WARNING("打开文件\"%s\"失败。errno:%d-%s.", mFilePath, errno, strerror(errno)); | ||
return false; | ||
} | ||
|
||
|
||
unsigned char* buffer = new unsigned char[6]; | ||
if (!fileReader.ReadBytes(buffer, 6)) { | ||
delete[] buffer; | ||
return false; | ||
} | ||
|
||
// 校验魔术字。 | ||
char* magic = ToString(buffer, 6); | ||
if (0 != strcmp(magic, MAGIC)) { | ||
MY_LOG_WARNING("魔术字校验失败。"); | ||
delete[] buffer; | ||
free(magic); | ||
return false; | ||
} | ||
free(magic); | ||
delete[] buffer; | ||
|
||
mYcFormat.header.magic = MAGIC; | ||
|
||
if (!fileReader.ReadUInt(&mYcFormat.header.methodSize)) { | ||
MY_LOG_WARNING("读取方法结构个数失败。"); | ||
return false; | ||
} | ||
|
||
if (!fileReader.ReadUInt(&mYcFormat.header.methodOffset)) { | ||
MY_LOG_WARNING("读取方法段偏移失败。"); | ||
return false; | ||
} | ||
|
||
if (!fileReader.ReadUInt(&mYcFormat.header.separatorDataSize)) { | ||
MY_LOG_WARNING("读取抽离数组size失败。"); | ||
return false; | ||
} | ||
|
||
if (!fileReader.ReadUInt(&mYcFormat.header.separatorDataOffset)) { | ||
MY_LOG_WARNING("读取抽离数据段偏移失败。"); | ||
return false; | ||
} | ||
|
||
// TODO 这里先不解析AdvmpMethod的数据。 | ||
|
||
unsigned int separatorDataSize = mYcFormat.header.separatorDataSize; | ||
// 解析抽离数据。 | ||
if (0 != separatorDataSize) { | ||
mYcFormat.separatorDatas = new SeparatorData*[separatorDataSize]; | ||
if (!fileReader.Seek(mYcFormat.header.separatorDataOffset)) { | ||
MY_LOG_WARNING("设置文件指针位置失败。"); | ||
return false; | ||
} | ||
|
||
for (int i = 0; i < separatorDataSize; i++) { | ||
mYcFormat.separatorDatas[i] = (SeparatorData*) calloc(1, sizeof(SeparatorData)); | ||
if (!fileReader.ReadUInt(&mYcFormat.separatorDatas[i]->methodIndex)) { | ||
MY_LOG_WARNING("%d. 读取SeparatorData中方法索引失败。", i); | ||
return false; | ||
} | ||
if (!fileReader.ReadUInt(&mYcFormat.separatorDatas[i]->instSize)) { | ||
MY_LOG_WARNING("%d. 读取SeparatorData中方法指令size失败。", i); | ||
return false; | ||
} | ||
mYcFormat.separatorDatas[i]->insts = new unsigned short[mYcFormat.separatorDatas[i]->instSize]; | ||
if (!fileReader.ReadUShorts(mYcFormat.separatorDatas[i]->insts, mYcFormat.separatorDatas[i]->instSize)) { | ||
MY_LOG_WARNING("%d. 读取SeparatorData中方法指令size失败。", i); | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
// | ||
|
||
YcFormat::YcFormat() | ||
: methods(NULL), separatorDatas(NULL) | ||
{ | ||
memset(&header, 0, sizeof(YcHeader)); | ||
} | ||
|
||
YcFormat::~YcFormat() { | ||
if (NULL != methods) { | ||
unsigned int size = header.methodSize; | ||
for (int i = 0; i < size; i++) { | ||
free(methods[i]); | ||
} | ||
delete[] methods; | ||
} | ||
if (NULL != separatorDatas) { | ||
unsigned int size = header.separatorDataSize; | ||
for (int i = 0; i < size; i++) { | ||
if (NULL != separatorDatas[i]->insts) { | ||
delete[] separatorDatas[i]->insts; | ||
} | ||
free(separatorDatas[i]); | ||
} | ||
delete[] separatorDatas; | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
|
||
// 打开并解析yc文件。 | ||
bool OpenAndParseYc(JNIEnv* env) { | ||
YcFile* ycFile = new YcFile(gAdvmp.ycFilePath); | ||
if (ycFile->parse()) { | ||
gAdvmp.ycFile = ycFile; | ||
} else { | ||
MY_LOG_ERROR("打开&解析yc文件失败!"); | ||
return false; | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////////////////////////////// | ||
|
||
// 释放Yc文件。 | ||
uLong ReleaseYcFile(const char* filePath, unsigned char* buffer) { | ||
MY_LOG_INFO("zip文件:%s", filePath); | ||
ZipReader zipReader(filePath); | ||
if (!zipReader.Open()) { | ||
MY_LOG_WARNING("打开zip文件失败:%s", filePath); | ||
return false; | ||
} | ||
|
||
char* filePathInZip = (char*) calloc(strlen(gYcFileName) + strlen("assets") + 1, sizeof(char)); | ||
uLong fileSize = zipReader.GetFileSizeInZip(filePathInZip); | ||
|
||
uLong bRet = 0; | ||
if (0 == fileSize) { | ||
goto _ret; | ||
} | ||
|
||
buffer = (unsigned char*) calloc(sizeof(unsigned char), fileSize); | ||
if (!zipReader.ReadBytes(filePathInZip, buffer, fileSize)) { | ||
goto _ret; | ||
} | ||
|
||
bRet = fileSize; | ||
|
||
_ret: | ||
if (NULL != filePathInZip) { | ||
free(filePathInZip); | ||
} | ||
return bRet; | ||
} |
Oops, something went wrong.